private static (int, int) GetAvailablePort() { if (PortQueue.Count != 0) { int gamePort = PortQueue.Dequeue(); return(gamePort, gamePort + NumServers); } else { return(-1, -1); } }
internal static void OnGameServerExited(object sender, GameServerArgs args) { string serverName = args.ServerName; int port = args.ServerPort; PortQueue.Enqueue(port); Output.WriteLine("" + $"\n-------------------------------------------" + $"\nGameServer: {serverName} exited..." + $"\n-------------------------------------------"); lock (ServersAvailable) { int serverIndexToDelete = -1; for (int serverCount = 0; serverCount < ServersAvailable.Count; serverCount++) { if (ServersAvailable[serverCount].MatchesName(serverName)) { serverIndexToDelete = serverCount; } } if (serverIndexToDelete != -1) { ServersAvailable.RemoveAt(serverIndexToDelete); } GameServerDict.Remove(serverName); GameServerComms.GameServerConnection.Remove(serverName); } if (serverName == "Welcome") { MakePersistentServer(); } }