예제 #1
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);
     }
 }
예제 #2
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);
     }
 }
예제 #3
0
        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!");
            }
        }
예제 #4
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);
     }
 }
예제 #5
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);
     }
 }
예제 #6
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);
     }
 }
예제 #7
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);
        }
예제 #8
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);
 }
예제 #9
0
 public static bool ConnectToRcon(SourceRcon Sr, string IP, int Port, string Pass, string ServerName)
 {
     if (Sr != null && !Sr.Connected)
     {
         int DotCount = 0;
         for (int i = 0; i < IP.Length; i++)
         {
             if (IP[i] == '.')
             {
                 DotCount++;
             }
         }
         if (DotCount != 3)
         {
             IPAddress[] ips = Dns.GetHostAddresses(IP);
             if (ips.Length > 0)
             {
                 IP = ips[0].ToString();
             }
         }
         if (IPAddress.TryParse(IP, out IPAddress iP))
         {
             bool Connect = Sr.Connect(new IPEndPoint(iP, Port), Pass);
             int  Counter = 0;
             while (!Sr.Connected)
             {
                 Thread.Sleep(100);
                 if (Counter++ > 3)
                 {
                     AtlasServerManager.GetInstance().Log("[Rcon->ConnectToRcon] " + ServerName + " Something is wrong with connection");
                     return(false);
                 }
                 else if (Sr.Connected)
                 {
                     break;
                 }
             }
         }
     }
     return(true);
 }
예제 #10
0
 private static void UpdateData(string input)
 {
     if (input != null && input.Length > 1)
     {
         if (input.Contains("Error! App "))
         {
             UpdateErrorText = input;
             UpdateError     = true;
         }
         if (input.Contains("progress: "))
         {
             string PercentText = Regex.Split(input, "progress: ")[1];
             PercentText = PercentText.Substring(0, PercentText.IndexOf(' '));
             string[] splts = input.Split('(');
             if (splts.Length == 3 && splts[2].Contains("/"))
             {
                 splts = Regex.Split(splts[2].Replace(")", ""), " / ");
                 if (splts.Length == 2)
                 {
                     if (splts[0] != "0" && splts[1] != "0")
                     {
                         DownloadSizeBytes  = ulong.Parse(splts[1]);
                         DownloadSizeString = FormatBytes((long)DownloadSizeBytes);
                         input = input.Replace(splts[0], FormatBytes(long.Parse(splts[0]))).Replace(splts[1], DownloadSizeString);
                     }
                     else if (splts[1] != "0")
                     {
                         DownloadSizeBytes  = ulong.Parse(splts[1]);
                         DownloadSizeString = FormatBytes((long)DownloadSizeBytes);
                         input = input.Replace(splts[1], DownloadSizeString);
                     }
                 }
             }
         }
         AtlasServerManager.GetInstance().Log("[Update]" + input);
     }
 }
예제 #11
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);
        }
예제 #12
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));
            }
        }
예제 #13
0
        // bool hadjunkpacket;

        internal void OnServerOutput(string output)
        {
            AtlasServerManager.GetInstance().Log("[RCON] " + output);
        }
예제 #14
0
        public void StartServer()
        {
            HasMadeFirstContact = false;
            string ExePath = ServerPath.TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Replace("/", @"\");

            if (ExePath.StartsWith("./") || ExePath.StartsWith(@".\"))
            {
                string tempEndDir = ExePath.Replace("./", "").Replace(@".\", "");
                ExePath = Path.GetDirectoryName(Application.ExecutablePath).TrimEnd(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar).Replace("/", @"\") + Path.DirectorySeparatorChar;
                if (tempEndDir.Length > 0)
                {
                    ExePath = Path.Combine(ExePath, tempEndDir);
                }
            }

            if (!ExePath.Contains(".") || !File.Exists(ExePath))
            {
                if (File.Exists(Path.Combine(ExePath + Path.DirectorySeparatorChar, "ShooterGameServer.exe")))
                {
                    ExePath = Path.Combine(ExePath + Path.DirectorySeparatorChar, @"ShooterGameServer.exe");
                }
                else if (File.Exists(Path.Combine(ExePath + Path.DirectorySeparatorChar, @"ShooterGame\Binaries\Win64\ShooterGameServer.exe")))
                {
                    ExePath = Path.Combine(ExePath + Path.DirectorySeparatorChar, @"ShooterGame\Binaries\Win64\ShooterGameServer.exe");
                }
                else if (File.Exists(Path.Combine(ExePath + Path.DirectorySeparatorChar, @"Binaries\Win64\ShooterGameServer.exe")))
                {
                    ExePath = Path.Combine(ExePath + Path.DirectorySeparatorChar, @"Binaries\Win64\ShooterGameServer.exe");
                }
                else if (File.Exists(Path.Combine(ExePath + Path.DirectorySeparatorChar, @"Win64\ShooterGameServer.exe")))
                {
                    ExePath = Path.Combine(ExePath + Path.DirectorySeparatorChar, @"Win64\ShooterGameServer.exe");
                }
            }

            if (!File.Exists(ExePath))
            {
                MessageBox.Show(ExePath + " Is Not found!!!", "ShooterGameServer.exe Not Found!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (IsRunning())
            {
                StopServer();
            }
            ServerPath      = ExePath.Substring(0, ExePath.IndexOf(@"\ShooterGame"));
            GamePortWasOpen = false;

            Backup.RestoreConfigs(AtlasServerManager.GetInstance(), ServerPath);

            /* Resolve DNS */
            string CurIP = ServerIp;

            if (CurIP != string.Empty)
            {
                int DotCount = 0;
                for (int i = 0; i < CurIP.Length; i++)
                {
                    if (CurIP[i] == '.')
                    {
                        DotCount++;
                    }
                }
                if (DotCount != 3)
                {
                    System.Net.IPAddress[] ips = System.Net.Dns.GetHostAddresses(CurIP);
                    if (ips.Length > 0)
                    {
                        CurIP = ips[0].ToString();
                        try
                        {
                            string ServerGrid = Path.Combine(ServerPath + Path.DirectorySeparatorChar, @"ShooterGame\ServerGrid.json");
                            if (File.Exists(ServerGrid))
                            {
                                string OwnProxGrid = Path.Combine(ServerPath + Path.DirectorySeparatorChar, @"ShooterGame\ServerGridOwnProx.json");
                                if (File.Exists(OwnProxGrid))
                                {
                                    File.Delete(OwnProxGrid);
                                }
                                using (StreamWriter sw = new StreamWriter(OwnProxGrid))
                                    using (StreamReader sr = new StreamReader(ServerGrid))
                                    {
                                        string line = "";
                                        while ((line = sr.ReadLine()) != null)
                                        {
                                            if (line.Contains("\"ip\": \""))
                                            {
                                                sw.WriteLine("      \"ip\": \"" + CurIP + "\",");
                                            }
                                            else
                                            {
                                                sw.WriteLine(line);
                                            }
                                        }
                                    }
                                File.Delete(ServerGrid);
                                File.Move(OwnProxGrid, ServerGrid);
                            }
                        }
                        catch (Exception e) { MessageBox.Show("Error: " + e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
                    }
                }
            }

            if (Upnp)
            {
                UPNP.AddUPNPServer(ServerPort, QueryPort, AltSaveDirectory);
            }

            try
            {
                ServerProcess = new Process
                {
                    StartInfo = new ProcessStartInfo(ExePath, "\"" + "Ocean?ServerX=" + ServerX + "?ServerY=" + ServerY + "?Port=" + ServerPort + "?QueryPort=" + QueryPort + "?AltSaveDirectoryName=" + AltSaveDirectory + "?MaxPlayers=" + MaxPlayers + "?ReservedPlayerSlots=" + ReservedPlayers + "?ServerAdminPassword="******"?ServerCrosshair=" + (Crosshair ? "true" : "false") + "?AllowThirdPersonPlayer=" + (Third ? "true" : "false") + "?MapPlayerLocation=" + (MapB ? "true" : "false") + "?serverPVE=" + (!PVP ? "true" : "false") + "?RCONEnabled=" + (Rcon ? ("true?RCONPort=" + RconPort) : "false") + "?EnablePvPGamma=" + (Gamma ? "true" : "false") + "?AllowAnyoneBabyImprintCuddle=" + (Imprint ? "true" : "false") + "?ShowFloatingDamageText=" + FTD + (CurIP == string.Empty ? "" : "?SeamlessIP=" + CurIP) + CustomArgs + "\" -game -server -log -NoCrashDialog" + (BattleEye ? "" : " -NoBattlEye") + (CustomAfterArgs == string.Empty ? "" : " " + CustomAfterArgs))
                    {
                        UseShellExecute  = false,
                        WorkingDirectory = Path.GetDirectoryName(ExePath)
                    }
                };

                ServerProcess.Start();
                int AffinityMask = 0;
                for (int i = 0; i < ProcessAffinity.Length; i++)
                {
                    AffinityMask |= (ProcessAffinity[i] ? 1 : 0) << i;
                }
                ServerProcess.ProcessorAffinity = (System.IntPtr)AffinityMask;
                switch (ProcessPriority)
                {
                case 1:
                    ServerProcess.PriorityClass = ProcessPriorityClass.AboveNormal;
                    break;

                case 2:
                    ServerProcess.PriorityClass = ProcessPriorityClass.High;
                    break;

                case 3:
                    ServerProcess.PriorityClass = ProcessPriorityClass.RealTime;
                    break;

                default:
                    ServerProcess.PriorityClass = ProcessPriorityClass.Normal;
                    break;
                }
                PID = ServerProcess.Id;
            }
            catch (Exception e)
            {
                ServerProcess = null;
                MessageBox.Show(e.Message + ": " + ExePath, "Error");
            }
        }