aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-12-24 21:52:00 +0000
committerBobTheBob <32057864+BobTheBob9@users.noreply.github.com>2021-12-24 21:52:00 +0000
commit352952bd8b12ef0a5d66fa2dc5341a4d5777f9b7 (patch)
tree8f0b6bcac5ac2ec4e07a879f2e57f8d847e8f25c
parent3dcd9f6b6da1c3f277b27a296f58bca3cbc3a775 (diff)
downloadNorthstarLauncher-352952bd8b12ef0a5d66fa2dc5341a4d5777f9b7.tar.gz
NorthstarLauncher-352952bd8b12ef0a5d66fa2dc5341a4d5777f9b7.zip
prevent playlist var names over 64 characters and send maxplayers on map change
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp22
-rw-r--r--NorthstarDedicatedTest/masterserver.h2
-rw-r--r--NorthstarDedicatedTest/playlist.cpp11
3 files changed, 28 insertions, 7 deletions
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index 8f3a6d53..9e0e2486 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -664,18 +664,18 @@ void MasterServerManager::AddSelfToServerList(int port, int authPort, char* name
requestThread.detach();
}
-void MasterServerManager::UpdateServerMapAndPlaylist(char* map, char* playlist)
+void MasterServerManager::UpdateServerMapAndPlaylist(char* map, char* playlist, int maxPlayers)
{
// dont call this if we don't have a server id
if (!*m_ownServerId)
return;
- std::thread requestThread([this, map, playlist] {
+ std::thread requestThread([this, map, playlist, maxPlayers] {
httplib::Client http(Cvar_ns_masterserver_hostname->m_pszString);
http.set_connection_timeout(25);
// we dont process this at all atm, maybe do later, but atm not necessary
- if (auto result = http.Post(fmt::format("/server/update_values?id={}&map={}&playlist={}", m_ownServerId, map, playlist).c_str()))
+ if (auto result = http.Post(fmt::format("/server/update_values?id={}&map={}&playlist={}&maxPlayers={}", m_ownServerId, map, playlist, maxPlayers).c_str()))
{
m_successfullyConnected = true;
}
@@ -790,7 +790,7 @@ void CHostState__State_NewGameHook(CHostState* hostState)
CHostState__State_NewGame(hostState);
int maxPlayers = 6;
- char* maxPlayersVar = GetCurrentPlaylistVar("max_players", true);
+ char* maxPlayersVar = GetCurrentPlaylistVar("max_players", false);
if (maxPlayersVar) // GetCurrentPlaylistVar can return null so protect against this
maxPlayers = std::stoi(maxPlayersVar);
@@ -801,13 +801,23 @@ void CHostState__State_NewGameHook(CHostState* hostState)
void CHostState__State_ChangeLevelMPHook(CHostState* hostState)
{
- g_MasterServerManager->UpdateServerMapAndPlaylist(hostState->m_levelName, (char*)GetCurrentPlaylistName());
+ int maxPlayers = 6;
+ char* maxPlayersVar = GetCurrentPlaylistVar("max_players", false);
+ if (maxPlayersVar) // GetCurrentPlaylistVar can return null so protect against this
+ maxPlayers = std::stoi(maxPlayersVar);
+
+ g_MasterServerManager->UpdateServerMapAndPlaylist(hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers);
CHostState__State_ChangeLevelMP(hostState);
}
void CHostState__State_ChangeLevelSPHook(CHostState* hostState)
{
- g_MasterServerManager->UpdateServerMapAndPlaylist(hostState->m_levelName, (char*)GetCurrentPlaylistName());
+ int maxPlayers = 6;
+ char* maxPlayersVar = GetCurrentPlaylistVar("max_players", false);
+ if (maxPlayersVar) // GetCurrentPlaylistVar can return null so protect against this
+ maxPlayers = std::stoi(maxPlayersVar);
+
+ g_MasterServerManager->UpdateServerMapAndPlaylist(hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers);
CHostState__State_ChangeLevelSP(hostState);
}
diff --git a/NorthstarDedicatedTest/masterserver.h b/NorthstarDedicatedTest/masterserver.h
index 5bb3549a..e51477a2 100644
--- a/NorthstarDedicatedTest/masterserver.h
+++ b/NorthstarDedicatedTest/masterserver.h
@@ -100,7 +100,7 @@ public:
void AuthenticateWithOwnServer(char* uid, char* playerToken);
void AuthenticateWithServer(char* uid, char* playerToken, char* serverId, char* password);
void AddSelfToServerList(int port, int authPort, char* name, char* description, char* map, char* playlist, int maxPlayers, char* password);
- void UpdateServerMapAndPlaylist(char* map, char* playlist);
+ void UpdateServerMapAndPlaylist(char* map, char* playlist, int playerCount);
void UpdateServerPlayerCount(int playerCount);
void WritePlayerPersistentData(char* playerId, char* pdata, size_t pdataSize);
void RemoveSelfFromServerList();
diff --git a/NorthstarDedicatedTest/playlist.cpp b/NorthstarDedicatedTest/playlist.cpp
index 6339d3ba..3de5b8c8 100644
--- a/NorthstarDedicatedTest/playlist.cpp
+++ b/NorthstarDedicatedTest/playlist.cpp
@@ -8,6 +8,8 @@
typedef char(*Onclc_SetPlaylistVarOverrideType)(void* a1, void* a2);
Onclc_SetPlaylistVarOverrideType Onclc_SetPlaylistVarOverride;
+// function type defined in gameutils.h
+SetPlaylistVarOverrideType SetPlaylistVarOverrideOriginal;
ConVar* Cvar_ns_use_clc_SetPlaylistVarOverride;
@@ -29,6 +31,14 @@ char Onclc_SetPlaylistVarOverrideHook(void* a1, void* a2)
return Onclc_SetPlaylistVarOverride(a1, a2);
}
+void SetPlaylistVarOverrideHook(const char* varName, const char* value)
+{
+ if (strlen(value) >= 64)
+ return;
+
+ SetPlaylistVarOverrideOriginal(varName, value);
+}
+
void InitialisePlaylistHooks(HMODULE baseAddress)
{
RegisterConCommand("setplaylist", SetPlaylistCommand, "Sets the current playlist", FCVAR_NONE);
@@ -39,6 +49,7 @@ void InitialisePlaylistHooks(HMODULE baseAddress)
HookEnabler hook;
ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x222180, &Onclc_SetPlaylistVarOverrideHook, reinterpret_cast<LPVOID*>(&Onclc_SetPlaylistVarOverride));
+ ENABLER_CREATEHOOK(hook, (char*)baseAddress + 0x18ED17, &SetPlaylistVarOverrideHook, reinterpret_cast<LPVOID*>(&SetPlaylistVarOverrideOriginal));
// patch to prevent clc_SetPlaylistVarOverride from being able to crash servers if we reach max overrides due to a call to Error (why is this possible respawn, wtf)
// todo: add a warning for this