aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/masterserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'NorthstarDedicatedTest/masterserver.cpp')
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp133
1 files changed, 99 insertions, 34 deletions
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index 99b74d70..c069268a 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -144,8 +144,14 @@ const char* HttplibErrorToString(httplib::Error error)
}
RemoteServerInfo::RemoteServerInfo(
- const char* newId, const char* newName, const char* newDescription, const char* newMap, const char* newPlaylist, int newPlayerCount,
- int newMaxPlayers, bool newRequiresPassword)
+ const char* newId,
+ const char* newName,
+ const char* newDescription,
+ const char* newMap,
+ const char* newPlaylist,
+ int newPlayerCount,
+ int newMaxPlayers,
+ bool newRequiresPassword)
{
// passworded servers don't have public ips
requiresPassword = newRequiresPassword;
@@ -214,7 +220,8 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(char* uid, char* or
SetCommonHttpClientOptions(curl);
std::string readBuffer;
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format("{}/client/origin_auth?id={}&token={}", Cvar_ns_masterserver_hostname->GetString(), uidStr, tokenStr).c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback);
@@ -361,8 +368,13 @@ void MasterServerManager::RequestServerList()
if (!strncmp((const char*)server.id, id, 32))
{
server = RemoteServerInfo(
- id, serverObj["name"].GetString(), serverObj["description"].GetString(), serverObj["map"].GetString(),
- serverObj["playlist"].GetString(), serverObj["playerCount"].GetInt(), serverObj["maxPlayers"].GetInt(),
+ id,
+ serverObj["name"].GetString(),
+ serverObj["description"].GetString(),
+ serverObj["map"].GetString(),
+ serverObj["playlist"].GetString(),
+ serverObj["playerCount"].GetInt(),
+ serverObj["maxPlayers"].GetInt(),
serverObj["hasPassword"].IsTrue());
newServer = &server;
createNewServerInfo = false;
@@ -373,8 +385,13 @@ void MasterServerManager::RequestServerList()
// server didn't exist
if (createNewServerInfo)
newServer = &m_remoteServers.emplace_back(
- id, serverObj["name"].GetString(), serverObj["description"].GetString(), serverObj["map"].GetString(),
- serverObj["playlist"].GetString(), serverObj["playerCount"].GetInt(), serverObj["maxPlayers"].GetInt(),
+ id,
+ serverObj["name"].GetString(),
+ serverObj["description"].GetString(),
+ serverObj["map"].GetString(),
+ serverObj["playlist"].GetString(),
+ serverObj["playerCount"].GetInt(),
+ serverObj["maxPlayers"].GetInt(),
serverObj["hasPassword"].IsTrue());
newServer->requiredMods.clear();
@@ -404,7 +421,8 @@ void MasterServerManager::RequestServerList()
}
std::sort(
- m_remoteServers.begin(), m_remoteServers.end(),
+ m_remoteServers.begin(),
+ m_remoteServers.end(),
[](RemoteServerInfo& a, RemoteServerInfo& b) { return a.playerCount > b.playerCount; });
}
else
@@ -555,7 +573,8 @@ void MasterServerManager::AuthenticateWithOwnServer(char* uid, char* playerToken
std::string readBuffer;
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format("{}/client/auth_with_self?id={}&playerToken={}", Cvar_ns_masterserver_hostname->GetString(), uidStr, tokenStr)
.c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
@@ -695,10 +714,15 @@ void MasterServerManager::AuthenticateWithServer(char* uid, char* playerToken, c
char* escapedPassword = curl_easy_escape(curl, passwordStr.c_str(), passwordStr.length());
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format(
- "{}/client/auth_with_server?id={}&playerToken={}&server={}&password={}", Cvar_ns_masterserver_hostname->GetString(),
- uidStr, tokenStr, serverIdStr, escapedPassword)
+ "{}/client/auth_with_server?id={}&playerToken={}&server={}&password={}",
+ Cvar_ns_masterserver_hostname->GetString(),
+ uidStr,
+ tokenStr,
+ serverIdStr,
+ escapedPassword)
.c_str());
curl_free(escapedPassword);
@@ -828,11 +852,19 @@ void MasterServerManager::AddSelfToServerList(
char* passwordEscaped = curl_easy_escape(curl, strPassword.c_str(), strPassword.length());
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format(
"{}/server/add_server?port={}&authPort={}&name={}&description={}&map={}&playlist={}&maxPlayers={}&password={}",
- Cvar_ns_masterserver_hostname->GetString(), port, authPort, nameEscaped, descEscaped, mapEscaped, playlistEscaped,
- maxPlayers, passwordEscaped)
+ Cvar_ns_masterserver_hostname->GetString(),
+ port,
+ authPort,
+ nameEscaped,
+ descEscaped,
+ mapEscaped,
+ playlistEscaped,
+ maxPlayers,
+ passwordEscaped)
.c_str());
curl_free(nameEscaped);
@@ -928,14 +960,22 @@ void MasterServerManager::AddSelfToServerList(
maxPlayers = std::stoi(maxPlayersVar);
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format(
"{}/server/"
"update_values?id={}&port={}&authPort={}&name={}&description={}&map={}&playlist={}&playerCount={}&"
"maxPlayers={}&password={}",
- Cvar_ns_masterserver_hostname->GetString(), m_ownServerId, Cvar_hostport->GetInt(),
- Cvar_ns_player_auth_port->GetInt(), escapedNameNew, escapedDescNew, escapedMapNew,
- escapedPlaylistNew, g_ServerAuthenticationManager->m_additionalPlayerData.size(), maxPlayers,
+ Cvar_ns_masterserver_hostname->GetString(),
+ m_ownServerId,
+ Cvar_hostport->GetInt(),
+ Cvar_ns_player_auth_port->GetInt(),
+ escapedNameNew,
+ escapedDescNew,
+ escapedMapNew,
+ escapedPlaylistNew,
+ g_ServerAuthenticationManager->m_additionalPlayerData.size(),
+ maxPlayers,
escapedPasswordNew)
.c_str());
@@ -978,7 +1018,8 @@ void MasterServerManager::AddSelfToServerList(
if (serverAddedJson.HasMember("serverAuthToken") && serverAddedJson["serverAuthToken"].IsString())
{
strncpy(
- m_ownServerAuthToken, serverAddedJson["serverAuthToken"].GetString(),
+ m_ownServerAuthToken,
+ serverAddedJson["serverAuthToken"].GetString(),
sizeof(m_ownServerAuthToken));
m_ownServerAuthToken[sizeof(m_ownServerAuthToken) - 1] = 0;
}
@@ -1034,10 +1075,15 @@ void MasterServerManager::UpdateServerMapAndPlaylist(char* map, char* playlist,
char* playlistEscaped = curl_easy_escape(curl, strPlaylist.c_str(), strPlaylist.length());
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format(
- "{}/server/update_values?id={}&map={}&playlist={}&maxPlayers={}", Cvar_ns_masterserver_hostname->GetString(),
- m_ownServerId, mapEscaped, playlistEscaped, maxPlayers)
+ "{}/server/update_values?id={}&map={}&playlist={}&maxPlayers={}",
+ Cvar_ns_masterserver_hostname->GetString(),
+ m_ownServerId,
+ mapEscaped,
+ playlistEscaped,
+ maxPlayers)
.c_str());
curl_free(mapEscaped);
@@ -1074,7 +1120,8 @@ void MasterServerManager::UpdateServerPlayerCount(int playerCount)
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format(
"{}/server/update_values?id={}&playerCount={}", Cvar_ns_masterserver_hostname->GetString(), m_ownServerId, playerCount)
.c_str());
@@ -1113,9 +1160,12 @@ void MasterServerManager::WritePlayerPersistentData(char* playerId, char* pdata,
std::string readBuffer;
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format(
- "{}/accounts/write_persistence?id={}&serverId={}", Cvar_ns_masterserver_hostname->GetString(), strPlayerId,
+ "{}/accounts/write_persistence?id={}&serverId={}",
+ Cvar_ns_masterserver_hostname->GetString(),
+ strPlayerId,
m_ownServerId)
.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1L);
@@ -1164,7 +1214,8 @@ void MasterServerManager::RemoveSelfFromServerList()
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(
- curl, CURLOPT_URL,
+ curl,
+ CURLOPT_URL,
fmt::format("{}/server/remove_server?id={}", Cvar_ns_masterserver_hostname->GetString(), m_ownServerId).c_str());
*m_ownServerId = 0;
@@ -1181,7 +1232,10 @@ void MasterServerManager::RemoveSelfFromServerList()
requestThread.detach();
}
-void ConCommand_ns_fetchservers(const CCommand& args) { g_MasterServerManager->RequestServerList(); }
+void ConCommand_ns_fetchservers(const CCommand& args)
+{
+ g_MasterServerManager->RequestServerList();
+}
void CHostState__State_NewGameHook(CHostState* hostState)
{
@@ -1213,8 +1267,13 @@ void CHostState__State_NewGameHook(CHostState* hostState)
UpdateServerInfoFromUnicodeToUTF8();
g_MasterServerManager->AddSelfToServerList(
- Cvar_hostport->GetInt(), Cvar_ns_player_auth_port->GetInt(), (char*)Cvar_ns_server_name->GetString(),
- (char*)Cvar_ns_server_desc->GetString(), hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers,
+ Cvar_hostport->GetInt(),
+ Cvar_ns_player_auth_port->GetInt(),
+ (char*)Cvar_ns_server_name->GetString(),
+ (char*)Cvar_ns_server_desc->GetString(),
+ hostState->m_levelName,
+ (char*)GetCurrentPlaylistName(),
+ maxPlayers,
(char*)Cvar_ns_server_password->GetString());
g_ServerAuthenticationManager->StartPlayerAuthServer();
g_ServerAuthenticationManager->m_bNeedLocalAuthForNewgame = false;
@@ -1262,7 +1321,7 @@ void CHostState__State_GameShutdownHook(CHostState* hostState)
CHostState__State_GameShutdown(hostState);
}
-MasterServerManager::MasterServerManager() : m_pendingConnectionInfo{}, m_ownServerId{""}, m_ownClientAuthToken{""} {}
+MasterServerManager::MasterServerManager() : m_pendingConnectionInfo {}, m_ownServerId {""}, m_ownClientAuthToken {""} {}
void InitialiseSharedMasterServer(HMODULE baseAddress)
{
@@ -1288,12 +1347,18 @@ void InitialiseSharedMasterServer(HMODULE baseAddress)
ENABLER_CREATEHOOK(
hook, (char*)baseAddress + 0x16E7D0, CHostState__State_NewGameHook, reinterpret_cast<LPVOID*>(&CHostState__State_NewGame));
ENABLER_CREATEHOOK(
- hook, (char*)baseAddress + 0x16E520, CHostState__State_ChangeLevelMPHook,
+ hook,
+ (char*)baseAddress + 0x16E520,
+ CHostState__State_ChangeLevelMPHook,
reinterpret_cast<LPVOID*>(&CHostState__State_ChangeLevelMP));
ENABLER_CREATEHOOK(
- hook, (char*)baseAddress + 0x16E5D0, CHostState__State_ChangeLevelSPHook,
+ hook,
+ (char*)baseAddress + 0x16E5D0,
+ CHostState__State_ChangeLevelSPHook,
reinterpret_cast<LPVOID*>(&CHostState__State_ChangeLevelSP));
ENABLER_CREATEHOOK(
- hook, (char*)baseAddress + 0x16E640, CHostState__State_GameShutdownHook,
+ hook,
+ (char*)baseAddress + 0x16E640,
+ CHostState__State_GameShutdownHook,
reinterpret_cast<LPVOID*>(&CHostState__State_GameShutdown));
}