Exemple #1
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);
 }
Exemple #2
0
        public static string GetGameBuildID(ArkServerInfo Server)
        {
            AcfReader appManifestReader = new AcfReader(Server.GameAppManifestACF);

            appManifestReader.ACFFileToStruct();
            appManifestReader.CheckIntegrity();
            ACF_Struct GameWorkshopACF = appManifestReader.ACFFileToStruct();

            return(GameWorkshopACF.SubACF["AppState"].SubItems["buildid"]);
        }
Exemple #3
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();
        }
Exemple #4
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);
 }
Exemple #5
0
        public static string SteamCMDCommand(ArkServerInfo Server)
        {
            string command = Server.SteamCMDDir + "SteamCMD.exe " + "+login anonymous +force_install_dir " + Server.ServerDir + " +app_update 376030";

            command = command + " +force_install_dir " + Server.SteamWorkshopDownloadDir;
            foreach (string mod in ActiveServerMods(Server))
            {
                command = command + " +workshop_download_item 346110 " + mod;
            }

            command = command + " +quit";
            return(command);
        }
Exemple #6
0
        public static string[] ActiveServerMods(ArkServerInfo Server)
        {
            string[] activeMods;

            var parser = new FileIniDataParser();

            parser.Parser.Configuration.AllowDuplicateKeys = true;
            IniData serverData = new IniData();

            serverData = parser.ReadFile(Server.GUSFile);

            activeMods = serverData["ServerSettings"]["ActiveMods"].Split(',');

            return(activeMods);
        }
Exemple #7
0
        public static void ServerStartCommand(ArkServerInfo Server)
        {
            Process startServer = new Process();

            startServer.StartInfo.FileName       = Server.RunBatFile;
            startServer.StartInfo.CreateNoWindow = false;

            startServer.Start();

            //Start a boot timer to make sure server boots properly. If not, close app and restart every 15 minutes until successful.
            System.Timers.Timer bootTimer = new System.Timers.Timer();
            bootTimer.Interval = 20000;
            bootTimer.Elapsed += (sender, e) => HasServerBooted(sender, e, Server);

            bootTimer.Start();
        }
        public static void ServerUpdateWValidate(ArkServerInfo Server)
        {
            string command = Server.SteamCMDDir + "SteamCMD.exe " + "+login anonymous +force_install_dir " + Server.ServerDir + " +app_update 376030 validate";

            command = command + " +force_install_dir " + Server.SteamWorkshopDownloadDir;
            foreach (string mod in GlobalVariables.ActiveServerMods(Server))
            {
                command = command + " +workshop_download_item 346110 " + mod;
            }

            command = command + " +quit";


            Process steamUpdateServer = new Process();

            steamUpdateServer.StartInfo.UseShellExecute        = false;
            steamUpdateServer.StartInfo.RedirectStandardInput  = true;
            steamUpdateServer.StartInfo.RedirectStandardOutput = true;
            //steamUpdateServer.StartInfo.CreateNoWindow = false;
            steamUpdateServer.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            steamUpdateServer.EnableRaisingEvents   = true;
            steamUpdateServer.StartInfo.FileName    = "cmd.exe";
            steamUpdateServer.Exited += (sender, e) =>
            {
                //Console.WriteLine(DateTime.Now + ": Process Complete for " + Server.Name + "    Time: {0} sec " +
                //"Exit code:    {1}", DateTime.Now.Second - steamUpdateServer.StartTime.Second, steamUpdateServer.ExitCode);
                Methods.Log(Server, DateTime.Now + ": Process Complete for " + Server.Name + " Time: " + (DateTime.Now.Second - steamUpdateServer.StartTime.Second) + " sec " +
                            "Exit code: " + steamUpdateServer.ExitCode);
                Server.CurrentlyUpdating = false;

                if (!Server.stopServerTimer)
                {
                    Server.GameUpdateNeeded = GlobalVariables.NeedsArkUpdate(Server);
                    Server.ModUpdateNeeded  = GlobalVariables.NeedsModUpdate(Server);
                }
                Methods.StartServerProcedure(Server);
                ((Process)sender).Dispose();
            };
            steamUpdateServer.Start();
            //Console.WriteLine(DateTime.Now + ": Running ServerUpdate with Validate method for " + Server.Name);
            Methods.Log(Server, DateTime.Now + ": Running ServerUpdate with Validate method for " + Server.Name);
            steamUpdateServer.StandardOutput.ReadToEndAsync();
            steamUpdateServer.StandardInput.WriteLine(command);
            Server.CurrentlyUpdating = true;
            steamUpdateServer.StandardInput.WriteLine("exit");
        }
Exemple #9
0
        public static void BackupServerFiles(ArkServerInfo Server)
        {
            List <string> listOfBackups   = new List <string>();
            string        SourcePath      = Server.SavedGame;
            string        DateStamp       = "Backup_" + DateTime.Now.ToString("MMddyyyy_hhmmss");
            string        DestinationPath = Server.BackupGames;

            //Now Create all of the directories
            foreach (string dirPath in Directory.GetDirectories(SourcePath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(dirPath.Replace(SourcePath, DestinationPath + DateStamp));
            }
            if (!Directory.Exists(DestinationPath))
            {
                Directory.CreateDirectory(DestinationPath);
            }
            string[] fileEntries = Directory.GetDirectories(DestinationPath);
            foreach (string fileName in fileEntries)
            {
                listOfBackups.Add(fileName);
            }
            Array.Clear(fileEntries, 0, fileEntries.Length);

            //Copy all the files & Replaces any files with the same name
            try
            {
                Directory.CreateDirectory(DestinationPath + "\\" + DateStamp);
                foreach (string newPath in Directory.GetFiles(SourcePath, "*.*",
                                                              SearchOption.AllDirectories).Where(name => !name.Contains("SaveGames")))
                {
                    File.Copy(newPath, newPath.Replace(SourcePath, DestinationPath + "\\" + DateStamp), true);
                }

                Log(Server, DateTime.Now + "Server " + Server.Name + ": Files copied to backup");
            }
            catch (Exception ex)
            {
                //Console.WriteLine(DateTime.Now + ": Could not save back up since: " + ex.Message);
                Log(Server, DateTime.Now + ": Could not save back up since: " + ex.Message);
            }
            while (Directory.GetDirectories(DestinationPath).Length > 10)
            {
                FileSystemInfo fileInfo = new DirectoryInfo(DestinationPath).GetFileSystemInfos().OrderByDescending(fi => fi.CreationTime).Last();
                Directory.Delete(fileInfo.FullName, true);
            }
        }
        public static void ConfigureServerInfoFile()
        {
            Console.WriteLine("How many servers do you want to add?");
            Int32.TryParse(Console.ReadLine(), out numOfServers);

            File.Delete(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ServerDirectories.txt"));

            //Add server to list
            for (var i = 0; i < numOfServers; i++)
            {
                ArkServerInfo tempServer = new ArkServerInfo();
                Console.WriteLine("Server Name: ");
                tempServer.Name = Console.ReadLine();
                //tempServer.IPAddress = ipAddress;
                string shooterGameDir;
                Console.WriteLine("Paste directory to shootergame.exe");
                shooterGameDir = Console.ReadLine();

                while (!Directory.Exists(shooterGameDir))
                {
                    Console.WriteLine("Directory does not exist, try again or exit: ");
                    shooterGameDir = Console.ReadLine();
                    if (shooterGameDir.Contains("exit"))
                    {
                        Environment.Exit(0);
                    }
                }
                tempServer.ServerDir = shooterGameDir + "\\";
                File.AppendAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ServerDirectories.txt"), tempServer.Name + "," + tempServer.ServerDir + Environment.NewLine);

                Servers.Add(tempServer);

                if (!File.Exists(tempServer.CurrentWorkshopACF))
                {
                    File.Copy(tempServer.UpdatedWorkshopACF, tempServer.CurrentWorkshopACF);
                }
                string sasFile = tempServer.SASLogs + "/SASLog" + DateTime.Now.ToString("MMddyyyy_hhmmss") + ".txt";
                if (!File.Exists(sasFile))
                {
                    tempServer.SASFile = sasFile;
                    var myFile = File.Create(sasFile);
                    myFile.Close();
                }
            }
        }
Exemple #11
0
        public static void Connect(ArkServerInfo Server)
        {
            RconBase client = new RconBase();

            client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort));

            if (client.Connected)
            {
                client.Authenticate(Server.ServerPassword);
                //Console.WriteLine(DateTime.Now + ": Client has been successfully connected!");
                Methods.Log(Server, DateTime.Now + ": Client has been successfully connected!");
            }
            if (!client.Connected)
            {
                //Console.WriteLine(DateTime.Now + ": Client can't connect successfully!");
                Methods.Log(Server, DateTime.Now + ": Client can't connect successfully!");
            }
            client.Disconnect();
        }
Exemple #12
0
        public static bool WorldSave(ArkServerInfo Server)
        {
            RconBase client = new RconBase();

            client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort));
            if (client.Connected)
            {
                client.Authenticate(Server.ServerPassword);
                RconPacket request        = new RconPacket(PacketType.ServerdataExeccommand, new Rcon.Commands.SaveWorld().ToString());
                RconPacket response       = client.SendReceive(request);
                string     stringResponse = response?.Body.Trim();
                if (stringResponse.Contains("World Saved"))
                {
                    Console.WriteLine(DateTime.Now + ": Server " + Server.Name + "- World Saved!");
                    Methods.Log(Server, DateTime.Now + ": Server " + Server.Name + "- World Saved!");
                    client.Disconnect();
                    return(true);
                }
            }
            client.Disconnect();
            return(false);
        }
Exemple #13
0
 public static void ShutdownServer(ArkServerInfo Server)
 {
     try
     {
         RconBase client = new RconBase();
         client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort));
         if (client.Connected)
         {
             client.Authenticate(Server.ServerPassword);
             RconPacket request  = new RconPacket(PacketType.ServerdataExeccommand, new Rcon.Commands.DoExit().ToString());
             RconPacket response = client.SendReceive(request);
             Console.WriteLine(response?.Body.Trim());
             Methods.Log(Server, response?.Body.Trim());
         }
         client.Disconnect();
     }
     catch (Exception ex)
     {
         //Console.WriteLine(DateTime.Now + ": Exception occured when trying to send a Ark Server Shutdown Command. Exception: " + ex.Message);
         Methods.Log(Server, DateTime.Now + ": Exception occured when trying to send a Ark Server Shutdown Command. Exception: " + ex.Message);
     }
 }
Exemple #14
0
        public static void GlobalNotification(ArkServerInfo Server, string message)
        {
            try
            {
                RconBase client = new RconBase();
                client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort));
                if (client.Connected)
                {
                    client.Authenticate(Server.ServerPassword);
                    RconPacket request  = new RconPacket(PacketType.ServerdataExeccommand, new Rcon.Commands.Broadcast(message).ToString());
                    RconPacket response = client.SendReceive(request);
                    //Console.WriteLine(DateTime.Now + ": Broadcast sent to " + Server.Name + " Server Message: " + message);
                    Methods.Log(Server, DateTime.Now + ": Broadcast sent to " + Server.Name + " Server Message: " + message);
                }

                client.Disconnect();
            }
            catch (Exception ex)
            {
                //Console.WriteLine(DateTime.Now + ": Exception occured when trying to send an Ark Server Global Notification. Exception: " + ex.Message);
                Methods.Log(Server, DateTime.Now + ": Exception occured when trying to send an Ark Server Global Notification. Exception: " + ex.Message);
            }
        }
Exemple #15
0
        public static bool IsServerResponding(ArkServerInfo Server)
        {
            bool       serverIsRunning = false;
            RconClient client          = new RconClient();

            try
            {
                client.Connect(Server.IPAddress, Int32.Parse(Server.RCONPort), Server.ServerPassword);
                if (client.IsConnected)
                {
                    serverIsRunning = true;
                }
            }
            catch (Exception ex)
            {
                serverIsRunning = false;
                //Console.WriteLine(DateTime.Now + ": " + Server.Name + " Exception:"  + ex.Message);
                Methods.Log(Server, DateTime.Now + ": " + Server.Name + " Exception:" + ex.Message);
            }
            client.Disconnect();


            return(serverIsRunning);
        }
Exemple #16
0
 public static bool IsProcessOpen(ArkServerInfo Server)
 {
     try
     {
         Process[] processes = Process.GetProcessesByName(appName);
         foreach (Process clsProcess in processes)
         {
             if (clsProcess.ProcessName.Contains(appName))
             {
                 if (clsProcess.MainModule.FileName.Contains(Server.ServerDir))
                 {
                     return(true);
                 }
             }
         }
         return(false);
     }
     catch (Exception ex)
     {
         //Console.WriteLine(DateTime.Now + ": Exception occured when checking if ShooterGameServer.exe is an active process. Exception: " + ex.Message);
         Methods.Log(Server, DateTime.Now + ": Exception occured when checking if ShooterGameServer.exe is an active process. Exception: " + ex.Message);
     }
     return(false);
 }
 public static void killServer(ArkServerInfo Server)
 {
     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();
                     Processes.ServerUpdateWValidate(Server);
                     Server.stopServerTimer = true;
                 }
             }
         }
     }
     catch (Exception ex)
     {
         //Console.WriteLine(DateTime.Now + ": Exception occured when killing ShooterGameServer.exe. Exception: " + ex.Message);
         Methods.Log(Server, DateTime.Now + ": Exception occured when killing ShooterGameServer.exe. Exception: " + ex.Message);
     }
 }
        public static void ServerUpdate(ArkServerInfo Server)
        {
            Process steamUpdateServer = new Process();

            steamUpdateServer.StartInfo.UseShellExecute        = false;
            steamUpdateServer.StartInfo.RedirectStandardInput  = true;
            steamUpdateServer.StartInfo.RedirectStandardOutput = true;
            //steamUpdateServer.StartInfo.CreateNoWindow = false;
            //steamUpdateServer.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
            steamUpdateServer.EnableRaisingEvents = true;
            steamUpdateServer.StartInfo.FileName  = "cmd.exe";
            steamUpdateServer.Exited += (sender, e) =>
            {
                //Console.WriteLine(DateTime.Now + ": Process Complete for " + Server.Name + "    Time: {0} sec " +
                //"Exit code:    {1}", DateTime.Now.Second - steamUpdateServer.StartTime.Second, steamUpdateServer.ExitCode);
                Methods.Log(Server, DateTime.Now + ": Process Complete for " + Server.Name + " Time: " + (DateTime.Now.Second - steamUpdateServer.StartTime.Second) + " sec " +
                            "Exit code: " + steamUpdateServer.ExitCode);

                Server.CurrentlyUpdating = false;

                if (!Server.stopServerTimer)
                {
                    Server.GameUpdateNeeded = GlobalVariables.NeedsArkUpdate(Server);
                    Server.ModUpdateNeeded  = GlobalVariables.NeedsModUpdate(Server);
                }
                Methods.StartServerProcedure(Server);
                ((Process)sender).Dispose();
            };
            //Console.WriteLine(DateTime.Now + ": Running ServerUpdate method for " + Server.Name);
            Methods.Log(Server, DateTime.Now + ": Running ServerUpdate method for " + Server.Name);
            steamUpdateServer.Start();
            Server.CurrentlyUpdating = true;
            steamUpdateServer.StandardInput.WriteLine(GlobalVariables.SteamCMDCommand(Server));
            steamUpdateServer.StandardOutput.ReadToEndAsync();
            steamUpdateServer.StandardInput.WriteLine("exit");
        }
Exemple #19
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++;
            }
        }
Exemple #20
0
        public static void ServerRestartTriggered(ArkServerInfo Server, string Reason)
        {
            string message = string.Format("Server needs to restart for the following reason: {0}", Reason);

            GlobalNotification(Server, message);
        }
Exemple #21
0
        public static bool NeedsModUpdate(ArkServerInfo Server)
        {
            bool workshopItemNeedsUpdate = false;

            AcfReader serverReader = new AcfReader(Server.CurrentWorkshopACF);

            serverReader.ACFFileToStruct();
            serverReader.CheckIntegrity();
            ACF_Struct atLaunchACF = serverReader.ACFFileToStruct();

            AcfReader updateReader = new AcfReader(Server.UpdatedWorkshopACF);

            updateReader.ACFFileToStruct();
            updateReader.CheckIntegrity();
            ACF_Struct UpdatedWorkshopACF = updateReader.ACFFileToStruct();

            foreach (string mod in ActiveServerMods(Server))
            {
                string[] UpdatedModNTimeData = new string[2];
                UpdatedModNTimeData[0] = mod;
                try
                {
                    UpdatedModNTimeData[1] = UpdatedWorkshopACF.SubACF["AppWorkshop"].SubACF["WorkshopItemsInstalled"].SubACF[mod].SubItems["timeupdated"];
                }
                catch (Exception ex)
                {
                    //Console.WriteLine(DateTime.Now + ": Error in NeedsModUpdate in AllActiveServerMods on mod " + mod + " with exception: " + ex.Message);
                    Methods.Log(Server, DateTime.Now + ": Exception occured when trying to read all active mod's timeupdated value. Exception: " + ex.Message);
                    break;
                }
                UpdatedModNTime.Add(UpdatedModNTimeData);
            }
            foreach (string mod in ActiveServerMods(Server))
            {
                string[] ServerModNTimeData = new string[2];
                ServerModNTimeData[0] = mod;
                try
                {
                    ServerModNTimeData[1] = atLaunchACF.SubACF["AppWorkshop"].SubACF["WorkshopItemsInstalled"].SubACF[mod].SubItems["timeupdated"];
                }
                catch (Exception ex)
                {
                    //Console.WriteLine(DateTime.Now + ": Error reading working time updated element. Exception: " + ex.Message);
                    Methods.Log(Server, DateTime.Now + ": Error reading working time updated element. Exception: " + ex.Message);
                }

                ServerModNTime.Add(ServerModNTimeData);
            }
            foreach (string[] BMod in UpdatedModNTime)
            {
                foreach (string[] AMod in ServerModNTime)
                {
                    //if (BMod[0] != "1257464589")
                    if (BMod[0] == AMod[0])
                    {
                        if (BMod[1] != AMod[1])
                        {
                            workshopItemNeedsUpdate    = true;
                            Server.theModNeedingUpdate = NameOfMod(BMod[0]);
                            //Console.WriteLine(DateTime.Now.ToString() + ": Restart Triggered for Server " + Server.Name + "  to update the following mod: " + BMod[0] + "-" + GlobalVariables.NameOfMod(BMod[0]));
                            Methods.Log(Server, DateTime.Now.ToString() + ": Restart Triggered to update the following mod: " + BMod[0] + "-" + GlobalVariables.NameOfMod(BMod[0]));
                            break;
                        }
                        if (BMod[1] == AMod[1])
                        {
                            workshopItemNeedsUpdate = false;
                        }
                    }
                }
                if (workshopItemNeedsUpdate)
                {
                    break;
                }
            }
            UpdatedModNTime.Clear();
            ServerModNTime.Clear();


            return(workshopItemNeedsUpdate);
        }