From 5dab48af923c76079e693b61eb0a2ba2d3918a50 Mon Sep 17 00:00:00 2001 From: SaltySnail Date: Mon, 10 Jun 2024 22:06:09 +0200 Subject: [PATCH] fix #247, add allow guests config setting. --- include/Common.h | 1 + src/TConfig.cpp | 6 ++++++ src/THeartbeatThread.cpp | 1 + src/TNetwork.cpp | 6 ++++++ 4 files changed, 14 insertions(+) diff --git a/include/Common.h b/include/Common.h index d89a65d..bca6235 100644 --- a/include/Common.h +++ b/include/Common.h @@ -77,6 +77,7 @@ public: int Port { 30814 }; std::string CustomIP {}; bool LogChat { true }; + bool AllowGuests { true }; bool SendErrors { true }; bool SendErrorsMessageEnabled { true }; int HTTPServerPort { 8080 }; diff --git a/src/TConfig.cpp b/src/TConfig.cpp index 7192f87..950f512 100644 --- a/src/TConfig.cpp +++ b/src/TConfig.cpp @@ -51,6 +51,8 @@ static constexpr std::string_view StrAuthKey = "AuthKey"; static constexpr std::string_view EnvStrAuthKey = "BEAMMP_AUTH_KEY"; static constexpr std::string_view StrLogChat = "LogChat"; static constexpr std::string_view EnvStrLogChat = "BEAMMP_LOG_CHAT"; +static constexpr std::string_view StrAllowGuests = "AllowGuests"; +static constexpr std::string_view EnvStrAllowGuests = "BEAMMP_NO_GUESTS"; static constexpr std::string_view StrPassword = "Password"; // Misc @@ -124,6 +126,8 @@ void TConfig::FlushToFile() { SetComment(data["General"][StrAuthKey.data()].comments(), " AuthKey has to be filled out in order to run the server"); data["General"][StrLogChat.data()] = Application::Settings.LogChat; SetComment(data["General"][StrLogChat.data()].comments(), " Whether to log chat messages in the console / log"); + data["General"][StrAllowGuests.data()] = Application::Settings.AllowGuests; + SetComment(data["General"][StrAllowGuests.data()].comments(), " Whether to allow guests"); data["General"][StrDebug.data()] = Application::Settings.DebugModeEnabled; data["General"][StrPrivate.data()] = Application::Settings.Private; data["General"][StrPort.data()] = Application::Settings.Port; @@ -248,6 +252,7 @@ void TConfig::ParseFromFile(std::string_view name) { TryReadValue(data, "General", StrResourceFolder, EnvStrResourceFolder, Application::Settings.Resource); TryReadValue(data, "General", StrAuthKey, EnvStrAuthKey, Application::Settings.Key); TryReadValue(data, "General", StrLogChat, EnvStrLogChat, Application::Settings.LogChat); + TryReadValue(data, "General", StrAllowGuests, EnvStrAllowGuests, Application::Settings.AllowGuests); TryReadValue(data, "General", StrPassword, "", Application::Settings.Password); // Misc TryReadValue(data, "Misc", StrSendErrors, "", Application::Settings.SendErrors); @@ -295,6 +300,7 @@ void TConfig::PrintDebug() { beammp_debug(std::string(StrDescription) + ": \"" + Application::Settings.ServerDesc + "\""); beammp_debug(std::string(StrTags) + ": " + TagsAsPrettyArray()); beammp_debug(std::string(StrLogChat) + ": \"" + (Application::Settings.LogChat ? "true" : "false") + "\""); + beammp_debug(std::string(StrAllowGuests) + ": \"" + (Application::Settings.AllowGuests ? "true" : "false") + "\""); beammp_debug(std::string(StrResourceFolder) + ": \"" + Application::Settings.Resource + "\""); // special! beammp_debug("Key Length: " + std::to_string(Application::Settings.Key.length()) + ""); diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index 2e282a4..7db562e 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -148,6 +148,7 @@ std::string THeartbeatThread::GenerateCall() { << "&clientversion=" << std::to_string(Application::ClientMajorVersion()) + ".0" // FIXME: Wtf. << "&name=" << Application::Settings.ServerName << "&tags=" << Application::Settings.ServerTags + << "&allowguests=" << (Application::Settings.AllowGuests ? "true" : "false") << "&modlist=" << mResourceManager.TrimmedList() << "&modstotalsize=" << mResourceManager.MaxModSize() << "&modstotal=" << mResourceManager.ModsLoaded() diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index e5bd4da..d347a37 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -389,6 +389,12 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { return false; }); + beammp_debugf("\t NotAllowedWithReason: {} \t AllowGuests: {} \t IsGuest: {}", NotAllowedWithReason, Application::Settings.AllowGuests, Client->IsGuest()); + if (!NotAllowedWithReason && !Application::Settings.AllowGuests && Client->IsGuest()) { //!NotAllowedWithReason because this message has the lowest priority + NotAllowedWithReason = true; + Reason = "No guests are allowed on this server! To join, sign up at; forum.beammp.com."; + } + if (NotAllowed) { ClientKick(*Client, "you are not allowed on the server!"); return {};