Skip to content

Commit 8669b3f

Browse files
committed
Enable servers and clients to declare compatibility with 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. Fixed "it's not spdlog, it's building a JSON dict" bug.
1 parent 806fa93 commit 8669b3f

File tree

6 files changed

+5172
-4114
lines changed

6 files changed

+5172
-4114
lines changed

Code/client/Services/Generic/TransportService.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11

2+
#include <BranchInfo.h>
23
#include <Services/TransportService.h>
34

45
#include <Events/ConnectedEvent.h>
@@ -112,7 +113,11 @@ void TransportService::OnConsume(const void* apData, uint32_t aSize)
112113
void TransportService::OnConnected()
113114
{
114115
AuthenticationRequest request{};
116+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
117+
request.Version = COMPATIBLE_WITH_BUILD_COMMIT;
118+
#else
115119
request.Version = BUILD_COMMIT;
120+
#endif
116121
request.SKSEActive = IsScriptExtenderLoaded();
117122
request.MO2Active = GetModuleHandleW(kMO2DllName);
118123

@@ -211,14 +216,18 @@ void TransportService::HandleAuthenticationResponse(const AuthenticationResponse
211216
// error finding
212217

213218
TiltedPhoques::String ErrorInfo;
214-
215219
ErrorInfo = "{";
216220

221+
TiltedPhoques::String protocolVersion{BUILD_COMMIT};
222+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
223+
protocolVersion = COMPATIBLE_WITH_BUILD_COMMIT;
224+
#endif
225+
217226
switch (acMessage.Type)
218227
{
219228
case AR::kWrongVersion:
220229
ErrorInfo += "\"error\": \"wrong_version\", \"data\": {";
221-
ErrorInfo += fmt::format("\"expectedVersion\": \"{}\", \"version\": \"{}\"", acMessage.Version, BUILD_COMMIT);
230+
ErrorInfo += fmt::format("\"expectedVersion\": \"{}\", \"protocolVersion\": \"{}\", \"version\": \"{}\"", acMessage.Version, protocolVersion, BUILD_COMMIT);
222231
ErrorInfo += "}";
223232
break;
224233
case AR::kModsMismatch:

Code/server/GameServer.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#include <Components.h>
1+
#include <BranchInfo.h>
2+
#include <Components.h>
23
#include <GameServer.h>
34
#include <Packet.hpp>
45

@@ -183,6 +184,9 @@ GameServer::GameServer(Console::ConsoleRegistry& aConsole) noexcept
183184

184185
UpdateInfo();
185186
spdlog::info("Server {} started on port {}", BUILD_COMMIT, GetPort());
187+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
188+
spdlog::info("Server is compatible with protocol version {}", COMPATIBLE_WITH_BUILD_COMMIT);
189+
#endif
186190
UpdateTitle();
187191

188192
m_pWorld = MakeUnique<World>();
@@ -825,9 +829,14 @@ void GameServer::HandleAuthenticationRequest(const ConnectionId_t aConnectionId,
825829
};
826830
#if 1
827831
// to make our testing life a bit easier.
828-
if (acRequest->Version != BUILD_COMMIT)
832+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
833+
const auto effectiveVersion = COMPATIBLE_WITH_BUILD_COMMIT;
834+
#else
835+
const auto effectiveVersion = BUILD_COMMIT;
836+
#endif
837+
if (acRequest->Version != effectiveVersion)
829838
{
830-
spdlog::info("New player {:x} '{}' tried to connect with client {} - Version mismatch", aConnectionId, remoteAddress, acRequest->Version.c_str());
839+
spdlog::info("New player {:x} '{}' tried to connect with client protocol version {} - Version mismatch", aConnectionId, remoteAddress, acRequest->Version.c_str());
831840
sendKick(RT::kWrongVersion);
832841
return;
833842
}
@@ -1037,8 +1046,12 @@ void GameServer::UpdateTitle() const
10371046
{
10381047
const auto name = m_info.name.empty() ? "Private server" : m_info.name;
10391048
const char* playerText = GetClientCount() <= 1 ? " player" : " players";
1040-
1041-
const auto title = fmt::format("{} - {} {} - {} Ticks - " BUILD_BRANCH "@" BUILD_COMMIT, name.c_str(), GetClientCount(), playerText, GetTickRate());
1049+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
1050+
constexpr auto protocolVersion = ", protocol version " COMPATIBLE_WITH_BUILD_COMMIT;
1051+
#else
1052+
constexpr auto protocolVersion = "";
1053+
#endif
1054+
const auto title = fmt::format("{} - {} {} - {} Ticks - " BUILD_BRANCH "@" BUILD_COMMIT "{}", name.c_str(), GetClientCount(), playerText, GetTickRate(), protocolVersion);
10421055

10431056
#if TP_PLATFORM_WINDOWS
10441057
SetConsoleTitleA(title.c_str());

0 commit comments

Comments
 (0)