示例#1
0
 private void OnClosed(object sender, EventArgs e)
 {
     IsConnected.Reset();
     Debug.Log("Disconnected from RosBridge: " + RosBridgeServerUrl);
     //modified
     connected = false;
 }
示例#2
0
        private void load(IAPIProvider api)
        {
            // Importantly, we are intentionally not using MessagePack here to correctly support derived class serialization.
            // More information on the limitations / reasoning can be found in osu-server-spectator's initialisation code.
            connector = api.GetHubConnector(nameof(OnlineMultiplayerClient), endpoint);

            if (connector != null)
            {
                connector.ConfigureConnection = connection =>
                {
                    // this is kind of SILLY
                    // https://github.com/dotnet/aspnetcore/issues/15198
                    connection.On <MultiplayerRoomState>(nameof(IMultiplayerClient.RoomStateChanged), ((IMultiplayerClient)this).RoomStateChanged);
                    connection.On <MultiplayerRoomUser>(nameof(IMultiplayerClient.UserJoined), ((IMultiplayerClient)this).UserJoined);
                    connection.On <MultiplayerRoomUser>(nameof(IMultiplayerClient.UserLeft), ((IMultiplayerClient)this).UserLeft);
                    connection.On <MultiplayerRoomUser>(nameof(IMultiplayerClient.UserKicked), ((IMultiplayerClient)this).UserKicked);
                    connection.On <int>(nameof(IMultiplayerClient.HostChanged), ((IMultiplayerClient)this).HostChanged);
                    connection.On <MultiplayerRoomSettings>(nameof(IMultiplayerClient.SettingsChanged), ((IMultiplayerClient)this).SettingsChanged);
                    connection.On <int, MultiplayerUserState>(nameof(IMultiplayerClient.UserStateChanged), ((IMultiplayerClient)this).UserStateChanged);
                    connection.On(nameof(IMultiplayerClient.LoadRequested), ((IMultiplayerClient)this).LoadRequested);
                    connection.On(nameof(IMultiplayerClient.MatchStarted), ((IMultiplayerClient)this).MatchStarted);
                    connection.On(nameof(IMultiplayerClient.ResultsReady), ((IMultiplayerClient)this).ResultsReady);
                    connection.On <int, IEnumerable <APIMod> >(nameof(IMultiplayerClient.UserModsChanged), ((IMultiplayerClient)this).UserModsChanged);
                    connection.On <int, BeatmapAvailability>(nameof(IMultiplayerClient.UserBeatmapAvailabilityChanged), ((IMultiplayerClient)this).UserBeatmapAvailabilityChanged);
                    connection.On <MatchRoomState>(nameof(IMultiplayerClient.MatchRoomStateChanged), ((IMultiplayerClient)this).MatchRoomStateChanged);
                    connection.On <int, MatchUserState>(nameof(IMultiplayerClient.MatchUserStateChanged), ((IMultiplayerClient)this).MatchUserStateChanged);
                    connection.On <MatchServerEvent>(nameof(IMultiplayerClient.MatchEvent), ((IMultiplayerClient)this).MatchEvent);
                    connection.On <MultiplayerPlaylistItem>(nameof(IMultiplayerClient.PlaylistItemAdded), ((IMultiplayerClient)this).PlaylistItemAdded);
                    connection.On <long>(nameof(IMultiplayerClient.PlaylistItemRemoved), ((IMultiplayerClient)this).PlaylistItemRemoved);
                    connection.On <MultiplayerPlaylistItem>(nameof(IMultiplayerClient.PlaylistItemChanged), ((IMultiplayerClient)this).PlaylistItemChanged);
                };

                IsConnected.BindTo(connector.IsConnected);
            }
        }
示例#3
0
        private void load()
        {
            IsConnected.BindValueChanged(connected => Schedule(() =>
            {
                if (connected.NewValue)
                {
                    // get all the users that were previously being watched
                    int[] users = watchingUsers.ToArray();
                    watchingUsers.Clear();

                    // resubscribe to watched users.
                    foreach (int userId in users)
                    {
                        WatchUser(userId);
                    }

                    // re-send state in case it wasn't received
                    if (IsPlaying)
                    {
                        BeginPlayingInternal(currentState);
                    }
                }
                else
                {
                    playingUsers.Clear();
                    playingUserStates.Clear();
                }
            }), true);
        }
示例#4
0
        private void load()
        {
            IsConnected.BindValueChanged(connected => Schedule(() =>
            {
                if (connected.NewValue)
                {
                    // get all the users that were previously being watched
                    int[] users = watchedUsers.ToArray();
                    watchedUsers.Clear();

                    // resubscribe to watched users.
                    foreach (int userId in users)
                    {
                        WatchUser(userId);
                    }

                    // re-send state in case it wasn't received
                    if (IsPlaying)
                    {
                        // TODO: this is likely sent out of order after a reconnect scenario. needs further consideration.
                        BeginPlayingInternal(currentState);
                    }
                }
                else
                {
                    playingUsers.Clear();
                    watchedUserStates.Clear();
                }
            }), true);
        }
示例#5
0
 private void OnConnected(object sender, EventArgs e)
 {
     IsConnected.Set();
     Debug.Log("Connected to RosBridge: " + RosBridgeServerUrl);
     //modified
     connected = true;
 }
示例#6
0
        public async Task <bool> Connect(Uri uri, bool ignoreReceiver = false)
        {
            try
            {
                ConnectionClosed = false;
                _commandCount    = 0;
                _connection      = new MessageWebSocket();
                _connection.Control.MessageType = SocketMessageType.Utf8;
                //  if(ignoreReceiver==false)
                _connection.MessageReceived += Connection_MessageReceived;

                _connection.Closed += Connection_Closed;
                await _connection.ConnectAsync(uri);

                IsConnected?.Invoke(true);

                _messageWriter = new DataWriter(_connection.OutputStream);
                return(true);
            }
            catch (Exception e)
            {
                switch (SocketError.GetStatus(e.HResult))
                {
                case SocketErrorStatus.HostNotFound:
                    // Handle HostNotFound Error
                    break;

                default:
                    // Handle Unknown Error
                    break;
                }
                return(false);
            }
        }
示例#7
0
 /// <summary>
 /// Serves as a hash function for a <see cref="osuTK.Input.GamePadCapabilities"/> object.
 /// </summary>
 /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a
 /// hash table.</returns>
 public override int GetHashCode()
 {
     return
         (buttons.GetHashCode() ^
          IsConnected.GetHashCode() ^
          IsMapped.GetHashCode() ^
          gamepad_type.GetHashCode());
 }
示例#8
0
 /// <summary>
 /// Serves as a hash function for a <see cref="OpenTK.Input.JoystickCapabilities"/> object.
 /// </summary>
 /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a
 /// hash table.</returns>
 public override int GetHashCode()
 {
     return
         (AxisCount.GetHashCode() ^
          ButtonCount.GetHashCode() ^
          HatCount.GetHashCode() ^
          IsConnected.GetHashCode() ^
          SupportsHaptics.GetHashCode());
 }
示例#9
0
        protected void ConnectAndWait()
        {
            RosSocket = ConnectToRos(protocol, RosBridgeServerUrl, OnConnected, OnClosed, Serializer);

            if (!IsConnected.WaitOne(SecondsTimeout * 1000))
            {
                Debug.LogWarning("Failed to connect to RosBridge at: " + RosBridgeServerUrl);
            }
        }
示例#10
0
 public override int GetHashCode()
 {
     unchecked {
         var hashCode = Name?.GetHashCode() ?? 0;
         hashCode = (hashCode * 397) ^ (Team?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (CarId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ (CarSkinId?.GetHashCode() ?? 0);
         hashCode = (hashCode * 397) ^ IsConnected.GetHashCode();
         hashCode = (hashCode * 397) ^ IsBookedForPlayer.GetHashCode();
         return(hashCode);
     }
 }
示例#11
0
 protected StatefulMultiplayerClient()
 {
     IsConnected.BindValueChanged(connected =>
     {
         // clean up local room state on server disconnect.
         if (!connected.NewValue)
         {
             Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
             LeaveRoom().CatchUnobservedExceptions();
         }
     });
 }
示例#12
0
 private void load()
 {
     IsConnected.BindValueChanged(connected =>
     {
         // clean up local room state on server disconnect.
         if (!connected.NewValue && Room != null)
         {
             Logger.Log("Connection to multiplayer server was lost.", LoggingTarget.Runtime, LogLevel.Important);
             LeaveRoom();
         }
     });
 }
示例#13
0
    protected override void ConnectAndWait()
    {
        RosSocket = ConnectToRos(protocol, RosBridgeServerUrl, OnConnected, OnClosed, Serializer);

        bool connected = IsConnected.WaitOne(SecondsTimeout * 1000);

        if (!connected)
        {
            Debug.LogWarning("Failed to connect to RosBridge at: " + RosBridgeServerUrl, gameObject);
            RosSocket = null;
            enabled   = false;
        }
    }
示例#14
0
        /// <inheritdoc/>
        public override string ToString()
        {
            StringBuilder message = new StringBuilder();

            foreach (string item in new string[] { ParatextId, Name, ShortName, LanguageTag, ProjectId,
                                                   IsConnectable.ToString(), IsConnected.ToString(), IsInstalled.ToString(),
                                                   AvailableRevision.ToString(), InstalledRevision.ToString() })
            {
                message.Append(item);
                message.Append(',');
            }

            return(message.ToString());
        }
示例#15
0
        public override string ToString()
        {
            var builder = new System.Text.StringBuilder();

            builder.AppendFormat("{0} {{", nameof(CarInfo)).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(CarId), CarId.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(IsConnected), IsConnected.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(CarModel), CarModel.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(CarSkin), CarSkin.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(DriverName), DriverName.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(DriverTeam), DriverTeam.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(DriverGuid), DriverGuid.ToString()).AppendLine();
            builder.AppendFormat("}}").AppendLine();
            return(builder.ToString());
        }
示例#16
0
    public void OnStatusChanged(StatusCode statusCode)
    {
        switch (statusCode)
        {
        case StatusCode.Connect:
            IsConnected = true;
            TLogger.DEBUG(IsConnected.ToString());
            break;

        case StatusCode.Disconnect:
        case StatusCode.DisconnectByServer:
        case StatusCode.DisconnectByServerLogic:
            IsConnected = false;
            break;
        }
    }
示例#17
0
        void tmrCheckService_InterfaceChanged(object sender, EventArgs e)
        {
            lblIsConnected.Text    = IsConnected.ToString();
            lblServerTime.Text     = ServerTime.ToString();
            lblServiceVersion.Text = ServiceVersion;
            lblStatus.Text         = Status;

            if (varXml.RebootComputer)
            {
                lblFault.Text = string.Format("{0} / {1}", FaultCount, varXml.FaultCountLimit);
            }
            else
            {
                lblFault.Text = string.Format("{0}", FaultCount);
            }
        }
            public override void Run()
            {
                Logger.Log("ConnectedThread: Run");

                byte[] buffer = new byte[16];

                int bytes;

                Logger.Log("IsConnected = " + IsConnected.ToString());

                while (IsConnected)
                {
                    try
                    {
                        //Logger.Log("READ READ READ HAHAHAHA1");
                        bytes = inStream.Read(buffer, 0, buffer.Length);// (buffer, 0, buffer.Length);


                        //inStream.FlushAsync();

                        //                    bytes = inStream.Read (buffer);
                        //string readMessage = new string(buffer, 0, bytes);
                        //                    Logger.Log ("READ READ READ HAHAHAHA2");
                        //                    string message = Encoding.ASCII.GetString (buffer, 0, bytes);

                        service.handler
                        .ObtainMessage(2, bytes, -1, buffer)
                        .SendToTarget();

                        //Logger.Log(message);


                        // Send the obtained bytes to the UI Activity
                        //                    service.handler
                        //                           .ObtainMessage(2, bytes, -1, buffer)
                        //                           .SendToTarget();
                    }
                    catch (IOException e)
                    {
                        Logger.Log(e.Message);
                        IsConnected = false;
                    }
                }
            }
示例#19
0
        public ConnectionViewModel()
        {
            DisconnectCommand = IsConnected.CombineLatest(IsConnecting, (a, b) => a || b).ToAsyncReactiveCommand();
            DisconnectCommand.Subscribe(() => Disconnect()).AddTo(Disposable);

            DisplayText = ConnectionName.CombineLatest(Host, Port, IsConnecting,
                                                       (name, host, port, isConnecting) =>
            {
                var hostport = host + (port == null ? "" : $":{port}");
                var status   = "";
                if (isConnecting)
                {
                    status = $" - {Resources.Connection_ConnectingText}";
                }
                var identity = string.IsNullOrWhiteSpace(name)
                        ? hostport
                        : $"{name} ({hostport})";
                return(identity + status);
            }).ToReactiveProperty();
        }
示例#20
0
        public override string ToString()
        {
            var builder = new System.Text.StringBuilder();

            builder.AppendFormat("{0} {{", nameof(Driver)).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(CarId), CarId.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(CarModel), CarModel.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(CarSkin), CarSkin.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(Name), Name.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(Team), Team.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(GUID), GUID.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(IsConnected), IsConnected.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(Position), Position.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(VelocityVector), VelocityVector.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(Speed), Speed.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(SplinePosition), SplinePosition.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(Gear), Gear.ToString()).AppendLine();
            builder.AppendFormat("    {0} = {1}", nameof(EngineRPM), EngineRPM.ToString()).AppendLine();
            builder.AppendFormat("}}").AppendLine();
            return(builder.ToString());
        }
示例#21
0
        public Worker(string gatewayEndpoint, string gatewayHeartbeatEndpoint, CancellationToken cancel)
        {
            _gatewayEndpoint          = gatewayEndpoint;
            _gatewayHeartbeatEndpoint = gatewayHeartbeatEndpoint;
            _id          = Guid.NewGuid();
            _isConnected = new BehaviorSubject <bool>(false);

            _rand   = new Random();
            _cancel = cancel;

            _heartbeatProc = Task.Run(HeartBeat, cancel).ConfigureAwait(false);

            _disconnected = IsConnected
                            .Buffer(2, 1)
                            .Where(buffer => buffer.Count > 1 && buffer[0] && !buffer[1])
                            .Subscribe(_ =>
            {
                StartWorkProc();
            });

            StartWorkProc();
        }
示例#22
0
        public override int GetHashCode()
        {
            unchecked // Overflow is fine, just wrap
            {
                int hash = (int)2166136261;
                // Suitable nullity checks etc, of course :)
                hash = (hash * 16777619) ^ ClientId.GetHashCode();
                hash = (hash * 16777619) ^ CleanSession.GetHashCode();
                hash = (hash * 16777619) ^ ClientIndex.GetHashCode();
                hash = (hash * 16777619) ^ IsConnected.GetHashCode();
                if (WillFlag)
                {
                    hash = (hash * 16777619) ^ WillFlag.GetHashCode();
                    hash = (hash * 16777619) ^ WillMessage.GetHashCode();
                    hash = (hash * 16777619) ^ WillQosLevel.GetHashCode();
                    hash = (hash * 16777619) ^ WillRetain.GetHashCode();
                    hash = (hash * 16777619) ^ WillTopic.GetHashCode();
                }

                return(hash);
            }
        }
示例#23
0
 /// <summary> Returns true if the vessel has any connection</summary>
 public static bool Connected(Guid id)
 {
     return(RT_API != null && (bool)IsConnected.Invoke(null, new Object[] { id }));
 }
示例#24
0
        public async Task <bool> Connect(Uri uri, bool ignoreReceiver = false)
        {
            try
            {
                ConnectionClosed = false;
                _commandCount    = 0;
                _connection      = new MessageWebSocket();
                _connection.Control.MessageType = SocketMessageType.Utf8;
                _connection.MessageReceived    += Connection_MessageReceived;
                _connection.Closed += Connection_Closed;

                try
                {
                    await _connection.ConnectAsync(uri).AsTask().WaitAsync(TimeSpan.FromSeconds(5));

                    _messageWriter = new DataWriter(_connection.OutputStream);

                    IsConnected?.Invoke(true);
                    return(true);
                }
                catch (TimeoutException)
                {
                    return(false);
                }

                //using (var cancellationTokenSource = new CancellationTokenSource(5000))
                //{
                //    var connectTask = _connection.ConnectAsync(uri).AsTask(cancellationTokenSource.Token);
                //    var result = await connectTask.ContinueWith((antecedent) =>
                //    {
                //        if (antecedent.Status == TaskStatus.RanToCompletion)
                //        {
                //            // connectTask ran to completion, so we know that the MessageWebSocket is connected.
                //            // Add additional code here to use the MessageWebSocket.
                //            IsConnected?.Invoke(true);

                //            _messageWriter = new DataWriter(_connection.OutputStream);
                //            return true;
                //        }
                //        else
                //        {
                //            // connectTask timed out, or faulted.
                //            return false;
                //        }
                //    });

                //    return result;
                //}
            }
            catch (Exception e)
            {
                switch (SocketError.GetStatus(e.HResult))
                {
                case SocketErrorStatus.HostNotFound:
                    // Handle HostNotFound Error
                    break;

                default:
                    // Handle Unknown Error
                    break;
                }
                return(false);
            }
        }
示例#25
0
 /// <summary>
 /// Serves as a hash function for a <see cref="osuTK.Input.GamePadState"/> object.
 /// </summary>
 /// <returns>A hash code for this instance that is suitable for use in hashing algorithms and data structures such as a
 /// hash table.</returns>
 public override int GetHashCode()
 {
     return
         (ThumbSticks.GetHashCode() ^ Buttons.GetHashCode() ^
          DPad.GetHashCode() ^ IsConnected.GetHashCode());
 }
示例#26
0
        /// <summary>
        /// ToString representation
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            if (m_Socket == null)
            {
                return("Not connected");
            }
            string rep = m_Socket.RemoteEndPoint.ToString();
            string lep = m_Socket.LocalEndPoint.ToString();

            return
                (m_Socket.ProtocolType.ToString() + String.Format(" State = {0} sockets L = {1} R = {2}", IsConnected.ToString(), lep, rep));
        }
示例#27
0
        protected virtual bool InitBase(string friendlyNamePrefix, string deviceType)
        {
            if (TheCommonUtils.CGuid(MyBaseThing.ID) == Guid.Empty)
            {
                MyBaseThing.ID = Guid.NewGuid().ToString();
                if (string.IsNullOrEmpty(MyBaseThing.FriendlyName))
                {
                    MyBaseThing.FriendlyName = $"{friendlyNamePrefix}: {MyBaseThing.ID}";
                }
            }

            MyBaseThing.LastUpdate = DateTimeOffset.Now;

            MyBaseThing.EngineName = MyBaseEngine.GetEngineName();
            MyBaseThing.DeviceType = deviceType;

            TheBaseEngine.WaitForStorageReadiness((pThing, pReady) =>
            {
                if (pReady != null)
                {
                    var receiverThings                      = new TheStorageMirror <TConnectionThing>(TheCDEngines.MyIStorageService);
                    receiverThings.CacheTableName           = nameof(TConnectionThing) + TheThing.GetSafeThingGuid(MyBaseThing, nameof(TConnectionThing));
                    receiverThings.IsRAMStore               = true;
                    receiverThings.CacheStoreInterval       = 1;
                    receiverThings.IsStoreIntervalInSeconds = true;
                    receiverThings.IsCachePersistent        = true;
                    receiverThings.UseSafeSave              = true;
                    receiverThings.RegisterEvent(eStoreEvents.StoreReady, (args) =>
                    {
                        var result = args.Para as TSM;
                        if (result != null && result.LVL == eMsgLevel.l1_Error)
                        {
                            MyBaseThing.SetStatus(3, "Error loading things");
                            TheBaseAssets.MySYSLOG.WriteToLog(98201, TSM.L(eDEBUG_LEVELS.ESSENTIALS) ? null : new TSM(MyBaseThing.EngineName, "Initialization", eMsgLevel.l6_Debug, String.Format("Error loading things for connection {0}", this.GetBaseThing().Address)));
                        }
                        else
                        {
                            MyConnectionThings = receiverThings;
                            if (MyConnectionThingsForm != null)
                            {
                                MyConnectionThingsForm.defDataSource = MyConnectionThings.StoreMID.ToString();
                            }
                            TheBaseAssets.MySYSLOG.WriteToLog(95272, TSM.L(eDEBUG_LEVELS.FULLVERBOSE) ? null : new TSM(MyBaseThing.EngineName, "Initialization", eMsgLevel.l6_Debug, String.Format("Things loaded for connection {0}", this.GetBaseThing().Address)));

                            if (AutoConnect)
                            {
                                Connect();
                                if (!IsConnected)
                                {
                                    TheCommonUtils.cdeRunTaskAsync("receiverAutoConnect", async o =>
                                    {
                                        await TheCommonUtils.TaskDelayOneEye(30000, 100).ConfigureAwait(false);
                                        while (!IsConnected && AutoConnect && TheBaseAssets.MasterSwitch)
                                        {
                                            Connect();
                                            await TheCommonUtils.TaskDelayOneEye(30000, 100).ConfigureAwait(false);
                                        }
                                    }).ContinueWith(t => t.Exception);
                                }
                            }
                            mIsInitialized = true;
                            FireEvent(eThingEvents.Initialized, this, true, true);
                            FireEvent("ServerInit", this, IsConnected.ToString(), true);
                        }
                    }
                                                 );
                    receiverThings.InitializeStore(false, false);
                }
            }, true);
            return(mIsInitialized);
        }