diff --git a/Novetus/NovetusCMD/Classes/LocalFuncs.cs b/Novetus/NovetusCMD/Classes/LocalFuncs.cs index c7a1ca4..fe6afca 100644 --- a/Novetus/NovetusCMD/Classes/LocalFuncs.cs +++ b/Novetus/NovetusCMD/Classes/LocalFuncs.cs @@ -34,6 +34,8 @@ namespace NovetusCMD GlobalFuncs.ConsolePrint("-port | Sets the server port.", 4, true); GlobalFuncs.ConsolePrint("-maxplayers | Sets the number of players.", 4, true); GlobalFuncs.ConsolePrint("-notifications | Toggles server join/leave notifications.", 4, true); + GlobalFuncs.ConsolePrint("-serverbrowsername | Changes the name the server uses upon connection to the master server.", 4, true); + GlobalFuncs.ConsolePrint("-serverbrowseraddress | Changes the master server address.", 4, true); GlobalFuncs.ConsolePrint("---------", 1, true); GlobalFuncs.ConsolePrint("How to launch:", 3, true); GlobalFuncs.ConsolePrint("---------", 1, true); diff --git a/Novetus/NovetusCMD/NovetusCMD.cs b/Novetus/NovetusCMD/NovetusCMD.cs index 089b224..004444d 100644 --- a/Novetus/NovetusCMD/NovetusCMD.cs +++ b/Novetus/NovetusCMD/NovetusCMD.cs @@ -38,7 +38,7 @@ namespace NovetusCMD try { NetFuncs.StartUPnP(device,protocol,port); - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + string IP = !string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString(); GlobalFuncs.ConsolePrint("UPnP: Port " + port + " opened on '" + IP + "' (" + protocol.ToString() + ")", 3); } catch (Exception ex) @@ -56,7 +56,7 @@ namespace NovetusCMD try { NetFuncs.StopUPnP(device,protocol,port); - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + string IP = !string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString(); GlobalFuncs.ConsolePrint("UPnP: Port " + port + " closed on '" + IP + "' (" + protocol.ToString() + ")", 3); } catch (Exception ex) @@ -72,7 +72,7 @@ namespace NovetusCMD try { INatDevice device = args.Device; - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + string IP = !string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString(); GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' registered.", 3); StartUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StartUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); @@ -89,7 +89,7 @@ namespace NovetusCMD try { INatDevice device = args.Device; - string IP = (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString()); + string IP = !string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : device.GetExternalIP().ToString(); GlobalFuncs.ConsolePrint("UPnP: Device '" + IP + "' disconnected.", 3); StopUPnP(device, Protocol.Udp, GlobalVars.UserConfiguration.RobloxPort); StopUPnP(device, Protocol.Tcp, GlobalVars.UserConfiguration.RobloxPort); @@ -293,6 +293,18 @@ namespace NovetusCMD LocalVars.OverrideINI = true; GlobalVars.UserConfiguration.PlayerLimit = Convert.ToInt32(CommandLine["maxplayers"]); } + + if (CommandLine["serverbrowsername"] != null) + { + LocalVars.OverrideINI = true; + GlobalVars.UserConfiguration.ServerBrowserServerName = CommandLine["serverbrowsername"]; + } + + if (CommandLine["serverbrowseraddress"] != null) + { + LocalVars.OverrideINI = true; + GlobalVars.UserConfiguration.ServerBrowserServerAddress = CommandLine["serverbrowseraddress"]; + } } } #endregion @@ -305,6 +317,16 @@ namespace NovetusCMD static void ServerExited(object sender, EventArgs e) { + string IP = SecurityFuncs.GetExternalIPAddress(); + string pingURL = "http://" + GlobalVars.UserConfiguration.ServerBrowserServerAddress + + "/query.php?name=" + GlobalVars.UserConfiguration.ServerBrowserServerName + + "&ip=" + (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : IP) + + "&port=" + GlobalVars.UserConfiguration.RobloxPort + + "&client=" + GlobalVars.UserConfiguration.SelectedClient + "&online=0"; + + GlobalFuncs.ConsolePrint("Server closed. Pinging master server.", 4); + string response = GlobalFuncs.HttpGet(pingURL); + GlobalFuncs.ConsolePrint(!response.Contains("ERROR:") ? "Pinging done. Response from the server was: " + response : response, response.Contains("ERROR:") ? 2 : 4); Environment.Exit(0); } #endregion diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs index e2cee64..67d4dd5 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs @@ -8,6 +8,7 @@ using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; using System.IO; +using System.Net; using System.Reflection; using System.Text; using System.Text.RegularExpressions; @@ -1978,5 +1979,29 @@ public class GlobalFuncs } } #endif + + //https://stackoverflow.com/questions/27108264/how-to-properly-make-a-http-web-get-request + public static string HttpGet(string uri) + { + try + { + HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); + request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; + + using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) + using (Stream stream = response.GetResponseStream()) + using (StreamReader reader = new StreamReader(stream)) + { + return reader.ReadToEnd(); + } + } + catch (Exception ex) + { +#if LAUNCHER || CMD || URI + LogExceptions(ex); +#endif + return "ERROR: " + ex.Message; + } + } } #endregion diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs index 40f3a14..20b6692 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; +using System.Net; using System.Threading.Tasks; using System.Windows.Forms; #endregion @@ -276,7 +277,7 @@ namespace NovetusLauncher string IP = await SecurityFuncs.GetExternalIPAddressAsync(); box.Text = ""; string[] lines1 = { - SecurityFuncs.Base64Encode((!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : IP)), + SecurityFuncs.Base64Encode(!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : IP), SecurityFuncs.Base64Encode(GlobalVars.UserConfiguration.RobloxPort.ToString()), SecurityFuncs.Base64Encode(GlobalVars.UserConfiguration.SelectedClient) }; @@ -425,7 +426,7 @@ namespace NovetusLauncher GlobalFuncs.LaunchRBXClient(ScriptType.Client, false, true, new EventHandler(ClientExited), ConsoleBox); break; case ScriptType.Server: - GlobalFuncs.LaunchRBXClient(ScriptType.Server, no3d, false, new EventHandler(ClientExitedBase), ConsoleBox); + GlobalFuncs.LaunchRBXClient(ScriptType.Server, no3d, false, new EventHandler(ServerExited), ConsoleBox); break; case ScriptType.Solo: GlobalFuncs.LaunchRBXClient(ScriptType.Solo, false, false, new EventHandler(ClientExited), ConsoleBox); @@ -483,6 +484,22 @@ namespace NovetusLauncher ClientExitedBase(sender, e); } + void ServerExited(object sender, EventArgs e) + { + string IP = SecurityFuncs.GetExternalIPAddress(); + string pingURL = "http://" + GlobalVars.UserConfiguration.ServerBrowserServerAddress + + "/query.php?name=" + GlobalVars.UserConfiguration.ServerBrowserServerName + + "&ip=" + (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : IP) + + "&port=" + GlobalVars.UserConfiguration.RobloxPort + + "&client=" + GlobalVars.UserConfiguration.SelectedClient + "&online=0"; + + GlobalFuncs.ConsolePrint("Server closed. Pinging master server.", 4, ConsoleBox); + string response = GlobalFuncs.HttpGet(pingURL); + GlobalFuncs.ConsolePrint(!response.Contains("ERROR:") ? "Pinging done. Response from the server was: " + response : response, response.Contains("ERROR:") ? 2 : 4, ConsoleBox); + + ClientExitedBase(sender, e); + } + void EasterEggExited(object sender, EventArgs e) { GlobalFuncs.UpdateRichPresence(GlobalVars.LauncherState.InLauncher, ""); diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml index ae58170..9fa5172 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/Stylish/LauncherFormStylishInterface.xaml @@ -761,10 +761,10 @@