void INetworkClientListener.NetworkClientDidDisconnect()
 {
     ThreadChecker.AssertReliableChannel();
     this.router.dispatcher.Enqueue(() => this.listener?.GameClientDidDisconnect());
     this._playerCollection.Clear();
     this.localPlayer = null;
 }
        void IGameServerClientAcceptorListener <TPlayer> .ClientAcceptorPlayerDidConnect(TPlayer player)
        {
            ThreadChecker.AssertReliableChannel();

            player.listener = this.router;
            this._playerCollection.Add(player.playerId, player);
            this.router.dispatcher.Enqueue(() => this.listener?.GameServerPlayerDidConnect(player, Channel.reliable));
        }
        void IRemoteClientListener.RemoteClientDidDisconnect(int playerId)
        {
            ThreadChecker.AssertReliableChannel();

            var player = this._playerCollection.Remove(playerId);

            this.router.dispatcher.Enqueue(() => this.listener?.GameClientPlayerDidDisconnect(player));
        }
        void IGameServerClientAcceptorListener <TPlayer> .ClientAcceptorPlayerDidDisconnect(TPlayer player)
        {
            ThreadChecker.AssertReliableChannel();

            player.listener = null;
            this._playerCollection.Remove(player.playerId);
            if (player.remoteIdentifiedEndPoint.HasValue)
            {
                this.networkServer.Unregister(player.remoteIdentifiedEndPoint.Value);
            }
            this.router.dispatcher.Enqueue(() => this.listener?.GameServerPlayerDidDisconnect(player));
        }
        void ITcpServerListener <TcpSocket> .SocketDidDisconnect(TcpSocket socket)
        {
            ThreadChecker.AssertReliableChannel();

            var channel = this.socketCollection.Remove(socket);

            if (channel == null)
            {
                return;
            }
            ReliableChannel.Remove(channel);
            this.listener?.NetworkServerPlayerDidDisconnect(channel);
        }
        void IRemoteClientListener.RemoteClientDidConnect(int playerId, bool isLocalPlayer)
        {
            ThreadChecker.AssertReliableChannel();

            var player = new TPlayer();

            player.Configure(playerId, isLocalPlayer);

            this._playerCollection.Add(playerId, player);

            this.listener?.GameClientPlayerDidConnect(player);
            if (player.isLocalPlayer)
            {
                this.localPlayer = player;
                this.router.dispatcher.Enqueue(() => this.listener?.GameClientDidIdentifyLocalPlayer(player));

                var endPoint = this.networkClient.localEndPoint;
                var remote   = this.networkClient.remoteEndPoint;
                this.natIdentifierAckHelper.Start(new NatIdentifierRequestMessage(player.playerId, endPoint.address, endPoint.port), remote);
            }
        }
        void INetworkServerListener.NetworkServerPlayerDidDisconnect(ReliableChannel channel)
        {
            ThreadChecker.AssertReliableChannel();

            this.clientAcceptor.NetworkServerPlayerDidDisconnect(channel);
        }
        void INetworkServerListener.NetworkServerDidAcceptPlayer(ReliableChannel reliable, UnreliableChannel unreliable)
        {
            ThreadChecker.AssertReliableChannel();

            this.clientAcceptor.NetworkServerDidAcceptPlayer(reliable, unreliable);
        }
        public static void Remove(ReliableChannel channel)
        {
            ThreadChecker.AssertReliableChannel();

            lock (socketLock) { aliveSockets.Remove(channel); }
        }
 void INetworkClientListener.NetworkClientDidReceiveMessage(MessageContainer container)
 {
     ThreadChecker.AssertReliableChannel();
     this.router.Route(container);
 }
 void INetworkClientListener.NetworkClientConnectDidTimeout()
 {
     ThreadChecker.AssertReliableChannel();
     this.router.dispatcher.Enqueue(() => this.listener?.GameClientConnectDidTimeout());
 }