From dd6a6a3c3a134482955935467e1c9ebca46d5427 Mon Sep 17 00:00:00 2001 From: Battlefield Duck Date: Sat, 14 Dec 2019 03:30:00 +0800 Subject: [PATCH] v1.4.1 - Fixed #4 - Fixed Rust server Windows Firewall bug - Fixed workshop map bug --- .gitignore | 3 ++ WindowsGSM/GameServer/CS.cs | 2 +- WindowsGSM/GameServer/CSCZ.cs | 2 +- WindowsGSM/GameServer/CSGO.cs | 2 +- WindowsGSM/GameServer/Check/CrashDetection.cs | 40 -------------- WindowsGSM/GameServer/GMOD.cs | 2 +- WindowsGSM/GameServer/HL2DM.cs | 2 +- WindowsGSM/GameServer/L4D2.cs | 2 +- WindowsGSM/GameServer/RUST.cs | 4 +- WindowsGSM/GameServer/TF2.cs | 2 +- WindowsGSM/MainWindow.xaml.cs | 52 ++++++++----------- WindowsGSM/Properties/AssemblyInfo.cs | 4 +- WindowsGSM/WindowsGSM.csproj | 1 - 13 files changed, 36 insertions(+), 82 deletions(-) create mode 100644 .gitignore delete mode 100644 WindowsGSM/GameServer/Check/CrashDetection.cs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95f8041 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vs +WindowsGSM/bin/ +WindowsGSM/obj/ \ No newline at end of file diff --git a/WindowsGSM/GameServer/CS.cs b/WindowsGSM/GameServer/CS.cs index 92aaf83..d5b8d50 100644 --- a/WindowsGSM/GameServer/CS.cs +++ b/WindowsGSM/GameServer/CS.cs @@ -60,10 +60,10 @@ public void SetParameter(string ip, string port, string map, string maxplayers, Param = "-console -game cstrike"; Param += String.Format("{0}", String.IsNullOrEmpty(ip) ? "" : $" -ip {ip}"); Param += String.Format("{0}", String.IsNullOrEmpty(port) ? "" : $" -port {port}"); - Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); Param += String.Format("{0}", String.IsNullOrEmpty(maxplayers) ? "" : $" -maxplayers {maxplayers}"); Param += String.Format("{0}", String.IsNullOrEmpty(gslt) ? "" : $" +sv_setsteamaccount {gslt}"); Param += String.Format("{0}", String.IsNullOrEmpty(additional) ? "" : $" {additional}"); + Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); } public (Process Process, string Error, string Notice) Start() diff --git a/WindowsGSM/GameServer/CSCZ.cs b/WindowsGSM/GameServer/CSCZ.cs index 680ee94..77fdd73 100644 --- a/WindowsGSM/GameServer/CSCZ.cs +++ b/WindowsGSM/GameServer/CSCZ.cs @@ -57,10 +57,10 @@ public void SetParameter(string ip, string port, string map, string maxplayers, Param = "-console -game czero"; Param += String.Format("{0}", String.IsNullOrEmpty(ip) ? "" : $" -ip {ip}"); Param += String.Format("{0}", String.IsNullOrEmpty(port) ? "" : $" -port {port}"); - Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); Param += String.Format("{0}", String.IsNullOrEmpty(maxplayers) ? "" : $" -maxplayers {maxplayers}"); Param += String.Format("{0}", String.IsNullOrEmpty(gslt) ? "" : $" +sv_setsteamaccount {gslt}"); Param += String.Format("{0}", String.IsNullOrEmpty(additional) ? "" : $" {additional}"); + Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); } public (Process Process, string Error, string Notice) Start() diff --git a/WindowsGSM/GameServer/CSGO.cs b/WindowsGSM/GameServer/CSGO.cs index 75f51d3..e7d798b 100644 --- a/WindowsGSM/GameServer/CSGO.cs +++ b/WindowsGSM/GameServer/CSGO.cs @@ -55,10 +55,10 @@ public void SetParameter(string ip, string port, string map, string maxplayers, Param = "-console -game csgo"; Param += String.Format("{0}", String.IsNullOrEmpty(ip) ? "" : $" -ip {ip}"); Param += String.Format("{0}", String.IsNullOrEmpty(port) ? "" : $" -port {port}"); - Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); Param += String.Format("{0}", String.IsNullOrEmpty(maxplayers) ? "" : $" -maxplayers_override {maxplayers}"); Param += String.Format("{0}", String.IsNullOrEmpty(gslt) ? "" : $" +sv_setsteamaccount {gslt}"); Param += String.Format("{0}", String.IsNullOrEmpty(additional) ? "" : $" {additional}"); + Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); } public (Process Process, string Error, string Notice) Start() diff --git a/WindowsGSM/GameServer/Check/CrashDetection.cs b/WindowsGSM/GameServer/Check/CrashDetection.cs deleted file mode 100644 index fcf9114..0000000 --- a/WindowsGSM/GameServer/Check/CrashDetection.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Threading.Tasks; -using System.Diagnostics; - -namespace WindowsGSM.GameServer.Check -{ - class CrashDetection - { - public async Task IsServerCrashed(Process process, string serverGame) - { - int exitCode; - switch (serverGame) - { - case (GameServer.CSGO.FullName): - case (GameServer.GMOD.FullName): - case (GameServer.TF2.FullName): - case (GameServer.MCPE.FullName): - case (GameServer.CS.FullName): - case (GameServer.CSCZ.FullName): - case (GameServer.HL2DM.FullName): - case (GameServer.L4D2.FullName): - exitCode = 0; break; - case (GameServer.RUST.FullName): - exitCode = -1; break; - default: return false; - } - - while (process != null) - { - if (process.HasExited) - { - return (process.ExitCode != exitCode); - } - - await Task.Delay(1000); - } - - return false; - } - } -} diff --git a/WindowsGSM/GameServer/GMOD.cs b/WindowsGSM/GameServer/GMOD.cs index f711018..1f99ceb 100644 --- a/WindowsGSM/GameServer/GMOD.cs +++ b/WindowsGSM/GameServer/GMOD.cs @@ -53,10 +53,10 @@ public void SetParameter(string ip, string port, string map, string maxplayers, Param = "-console -game garrysmod"; Param += String.Format("{0}", String.IsNullOrEmpty(ip) ? "" : $" -ip {ip}"); Param += String.Format("{0}", String.IsNullOrEmpty(port) ? "" : $" -port {port}"); - Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); Param += String.Format("{0}", String.IsNullOrEmpty(maxplayers) ? "" : $" -maxplayers {maxplayers}"); Param += String.Format("{0}", String.IsNullOrEmpty(gslt) ? "" : $" +sv_setsteamaccount {gslt}"); Param += String.Format("{0}", String.IsNullOrEmpty(additional) ? "" : $" {additional}"); + Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); } public (Process Process, string Error, string Notice) Start() diff --git a/WindowsGSM/GameServer/HL2DM.cs b/WindowsGSM/GameServer/HL2DM.cs index 29a0f12..1d7b1f8 100644 --- a/WindowsGSM/GameServer/HL2DM.cs +++ b/WindowsGSM/GameServer/HL2DM.cs @@ -49,10 +49,10 @@ public void SetParameter(string ip, string port, string map, string maxplayers, Param = "-console -game hl2mp"; Param += String.Format("{0}", String.IsNullOrEmpty(ip) ? "" : $" -ip {ip}"); Param += String.Format("{0}", String.IsNullOrEmpty(port) ? "" : $" -port {port}"); - Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); Param += String.Format("{0}", String.IsNullOrEmpty(maxplayers) ? "" : $" -maxplayers {maxplayers}"); Param += String.Format("{0}", String.IsNullOrEmpty(gslt) ? "" : $" +sv_setsteamaccount {gslt}"); Param += String.Format("{0}", String.IsNullOrEmpty(additional) ? "" : $" {additional}"); + Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); } public (Process Process, string Error, string Notice) Start() diff --git a/WindowsGSM/GameServer/L4D2.cs b/WindowsGSM/GameServer/L4D2.cs index e923a0a..27d571c 100644 --- a/WindowsGSM/GameServer/L4D2.cs +++ b/WindowsGSM/GameServer/L4D2.cs @@ -49,10 +49,10 @@ public void SetParameter(string ip, string port, string map, string maxplayers, Param = "-console -game left4dead2"; Param += String.Format("{0}", String.IsNullOrEmpty(ip) ? "" : $" -ip {ip}"); Param += String.Format("{0}", String.IsNullOrEmpty(port) ? "" : $" -port {port}"); - Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); Param += String.Format("{0}", String.IsNullOrEmpty(maxplayers) ? "" : $" -maxplayers {maxplayers}"); Param += String.Format("{0}", String.IsNullOrEmpty(gslt) ? "" : $" +sv_setsteamaccount {gslt}"); Param += String.Format("{0}", String.IsNullOrEmpty(additional) ? "" : $" {additional}"); + Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); } public (Process Process, string Error, string Notice) Start() diff --git a/WindowsGSM/GameServer/RUST.cs b/WindowsGSM/GameServer/RUST.cs index e4572c9..3ac88a8 100644 --- a/WindowsGSM/GameServer/RUST.cs +++ b/WindowsGSM/GameServer/RUST.cs @@ -78,7 +78,7 @@ public void SetParameter(string ip, string port, string map, string maxplayers) if (!File.Exists(rustPath)) { - return (null, "srcds.exe not found (" + rustPath + ")", ""); + return (null, "RustDedicated.exe not found (" + rustPath + ")", ""); } if (string.IsNullOrWhiteSpace(Param)) @@ -92,7 +92,7 @@ public void SetParameter(string ip, string port, string map, string maxplayers) return (null, "", "server.cfg not found (" + serverConfigPath + ")"); } - WindowsFirewall firewall = new WindowsFirewall("srcds.exe", rustPath); + WindowsFirewall firewall = new WindowsFirewall("RustDedicated.exe", rustPath); if (!firewall.IsRuleExist()) { firewall.AddRule(); diff --git a/WindowsGSM/GameServer/TF2.cs b/WindowsGSM/GameServer/TF2.cs index a0d067e..5192369 100644 --- a/WindowsGSM/GameServer/TF2.cs +++ b/WindowsGSM/GameServer/TF2.cs @@ -56,10 +56,10 @@ public void SetParameter(string ip, string port, string map, string maxplayers, Param = "-console -game tf"; Param += String.Format("{0}", String.IsNullOrEmpty(ip) ? "" : $" -ip {ip}"); Param += String.Format("{0}", String.IsNullOrEmpty(port) ? "" : $" -port {port}"); - Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); Param += String.Format("{0}", String.IsNullOrEmpty(maxplayers) ? "" : $" -maxplayers {maxplayers}"); Param += String.Format("{0}", String.IsNullOrEmpty(gslt) ? "" : $" +sv_setsteamaccount {gslt}"); Param += String.Format("{0}", String.IsNullOrEmpty(additional) ? "" : $" {additional}"); + Param += String.Format("{0}", String.IsNullOrEmpty(map) ? "" : $" +map {map}"); } public (Process Process, string Error, string Notice) Start() diff --git a/WindowsGSM/MainWindow.xaml.cs b/WindowsGSM/MainWindow.xaml.cs index ccc0c39..b060c4d 100644 --- a/WindowsGSM/MainWindow.xaml.cs +++ b/WindowsGSM/MainWindow.xaml.cs @@ -52,7 +52,7 @@ private enum ServerStatus Restoring = 11 } - public static readonly string WGSM_VERSION = "v1.4.0"; + public static readonly string WGSM_VERSION = "v1.4.1"; public static readonly int MAX_SERVER = 100; public static readonly string WGSM_PATH = Process.GetCurrentProcess().MainModule.FileName.Replace(@"\WindowsGSM.exe", ""); //public static readonly string WGSM_PATH = @"D:\WindowsGSMtest2"; @@ -964,42 +964,34 @@ await Task.Run(() => private async void StartServerCrashDetector(Function.ServerTable server) { - GameServer.Check.CrashDetection detector = new GameServer.Check.CrashDetection(); + Process p = g_Process[Int32.Parse(server.ID)]; - if (await detector.IsServerCrashed(g_Process[Int32.Parse(server.ID)], server.Game)) + while (g_iServerStatus[Int32.Parse(server.ID)] == ServerStatus.Started) { - g_iServerStatus[Int32.Parse(server.ID)] = ServerStatus.Stopped; - Log(server.ID, "Server: Crashed"); - //Log(server.ID, "[WARNING] Exit Code: " + g_Process[Int32.Parse(server.ID)].ExitCode.ToString()); - SetServerStatus(server, "Stopped"); - - g_Process[Int32.Parse(server.ID)] = null; - - if (g_bDiscordAlert[Int32.Parse(server.ID)]) + if (p != null && p.HasExited) { - Discord.Webhook webhook = new Discord.Webhook(g_DiscordWebhook[Int32.Parse(server.ID)]); - await webhook.Send(server.ID, server.Game, "Crashed", server.Name, server.IP, server.Port); - } + g_iServerStatus[Int32.Parse(server.ID)] = ServerStatus.Stopped; + Log(server.ID, "Server: Crashed"); + //Log(server.ID, "[WARNING] Exit Code: " + g_Process[Int32.Parse(server.ID)].ExitCode.ToString()); + SetServerStatus(server, "Stopped"); - if (g_bAutoRestart[Int32.Parse(server.ID)]) - { - GameServer_Start(server); - } - } - else if (g_iServerStatus[Int32.Parse(server.ID)] == ServerStatus.Started && g_Process[Int32.Parse(server.ID)].HasExited) - { - g_iServerStatus[Int32.Parse(server.ID)] = ServerStatus.Stopped; - Log(server.ID, "Server: Stopped"); - Log(server.ID, "[Notice] Server stopped externally"); - SetServerStatus(server, "Stopped"); + g_Process[Int32.Parse(server.ID)] = null; - g_Process[Int32.Parse(server.ID)] = null; + if (g_bDiscordAlert[Int32.Parse(server.ID)]) + { + Discord.Webhook webhook = new Discord.Webhook(g_DiscordWebhook[Int32.Parse(server.ID)]); + await webhook.Send(server.ID, server.Game, "Crashed", server.Name, server.IP, server.Port); + } - if (g_bDiscordAlert[Int32.Parse(server.ID)]) - { - Discord.Webhook webhook = new Discord.Webhook(g_DiscordWebhook[Int32.Parse(server.ID)]); - await webhook.Send(server.ID, server.Game, "Stopped", server.Name, server.IP, server.Port); + if (g_bAutoRestart[Int32.Parse(server.ID)]) + { + GameServer_Start(server); + } + + break; } + + await Task.Delay(1000); } } diff --git a/WindowsGSM/Properties/AssemblyInfo.cs b/WindowsGSM/Properties/AssemblyInfo.cs index 8144160..ce4953c 100644 --- a/WindowsGSM/Properties/AssemblyInfo.cs +++ b/WindowsGSM/Properties/AssemblyInfo.cs @@ -51,7 +51,7 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.0.0")] -[assembly: AssemblyFileVersion("1.4.0.0")] +[assembly: AssemblyVersion("1.4.1.0")] +[assembly: AssemblyFileVersion("1.4.1.0")] [assembly: NeutralResourcesLanguage("en")] diff --git a/WindowsGSM/WindowsGSM.csproj b/WindowsGSM/WindowsGSM.csproj index 2052297..0e16437 100644 --- a/WindowsGSM/WindowsGSM.csproj +++ b/WindowsGSM/WindowsGSM.csproj @@ -170,7 +170,6 @@ -