Skip to content

Commit 86f5ffc

Browse files
committed
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.
1 parent 5c4d52e commit 86f5ffc

File tree

9 files changed

+5178
-4115
lines changed

9 files changed

+5178
-4115
lines changed

Code/client/Services/Debug/DebugService.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,12 @@
6969
#include <inttypes.h>
7070
extern thread_local bool g_overrideFormId;
7171

72-
constexpr char kBuildTag[] = "Build: " BUILD_COMMIT " " BUILD_BRANCH " EVO\nBuilt: " __TIMESTAMP__;
72+
#define COMPAT_STRING
73+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
74+
#define COMPAT_STRING "\nCompatible with protocol version " COMPATIBLE_WITH_BUILD_COMMIT
75+
#endif
76+
constexpr char kBuildTag[] = "Build: " BUILD_COMMIT " " BUILD_BRANCH " EVO\nBuilt: " __TIMESTAMP__ COMPAT_STRING;
77+
7378
static void DrawBuildTag()
7479
{
7580
auto* pWindow = BSGraphics::GetMainWindow();

Code/client/Services/Generic/InputService.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <TiltedOnlinePCH.h>
2+
#include <BranchInfo.h>
23

34
#include <Services/InputService.h>
45
#include <Services/OverlayService.h>
@@ -103,7 +104,11 @@ void SetUIActive(OverlayService& aOverlay, auto apRenderer, bool aActive)
103104
aOverlay.SetActive(aActive);
104105

105106
// Ensures the game is actually loaded, in case the initial event was sent too early
107+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
108+
aOverlay.SetVersion(COMPATIBLE_WITH_BUILD_COMMIT);
109+
#else
106110
aOverlay.SetVersion(BUILD_COMMIT);
111+
#endif
107112
aOverlay.GetOverlayApp()->ExecuteAsync("enterGame");
108113

109114
apRenderer->SetCursorVisible(aActive);

Code/client/Services/Generic/OverlayService.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include <TiltedOnlinePCH.h>
2+
#include <BranchInfo.h>
23

34
#include <Services/OverlayService.h>
45

@@ -217,7 +218,11 @@ void OverlayService::SetInGame(bool aInGame) noexcept
217218

218219
if (m_inGame)
219220
{
221+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
222+
SetVersion(COMPATIBLE_WITH_BUILD_COMMIT);
223+
#else
220224
SetVersion(BUILD_COMMIT);
225+
#endif
221226
m_pOverlay->ExecuteAsync("enterGame");
222227
}
223228
else

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());

Code/server/Services/ServerListService.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#include <BranchInfo.h>
12
#include <Events/PlayerJoinEvent.h>
23
#include <Events/PlayerLeaveEvent.h>
34
#include <Events/UpdateEvent.h>
@@ -75,7 +76,11 @@ void ServerListService::PostAnnouncement(String acName, String acDesc, String ac
7576
uint16_t aPlayerCount, uint16_t aPlayerMaxCount, String acTagList,
7677
bool aPublic, bool aPassword, int32 aFlags) noexcept
7778
{
79+
#ifdef COMPATIBLE_WITH_BUILD_COMMIT
80+
const std::string kVersion{COMPATIBLE_WITH_BUILD_COMMIT};
81+
#else
7882
const std::string kVersion{BUILD_COMMIT};
83+
#endif
7984
const httplib::Params params{
8085
{"name", std::string(acName.c_str(), acName.size())},
8186
{"desc", std::string(acDesc.c_str(), acDesc.size())},

0 commit comments

Comments
 (0)