예제 #1
0
        /// <summary>
        /// Gets commands (and details) from all clients
        /// </summary>
        public static List <ClientCommandInfo> GetCommandsFromAllCLients()
        {
            List <ClientCommandInfo> clientCommandsList = new List <ClientCommandInfo>();

            if (serverInstance == null)
            {
                return(clientCommandsList);
            }

            lock (serverInstance.clientHandlerListLocker)
            {
                string commandTxt;

                for (int i = 0; i < serverInstance.clientList.Count; i++)
                {
                    commandTxt = serverInstance.clientList[i].GetCommandFromClient();
                    if (String.IsNullOrEmpty(commandTxt))
                    {
                        continue;
                    }

                    ClientHandlerInfo clientInfo = new ClientHandlerInfo
                                                   (
                        serverInstance.clientList[i].IsWorking,
                        serverInstance.clientList[i].ClientIp,
                        serverInstance.clientList[i].ClientId
                                                   );

                    clientCommandsList.Add(new ClientCommandInfo(clientInfo, commandTxt));
                }
            }

            return(clientCommandsList);
        }
예제 #2
0
        /// <summary>
        /// Gets info about specific connected client by client ID
        /// </summary>
        public static ClientHandlerInfo GetClientInfo(int clientId)
        {
            ClientHandlerInfo clientInfo = null;

            if (serverInstance == null)
            {
                return(clientInfo);
            }

            lock (serverInstance.clientHandlerListLocker)
            {
                foreach (ClientHandler clientHandler in serverInstance.clientList)
                {
                    if (clientHandler.ClientId == clientId)
                    {
                        clientInfo = new ClientHandlerInfo
                                     (
                            clientHandler.IsWorking,
                            clientHandler.ClientIp,
                            clientHandler.ClientId
                                     );
                        break;
                    }
                }
            }

            return(clientInfo);
        }
예제 #3
0
        /// <summary>
        /// Gets info about all connected clients
        /// </summary>
        public static List <ClientHandlerInfo> GetCurrentClientsInfo()
        {
            List <ClientHandlerInfo> clientInfoList = new List <ClientHandlerInfo>();

            if (serverInstance == null)
            {
                return(clientInfoList);
            }

            lock (serverInstance.clientHandlerListLocker)
            {
                for (int i = 0; i < serverInstance.clientList.Count; i++)
                {
                    ClientHandlerInfo clientInfo = new ClientHandlerInfo
                                                   (
                        serverInstance.clientList[i].IsWorking,
                        serverInstance.clientList[i].ClientIp,
                        serverInstance.clientList[i].ClientId
                                                   );
                    clientInfoList.Add(clientInfo);
                }
            }

            return(clientInfoList);
        }
예제 #4
0
        private async void HandleClientActivityCheckAsync()
        {
            _logger.UpdateLog("Client activity check handling started!");
            List <PlayerDetails> playerDetailsList = null;
            ClientHandlerInfo    clientHandlerInfo = null;
            int tcpClientId = -1;

            while (this.State == WorkingState.Enabled)
            {
                await Task.Factory.StartNew(() => Thread.Sleep(_activityCheckTickRate));

                playerDetailsList = _playerHandler.GetAllPlayers();
                if (playerDetailsList == null)
                {
                    continue;
                }

                foreach (PlayerDetails details in playerDetailsList)
                {
                    tcpClientId       = details.TcpClientId;
                    clientHandlerInfo = TcpServer.GetClientInfo(tcpClientId);
                    if (clientHandlerInfo == null)
                    {
                        continue;
                    }

                    if (!clientHandlerInfo.IsWorking)
                    {
                        _logger.UpdateLog($"Activity check - unregistering player with TCP client ID [{tcpClientId}]...");
                        _playerHandler.UnregisterPlayer(tcpClientId);
                    }
                }

                playerDetailsList.Clear();
                playerDetailsList = null;
                clientHandlerInfo = null;
            }
        }
예제 #5
0
 public ClientCommandInfo(ClientHandlerInfo clientInfo, string commandTxt)
 {
     this.ClientInfo = clientInfo;
     this.CommandTxt = commandTxt;
 }