/// <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); }
/// <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); }
/// <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); }
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; } }
public ClientCommandInfo(ClientHandlerInfo clientInfo, string commandTxt) { this.ClientInfo = clientInfo; this.CommandTxt = commandTxt; }