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"); } }