Exemplo n.º 1
0
 protected void InvokeDisconnected(SocketClient a)
 {
     if (_disconnectedInvoked == false)
     {
         DisconnectedFromServer?.Invoke(a, a.Ip, a.Port);
         _disconnectedInvoked = true;
     }
 }
 protected void RaiseDisconnected()
 {
     if (_disconnectedInvoked == false)
     {
         DisconnectedFromServer?.Invoke(this);
         _disconnectedInvoked = true;
     }
 }
Exemplo n.º 3
0
 private void OnPeerDisconnect(NetPeer peer, DisconnectInfo disconnectInfo)
 {
     if (peer.Id == _serverPeer.Id)
     {
         Log.Information("Client disconnected from server with reason {reason}", disconnectInfo.Reason);
         Stop();
         DisconnectedFromServer?.Invoke(this, disconnectInfo.Reason);
     }
 }
Exemplo n.º 4
0
        private void SetHubConnection(string hostname, int port)
        {
            _hubConnection = new HubConnection($"http://{hostname}:{port}/");

            _hubConnection.Error += q =>
            {
                IsConnected = false;
                ClearConnection();
                DisconnectedFromServer?.Invoke(this, null);
            };

            _hubProxy = _hubConnection.CreateHubProxy("ChatHub");
            _hubProxy.On <Message>("MessageFromServer", message => { MessageRecieved?.Invoke(this, message); });

            ServicePointManager.DefaultConnectionLimit = 10;
        }
Exemplo n.º 5
0
        private async Task ListenGameState(Channel channel)
        {
            var mapState    = new ClientMapData();
            var playerState = new ClientPlayerState();
            await mSyncContext.Execute(() => PlayerConnected?.Invoke(playerState), channel.ShutdownToken);

            try
            {
                while (true)
                {
                    try
                    {
                        mGameService = new GameService.GameServiceClient(channel);
                        using (var call = mGameService.ConnectAndListenState(new Empty()))
                            using (var stateStream = call.ResponseStream)
                            {
                                while (await stateStream.MoveNext(channel.ShutdownToken))
                                {
                                    channel.ShutdownToken.ThrowIfCancellationRequested();
                                    var state = stateStream.Current;

                                    if (state.Map != null)
                                    {
                                        mapState.State = new MapState(state.Map);
                                    }

                                    if (state.Player != null)
                                    {
                                        playerState.PlayerState = new PlayerState(state.Player);
                                    }

                                    channel.ShutdownToken.ThrowIfCancellationRequested();

                                    if (!mMapLoaded)
                                    {
                                        mMapLoaded = true;
                                        await mSyncContext.Execute(() =>
                                        {
                                            MapLoaded?.Invoke(mapState);
                                            BaseCreated?.Invoke(state.BasePos.ToUnity());
                                        }, channel.ShutdownToken);

                                        var tChat = ListenChat(mGameService, channel);

                                        var t0 = mWorkerCreationStateListener.ListenCreations(mChannel);
                                        var t1 = mBuildingTemplateCreationStateListener.ListenCreations(mChannel);
                                        var t2 = mCentralBuildingCreationStateListener.ListenCreations(mChannel);
                                        var t3 = mMiningCampCreationListener.ListenCreations(mChannel);
                                        var t4 = mBarrakCreationListener.ListenCreations(mChannel);
                                        var t5 = mRangedWarriorCreationStateListener.ListenCreations(mChannel);
                                        var t6 = mMeeleeWarriorCreationStateListener.ListenCreations(mChannel);
                                    }
                                }
                            }

                        break;
                    }
                    catch (RpcException e)
                    {
                        if (e.Status.StatusCode != StatusCode.Unavailable)
                        {
                            throw;
                        }

                        await Task.Delay(TimeSpan.FromSeconds(0.5));
                    }
                }
            }
            catch (Exception e)
            {
                Debug.LogError(e);
                DisconnectedFromServer?.Invoke();
                throw;
            }
        }
Exemplo n.º 6
0
 // Fired when Bluetooth client disconnected from the Bluetooth server
 // Provides BluetoothDevice of server device disconnected from
 private void JavaDisconnectedFromServerHandler(string deviceAddress)
 {
     DisconnectedFromServer?.Invoke(GetDeviceFromAddress(deviceAddress));
 }
Exemplo n.º 7
0
 protected virtual void OnDisconnect(DisconnectReasonType reason)
 {
     DisconnectedFromServer?.Invoke(_clientId, reason);
 }
 public void DisconnectFromServer()
 {
     Stop = true;
     //  client.Close();
     DisconnectedFromServer?.Invoke(this, false);
 }