Пример #1
0
        private static void BroadCastModUpdateRestartNotification(object sender, EventArgs e, ArkServerInfo Server)
        {
            int ticks = 0;

            System.Timers.Timer timer = (System.Timers.Timer)sender;
            ticks = Server.nOfTicks;

            int minutesTillRestart = GlobalVariables.presetTimeToRestart - ticks;

            if (minutesTillRestart == 10)
            {
                RCONCommands.GlobalNotification(Server, GlobalVariables.serverRestartNotification(minutesTillRestart));
            }
            if (minutesTillRestart < 6 && minutesTillRestart > 0)
            {
                RCONCommands.GlobalNotification(Server, GlobalVariables.serverRestartNotification(minutesTillRestart));
            }
            //if (minutesTillRestart == 1)
            //    Methods.BackupServerFiles(Server);
            if (minutesTillRestart == 0)
            {
                RCONCommands.GlobalNotification(Server, GlobalVariables.serverRestartNotification(minutesTillRestart));
                timer.Close();

                Server.nOfTicks = 0;

                Methods.ModUpdateShutdownProcedure(Server);
            }
            if (minutesTillRestart != 0)
            {
                Server.nOfTicks++;
            }
        }
Пример #2
0
        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++;
            }
        }
Пример #3
0
 public static void ArkUpdateShutdownProcedure(ArkServerInfo Server)
 {
     if (RCONCommands.WorldSave(Server))
     {
         Task stopServer = Task.Factory.StartNew(() => StableServer_Main.killServer(Server));
         stopServer.Wait(2000);
     }
     Thread.Sleep(2000);
     Processes.ServerUpdate(Server);
 }
Пример #4
0
        public static void BroadCastModUpdateRestartTimer(ArkServerInfo Server, string Reason)
        {
            //Notifies players that a server restart is coming and gives the reason.
            RCONCommands.ServerRestartTriggered(Server, Reason);

            System.Timers.Timer restartTimer = new System.Timers.Timer();
            restartTimer.Interval = 60000;
            restartTimer.Elapsed += (sender, e) => BroadCastModUpdateRestartNotification(sender, e, Server);

            restartTimer.Start();
        }
Пример #5
0
 public static void ModUpdateShutdownProcedure(ArkServerInfo Server)
 {
     if (RCONCommands.WorldSave(Server))
     {
         Task stopServer = Task.Factory.StartNew(() => StableServer_Main.killServer(Server));
         stopServer.Wait(2000);
     }
     Thread.Sleep(2000);
     Server.ModUpdateNeeded = false;
     StartServerProcedure(Server);
 }
        static void Main(string[] args)
        {
            Task startServer = Task.Factory.StartNew(() => Init());

            startServer.Wait();
            if (startServer.IsCompleted)
            {
                Console.WriteLine(DateTime.Now + ": Initialization process completed.");
            }


            //While readline doesn't equal exit, keep the application open.
            string response = "";

            while (response != "Exit")
            {
                Console.Write(DateTime.Now + ": Ready for command: ");
                response = Console.ReadLine();
                if (response == "stop global timer")
                {
                    primaryTimer.Stop();
                    Console.WriteLine(DateTime.Now + ": Stopping global timer.");
                }
                if (response == "start global timer" && !primaryTimer.Enabled)
                {
                    primaryTimer.Start();
                    Console.WriteLine(DateTime.Now + ": Starting global timer.");
                }
                if (response.Contains("check"))
                {
                    if (response.Contains("timer"))
                    {
                        Console.Write(DateTime.Now + ": Timer is ");
                        if (primaryTimer.Enabled == true)
                        {
                            Console.WriteLine("running.");
                        }
                        else
                        {
                            Console.WriteLine("stopped");
                        }
                    }
                }
                if (response.Contains("restart"))
                {
                    foreach (var Server in Servers)
                    {
                        if (response.Contains(Server.Name))
                        {
                            Console.WriteLine(DateTime.Now + ": Restart triggered by admin for " + Server.Name);
                            RestartProcedures.BroadCastModUpdateRestartTimer(Server, "Admin Triggered a restart");
                        }
                    }
                }
                if (response.Contains("update"))
                {
                    foreach (var Server in Servers)
                    {
                        if (response.Contains(Server.Name))
                        {
                            Console.WriteLine(DateTime.Now + ": Update triggered by admin for " + Server.Name);
                            RestartProcedures.BroadCastArkUpdateRestartTimer(Server, "Admin triggered restart to update server.");
                        }
                    }
                }
                if (response.ToLower().Contains("bm all:"))
                {
                    try
                    {
                        string trimResponse = response.Substring(response.IndexOf(':') + 1);
                        foreach (var Server in Servers)
                        {
                            Console.WriteLine(DateTime.Now + ": Message sent to " + Server.Name + " - " + trimResponse);
                            RCONCommands.GlobalNotification(Server, trimResponse);
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine("Does not contain : character. Exception: " + ex.Message);
                    }
                }
                if (response == "Exit")
                {
                    primaryTimer.Stop();
                    Environment.Exit(0);
                }
            }
        }
        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++;
        }