From 8c73eb8aea397d7fa534b87b9a7e57b49a4bef56 Mon Sep 17 00:00:00 2001 From: Starystars67 Date: Thu, 28 Sep 2023 12:40:55 +0100 Subject: [PATCH 1/3] Added Tags Feature to the BeamMP Server. This allows better filtering on the server list. --- include/Common.h | 1 + src/TConfig.cpp | 7 ++++++- src/THeartbeatThread.cpp | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/Common.h b/include/Common.h index 47b0812..0cec7b0 100644 --- a/include/Common.h +++ b/include/Common.h @@ -43,6 +43,7 @@ public: struct TSettings { std::string ServerName { "BeamMP Server" }; std::string ServerDesc { "BeamMP Default Description" }; + std::string ServerTags { "BeamMP,Server" }; std::string Resource { "Resources" }; std::string MapName { "/levels/gridmap_v2/info.json" }; std::string Key {}; diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 645325b..928ae1a 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -15,6 +15,7 @@ static constexpr std::string_view StrMaxPlayers = "MaxPlayers"; static constexpr std::string_view StrMap = "Map"; static constexpr std::string_view StrName = "Name"; static constexpr std::string_view StrDescription = "Description"; +static constexpr std::string_view StrTags = "Tags"; static constexpr std::string_view StrResourceFolder = "ResourceFolder"; static constexpr std::string_view StrAuthKey = "AuthKey"; static constexpr std::string_view StrLogChat = "LogChat"; @@ -102,6 +103,8 @@ void TConfig::FlushToFile() { data["General"][StrPrivate.data()] = Application::Settings.Private; data["General"][StrPort.data()] = Application::Settings.Port; data["General"][StrName.data()] = Application::Settings.ServerName; + SetComment(data["General"][StrTags.data()].comments(), " Add custom identifying tags to your server to make it easier to find. Format should be TagA,TagB,TagC. Note the comma seperation."); + data["General"][StrTags.data()] = Application::Settings.ServerTags; data["General"][StrMaxCars.data()] = Application::Settings.MaxCars; data["General"][StrMaxPlayers.data()] = Application::Settings.MaxPlayers; data["General"][StrMap.data()] = Application::Settings.MapName; @@ -129,7 +132,7 @@ void TConfig::FlushToFile() { std::stringstream Ss; Ss << "# This is the BeamMP-Server config file.\n" "# Help & Documentation: `https://wiki.beammp.com/en/home/server-maintenance`\n" - "# IMPORTANT: Fill in the AuthKey with the key you got from `https://beammp.com/k/dashboard` on the left under \"Keys\"\n" + "# IMPORTANT: Fill in the AuthKey with the key you got from `https://keymaster.beammp.com/` on the left under \"Keys\"\n" << data; auto File = std::fopen(mConfigFileName.c_str(), "w+"); if (!File) { @@ -189,6 +192,7 @@ void TConfig::ParseFromFile(std::string_view name) { TryReadValue(data, "General", StrMap, Application::Settings.MapName); TryReadValue(data, "General", StrName, Application::Settings.ServerName); TryReadValue(data, "General", StrDescription, Application::Settings.ServerDesc); + TryReadValue(data, "General", StrTags, Application::Settings.ServerTags); TryReadValue(data, "General", StrResourceFolder, Application::Settings.Resource); TryReadValue(data, "General", StrAuthKey, Application::Settings.Key); TryReadValue(data, "General", StrLogChat, Application::Settings.LogChat); @@ -236,6 +240,7 @@ void TConfig::PrintDebug() { beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.MapName + "\""); beammp_debug(std::string(StrName) + ": \"" + Application::Settings.ServerName + "\""); beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\""); + beammp_debug(std::string(StrTags) + ": \"" + Application::Settings.ServerTags + "\""); beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.LogChat ? "true" : "false") + "\""); beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\""); beammp_debug(std::string(StrSSLKeyPath) + ": \"" + Application::Settings.SSLKeyPath + "\""); diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index 1d860d8..f510087 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -129,6 +129,7 @@ std::string THeartbeatThread::GenerateCall() { << "&version=" << Application::ServerVersionString() << "&clientversion=" << std::to_string(Application::ClientMajorVersion()) + ".0" // FIXME: Wtf. << "&name=" << Application::Settings.ServerName + << "&tags=" << Application::Settings.ServerTags << "&modlist=" << mResourceManager.TrimmedList() << "&modstotalsize=" << mResourceManager.MaxModSize() << "&modstotal=" << mResourceManager.ModsLoaded() From dc4ead532df96e0f5a9e564711d2dc4b7b06148b Mon Sep 17 00:00:00 2001 From: Starystars67 Date: Mon, 18 Dec 2023 14:10:07 +0000 Subject: [PATCH 2/3] Changed default tag to Freeroam as that is the majority of servers. --- include/Common.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Common.h b/include/Common.h index 0cec7b0..9608150 100644 --- a/include/Common.h +++ b/include/Common.h @@ -43,7 +43,7 @@ public: struct TSettings { std::string ServerName { "BeamMP Server" }; std::string ServerDesc { "BeamMP Default Description" }; - std::string ServerTags { "BeamMP,Server" }; + std::string ServerTags { "Freeroam" }; std::string Resource { "Resources" }; std::string MapName { "/levels/gridmap_v2/info.json" }; std::string Key {}; From 6787843b378c8f877f581709f1451212e4287a26 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Thu, 28 Dec 2023 12:58:29 +0100 Subject: [PATCH 3/3] pretty-print tags on startup --- include/Common.h | 2 ++ include/TConfig.h | 1 + src/Common.cpp | 11 +++++++++++ src/TConfig.cpp | 12 +++++++++++- src/TConsole.cpp | 11 ----------- 5 files changed, 25 insertions(+), 12 deletions(-) diff --git a/include/Common.h b/include/Common.h index fab1d30..df26435 100644 --- a/include/Common.h +++ b/include/Common.h @@ -137,6 +137,8 @@ private: static inline Version mVersion { 3, 2, 0 }; }; +void SplitString(std::string const& str, const char delim, std::vector& out); + std::string ThreadName(bool DebugModeOverride = false); void RegisterThread(const std::string& str); #define RegisterThreadAuto() RegisterThread(__func__) diff --git a/include/TConfig.h b/include/TConfig.h index 634fcb8..72fe2c1 100644 --- a/include/TConfig.h +++ b/include/TConfig.h @@ -27,6 +27,7 @@ private: void TryReadValue(toml::value& Table, const std::string& Category, const std::string_view& Key, int& OutValue); void ParseOldFormat(); + std::string TagsAsPrettyArray() const; bool IsDefault(); bool mFailed { false }; std::string mConfigFileName; diff --git a/src/Common.cpp b/src/Common.cpp index af345ad..d68dcf1 100644 --- a/src/Common.cpp +++ b/src/Common.cpp @@ -348,3 +348,14 @@ std::string GetPlatformAgnosticErrorString() { return "(no human-readable errors on this platform)"; #endif } + +// TODO: add unit tests to SplitString +void SplitString(const std::string& str, const char delim, std::vector& out) { + size_t start; + size_t end = 0; + + while ((start = str.find_first_not_of(delim, end)) != std::string::npos) { + end = str.find(delim, start); + out.push_back(str.substr(start, end - start)); + } +} diff --git a/src/TConfig.cpp b/src/TConfig.cpp index cc69c85..4ae18b7 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -214,7 +214,7 @@ void TConfig::PrintDebug() { beammp_debug(std::string(StrMap) + ": \"" + Application::Settings.MapName + "\""); beammp_debug(std::string(StrName) + ": \"" + Application::Settings.ServerName + "\""); beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\""); - beammp_debug(std::string(StrTags) + ": \"" + Application::Settings.ServerTags + "\""); + beammp_debug(std::string(StrTags) + ": " + TagsAsPrettyArray()); beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.LogChat ? "true" : "false") + "\""); beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\""); // special! @@ -274,3 +274,13 @@ void TConfig::ParseOldFormat() { Str >> std::ws; } } +std::string TConfig::TagsAsPrettyArray() const { + std::vector TagsArray = {}; + SplitString(Application::Settings.ServerTags, ',', TagsArray); + std::string Pretty = {}; + for (size_t i = 0; i < TagsArray.size() - 1; ++i) { + Pretty += '\"' + TagsArray[i] + "\", "; + } + Pretty += '\"' + TagsArray.at(TagsArray.size()-1) + "\""; + return Pretty; +} diff --git a/src/TConsole.cpp b/src/TConsole.cpp index cde978e..11e753e 100644 --- a/src/TConsole.cpp +++ b/src/TConsole.cpp @@ -52,17 +52,6 @@ TEST_CASE("TrimString") { CHECK(TrimString("") == ""); } -// TODO: add unit tests to SplitString -static inline void SplitString(std::string const& str, const char delim, std::vector& out) { - size_t start; - size_t end = 0; - - while ((start = str.find_first_not_of(delim, end)) != std::string::npos) { - end = str.find(delim, start); - out.push_back(str.substr(start, end - start)); - } -} - static std::string GetDate() { std::chrono::system_clock::time_point now = std::chrono::system_clock::now(); time_t tt = std::chrono::system_clock::to_time_t(now);