internal static void DisconnectClient(ClientObject client)
 {
     lock (client.disconnectLock)
     {
         //Remove clients from list
         if (clients.Contains(client))
         {
             List<ClientObject> newList = new List<ClientObject>(clients);
             newList.Remove(client);
             clients = newList.AsReadOnly();
             Server.playerCount = GetActiveClientCount();
             Server.players = GetActivePlayerNames();
             DarkLog.Debug("Online players is now: " + Server.playerCount + ", connected: " + clients.Count);
             if (!Settings.settingsStore.keepTickingWhileOffline && clients.Count == 0)
             {
                 Messages.WarpControl.HoldSubspace();
             }
             Messages.WarpControl.DisconnectPlayer(client.playerName);
         }
         //Disconnect
         if (client.connectionStatus != ConnectionStatus.DISCONNECTED)
         {
             DMPPluginHandler.FireOnClientDisconnect(client);
             if (client.playerName != null)
             {
                 Messages.Chat.RemovePlayer(client.playerName);
             }
             client.connectionStatus = ConnectionStatus.DISCONNECTED;
             if (client.authenticated)
             {
                 ServerMessage newMessage = new ServerMessage();
                 newMessage.type = ServerMessageType.PLAYER_DISCONNECT;
                 using (MessageWriter mw = new MessageWriter())
                 {
                     mw.Write<string>(client.playerName);
                     newMessage.data = mw.GetMessageBytes();
                 }
                 SendToAll(client, newMessage, true);
                 LockSystem.fetch.ReleasePlayerLocks(client.playerName);
             }
             try
             {
                 if (client.connection != null)
                 {
                     client.connection.GetStream().Close();
                     client.connection.Close();
                 }
             }
             catch (Exception e)
             {
                 DarkLog.Debug("Error closing client connection: " + e.Message);
             }
             Server.lastPlayerActivity = Server.serverClock.ElapsedMilliseconds;
         }
     }
 }
示例#2
0
        private void DisconnectClient(ClientObject client, string aReason)
        {
            if (client.connectionStatus != ConnectionStatus.DISCONNECTED)
            {
                DMPPluginHandler.FireOnClientDisconnect(client);
                if (client.playerName != null)
                {
                    if (playerChatChannels.ContainsKey(client.playerName))
                    {
                        playerChatChannels.Remove(client.playerName);
                    }
                    if (playerDownloadedScreenshotIndex.ContainsKey(client.playerName))
                    {
                        playerDownloadedScreenshotIndex.Remove(client.playerName);
                    }
                    if (playerUploadedScreenshotIndex.ContainsKey(client.playerName))
                    {
                        playerUploadedScreenshotIndex.Remove(client.playerName);
                    }
                    if (playerWatchScreenshot.ContainsKey(client.playerName))
                    {
                        playerWatchScreenshot.Remove(client.playerName);
                    }
                }
                client.connectionStatus = ConnectionStatus.DISCONNECTED;
                if (client.authenticated)
                {
                    Messages.ServerClient_PlayerLeaveSend msg = new Messages.ServerClient_PlayerLeaveSend();
                    msg.name = client.playerName;
                    BroadcastBut(client, msg);

                    lockSystem.ReleasePlayerLocks(client.playerName);
                }

                m_clients.Remove(client);

                try
                {
                    m_server.Kick(client.Id, aReason);
                }
                catch (Exception e)
                {
                    DarkLog.Debug("Error closing client connection: " + e.Message);
                }
                Server.lastPlayerActivity = Server.serverClock.ElapsedMilliseconds;
            }
        }