private static void SendServerDataToMainServer(object sender, ElapsedEventArgs e) { if (EstablishedConnection) { MainServerCommsSend.ServerData(ServerName, Server.ServerState, Server.GetCurrentNumPlayers(), Server.MaxNumPlayers, Server.MapName); } }
public static void Update() { Console.WriteLine($"\n\t\tStarted MainServerComms Update thread."); DateTime TickTimer = DateTime.Now; double SendTime = 1000; int numTimesServerIsEmpty = 0; while (EstablishedConnection) { while (TickTimer < DateTime.Now) { int currentNumPlayers = Server.GetCurrentNumPlayers(); if (currentNumPlayers == 0) { numTimesServerIsEmpty += 1; } else { numTimesServerIsEmpty = 0; } if (TimeOut != -1 && numTimesServerIsEmpty >= TimeOut) { Console.WriteLine("\n\t\t------------------------------------------------------------" + $"\n\t\tGameServer {ServerName} is shutting down due to no players present..." + "\n\t\t------------------------------------------------------------"); Environment.Exit(0); EstablishedConnection = false; break; } if (EstablishedConnection) { MainServerCommsSend.ServerData(ServerName, currentNumPlayers, Server.MaxNumPlayers, Server.MapName); } TickTimer = TickTimer.AddMilliseconds(SendTime); if (TickTimer > DateTime.Now) { Thread.Sleep(TickTimer - DateTime.Now); } } } Console.WriteLine($"\t\tEnding MainServerComms server: {Port}"); Environment.Exit(1); }