Example #1
0
 static bool BroadCastMessage(string Message)
 {
     try
     {
         bool FirstRun = true;
         AtlasServerManager.GetInstance().Invoke((System.Windows.Forms.MethodInvoker) delegate()
         {
             foreach (ArkServerListViewItem ASLVI in AtlasServerManager.GetInstance().ServerList.Items)
             {
                 if (!FirstRun)
                 {
                     Thread.Sleep(4000);
                 }
                 if (!ConnectToRcon(ASLVI.GetServerData().RconConnection, /*ASLVI.GetServerData().ServerIp*/ "127.0.0.1", ASLVI.GetServerData().RconPort, ASLVI.GetServerData().Pass))
                 {
                     continue;
                 }
                 ASLVI.GetServerData().RconConnection.ServerCommand("broadcast " + Message);
                 FirstRun = false;
             }
         });
         return(true);
     }
     catch (Exception e)
     {
         AtlasServerManager.GetInstance().Log("[Rcon->BroadCastMessage] Connection failed: " + e.Message);
         return(false);
     }
 }
Example #2
0
 public static bool SendCommandToAll(string Command)
 {
     try
     {
         AtlasServerManager.GetInstance().Invoke((System.Windows.Forms.MethodInvoker) delegate()
         {
             foreach (ArkServerListViewItem ASLVI in AtlasServerManager.GetInstance().ServerList.Items)
             {
                 if (ASLVI.GetServerData().RconConnection == null)
                 {
                     ASLVI.GetServerData().RconConnection = new SourceRcon();
                 }
                 if (!ConnectToRcon(ASLVI.GetServerData().RconConnection, ASLVI.GetServerData().RCONIP == string.Empty ? ASLVI.GetServerData().ServerIp : ASLVI.GetServerData().RCONIP, ASLVI.GetServerData().RconPort, ASLVI.GetServerData().Pass, ASLVI.GetServerData().AltSaveDirectory))
                 {
                     continue;
                 }
                 ASLVI.GetServerData().RconConnection.ServerCommand(Command);
             }
         });
         return(true);
     }
     catch (Exception e)
     {
         AtlasServerManager.GetInstance().Log("[Rcon->BroadCastMessage] Connection failed: " + e.Message);
         return(false);
     }
 }
        public static void CheckServerStatus(object Data)
        {
            AtlasServerManager ArkMgr = (AtlasServerManager)Data;

            while (true)
            {
                if (!ArkMgr.Updating && ArkMgr.checkBootWhenOff.Checked)
                {
                    ArkMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
                    {
                        foreach (ArkServerListViewItem ASLVI in ArkMgr.ServerList.Items)
                        {
                            if (ASLVI.Checked && !ASLVI.GetServerData().IsRunning())
                            {
                                ArkMgr.Log("Server Port: " + ASLVI.Text + " Was Offline Booting Now!");
                                if (ASLVI.GetServerData().ServerProcess != null && !ASLVI.GetServerData().ServerProcess.HasExited&& ASLVI.GetServerData().ServerProcess.Id != 0)
                                {
                                    ASLVI.GetServerData().ServerProcess.Kill();
                                    ASLVI.GetServerData().ServerProcess = null;
                                }
                                ASLVI.GetServerData().StartServer();
                            }
                            ASLVI.UpdateStatus();
                        }
                    });
                }
                Thread.Sleep((int)(ArkMgr.numServerMonitor.Value) * 1000);
            }
        }
        public static void CheckServerStatus(AtlasServerManager AtlasMgr, CancellationToken token)
        {
            int  ServerStatus = 0, SleepTime = 3000;
            bool SavedAfterLaunch = false;

            while (true)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }
                AtlasMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
                {
                    if (!ServerUpdater.Updating && AtlasMgr.BootWhenOffCheck.Checked)
                    {
                        foreach (ArkServerListViewItem ASLVI in AtlasMgr.ServerList.Items)
                        {
                            if (ASLVI.Checked && (ServerStatus = ASLVI.GetServerData().IsRunning(AtlasMgr)) != 1)
                            {
                                switch (ServerStatus)
                                {
                                case 0:
                                    AtlasMgr.Log("Server: " + ASLVI.Text + " Was Offline Booting Now, Process was not running!");
                                    break;

                                case 2:
                                    AtlasMgr.Log("Server: " + ASLVI.Text + " Was Offline Booting Now, Query Port was not running!");
                                    break;

                                case 3:
                                    AtlasMgr.Log("Server: " + ASLVI.Text + " Booting Now!");
                                    break;

                                case 4:
                                    AtlasMgr.Log("Server: " + ASLVI.Text + " Game Port is offline Attempting Rcon Save Please wait 1 minute!");
                                    continue;
                                }
                                ASLVI.GetServerData().StartServer();
                                SavedAfterLaunch = false;
                                if (AtlasMgr.StartupDelayNum.Value > 0)
                                {
                                    Thread.Sleep((int)AtlasMgr.StartupDelayNum.Value * 1000);
                                }
                            }
                            ASLVI.UpdateStatus();
                        }

                        if (!SavedAfterLaunch)
                        {
                            SavedAfterLaunch = true;
                            Registry.SaveRegConfig(AtlasMgr);
                        }
                    }
                    SleepTime = (int)AtlasMgr.numServerMonitor.Value * 1000;
                });
                Thread.Sleep(SleepTime);
            }
        }
Example #5
0
        private static int GetCurrentBuildID(AtlasServerManager AtlasMgr)
        {
            AtlasMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
            {
                foreach (ArkServerListViewItem ASLVI in AtlasMgr.ServerList.Items)
                {
                    string UpdatePath = ASLVI.GetServerData().ServerPath;
                    if (UpdatePath.StartsWith("./") || UpdatePath.StartsWith(@".\"))
                    {
                        UpdatePath = UpdatePath.Replace("./", System.AppDomain.CurrentDomain.BaseDirectory).Replace(@".\", System.AppDomain.CurrentDomain.BaseDirectory).Replace("//", "/").Replace(@"\\", @"\");
                    }

                    if (!Directory.Exists(Path.GetDirectoryName(UpdatePath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(UpdatePath));
                    }

                    if (UpdatePath.Contains(@"ShooterGame\Binaries\Win64"))
                    {
                        UpdatePath = Regex.Split(UpdatePath, "\\ShooterGame")[0];
                    }

                    if (!UpdatePaths.Contains(UpdatePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\')))
                    {
                        UpdatePaths.Add(UpdatePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\'));
                    }
                }
            });

            int    Version = 0;
            string SteamAppsDir;

            foreach (string UpdatePath in UpdatePaths)
            {
                SteamAppsDir = Path.Combine(UpdatePath, @"steamapps\");
                if (Directory.Exists(SteamAppsDir) && File.Exists(SteamAppsDir + "appmanifest_1006030.acf"))
                {
                    using (StreamReader Sr = new StreamReader(SteamAppsDir + "appmanifest_1006030.acf"))
                    {
                        string output     = Sr.ReadToEnd();
                        int    BuildIndex = output.IndexOf("\"buildid\"		\"");
                        if (BuildIndex != -1)
                        {
                            BuildIndex += 12;
                            int EndIndex = output.IndexOf('"', BuildIndex) - BuildIndex;
                            if (EndIndex != -1)
                            {
                                int.TryParse(output.Substring(BuildIndex, EndIndex), out Version);
                            }
                            break;
                        }
                    }
                }
            }
            UpdatePaths.Clear();
            return(Version);
        }
Example #6
0
 private static void StartServers(AtlasServerManager ArkMgr)
 {
     ArkMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
     {
         foreach (ArkServerListViewItem ASLVI in ArkMgr.ServerList.Items)
         {
             ASLVI.GetServerData().StartServer();
         }
     });
 }
Example #7
0
        public static void BackupConfigs(AtlasServerManager AtlasMgr)
        {
            List <string> UpdatePaths = new List <string>();

            foreach (ArkServerListViewItem ASLVI in AtlasMgr.ServerList.Items)
            {
                string UpdatePath = ASLVI.GetServerData().ServerPath;
                if (UpdatePath.StartsWith("./") || UpdatePath.StartsWith(@".\"))
                {
                    UpdatePath = UpdatePath.Replace("./", System.AppDomain.CurrentDomain.BaseDirectory).Replace(@".\", System.AppDomain.CurrentDomain.BaseDirectory).Replace("//", "/").Replace(@"\\", @"\");
                }
                if (!Directory.Exists(Path.GetDirectoryName(UpdatePath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(UpdatePath));
                }
                if (UpdatePath.Contains(@"ShooterGame\Binaries\Win64"))
                {
                    UpdatePath = Regex.Split(UpdatePath, "\\ShooterGame")[0];
                }
                if (!UpdatePaths.Contains(UpdatePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\')))
                {
                    UpdatePaths.Add(UpdatePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\'));
                }
            }

            string BackupPath, FilesPath;

            string[] Files;
            foreach (string UpdatePath in UpdatePaths)
            {
                AtlasMgr.Log("[Atlas] Backing up INI and DB Configs at Path: " + UpdatePath);
                BackupPath = Path.Combine(UpdatePath + Path.DirectorySeparatorChar, @"ConfigRestore\");
                if (!Directory.Exists(BackupPath))
                {
                    Directory.CreateDirectory(BackupPath);
                }
                FilesPath = Path.Combine(UpdatePath + Path.DirectorySeparatorChar, @"ShooterGame\Config\");
                Files     = Directory.GetFiles(FilesPath, "*.ini", SearchOption.TopDirectoryOnly);
                foreach (string file in Files)
                {
                    File.Copy(file, BackupPath + Path.GetFileName(file), true);
                }

                FilesPath = Path.Combine(UpdatePath + Path.DirectorySeparatorChar, @"AtlasTools\RedisDatabase\");

                Files = Directory.GetFiles(FilesPath, "*.conf", SearchOption.TopDirectoryOnly);
                foreach (string file in Files)
                {
                    File.Copy(file, BackupPath + Path.GetFileName(file), true);
                }
            }

            AtlasMgr.Log("[Atlas] Backing up INI and DB Configs Completed!");
        }
Example #8
0
        private static void UpdateArk(AtlasServerManager ArkMgr, string UpdateVersion)
        {
            ArkMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
            {
                foreach (ArkServerListViewItem ASLVI in ArkMgr.ServerList.Items)
                {
                    string UpdatePath = ASLVI.GetServerData().ServerPath;
                    if (UpdatePath.StartsWith("./") || UpdatePath.StartsWith(@".\"))
                    {
                        UpdatePath = UpdatePath.Replace("./", System.AppDomain.CurrentDomain.BaseDirectory).Replace(@".\", System.AppDomain.CurrentDomain.BaseDirectory).Replace("//", "/").Replace(@"\\", @"\");
                    }

                    if (!Directory.Exists(Path.GetDirectoryName(UpdatePath)))
                    {
                        Directory.CreateDirectory(Path.GetDirectoryName(UpdatePath));
                    }

                    if (UpdatePath.Contains(@"ShooterGame\Binaries\Win64"))
                    {
                        UpdatePath = Regex.Split(UpdatePath, "\\ShooterGame")[0];
                    }

                    if (!UpdatePaths.Contains(UpdatePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\')))
                    {
                        UpdatePaths.Add(UpdatePath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar, '\\'));
                    }
                }
            });

            foreach (string UpdatePath in UpdatePaths)
            {
                ArkMgr.Log("[Ark] Updating Path: " + UpdatePath);
                ArkMgr.UpdateProcess = new Process()
                {
                    StartInfo = new ProcessStartInfo(ArkMgr.SteamPath + "steamcmd.exe", "+@NoPromptForPassword 1 +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir \"" + UpdatePath + "\" +app_update 1006030 validate +quit")
                    {
                        UseShellExecute        = false,
                        RedirectStandardInput  = true,
                        RedirectStandardOutput = true,
                        CreateNoWindow         = true,
                        WorkingDirectory       = ArkMgr.SteamPath
                    }
                };
                ArkMgr.UpdateProcess.OutputDataReceived += (s, e) => UpdateData(e.Data);
                ArkMgr.UpdateProcess.Start();
                ArkMgr.UpdateProcess.BeginOutputReadLine();
                ArkMgr.UpdateProcess.WaitForExit();
            }
            if (!UpdateError)
            {
                using (StreamWriter w = new StreamWriter(ArkMgr.SteamPath + "AtlasLatestVersion.txt")) w.WriteLine(UpdateVersion);
            }
        }
Example #9
0
        public static bool SaveWorld()
        {
            int FailCount = 0;

            AtlasServerManager.GetInstance().Invoke((System.Windows.Forms.MethodInvoker) delegate()
            {
                foreach (ArkServerListViewItem ASLVI in AtlasServerManager.GetInstance().ServerList.Items)
                {
                    if (!ConnectToRcon(ASLVI.GetServerData().RconConnection, ASLVI.GetServerData().RCONIP == string.Empty ? ASLVI.GetServerData().ServerIp : ASLVI.GetServerData().RCONIP, ASLVI.GetServerData().RconPort, ASLVI.GetServerData().Pass, ASLVI.GetServerData().AltSaveDirectory))
                    {
                        FailCount++;
                        continue;
                    }
                    ASLVI.GetServerData().RconConnection.ServerCommand("DoExit");
                }
            });
            return(FailCount != AtlasServerManager.GetInstance().ServerList.Items.Count);
        }
Example #10
0
        static bool SaveWorld()
        {
            bool FirstRun  = true;
            int  FailCount = 0;

            AtlasServerManager.GetInstance().Invoke((System.Windows.Forms.MethodInvoker) delegate()
            {
                foreach (ArkServerListViewItem ASLVI in AtlasServerManager.GetInstance().ServerList.Items)
                {
                    if (!FirstRun)
                    {
                        Thread.Sleep(4000);
                    }
                    if (!ConnectToRcon(ASLVI.GetServerData().RconConnection, ASLVI.GetServerData().ServerIp, ASLVI.GetServerData().RconPort, ASLVI.GetServerData().Pass))
                    {
                        FailCount++;
                        continue;
                    }
                    ASLVI.GetServerData().RconConnection.ServerCommand("DoExit");
                    FirstRun = false;
                }
            });
            return(FailCount != AtlasServerManager.GetInstance().ServerList.Items.Count);
        }
Example #11
0
        public static void CheckForUpdates(AtlasServerManager AtlasMgr, CancellationToken token)
        {
            if (AtlasMgr.checkAutoServerUpdate.Checked || ForcedUpdate)
            {
                AtlasMgr.Log("[Atlas] Checking for updates, can take up to 30 seconds...");
            }
            int UpdateVersion = 0, CurrentVer = 0;

            while (true)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }
                if (AtlasMgr.checkAutoServerUpdate.Checked || ForcedUpdate)
                {
                    if (AtlasMgr.DebugCheck.Checked)
                    {
                        AtlasMgr.Log("[Atlas->Debug] Checking for Update");
                    }
                    UpdateVersion = GetAtlasServerBuildID(AtlasMgr);
                    if (AtlasMgr.DebugCheck.Checked)
                    {
                        AtlasMgr.Log("[Atlas->Debug] Atlas Latest Build: " + UpdateVersion);
                    }
                    if (UpdateVersion != 0)
                    {
                        CurrentVer = GetCurrentBuildID(AtlasMgr);
                        if (AtlasMgr.DebugCheck.Checked)
                        {
                            AtlasMgr.Log("[Atlas->Debug] Atlas Current Build: " + CurrentVer);
                        }
                        if (CurrentVer != UpdateVersion)
                        {
                            Updating = true;
                            AtlasMgr.Log("[Atlas] BuildID " + UpdateVersion + " Released!");
                            if (AtlasMgr.DebugCheck.Checked)
                            {
                                AtlasMgr.Log("[Atlas->Debug] Checking if servers are still online");
                            }
                            bool ServerStillOpen = false;
                            AtlasMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
                            {
                                foreach (ArkServerListViewItem ASLVI in AtlasMgr.ServerList.Items)
                                {
                                    if (ASLVI.GetServerData().IsRunning())
                                    {
                                        ServerStillOpen = true;
                                    }
                                }
                            });
                            if (ServerStillOpen)
                            {
                                int SleepTime = (int)AtlasMgr.numServerWarning.Value / 2;
                                AtlasMgr.Log("[Atlas] Update Broadcasting " + (int)AtlasMgr.numServerWarning.Value + " Minutes");
                                SourceRconTools.SendCommandToAll("broadcast " + GenerateUpdateMessage(AtlasMgr, (int)AtlasMgr.numServerWarning.Value));
                                Thread.Sleep(SleepTime * 60000);

                                AtlasMgr.Log("[Atlas] Update Broadcasting " + SleepTime + " Minutes");
                                SourceRconTools.SendCommandToAll("broadcast " + GenerateUpdateMessage(AtlasMgr, SleepTime));
                                SleepTime = (int)AtlasMgr.numServerWarning.Value / 4;
                                Thread.Sleep(SleepTime * 60000);

                                AtlasMgr.Log("[Atlas] Update Broadcasting " + SleepTime + " Minutes");
                                SourceRconTools.SendCommandToAll("broadcast " + GenerateUpdateMessage(AtlasMgr, SleepTime));
                                SleepTime = (int)AtlasMgr.numServerWarning.Value / 4;
                                Thread.Sleep((SleepTime * 60000) - 35000);

                                AtlasMgr.Log("[Atlas] Update Broadcasting 30 Seconds");
                                SourceRconTools.SendCommandToAll("broadcast " + GenerateUpdateMessage(AtlasMgr, 30, "Seconds"));
                                Thread.Sleep(30000);
                                AtlasMgr.Log("[Atlas] Update Saving World");
                                SourceRconTools.SendCommandToAll("broadcast " + AtlasMgr.ServerUpdatingMessage.Text);
                                Thread.Sleep(5000);
                                if (!SourceRconTools.SaveWorld())
                                {
                                    AtlasMgr.Log("[Atlas] Failed Saving World, Not Updating!");
                                    //continue;
                                }
                            }

                            while (ServerStillOpen)
                            {
                                ServerStillOpen = false;
                                AtlasMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
                                {
                                    foreach (ArkServerListViewItem ASLVI in AtlasMgr.ServerList.Items)
                                    {
                                        if (ASLVI.GetServerData().IsRunning())
                                        {
                                            ServerStillOpen = true;
                                        }
                                    }
                                });
                                if (!ServerStillOpen)
                                {
                                    break;
                                }
                                Thread.Sleep(3000);
                                if (AtlasMgr.DebugCheck.Checked)
                                {
                                    AtlasMgr.Log("[Atlas->Debug] Waiting for all servers to close");
                                }
                            }
                            AtlasMgr.Log("[Atlas] Current BuildID: " + CurrentVer + ", Updating To BuildID: " + UpdateVersion);
                            UpdateAtlas(AtlasMgr, UpdateVersion.ToString());
                            if (UpdateError)
                            {
                                AtlasMgr.Log("[Atlas] Update Error, Retrying...");
                                UpdateError = false;
                                if (UpdateErrorText.Contains("606") || UpdateErrorText.Contains("602"))
                                {
                                    AtlasServerManager.GetInstance().Log("[Update] Attempting to fix update error!");
                                    try
                                    {
                                        Directory.Delete(AtlasServerManager.GetInstance().SteamPath + @"steamapps\", true);
                                        Directory.Delete(AtlasServerManager.GetInstance().SteamPath + @"steamapps\", true);
                                    }
                                    catch
                                    { }
                                }
                                continue;
                            }

                            if (token.IsCancellationRequested)
                            {
                                Updating = false;
                                break;
                            }
                            AtlasMgr.Log("[Atlas] Updated, Launching Servers if offline!");
                            FirstLaunch = ForcedUpdate = Updating = false;
                            StartServers(AtlasMgr);
                        }
                        else
                        {
                            Updating = false;
                        }
                    }
                }
                else
                {
                    Updating = false;
                }
                if (token.IsCancellationRequested)
                {
                    Updating = false;
                    break;
                }
                if (FirstLaunch)
                {
                    AtlasMgr.Log("[Atlas] No updates found, Booting servers if offline!");
                    FirstLaunch = false;
                    StartServers(AtlasMgr);
                }
                Thread.Sleep((int)(AtlasMgr.numServerUpdate.Value * 60000));
            }
        }