public void DisconnectCommunicator(CommunicatorClient client) { if (client == null) { return; } lock (GameServers) { GameServerQueue.Remove(client); if (client.ServerId != 0) { GameServers.Remove(client.ServerId); } GenerateServerList(); } Timer.Add($"Disconnect-comm-{DateTime.Now.Ticks}", 1000, false, () => { client.Socket?.Close(); }); Logger.WriteLog(LogType.Network, $"The game server (Id: {client.ServerId}, Address: {client.Socket.RemoteAddress}) has disconnected!"); }
public bool AuthenticateGameServer(LoginRequestPacket packet, CommunicatorClient client) { lock (GameServers) { if (GameServers.ContainsKey(packet.ServerId)) { DisconnectCommunicator(client); Logger.WriteLog(LogType.Debug, $"A server tried to connect to an already in use server slot! Remote Address: {client.Socket.RemoteAddress}"); return(false); } if (!Config.Servers.ContainsKey(packet.ServerId.ToString())) { DisconnectCommunicator(client); Logger.WriteLog(LogType.Debug, $"A server tried to connect to a non-defined server slot! Remote Address: {client.Socket.RemoteAddress}"); return(false); } if (Config.Servers[packet.ServerId.ToString()] != packet.Password) { DisconnectCommunicator(client); Logger.WriteLog(LogType.Error, $"A server tried to log in with an invalid password! Remote Address: {client.Socket.RemoteAddress}"); return(false); } GameServerQueue.Remove(client); GameServers.Add(packet.ServerId, client); Logger.WriteLog(LogType.Network, $"The Game server (Id: {packet.ServerId}, Address: {client.Socket.RemoteAddress}, Public Address: {packet.PublicAddress}) has authenticated! Requesting info..."); return(true); } }