public static void DetectServers(bool Inital = false) { var serverProcesses = Process.GetProcessesByName("h2Server"); if (Inital) { MainThread.WriteLine($"Servers Detected:\t{serverProcesses.Length}"); if (serverProcesses.Length > 0) { ExecutionPath = serverProcesses[0].MainModule?.FileName.Replace("\\h2server.exe", "") .Replace("\\H2Server.exe", ""); MainThread.WriteLine($"Server Launch Path:\t{ExecutionPath}"); MainThread.WriteLine($"Server Playlist Folder:\t{PlaylistFolder}"); } } else { for (var i = 0; i < Servers.Count; i++) { if (Servers[i].ServerProcess.HasExited) { if (!Servers[i].AutoRestart) { MainThread.WriteLine($"{Servers[i].FormattedName} has closed detaching.."); Servers[i].KillConsoleProxy(); Servers.RemoveAt(i); } else { MainThread.WriteLine($"{Servers[i].FormattedName} has closed restarting service.."); var Service = new ServiceController(Servers[i].ServiceName); if (Service.Status != ServiceControllerStatus.Stopped) { Service.Stop(); Servers[i].ServerProcess.Kill(); } Service.Start(); Servers[i].KillConsoleProxy(); Servers.RemoveAt(i); } } } } for (var i = 0; i < serverProcesses.Length; i++) { if (!Servers.ServerCollected(serverProcesses[i])) { MainThread.WriteLine($"Attaching To Server..."); var newServer = new ServerContainer(serverProcesses[i]); newServer.Index = i; if (newServer.isLive) { MainThread.WriteLine($"Attached to: {newServer.FormattedName}"); MainThread.WriteLine($"Service Name: {newServer.ServiceName}"); newServer.LaunchConsoleProxy(); Servers.Add(newServer); } else { MainThread.WriteLine( $"Skipping LAN Server: {newServer.FormattedName}"); } } } }