public static void StartServerProcedure(ArkServerInfo Server) { if (!GlobalVariables.IsProcessOpen(Server)) { Task startServer = Task.Factory.StartNew(() => ServerStartCommand(Server)); startServer.Wait(2000); } }
private static void HasServerBooted(object sender, EventArgs e, ArkServerInfo Server) { if (GlobalVariables.IsProcessOpen(Server)) { if (RCONCommands.IsServerResponding(Server)) { Server.nNotRunning = 0; //StableServer.nAbEventsTriggered = 1; Server.nEventsProcessOpenNotResponding = 0; Server.stopServerTimer = false; if (File.Exists(Server.UpdatedWorkshopACF)) { File.Delete(Server.CurrentWorkshopACF); File.Copy(Server.UpdatedWorkshopACF, Server.CurrentWorkshopACF); } else { File.Copy(Server.UpdatedWorkshopACF, Server.CurrentWorkshopACF); } ((System.Timers.Timer)sender).Close(); } if (Server.nNotRunning == 45) { //Console.WriteLine(DateTime.Now + ": Killing Server " + Server.Name + " due to boot time exceeding " + Server.nNotRunning * ((System.Timers.Timer)sender).Interval / 60000 + " minutes."); Log(Server, DateTime.Now + ": Killing Server " + Server.Name + " due to boot time exceeding " + Server.nNotRunning * ((System.Timers.Timer)sender).Interval / 60000 + " minutes."); //kill process and restart it. try { Process[] processes = Process.GetProcessesByName(GlobalVariables.appName); foreach (Process clsProcess in processes) { if (clsProcess.ProcessName.Contains(GlobalVariables.appName)) { if (clsProcess.MainModule.FileName.Contains(Server.ServerDir)) { clsProcess.Kill(); ((System.Timers.Timer)sender).Close(); Thread.Sleep(2000); StartServerProcedure(Server); } } } } catch (Exception ex) { //Console.WriteLine(DateTime.Now + ": Exception occured when killing ShooterGameServer.exe. Exception: " + ex.Message); Log(Server, DateTime.Now + ": Exception occured when killing ShooterGameServer.exe. Exception: " + ex.Message); } //Reset Events not running Server.nNotRunning = 0; } Server.nNotRunning++; } }
private static void CheckRoutine(object sender, EventArgs e) { //Run Server check foreach (var Server in Servers) { //Log that server is currently updating game files if (Server.CurrentlyUpdating) { //Console.WriteLine(DateTime.Now + ": " + Server.Name + " is currently updating."); Methods.Log(Server, DateTime.Now + ": " + Server.Name + " is currently updating."); } //If any event was triggered, or if the server is updating, do not run check routines. if (!Server.stopServerTimer && !Server.CurrentlyUpdating) { //Console.WriteLine(DateTime.Now + ": Entered " + Server.Name + "'s check method. RunningTimer = " + nRunningEventsTriggered); Methods.Log(Server, DateTime.Now + ": Entered " + Server.Name + "'s check method. RunningTimer = " + nRunningEventsTriggered); bool processOpen = GlobalVariables.IsProcessOpen(Server); bool ServerIsResponding = RCONCommands.IsServerResponding(Server); //Console.WriteLine("Server Response: " + ServerIsResponding); Methods.Log(Server, "Server Response: " + ServerIsResponding); Server.ModUpdateNeeded = GlobalVariables.NeedsModUpdate(Server); //Console.WriteLine("Mods are up to date: " + !Server.ModUpdateNeeded); Methods.Log(Server, DateTime.Now + ": Mods are up to date: " + !Server.ModUpdateNeeded); Server.GameUpdateNeeded = GlobalVariables.NeedsArkUpdate(Server); //Console.WriteLine("Game is up to date: " + !Server.GameUpdateNeeded); Methods.Log(Server, DateTime.Now + ": Game are up to date: " + !Server.GameUpdateNeeded); if (Server.ModUpdateNeeded && processOpen) { //Restart and Update the server if update is needed. RestartProcedures.BroadCastArkUpdateRestartTimer(Server, "Mod Update: " + Server.theModNeedingUpdate); Server.ModUpdateNeeded = false; Server.stopServerTimer = true; } //If process is open and game needs to be updated, trigger restart counter if (Server.GameUpdateNeeded && processOpen) { RestartProcedures.BroadCastArkUpdateRestartTimer(Server, "Ark Update"); Server.GameUpdateNeeded = false; Server.stopServerTimer = true; } if (processOpen && !ServerIsResponding) { if (Server.nEventsProcessOpenNotResponding == 10) { RestartUnresponsive(Server); } if (!Server.CurrentlyUpdating) { Server.nEventsProcessOpenNotResponding++; } } if (nRunningEventsTriggered % 60 == 0) { string message = "25 TC Reward points for recruiting players. See Dicord for more information."; Console.WriteLine(DateTime.Now + ": Message sent to " + Server.Name + " - " + message); RCONCommands.GlobalNotification(Server, message); } //Run Game Version Update every 20 minutes if (nRunningEventsTriggered % 20 == 0) { Processes.ModVersionUpdate(Server); } //If process is not running, AND timer is not stopped and server is not update then trigger the start routine. if (!processOpen) { Methods.StartServerProcedure(Server); } } //If the server has ran for 12 hours, trigger the routine maintenance restart. //if (nRagEventsTriggered % GlobalVariables.timeIntervalMaintenanceRestart == 0 && RagProcessOpen) //{ // ServerRestartForModORRoutineMaintenance(Ragnarok, "Routine Maintenance"); // RagnarokTimerTriggerStopped = true; //} //Backup the server every 2 hours. if (nRunningEventsTriggered % 30 == 0) { Methods.BackupServerFiles(Server); } } nRunningEventsTriggered++; }