Пример #1
0
        /// <summary>
        /// Removes the player.
        /// </summary>
        /// <param name="connection">Connection.</param>
        public void RemovePlayer(Connection connection)
        {
            var connectInfos = ConnectionManager.Get(connection);
            var cos          = connectInfos.Lobby.Connection.ToArray();

            foreach (var lobbyConnection in cos)
            {
                //var connectInfos = ConnectionManager.Get(connection);
                var lobbyConnectInfos = ConnectionManager.Get(lobbyConnection);
                var pseudo            = lobbyConnectInfos.Pseudo;
                if ((IsStarted == false && connection == lobbyConnection) ||
                    IsStarted)
                {
                    Console.WriteLine("[LobbyRoom - " + _name + "] " + pseudo + " disconnected");
                    _connections.Remove(lobbyConnection);
                    if (_connections.Count == 0)
                    {
                        LobbyManager.DeleteLobby(_name);
                    }
                    lobbyConnectInfos.Lobby = null;
                    LobbyRoom.Unregister(lobbyConnection);
                    NetworkGame.Unregister(lobbyConnection);
                    if (lobbyConnection.ConnectionInfo.ConnectionState == ConnectionState.Established)
                    {
                        Console.WriteLine("Client: " + pseudo + " is still connected, register it on LobbySelector");
                        SelectLobby.Register(lobbyConnection);
                        lobbyConnection.SendObject("LobbySelect");
                    }
                }
            }
        }