From b50bcb9ef07df07c7021c3114cdd20d3047070a3 Mon Sep 17 00:00:00 2001 From: Bitl Date: Thu, 4 Aug 2022 15:21:24 -0700 Subject: [PATCH] byebye query system, hello list/delist! --- LICENSE | 14 ++- LICENSE-QUERY-PHP => LICENSE-MASTER-SERVER | 0 Novetus/NovetusCMD/NovetusCMD.cs | 2 +- .../StorageAndFunctions/GlobalFuncs.cs | 87 +++++++------------ .../StorageAndFunctions/GlobalVars.cs | 1 + .../StorageAndFunctions/SecurityFuncs.cs | 51 +++++++++++ .../Forms/LauncherForm/LauncherFormShared.cs | 2 +- .../NovetusLauncher/Forms/ServerBrowser.cs | 3 +- changelog.txt | 4 +- delist.php | 36 ++++++++ list.php | 45 ++++++++++ query.php | 83 ------------------ scripts/batch/github_sync.bat | 5 +- 13 files changed, 180 insertions(+), 153 deletions(-) rename LICENSE-QUERY-PHP => LICENSE-MASTER-SERVER (100%) create mode 100644 delist.php create mode 100644 list.php delete mode 100644 query.php diff --git a/LICENSE b/LICENSE index e5cdcb8..92e6374 100644 --- a/LICENSE +++ b/LICENSE @@ -28,23 +28,19 @@ Note: Older Novetus versions will say that they are under the GPL, but they are Read it here https://github.com/Novetus/Novetus_src/blob/master/LICENCE or in LICENCE.txt. ------------------------------------------------------------ -query.php license (GPL 3.0) +Master Server license (GPL 3.0) ------------------------------------------------------------ - -This file is part of Novetus, but unlike the rest of the program where it is under the MIT license, -this file is under the GPL 3.0 license. - -Novetus's query.php is free software: you can redistribute it and/or modify +Novetus' Master Server is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. -Novetus's query.php is distributed in the hope that it will be useful, +Novetus' Master Server is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License -along with Novetus's query.php. If not, see . +along with Novetus' Master Server. If not, see . -Read it here https://github.com/Novetus/Novetus_src/blob/master/LICENSE-QUERY-PHP or in LICENSE-QUERY-PHP.txt. \ No newline at end of file +Read it here https://github.com/Novetus/Novetus_src/blob/master/LICENSE-MASTER-SERVER or in LICENSE-MASTER-SERVER.txt. \ No newline at end of file diff --git a/LICENSE-QUERY-PHP b/LICENSE-MASTER-SERVER similarity index 100% rename from LICENSE-QUERY-PHP rename to LICENSE-MASTER-SERVER diff --git a/Novetus/NovetusCMD/NovetusCMD.cs b/Novetus/NovetusCMD/NovetusCMD.cs index 0271959..3d18df2 100644 --- a/Novetus/NovetusCMD/NovetusCMD.cs +++ b/Novetus/NovetusCMD/NovetusCMD.cs @@ -349,7 +349,7 @@ namespace NovetusCMD static void ServerExited(object sender, EventArgs e) { GlobalVars.GameOpened = ScriptType.None; - GlobalFuncs.PingMasterServer(0, "The server has removed itself from the master server list."); + GlobalFuncs.PingMasterServer(false, "The server has removed itself from the master server list."); CloseHandlerInternal(); } diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs index edb401c..5912374 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalFuncs.cs @@ -1380,55 +1380,13 @@ public class GlobalFuncs return ""; } + + public static void GeneratePlayerID() { - CryptoRandom random = new CryptoRandom(); - int randomID = 0; - int randIDmode = random.Next(0, 8); - int idlimit = 0; - - switch (randIDmode) - { - case 0: - idlimit = 9; - break; - case 1: - idlimit = 99; - break; - case 2: - idlimit = 999; - break; - case 3: - idlimit = 9999; - break; - case 4: - idlimit = 99999; - break; - case 5: - idlimit = 999999; - break; - case 6: - idlimit = 9999999; - break; - case 7: - idlimit = 99999999; - break; - case 8: - default: - break; - } - - if (idlimit > 0) - { - randomID = random.Next(0, idlimit); - } - else - { - randomID = random.Next(); - } - - //2147483647 is max id. - GlobalVars.UserConfiguration.UserID = randomID; + int randomID = SecurityFuncs.GenerateRandomNumber(); + //2147483647 is max id. + GlobalVars.UserConfiguration.UserID = randomID; } public static string GenerateAndReturnTripcode() @@ -2334,9 +2292,11 @@ public class GlobalFuncs break; case ScriptType.Server: #if LAUNCHER - PingMasterServer(1, "Server will now display on the defined master server.", box); + PingMasterServer(true, "Server will now display on the defined master server.", box); + ConsolePrint("Your server's ID is " + GlobalVars.ServerID, 4, box); #elif CMD - PingMasterServer(1, "Server will now display on the defined master server."); + PingMasterServer(true, "Server will now display on the defined master server."); + ConsolePrint("Your server's ID is " + GlobalVars.ServerID, 4); #endif goto default; default: @@ -2376,18 +2336,30 @@ public class GlobalFuncs } #if LAUNCHER - public static void PingMasterServer(int online, string reason, RichTextBox box) + public static void PingMasterServer(bool online, string reason, RichTextBox box) #else - public static void PingMasterServer(int online, string reason) + public static void PingMasterServer(bool online, string reason) #endif { - string pingURL = "http://" + GlobalVars.UserConfiguration.ServerBrowserServerAddress + - "/query.php?name=" + GlobalVars.UserConfiguration.ServerBrowserServerName + + string pingURL = ""; + + if (online) + { + GlobalVars.ServerID = SecurityFuncs.GenerateRandomNumber(); + pingURL = "http://" + GlobalVars.UserConfiguration.ServerBrowserServerAddress + + "/list.php?name=" + GlobalVars.UserConfiguration.ServerBrowserServerName + "&ip=" + (!string.IsNullOrWhiteSpace(GlobalVars.UserConfiguration.AlternateServerIP) ? GlobalVars.UserConfiguration.AlternateServerIP : GlobalVars.ExternalIP) + "&port=" + GlobalVars.UserConfiguration.RobloxPort + "&client=" + GlobalVars.UserConfiguration.SelectedClient + - "&version=" + GlobalVars.ProgramInformation.Version + - "&online=" + online; + "&version=" + GlobalVars.ProgramInformation.Version + + "&id=" + GlobalVars.ServerID; + } + else + { + pingURL = "http://" + GlobalVars.UserConfiguration.ServerBrowserServerAddress + + "/delist.php?id=" + GlobalVars.ServerID; + GlobalVars.ServerID = 0; + } #if LAUNCHER ConsolePrint("Pinging master server. " + reason, 4, box); @@ -2400,6 +2372,11 @@ public class GlobalFuncs #elif CMD ConsolePrint(response, response.Contains("ERROR:") ? 2 : 4); #endif + + if (response.Contains("ERROR:")) + { + GlobalVars.ServerID = 0; + } } public static void OpenClient(ScriptType type, string rbxexe, string args, string clientname, string mapname, EventHandler e, bool customization = false) diff --git a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs index 27bf00e..391c208 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/GlobalVars.cs @@ -96,6 +96,7 @@ public static class GlobalVars public static bool ColorsLoaded = false; public static int ValidatedExtraFiles = 0; public static bool NoFileList = false; + public static int ServerID = 0; #endregion } #endregion diff --git a/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs b/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs index 0feee12..3466dd6 100644 --- a/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs +++ b/Novetus/NovetusCore/StorageAndFunctions/SecurityFuncs.cs @@ -28,6 +28,57 @@ public class SecurityFuncs .Select(s => s[random.Next(s.Length)]).ToArray()); } + public static int GenerateRandomNumber() + { + CryptoRandom random = new CryptoRandom(); + int randomID = 0; + int randIDmode = random.Next(0, 8); + int idlimit = 0; + + switch (randIDmode) + { + case 0: + idlimit = 9; + break; + case 1: + idlimit = 99; + break; + case 2: + idlimit = 999; + break; + case 3: + idlimit = 9999; + break; + case 4: + idlimit = 99999; + break; + case 5: + idlimit = 999999; + break; + case 6: + idlimit = 9999999; + break; + case 7: + idlimit = 99999999; + break; + case 8: + default: + break; + } + + if (idlimit > 0) + { + randomID = random.Next(0, idlimit); + } + else + { + randomID = random.Next(); + } + + //2147483647 is max id. + return randomID; + } + //these 2 methods are for the clientinfo creator. public static string Base64DecodeNew(string base64EncodedData) { diff --git a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs index 495f4d0..d8532e1 100644 --- a/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs +++ b/Novetus/NovetusLauncher/Forms/LauncherForm/LauncherFormShared.cs @@ -599,7 +599,7 @@ namespace NovetusLauncher void ServerExited(object sender, EventArgs e) { GlobalVars.GameOpened = ScriptType.None; - GlobalFuncs.PingMasterServer(0, "The server has removed itself from the master server list.", ConsoleBox); + GlobalFuncs.PingMasterServer(false, "The server has removed itself from the master server list.", ConsoleBox); ClientExitedBase(sender, e); } diff --git a/Novetus/NovetusLauncher/Forms/ServerBrowser.cs b/Novetus/NovetusLauncher/Forms/ServerBrowser.cs index d2cb4f8..30fa618 100644 --- a/Novetus/NovetusLauncher/Forms/ServerBrowser.cs +++ b/Novetus/NovetusLauncher/Forms/ServerBrowser.cs @@ -140,7 +140,8 @@ namespace NovetusLauncher string line; while ((line = await reader.ReadLineAsync()) != null) { - string DecodedLine = SecurityFuncs.Base64DecodeOld(line); + string[] initialLine = line.Split('|'); + string DecodedLine = SecurityFuncs.Base64DecodeOld(initialLine[1]); string[] serverInfo = DecodedLine.Split('|'); GameServer gameServer = new GameServer(serverInfo[0], serverInfo[1], serverInfo[2], serverInfo[3], serverInfo[4]); if (gameServer.IsValid()) diff --git a/changelog.txt b/changelog.txt index add6276..6c35229 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,4 @@ -1.3 Snapshot v22.8250.17845.1 +1.3 Snapshot v22.8251.26754.1 Enhancements: - The initial file list for the Mod Package Creator now checks if all lines are created on the file. - The initial file list now generates when launching the SDK if one is not generated already. @@ -8,6 +8,8 @@ Enhancements: - This plugin is disabled by default, so the server host will have to enable it manually if they wish to enable this feature. - Made Master Server ping messages more verbose. - Improved the stability of master server pings. +- The Master Server has been split into 2 files: list.php and delist.php + - Each server has a randomly generated ID that is only visible to the server host (in the console) and the master server host (in serverlist.txt) ---------------------------------------------------------------------------- 1.3 Snapshot v22.8245.27180.1 diff --git a/delist.php b/delist.php new file mode 100644 index 0000000..8e60e5d --- /dev/null +++ b/delist.php @@ -0,0 +1,36 @@ +. + +Read it here https://github.com/Novetus/Novetus_src/blob/master/LICENSE-MASTER-SERVER or in LICENSE-MASTER-SERVER.txt. +*/ + +//id +$id = $_GET["id"]; + +if (!empty($id) and is_numeric($id)) +{ + $file = 'serverlist.txt'; + + foreach(file($file) as $line) + { + if (strpos($line, $id) !== false) + { + $file_contents = file_get_contents($file); + $contents = str_replace($line, '', $file_contents); + file_put_contents($file, $contents); + } + } +} +?> \ No newline at end of file diff --git a/list.php b/list.php new file mode 100644 index 0000000..60a7ce4 --- /dev/null +++ b/list.php @@ -0,0 +1,45 @@ +. + +Read it here https://github.com/Novetus/Novetus_src/blob/master/LICENSE-MASTER-SERVER or in LICENSE-MASTER-SERVER.txt. +*/ + +//NOVETUS MASTER SERVER QUERY CODE +//thanks to idkwhatnametoget for the port fix + +//name +$name = $_GET["name"]; +//port +$port = $_GET["port"]; +//client +$client = $_GET["client"]; +//version +$version = $_GET["version"]; +//id +$id = $_GET["id"]; + +if (!empty($port) and $port < 65535 and is_numeric($port) and !empty($name) and !empty($client) and !empty($version) and !empty($id) and is_numeric($id)) +{ + //server ip + $ip = $_GET["ip"]; + + $file = 'serverlist.txt'; + + //ONLY the $name and $client arguments will show up in the master server! + $text = $id.'|'.base64_encode(base64_encode($name).'|'.base64_encode($ip).'|'.base64_encode($port).'|'.base64_encode($client).'|'.base64_encode($version))."\r\n"; + + file_put_contents($file, $text, FILE_APPEND); +} +?> \ No newline at end of file diff --git a/query.php b/query.php deleted file mode 100644 index 6d9215d..0000000 --- a/query.php +++ /dev/null @@ -1,83 +0,0 @@ -. -*/ - -//NOVETUS MASTER SERVER QUERY CODE -//thanks to idkwhatnametoget for the port fix - -//name -$name = $_GET["name"]; -//port -$port = $_GET["port"]; -//client -$client = $_GET["client"]; -//version -$version = $_GET["version"]; - -if (!empty($port) and $port < 65535 and is_numeric($port) and !empty($name) and !empty($client) and !empty($version)) -{ - //server ip - $ip = $_GET["ip"]; - //online status - $online = $_GET["online"]; - - //strings - $deleteentry = 1; - $status = "Offline"; - - $file = 'serverlist.txt'; - - //ONLY the $name and $client arguments will show up in the master server! - $text = base64_encode(base64_encode($name).'|'.base64_encode($ip).'|'.base64_encode($port).'|'.base64_encode($client).'|'.base64_encode($version))."\r\n"; - - if ($online == 1) - { - $deleteentry = 0; - - foreach(file($file) as $line) - { - if (strpos($line, $text) !== false) - { - $file_contents = file_get_contents($file); - $contents = str_replace($line, '', $file_contents); - file_put_contents($file, $contents); - } - } - - file_put_contents($file, $text, FILE_APPEND); - - $status = "Online"; - } - - if ($deleteentry == 1) - { - foreach(file($file) as $line) - { - if (strpos($line, $text) !== false) - { - $file_contents = file_get_contents($file); - $contents = str_replace($line, '', $file_contents); - file_put_contents($file, $contents); - } - } - } - - // Display the server info to browsers. - echo "" . htmlspecialchars($name) . ". A " . htmlspecialchars($client) . " server running on ". htmlspecialchars($version) .". Server Status: " . htmlspecialchars($status) . ""; -} -?> \ No newline at end of file diff --git a/scripts/batch/github_sync.bat b/scripts/batch/github_sync.bat index 46a1622..797a6f5 100644 --- a/scripts/batch/github_sync.bat +++ b/scripts/batch/github_sync.bat @@ -135,10 +135,11 @@ XCOPY "%cd%\litefiles\Novetus_dependency_installer.bat" "%scriptsdir%\batch\Nove XCOPY "%cd%\Novetus\Novetus_launcher_legacy.bat" "%scriptsdir%\batch" /y XCOPY "%cd%\Novetus\documentation.txt" "%dest%" /y XCOPY /c "%cd%\Novetus\.itch.toml" "%dest%" /y -XCOPY "%cd%\Novetus\query.php" "%dest%" /y +XCOPY "%cd%\Novetus\masterserver\list.php" "%dest%" /y +XCOPY "%cd%\Novetus\masterserver\delist.php" "%dest%" /y +XCOPY "%cd%\Novetus\masterserver\LICENSE-MASTER-SERVER.txt" "%dest%\LICENSE-MASTER-SERVER" /y XCOPY "%cd%\Novetus\changelog.txt" "%dest%\changelog.txt" /y XCOPY "%cd%\Novetus\LICENSE.txt" "%dest%\LICENSE" /y -XCOPY "%cd%\Novetus\LICENSE-QUERY-PHP.txt" "%dest%\LICENSE-QUERY-PHP" /y XCOPY "%cd%\Novetus\LICENSE-RESHADE.txt" "%dest%\LICENSE-RESHADE" /y XCOPY "%cd%\Novetus\README-AND-CREDITS.TXT" "%dest%" /y XCOPY "%cd%\Novetus\addons\Addon_Template.lua" "%dest%" /y