Beispiel #1
0
        public static void SaveRegConfig(AtlasServerManager ArkMgr)
        {
            try
            {
                key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\AtlasServerManager", true);
                if (key != null)
                {
                    /* BOOL */
                    key.SetValue("AutoServerUpdate", ArkMgr.checkAutoServerUpdate.Checked ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                    key.SetValue("AutoModUpdate", ArkMgr.checkAutoModUpdate.Checked ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                    key.SetValue("BootWhenOff", ArkMgr.checkBootWhenOff.Checked ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);

                    /* DECIMAL */
                    key.SetValue("ServerUpdate", ArkMgr.numServerUpdate.Value.ToString(), Microsoft.Win32.RegistryValueKind.String);
                    key.SetValue("ServerWarning", ArkMgr.numServerWarning.Value.ToString(), Microsoft.Win32.RegistryValueKind.String);
                    key.SetValue("AutoUpdateMod", ArkMgr.numAutoUpdateMod.Value.ToString(), Microsoft.Win32.RegistryValueKind.String);
                    key.SetValue("AutoUpdateModWarning", ArkMgr.numAutoUpdateModWarning.Value.ToString(), Microsoft.Win32.RegistryValueKind.String);
                    key.SetValue("ServerMonitor", ArkMgr.numServerMonitor.Value.ToString(), Microsoft.Win32.RegistryValueKind.String);

                    /* STRING */
                    key.SetValue("ServerDataPath", ArkMgr.ServerPath, Microsoft.Win32.RegistryValueKind.String);

                    SaveRegServers(ArkMgr);
                }
            }
            catch (Exception e) { System.Windows.Forms.MessageBox.Show("Failed To Save Setting: " + e.Message); }
        }
Beispiel #2
0
 private static void LoadRegServers(AtlasServerManager ArkMgr)
 {
     key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\AtlasServerManager\\Servers");
     if (key != null)
     {
         string[] Servers = key.GetSubKeyNames();
         foreach (string Srv in Servers)
         {
             if (Srv.StartsWith("Server"))
             {
                 AtlasServerData ASD = LoadRegServer(ArkMgr, Srv);
                 try
                 {
                     if (ASD.PID != 0)
                     {
                         ASD.ServerProcess = Process.GetProcessById(ASD.PID);
                     }
                 }
                 catch { ASD.PID = 0; }
                 ArkMgr.ServerList.Items.Add(new ArkServerListViewItem(ASD));
             }
         }
         key.Close();
     }
 }
Beispiel #3
0
        public static bool SaveRegServer(AtlasServerManager ArkMgr, AtlasServerData Asd, int ActIndex, bool DefaultServerSave = false, bool SaveLastOverride = false)
        {
            key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\AtlasServerManager\\Servers\\" + (DefaultServerSave ? (SaveLastOverride ? "LastSaved" : "Default") : "Server" + ActIndex), true);
            if (key == null)
            {
                key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\AtlasServerManager\\Servers\\" + (DefaultServerSave ? (SaveLastOverride ? "LastSaved" : "Default") : "Server" + ActIndex));
            }
            else if (DefaultServerSave && !SaveLastOverride)
            {
                return(true);
            }
            if (key != null)
            {
                /* BOOL */
                key.SetValue("Rcon", Asd.Rcon ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("WildWipe", Asd.WildWipe ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("PVP", Asd.PVP ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("MapB", Asd.MapB ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("Gamma", Asd.Gamma ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("Third", Asd.Third ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("Crosshair", Asd.Crosshair ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("HitMarker", Asd.HitMarker ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("Imprint", Asd.Imprint ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("FTD", Asd.FTD ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);

                if (Asd.ProcessAffinity == null)
                {
                    Asd.ProcessAffinity = new bool[Environment.ProcessorCount];
                    for (int i = 0; i < Environment.ProcessorCount; i++)
                    {
                        Asd.ProcessAffinity[i] = true;
                    }
                }

                for (int i = 0; i < Environment.ProcessorCount; i++)
                {
                    key.SetValue("ProcessAffinity" + i, Asd.ProcessAffinity[i] ? 1 : 0, Microsoft.Win32.RegistryValueKind.DWord);
                }

                /* INT */
                key.SetValue("ServerPort", Asd.ServerPort, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("QueryPort", Asd.QueryPort, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("RconPort", Asd.RconPort, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("MaxPlayers", Asd.MaxPlayers, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("ReservedPlayers", Asd.ReservedPlayers, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("ServerX", Asd.ServerX, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("ServerY", Asd.ServerY, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("PID", Asd.PID, Microsoft.Win32.RegistryValueKind.DWord);
                key.SetValue("ProcessPriority", Asd.ProcessPriority, Microsoft.Win32.RegistryValueKind.DWord);

                /* STRING */
                key.SetValue("Pass", Asd.Pass, Microsoft.Win32.RegistryValueKind.String);
                key.SetValue("CustomArgs", Asd.CustomArgs, Microsoft.Win32.RegistryValueKind.String);
                key.SetValue("ServerPath", Asd.ServerPath, Microsoft.Win32.RegistryValueKind.String);
                key.SetValue("AltSaveDirectory", Asd.AltSaveDirectory, Microsoft.Win32.RegistryValueKind.String);
                key.SetValue("ServerIp", Asd.ServerIp, Microsoft.Win32.RegistryValueKind.String);
                return(true);
            }
            return(false);
        }
 public int IsRunning(AtlasServerManager AtlasMgr)
 {
     if (ServerProcess == null || ServerProcess.HasExited || ServerProcess.Id == 0)
     {
         return(0);
     }
     if (AttemptRconSave && DateTime.Now.Subtract(RconSavedEstimate).TotalSeconds <= 0)
     {
         return(1);
     }
     if (HasMadeFirstContact && AtlasMgr != null)
     {
         if (AtlasMgr.QueryPortCheck.Checked && DateTime.Now.Subtract(LastSourceQueryReply).TotalSeconds > 60)
         {
             return(2);
         }
         bool bWasGamePortOpen = GamePortWasOpen;
         if (AtlasMgr.GamePortCheck.Checked && !CheckGamePort() && bWasGamePortOpen)
         {
             if (!AttemptRconSave)
             {
                 AttemptRconSave = true;
                 SourceRconTools.SendCommand("DoExit", this);
                 RconSavedEstimate = DateTime.Now.AddMinutes(1);
                 return(4);
             }
             AttemptRconSave = false;
             return(3);
         }
     }
     return(1);
 }
        public void InitStartServer(AtlasServerManager ArkMgr)
        {
            string ArkManagerPath = AtlasServerManager.GetInstance().ArkManagerPath;

            FinalServerPath = ServerPath;
            if (FinalServerPath[0] == '.' && (FinalServerPath[1] == '\\' || FinalServerPath[1] == '/'))
            {
                string[] BaseFolder = FinalServerPath.Replace(".\\", "").Replace("./", "").Split('/');
                if (BaseFolder.Length == 1)
                {
                    BaseFolder = BaseFolder[0].Split('\\');
                }
                if (BaseFolder.Length > 0)
                {
                    if (!Directory.Exists(ArkManagerPath + BaseFolder[0]))
                    {
                        Directory.CreateDirectory(ArkManagerPath + BaseFolder[0]);
                    }
                    FinalServerPath = FinalServerPath.Replace(".\\", ArkManagerPath).Replace("./", ArkManagerPath);
                }
                else
                {
                    FinalServerPath = ArkManagerPath + @".\AtlasServerData\";
                }
            }
            else if (!File.Exists(FinalServerPath))
            {
                MessageBox.Show(FinalServerPath + " Path not found!");
            }
        }
Beispiel #6
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);
     }
 }
 private static void SaveRegServers(AtlasServerManager AtlasMgr)
 {
     key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\AtlasServerManager\\Servers", true);
     if (key == null)
     {
         key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\AtlasServerManager\\Servers");
     }
     if (key != null)
     {
         int ActIndex = 0, CurActIndex;
         foreach (AtlasServerData Asd in AtlasMgr.ServerList.GetServerList())
         {
             if (SaveRegServer(Asd, ActIndex))
             {
                 ActIndex++;
             }
         }
         foreach (string s in key.GetSubKeyNames())
         {
             if ((s.Contains("Server")) && int.TryParse(s.Replace("Server", ""), out CurActIndex) && CurActIndex > ActIndex)
             {
                 key.DeleteSubKey("Server" + CurActIndex);
             }
         }
         key.Close();
     }
 }
Beispiel #8
0
 public static void Start(AtlasServerManager form1)
 {
     Workers = new Thread[(int)WorkerType.Max];
     AddWorker(WorkerType.StatusUdpdate, new ParameterizedThreadStart(ArkServerStatusUpdate.UpdateStatus), form1);
     AddWorker(WorkerType.ServerStatusCheck, new ParameterizedThreadStart(ArkServerMonitor.CheckServerStatus), form1);
     AddWorker(WorkerType.ServerUpdateCheck, new ParameterizedThreadStart(ArkServerUpdater.CheckForUpdates), form1);
 }
Beispiel #9
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);
            }
        }
Beispiel #11
0
        private static void UpdateAtlas(AtlasServerManager AtlasMgr, string UpdateVersion)
        {
            AtlasMgr.FirstDl = false;

            if (AtlasMgr.DebugCheck.Checked)
            {
                AtlasMgr.Log("[Atlas->Debug] " + UpdatePaths.Count + " Update Paths found");
            }
            foreach (string UpdatePath in UpdatePaths)
            {
                AtlasMgr.Log("[Atlas] Updating Path: " + UpdatePath);
                UpdateProcess = new Process()
                {
                    StartInfo = new ProcessStartInfo(AtlasMgr.SteamPath + "steamcmd.exe", "+@NoPromptForPassword 1 +@sSteamCmdForcePlatformType windows +login anonymous +force_install_dir \"" + UpdatePath + "\" +app_update 1006030 validate +quit")
                    {
                        UseShellExecute        = false,
                        RedirectStandardOutput = !AtlasMgr.SteamWindowCheck.Checked,
                        CreateNoWindow         = !AtlasMgr.SteamWindowCheck.Checked,
                        WorkingDirectory       = AtlasMgr.SteamPath
                    }
                };

                if (!AtlasMgr.SteamWindowCheck.Checked)
                {
                    UpdateProcess.OutputDataReceived += (s, e) => UpdateData(e.Data);
                }
                UpdateProcess.Start();
                if (!AtlasMgr.SteamWindowCheck.Checked)
                {
                    UpdateProcess.BeginOutputReadLine();
                }
                UpdateProcess.WaitForExit();
            }
            UpdatePaths.Clear();
        }
Beispiel #12
0
        public static void RestoreConfigs(AtlasServerManager AtlasMgr, string UpdatePath)
        {
            if (!AtlasMgr.ConfigReplaceCheck.Checked)
            {
                return;
            }

            string BackupPath = Path.Combine(UpdatePath + Path.DirectorySeparatorChar, @"ConfigRestore\");

            if (Directory.Exists(BackupPath))
            {
                string   FilesPath = Path.Combine(UpdatePath + Path.DirectorySeparatorChar, @"ShooterGame\Config\");
                string[] Files     = Directory.GetFiles(BackupPath, "*.ini", SearchOption.TopDirectoryOnly);
                foreach (string file in Files)
                {
                    File.Copy(file, FilesPath + Path.GetFileName(file), true);
                }

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

                Files = Directory.GetFiles(BackupPath, "*.conf", SearchOption.TopDirectoryOnly);
                foreach (string file in Files)
                {
                    File.Copy(file, FilesPath + Path.GetFileName(file), true);
                }
            }
        }
Beispiel #13
0
 public static void DestroyAndRecreateThread(AtlasServerManager form1, WorkerType ThreadIndex)
 {
     if (Workers[(int)ThreadIndex] != null)
     {
         Workers[(int)ThreadIndex].Abort();
     }
     AddWorker(ThreadIndex, new ParameterizedThreadStart(ArkServerStatusUpdate.UpdateStatus), form1);
 }
        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);
            }
        }
Beispiel #15
0
 public static void Init(AtlasServerManager AtlasMgr, bool StartUpdateCheck)
 {
     AddWorker(WorkerType.StatusUpdate, AtlasMgr);
     AddWorker(WorkerType.ServerMonitor, AtlasMgr);
     if (StartUpdateCheck)
     {
         AddWorker(WorkerType.ServerUpdate, AtlasMgr);
     }
 }
Beispiel #16
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);
        }
Beispiel #17
0
 private static void StartServers(AtlasServerManager ArkMgr)
 {
     ArkMgr.Invoke((System.Windows.Forms.MethodInvoker) delegate()
     {
         foreach (ArkServerListViewItem ASLVI in ArkMgr.ServerList.Items)
         {
             ASLVI.GetServerData().StartServer();
         }
     });
 }
        public static void UpdateStatus(AtlasServerManager AtlasMgr, CancellationToken token)
        {
            PerformanceCounter cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total"), MemA = new PerformanceCounter("Memory", "Available KBytes");

            int    Players = 0, TotalPlayers = 0;
            double AMem = 0;

            GetPhysicallyInstalledSystemMemory(out TotalMemA);
            TotalMem = TotalMemA / 1048576;
            while (true)
            {
                if (token.IsCancellationRequested)
                {
                    break;
                }
                try
                {
                    cpu.NextValue();
                    AtlasMgr.Invoke((MethodInvoker) delegate()
                    {
                        if (AtlasMgr.ServerList.Items.Count > 0)
                        {
                            foreach (ArkServerListViewItem ASD in AtlasMgr.ServerList.Items)
                            {
                                if (ASD.GetServerData().IsRunning())
                                {
                                    ASD.GetServerData().GetPlayersOnline(AtlasMgr, ASD);
                                }
                            }
                        }
                    });

                    Thread.Sleep(3000);
                    AMem = (TotalMemA - MemA.NextValue()) / 1048576;
                    AtlasMgr.Invoke((MethodInvoker) delegate()
                    {
                        if (AtlasMgr.ServerList.Items.Count > 0)
                        {
                            foreach (ArkServerListViewItem ASD in AtlasMgr.ServerList.Items)
                            {
                                int.TryParse(ASD.SubItems[5].Text, out Players);
                                TotalPlayers += Players;
                                ASD.UpdateStatus();
                            }
                        }
                    });
                    AtlasMgr.Text = AtlasMgr.ASMTitle + " | CPU: " + (int)cpu.NextValue() + "%, Mem: " + AMem.ToString("#.##") + " GB / " + TotalMem + " GB - Players Online: " + TotalPlayers;
                    TotalPlayers  = 0;
                    Thread.Sleep(2000);
                }
                catch
                {
                }
            }
        }
Beispiel #19
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!");
        }
Beispiel #20
0
 private static void UpdateData(string input)
 {
     if (input != null && input.Length > 1)
     {
         if (input.Contains("Error! App "))
         {
             UpdateError = true;
         }
         AtlasServerManager.GetInstance().Log("[Update]" + input);
     }
 }
Beispiel #21
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);
            }
        }
Beispiel #22
0
        public static AtlasServerData LoadRegServer(AtlasServerManager ArkMgr, string Srv)
        {
            AtlasServerData Asd = new AtlasServerData();

            key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\AtlasServerManager\\Servers\\" + Srv);
            if (key != null)
            {
                /* BOOL */
                Asd.Rcon      = (int)key.GetValue("Rcon", Asd.Rcon ? 1 : 0) == 1 ? true : false;
                Asd.WildWipe  = (int)key.GetValue("WildWipe", Asd.WildWipe ? 1 : 0) == 1 ? true : false;
                Asd.PVP       = (int)key.GetValue("PVP", Asd.PVP ? 1 : 0) == 1 ? true : false;
                Asd.MapB      = (int)key.GetValue("MapB", Asd.MapB ? 1 : 0) == 1 ? true : false;
                Asd.Gamma     = (int)key.GetValue("Gamma", Asd.Gamma ? 1 : 0) == 1 ? true : false;
                Asd.Third     = (int)key.GetValue("Third", Asd.Third ? 1 : 0) == 1 ? true : false;
                Asd.Crosshair = (int)key.GetValue("Crosshair", Asd.Crosshair ? 1 : 0) == 1 ? true : false;
                Asd.HitMarker = (int)key.GetValue("HitMarker", Asd.HitMarker ? 1 : 0) == 1 ? true : false;
                Asd.Imprint   = (int)key.GetValue("Imprint", Asd.Imprint ? 1 : 0) == 1 ? true : false;
                Asd.FTD       = (int)key.GetValue("FTD", Asd.FTD ? 1 : 0) == 1 ? true : false;

                Asd.ProcessAffinity = new bool[Environment.ProcessorCount];
                for (int i = 0; i < Environment.ProcessorCount; i++)
                {
                    Asd.ProcessAffinity[i] = (int)key.GetValue("ProcessAffinity" + i, 1) == 1 ? true : false;
                }

                /* INT */
                Asd.ServerPort      = (int)key.GetValue("ServerPort", Asd.ServerPort);
                Asd.QueryPort       = (int)key.GetValue("QueryPort", Asd.QueryPort);
                Asd.RconPort        = (int)key.GetValue("RconPort", Asd.RconPort);
                Asd.MaxPlayers      = (int)key.GetValue("MaxPlayers", Asd.MaxPlayers);
                Asd.ReservedPlayers = (int)key.GetValue("ReservedPlayers", Asd.ReservedPlayers);
                Asd.ServerX         = (int)key.GetValue("ServerX", Asd.ServerX);
                Asd.ServerY         = (int)key.GetValue("ServerY", Asd.ServerY);
                Asd.PID             = (int)key.GetValue("PID", Asd.PID);
                Asd.ProcessPriority = (int)key.GetValue("ProcessPriority", 0);

                /* STRING */
                Asd.Pass             = (string)key.GetValue("Pass", Asd.Pass);
                Asd.CustomArgs       = (string)key.GetValue("CustomArgs", Asd.CustomArgs);
                Asd.ServerPath       = (string)key.GetValue("ServerPath", Asd.ServerPath);
                Asd.AltSaveDirectory = (string)key.GetValue("AltSaveDirectory", Asd.AltSaveDirectory);
                Asd.FinalServerPath  = string.Empty;
                Asd.ServerIp         = (string)key.GetValue("ServerIp", Asd.ServerIp);
                Asd.Loaded           = true;
            }
            else
            {
                Asd.Loaded = false;
            }
            return(Asd);
        }
 public void GetPlayersOnline(AtlasServerManager ArkMgr, ArkServerListViewItem server)
 {
     new SourceQuery(ServerIp, QueryPort, (SourceQuery.ServerData SrvData) =>
     {
         ArkMgr.Invoke((MethodInvoker) delegate()
         {
             if (server != null)
             {
                 server.SubItems[4].Text = SrvData.Players.ToString();
                 HasMadeFirstContact     = true;
                 LastSourceQueryReply    = DateTime.Now;
             }
         });
     }).Dispose();
 }
Beispiel #24
0
 private static int GetAtlasServerBuildID(AtlasServerManager AtlasMgr)
 {
     try
     {
         if (!Directory.Exists(AtlasMgr.SteamPath))
         {
             Directory.CreateDirectory(AtlasMgr.SteamPath);
         }
         if (!File.Exists(AtlasMgr.SteamPath + "steamcmd.exe"))
         {
             File.WriteAllBytes(AtlasMgr.SteamPath + "steamcmd.exe", Properties.Resources.steamcmd);
         }
         UpdateProcess = new Process()
         {
             StartInfo = new ProcessStartInfo("cmd.exe", "/c steamcmd +@NoPromptForPassword 1 +@sSteamCmdForcePlatformType windows +login anonymous +app_info_update 1 +app_info_print 1006030 +app_info_print 1006030 +app_info_print 1006030 +quit > \"" + AtlasMgr.SteamPath + "CurrentVersion.dat\"")
             {
                 UseShellExecute  = false,
                 CreateNoWindow   = true,
                 WorkingDirectory = AtlasMgr.SteamPath
             }
         };
         UpdateProcess.Start();
         UpdateProcess.WaitForExit();
         if (File.Exists(AtlasMgr.SteamPath + "CurrentVersion.dat"))
         {
             using (StreamReader Sr = new StreamReader(AtlasMgr.SteamPath + "CurrentVersion.dat"))
             {
                 string output     = Sr.ReadToEnd();
                 int    Version    = 0;
                 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);
                     }
                 }
                 return(Version);
             }
         }
         AtlasMgr.Log("[Update] Failed to get latest Version Trying again shortly...");
         Thread.Sleep(5000);
     }
     catch { AtlasMgr.Log("[Update] Failed Checking For Updates..."); }
     return(0);
 }
        public static void LoadRegConfig(AtlasServerManager AtlasMgr)
        {
            try
            {
                key = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\AtlasServerManager", true);
                if (key == null)
                {
                    key = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\AtlasServerManager");
                }

                if (key != null)
                {
                    for (int i = 0; i < AtlasMgr.ServerList.Columns.Count; i++)
                    {
                        AtlasMgr.ServerList.Columns[i].DisplayIndex = (int)key.GetValue("ColOrder" + i, i);
                        AtlasMgr.ServerList.Columns[i].Width        = (int)key.GetValue("ColWidth" + i, AtlasMgr.ServerList.Columns[i].Width);
                    }
                    /* BOOL */
                    AtlasMgr.checkAutoServerUpdate.Checked = (int)key.GetValue("AutoServerUpdate", 1) == 1 ? true : false;
                    AtlasMgr.BootWhenOffCheck.Checked      = (int)key.GetValue("BootWhenOff", 1) == 1 ? true : false;
                    AtlasMgr.QueryPortCheck.Checked        = (int)key.GetValue("QueryPortCheck", 1) == 1 ? true : false;
                    AtlasMgr.GamePortCheck.Checked         = (int)key.GetValue("GamePortCheck", 1) == 1 ? true : false;
                    AtlasMgr.SteamWindowCheck.Checked      = (int)key.GetValue("ShowSteamWindow", 0) == 1 ? true : false;
                    AtlasMgr.ConfigReplaceCheck.Checked    = (int)key.GetValue("ConfigReplacer", 1) == 1 ? true : false;

                    /* DECIMAL */
                    decimal value = 1.0M;
                    decimal.TryParse((string)key.GetValue("ServerUpdate", AtlasMgr.numServerUpdate.Value.ToString()), out value);
                    AtlasMgr.numServerUpdate.Value = value;
                    decimal.TryParse((string)key.GetValue("ServerWarning", AtlasMgr.numServerWarning.Value.ToString()), out value);
                    AtlasMgr.numServerWarning.Value = value;
                    decimal.TryParse((string)key.GetValue("ServerMonitor", AtlasMgr.numServerMonitor.Value.ToString()), out value);
                    AtlasMgr.numServerMonitor.Value = value;
                    decimal.TryParse((string)key.GetValue("StartupDelay", "0"), out value);
                    AtlasMgr.StartupDelayNum.Value = value;

                    /* STRING */
                    AtlasMgr.ServerPath = (string)key.GetValue("ServerDataPath", string.Empty);
                    AtlasMgr.ServerUpdateMessage.Text   = (string)key.GetValue("ServerUpdateMessage", AtlasMgr.ServerUpdateMessage.Text);
                    AtlasMgr.ServerUpdatingMessage.Text = (string)key.GetValue("ServerUpdatingMessage", AtlasMgr.ServerUpdatingMessage.Text);

                    LoadRegServers(AtlasMgr);
                }
            }
            catch (Exception e) { System.Windows.Forms.MessageBox.Show("Failed To Load Setting: " + e.StackTrace); }
        }
Beispiel #26
0
        public static void UpdateStatus(object Data)
        {
            AtlasServerManager form1 = (AtlasServerManager)Data;

            PerformanceCounter cpu = new PerformanceCounter("Processor", "% Processor Time", "_Total"), MemA = new PerformanceCounter("Memory", "Available KBytes"), perfCounter = new PerformanceCounter("Process", "% Processor Time", "ShooterGameServer"), MemB = new PerformanceCounter("Memory", "Available KBytes", "ShooterGameServer");

            double AMem;

            GetPhysicallyInstalledSystemMemory(out TotalMemA);
            TotalMem = (TotalMemA / 1048576);
            while (true)
            {
                bool CountPlayers = CountPlayerTick++ >= 3;
                cpu.NextValue();
                Thread.Sleep(5000);
                AMem = ((TotalMemA - MemA.NextValue()) / 1048576);
                form1.Invoke((MethodInvoker) delegate()
                {
                    form1.Text = "Atlas Server Manager | CPU: " + (int)cpu.NextValue() + "%, Mem: " + AMem.ToString("#.##") + " GB / " + TotalMem + " GB";
                    if (form1.ServerList.Items.Count > 0)
                    {
                        try
                        {
                            foreach (ArkServerListViewItem ASD in form1.ServerList.Items)
                            {
                                if (ASD.GetServerData().IsRunning())
                                {
                                    ASD.SubItems[5].Text = GetCPUPercentByID(perfCounter, ASD.GetServerData().ServerProcess.Id);
                                    if (CountPlayers)
                                    {
                                        ASD.GetServerData().GetPlayersOnline(form1, ASD);
                                    }
                                }
                            }
                        }
                        catch
                        {
                        }
                    }
                });
                if (CountPlayers)
                {
                    CountPlayerTick = 0;
                }
            }
        }
Beispiel #27
0
 public static bool SendCommand(string Command, Includes.ArkServerListViewItem ASLVI)
 {
     try
     {
         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))
         {
             return(false);
         }
         ASLVI.GetServerData().RconConnection.ServerCommand(Command);
         return(true);
     }
     catch (Exception e)
     {
         AtlasServerManager.GetInstance().Log("[Rcon->BroadCastMessage] Connection failed: " + e.Message);
         return(false);
     }
 }
Beispiel #28
0
 public static bool SendCommand(string Command, AtlasServerData ASD)
 {
     try
     {
         if (!ConnectToRcon(ASD.RconConnection, ASD.RCONIP == string.Empty ? ASD.ServerIp : ASD.RCONIP, ASD.RconPort, ASD.Pass, ASD.AltSaveDirectory))
         {
             return(false);
         }
         ASD.RconConnection.ServerCommand(Command);
         return(true);
     }
     catch (Exception e)
     {
         AtlasServerManager.GetInstance().Log("[Rcon->BroadCastMessage] Connection failed: " + e.Message + ", " + ASD.RCONIP == string.Empty ? ASD.ServerIp : ASD.RCONIP);
         return(false);
     }
 }
Beispiel #29
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);
        }
Beispiel #30
0
 public static bool AddUPNPServer(int ServerPort, int QueryPort, string AltSaveDir)
 {
     Init();
     if (UpnpMap == null)
     {
         AtlasServerManager.GetInstance().Log("[Auto Port Forwarding] UPNP Does not seeem enabled at the router admins interface");
         return(false);
     }
     foreach (IStaticPortMapping EMaps in UpnpMap)
     {
         if (EMaps.ExternalPort == ServerPort || EMaps.ExternalPort == QueryPort)
         {
             return(false);
         }
     }
     UpnpMap.Add(ServerPort, "UDP", ServerPort, LocalIPAddress, true, "Atlas Server: " + AltSaveDir);
     UpnpMap.Add(QueryPort, "UDP", QueryPort, LocalIPAddress, true, "Atlas Query: " + AltSaveDir);
     return(true);
 }