Beispiel #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");
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Delete a client from the ConnectManager
        /// This method is called is a client exit during a game
        /// Then all client are kicked from the lobby
        /// </summary>
        /// <param name="connection">Connection.</param>
        public static void RemoveClient(Connection connection)
        {
            connection.CloseConnection(true);

            var connectInfos = ConnectionManager.Get(connection);
            var pseudo       = connectInfos.Pseudo;

            Console.WriteLine("Client: " + pseudo + " left.");
            if (connectInfos.Lobby != null)
            {
                // Disconnect client from the current lobby
                var nbPlayers = connectInfos.Lobby.NbPlayers;
                connectInfos.Lobby.RemovePlayer(connection);
            }
            ConnectionManager.Remove(connection);
        }