From 0a6eecee6962433c46dae4833fcb7b93ea0ad14e Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Wed, 9 Oct 2024 16:37:16 +0200 Subject: [PATCH 1/4] report correct client minimum version to the backend --- include/Common.h | 2 +- src/THeartbeatThread.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/Common.h b/include/Common.h index f6721c1..f461ba8 100644 --- a/include/Common.h +++ b/include/Common.h @@ -74,7 +74,7 @@ public: static TConsole& Console() { return mConsole; } static std::string ServerVersionString(); static const Version& ServerVersion() { return mVersion; } - static uint8_t ClientMajorVersion() { return 2; } + static std::string ClientMinimumVersion() { return "2.2.0"; } static std::string PPS() { return mPPS; } static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; } diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index 849b321..3af72c3 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -20,6 +20,7 @@ #include "ChronoWrapper.h" #include "Client.h" +#include "Common.h" #include "Http.h" // #include "SocketIO.h" #include @@ -146,7 +147,7 @@ std::string THeartbeatThread::GenerateCall() { << "&map=" << Application::Settings.getAsString(Settings::Key::General_Map) << "&private=" << (Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false") << "&version=" << Application::ServerVersionString() - << "&clientversion=" << std::to_string(Application::ClientMajorVersion()) + ".0" // FIXME: Wtf. + << "&clientversion=" << Application::ClientMinimumVersion() << "&name=" << Application::Settings.getAsString(Settings::Key::General_Name) << "&tags=" << Application::Settings.getAsString(Settings::Key::General_Tags) << "&guests=" << (Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false") From 3403c8acba91ad200287bdfeaec320ced035e05a Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Wed, 9 Oct 2024 16:44:38 +0200 Subject: [PATCH 2/4] fix version check on auth --- include/Common.h | 2 +- src/THeartbeatThread.cpp | 2 +- src/TNetwork.cpp | 7 ++++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/include/Common.h b/include/Common.h index f461ba8..cebbfcb 100644 --- a/include/Common.h +++ b/include/Common.h @@ -74,7 +74,7 @@ public: static TConsole& Console() { return mConsole; } static std::string ServerVersionString(); static const Version& ServerVersion() { return mVersion; } - static std::string ClientMinimumVersion() { return "2.2.0"; } + static Version ClientMinimumVersion() { return Version { 2, 2, 0 }; } static std::string PPS() { return mPPS; } static void SetPPS(const std::string& NewPPS) { mPPS = NewPPS; } diff --git a/src/THeartbeatThread.cpp b/src/THeartbeatThread.cpp index 3af72c3..303cc9b 100644 --- a/src/THeartbeatThread.cpp +++ b/src/THeartbeatThread.cpp @@ -147,7 +147,7 @@ std::string THeartbeatThread::GenerateCall() { << "&map=" << Application::Settings.getAsString(Settings::Key::General_Map) << "&private=" << (Application::Settings.getAsBool(Settings::Key::General_Private) ? "true" : "false") << "&version=" << Application::ServerVersionString() - << "&clientversion=" << Application::ClientMinimumVersion() + << "&clientversion=" << Application::ClientMinimumVersion().AsString() << "&name=" << Application::Settings.getAsString(Settings::Key::General_Name) << "&tags=" << Application::Settings.getAsString(Settings::Key::General_Tags) << "&guests=" << (Application::Settings.getAsBool(Settings::Key::General_AllowGuests) ? "true" : "false") diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 78784de..bf3812e 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -293,9 +293,10 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { if (Data.size() > 3 && std::equal(Data.begin(), Data.begin() + VC.size(), VC.begin(), VC.end())) { std::string ClientVersionStr(reinterpret_cast(Data.data() + 2), Data.size() - 2); Version ClientVersion = Application::VersionStrToInts(ClientVersionStr + ".0"); - if (ClientVersion.major != Application::ClientMajorVersion()) { - beammp_errorf("Client tried to connect with version '{}', but only versions '{}.x.x' is allowed", - ClientVersion.AsString(), Application::ClientMajorVersion()); + Version MinClientVersion = Application::ClientMinimumVersion(); + if (Application::IsOutdated(ClientVersion, MinClientVersion)) { + beammp_errorf("Client tried to connect with version '{}', but only versions >= {} are allowed", + ClientVersion.AsString(), Application::ClientMinimumVersion().AsString()); ClientKick(*Client, "Outdated Version!"); return nullptr; } From 7dd2d89ad920181bcc895f9779ae283b43c26785 Mon Sep 17 00:00:00 2001 From: Lion Kortlepel Date: Wed, 9 Oct 2024 16:48:40 +0200 Subject: [PATCH 3/4] clarify auth version reject message --- include/Common.h | 10 +++++----- src/TNetwork.cpp | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/Common.h b/include/Common.h index cebbfcb..9944fc7 100644 --- a/include/Common.h +++ b/include/Common.h @@ -162,13 +162,13 @@ void RegisterThread(const std::string& str); #else #define _function_name std::string(__func__) #endif - + #ifndef NDEBUG #define DEBUG #endif - + #if defined(DEBUG) - + // if this is defined, we will show the full function signature infront of // each info/debug/warn... call instead of the 'filename:line' format. #if defined(BMP_FULL_FUNCTION_NAMES) @@ -178,7 +178,7 @@ void RegisterThread(const std::string& str); #endif #endif // defined(DEBUG) - + #define beammp_warn(x) Application::Console().Write(_this_location + std::string("[WARN] ") + (x)) #define beammp_info(x) Application::Console().Write(_this_location + std::string("[INFO] ") + (x)) #define beammp_error(x) \ @@ -221,7 +221,7 @@ void RegisterThread(const std::string& str); #else #define beammp_trace(x) #endif // defined(DEBUG) - + #define beammp_errorf(...) beammp_error(fmt::format(__VA_ARGS__)) #define beammp_infof(...) beammp_info(fmt::format(__VA_ARGS__)) #define beammp_debugf(...) beammp_debug(fmt::format(__VA_ARGS__)) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index bf3812e..a5fc7c2 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -297,7 +297,7 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { if (Application::IsOutdated(ClientVersion, MinClientVersion)) { beammp_errorf("Client tried to connect with version '{}', but only versions >= {} are allowed", ClientVersion.AsString(), Application::ClientMinimumVersion().AsString()); - ClientKick(*Client, "Outdated Version!"); + ClientKick(*Client, fmt::format("Outdated version, launcher version >={} required to join!", MinClientVersion.AsString())); return nullptr; } } else { From c39beb5b72b9e3b530df4de94db8ba84c4f9ea69 Mon Sep 17 00:00:00 2001 From: Lion Date: Wed, 9 Oct 2024 18:03:01 +0200 Subject: [PATCH 4/4] reuse minclientversion where possible Co-authored-by: Tixx <83774803+WiserTixx@users.noreply.github.com> --- src/TNetwork.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index a5fc7c2..f89035a 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -296,7 +296,7 @@ std::shared_ptr TNetwork::Authentication(TConnection&& RawConnection) { Version MinClientVersion = Application::ClientMinimumVersion(); if (Application::IsOutdated(ClientVersion, MinClientVersion)) { beammp_errorf("Client tried to connect with version '{}', but only versions >= {} are allowed", - ClientVersion.AsString(), Application::ClientMinimumVersion().AsString()); + ClientVersion.AsString(), MinClientVersion.AsString()); ClientKick(*Client, fmt::format("Outdated version, launcher version >={} required to join!", MinClientVersion.AsString())); return nullptr; }