From fd697318733e7625aeea3fb541c618dd11475f81 Mon Sep 17 00:00:00 2001 From: Richard Fortier Date: Sat, 29 Nov 2025 17:29:56 -0500 Subject: [PATCH] Enable public released server compatibility. That is, enable servers and clients to declare compatibility with current-release public servers. Declare which public server version your new build can support in top-level xmake.lua. MASTER builds will never declare support for a different version. You can also comment out the COMPATIBLE_WITH_BUILD_COMMIT line in xmake.lua to turn it off in other branches. Needed a few changes to "lie" to the public server list and send the protocol-compatible build commit instead of the actual build commit. Removed pnpm-lock.yaml; review comment. --- Code/client/Services/Debug/DebugService.cpp | 7 +++++- Code/client/Services/Generic/InputService.cpp | 5 ++++ .../Services/Generic/OverlayService.cpp | 5 ++++ .../Services/Generic/TransportService.cpp | 13 +++++++++-- Code/server/GameServer.cpp | 23 +++++++++++++++---- Code/server/Services/ServerListService.cpp | 5 ++++ Code/skyrim_ui/src/assets/i18n/en.json | 2 +- xmake.lua | 3 +++ 8 files changed, 54 insertions(+), 9 deletions(-) diff --git a/Code/client/Services/Debug/DebugService.cpp b/Code/client/Services/Debug/DebugService.cpp index 442eaed93..886932b84 100644 --- a/Code/client/Services/Debug/DebugService.cpp +++ b/Code/client/Services/Debug/DebugService.cpp @@ -69,7 +69,12 @@ #include extern thread_local bool g_overrideFormId; -constexpr char kBuildTag[] = "Build: " BUILD_COMMIT " " BUILD_BRANCH " EVO\nBuilt: " __TIMESTAMP__; +#define COMPAT_STRING +#ifdef COMPATIBLE_WITH_BUILD_COMMIT +#define COMPAT_STRING "\nCompatible with protocol version " COMPATIBLE_WITH_BUILD_COMMIT +#endif +constexpr char kBuildTag[] = "Build: " BUILD_COMMIT " " BUILD_BRANCH " EVO\nBuilt: " __TIMESTAMP__ COMPAT_STRING; + static void DrawBuildTag() { auto* pWindow = BSGraphics::GetMainWindow(); diff --git a/Code/client/Services/Generic/InputService.cpp b/Code/client/Services/Generic/InputService.cpp index 558ead849..3d6d823f4 100644 --- a/Code/client/Services/Generic/InputService.cpp +++ b/Code/client/Services/Generic/InputService.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -103,7 +104,11 @@ void SetUIActive(OverlayService& aOverlay, auto apRenderer, bool aActive) aOverlay.SetActive(aActive); // Ensures the game is actually loaded, in case the initial event was sent too early +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + aOverlay.SetVersion(COMPATIBLE_WITH_BUILD_COMMIT); +#else aOverlay.SetVersion(BUILD_COMMIT); +#endif aOverlay.GetOverlayApp()->ExecuteAsync("enterGame"); apRenderer->SetCursorVisible(aActive); diff --git a/Code/client/Services/Generic/OverlayService.cpp b/Code/client/Services/Generic/OverlayService.cpp index 7f1d97e00..3c2c3d023 100644 --- a/Code/client/Services/Generic/OverlayService.cpp +++ b/Code/client/Services/Generic/OverlayService.cpp @@ -1,4 +1,5 @@ #include +#include #include @@ -217,7 +218,11 @@ void OverlayService::SetInGame(bool aInGame) noexcept if (m_inGame) { +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + SetVersion(COMPATIBLE_WITH_BUILD_COMMIT); +#else SetVersion(BUILD_COMMIT); +#endif m_pOverlay->ExecuteAsync("enterGame"); } else diff --git a/Code/client/Services/Generic/TransportService.cpp b/Code/client/Services/Generic/TransportService.cpp index 0f3f684dc..5a47313f0 100644 --- a/Code/client/Services/Generic/TransportService.cpp +++ b/Code/client/Services/Generic/TransportService.cpp @@ -1,4 +1,5 @@ +#include #include #include @@ -112,7 +113,11 @@ void TransportService::OnConsume(const void* apData, uint32_t aSize) void TransportService::OnConnected() { AuthenticationRequest request{}; +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + request.Version = COMPATIBLE_WITH_BUILD_COMMIT; +#else request.Version = BUILD_COMMIT; +#endif request.SKSEActive = IsScriptExtenderLoaded(); request.MO2Active = GetModuleHandleW(kMO2DllName); @@ -211,14 +216,18 @@ void TransportService::HandleAuthenticationResponse(const AuthenticationResponse // error finding TiltedPhoques::String ErrorInfo; - ErrorInfo = "{"; + TiltedPhoques::String protocolVersion{BUILD_COMMIT}; +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + protocolVersion = COMPATIBLE_WITH_BUILD_COMMIT; +#endif + switch (acMessage.Type) { case AR::kWrongVersion: ErrorInfo += "\"error\": \"wrong_version\", \"data\": {"; - ErrorInfo += fmt::format("\"expectedVersion\": \"{}\", \"version\": \"{}\"", acMessage.Version, BUILD_COMMIT); + ErrorInfo += fmt::format("\"expectedVersion\": \"{}\", \"protocolVersion\": \"{}\", \"version\": \"{}\"", acMessage.Version, protocolVersion, BUILD_COMMIT); ErrorInfo += "}"; break; case AR::kModsMismatch: diff --git a/Code/server/GameServer.cpp b/Code/server/GameServer.cpp index ba4176b83..e49a924a8 100644 --- a/Code/server/GameServer.cpp +++ b/Code/server/GameServer.cpp @@ -1,4 +1,5 @@ -#include +#include +#include #include #include @@ -183,6 +184,9 @@ GameServer::GameServer(Console::ConsoleRegistry& aConsole) noexcept UpdateInfo(); spdlog::info("Server {} started on port {}", BUILD_COMMIT, GetPort()); +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + spdlog::info("Server is compatible with protocol version {}", COMPATIBLE_WITH_BUILD_COMMIT); +#endif UpdateTitle(); m_pWorld = MakeUnique(); @@ -825,9 +829,14 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId, }; #if 1 // to make our testing life a bit easier. - if (acRequest->Version != BUILD_COMMIT) +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + const auto effectiveVersion = COMPATIBLE_WITH_BUILD_COMMIT; +#else + const auto effectiveVersion = BUILD_COMMIT; +#endif + if (acRequest->Version != effectiveVersion) { - spdlog::info("New player {:x} '{}' tried to connect with client {} - Version mismatch", aConnectionId, remoteAddress, acRequest->Version.c_str()); + spdlog::info("New player {:x} '{}' tried to connect with client protocol version {} - Version mismatch", aConnectionId, remoteAddress, acRequest->Version.c_str()); sendKick(RT::kWrongVersion); return; } @@ -1037,8 +1046,12 @@ void GameServer::UpdateTitle() const { const auto name = m_info.name.empty() ? "Private server" : m_info.name; const char* playerText = GetClientCount() <= 1 ? " player" : " players"; - - const auto title = fmt::format("{} - {} {} - {} Ticks - " BUILD_BRANCH "@" BUILD_COMMIT, name.c_str(), GetClientCount(), playerText, GetTickRate()); +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + constexpr auto protocolVersion = ", protocol version " COMPATIBLE_WITH_BUILD_COMMIT; +#else + constexpr auto protocolVersion = ""; +#endif + const auto title = fmt::format("{} - {} {} - {} Ticks - " BUILD_BRANCH "@" BUILD_COMMIT "{}", name.c_str(), GetClientCount(), playerText, GetTickRate(), protocolVersion); #if TP_PLATFORM_WINDOWS SetConsoleTitleA(title.c_str()); diff --git a/Code/server/Services/ServerListService.cpp b/Code/server/Services/ServerListService.cpp index 9ead32cf4..66b938c02 100644 --- a/Code/server/Services/ServerListService.cpp +++ b/Code/server/Services/ServerListService.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -75,7 +76,11 @@ void ServerListService::PostAnnouncement(String acName, String acDesc, String ac uint16_t aPlayerCount, uint16_t aPlayerMaxCount, String acTagList, bool aPublic, bool aPassword, int32 aFlags) noexcept { +#ifdef COMPATIBLE_WITH_BUILD_COMMIT + const std::string kVersion{COMPATIBLE_WITH_BUILD_COMMIT}; +#else const std::string kVersion{BUILD_COMMIT}; +#endif const httplib::Params params{ {"name", std::string(acName.c_str(), acName.size())}, {"desc", std::string(acDesc.c_str(), acDesc.size())}, diff --git a/Code/skyrim_ui/src/assets/i18n/en.json b/Code/skyrim_ui/src/assets/i18n/en.json index aa105935e..204b67e30 100644 --- a/Code/skyrim_ui/src/assets/i18n/en.json +++ b/Code/skyrim_ui/src/assets/i18n/en.json @@ -162,7 +162,7 @@ }, "ERROR": { "ERRORS": { - "WRONG_VERSION": "This server expects version {{expectedVersion}} but you are on version {{version}}.", + "WRONG_VERSION": "This server requires protocol version {{expectedVersion}}\n but you are on protocol version {{protocolVersion}}, build {{version}}.\nUpdate your version or run the private server that comes with it.", "MODS_MISMATCH": "This server has ModPolicy enabled.{{mods}}", "MODS_MISMATCH_REMOVE": "Please remove the following mods to join:\n{{mods}}", "MODS_MISMATCH_INSTALL": "Please install the following mods to join:\n{{mods}}", diff --git a/xmake.lua b/xmake.lua index 7108f6b73..210dcd0dd 100644 --- a/xmake.lua +++ b/xmake.lua @@ -83,6 +83,9 @@ before_build(function (target) bool_to_number[branch == "bluedove"], bool_to_number[branch == "prerel"]) + -- Comment out next line if incompatible with current release, or, fix compatibility version. + contents = contents .. "#if !IS_MASTER\n" .. " #define COMPATIBLE_WITH_BUILD_COMMIT \"v1.8.0\"\n" .. " #endif" + -- fix always-compiles problem by updating the file only if content has changed. local filepath = "build/BranchInfo.h" local old_content = nil