aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/masterserver.cpp
diff options
context:
space:
mode:
authorNorthstar <northstar@northstar.tf>2022-04-13 19:29:44 -0300
committerBarichello <artur@barichello.me>2022-04-13 19:30:40 -0300
commit47ea109be0d73120ddfe6896494e1fce986515b3 (patch)
treefb440b3ab2a00bf506182a9c9a9500d1c4711e0c /NorthstarDedicatedTest/masterserver.cpp
parent04b0b417d1c9f45a708d3e2eec9146fabe09c1d1 (diff)
downloadNorthstarLauncher-47ea109be0d73120ddfe6896494e1fce986515b3.tar.gz
NorthstarLauncher-47ea109be0d73120ddfe6896494e1fce986515b3.zip
Format project
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 63ae49a9..8cb4f9bb 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -146,8 +146,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;
@@ -216,7 +222,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);
@@ -363,8 +370,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;
@@ -375,8 +387,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();
@@ -406,7 +423,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
@@ -557,7 +575,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");
@@ -697,10 +716,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);
@@ -830,11 +854,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);
@@ -930,14 +962,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());
@@ -980,7 +1020,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;
}
@@ -1036,10 +1077,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);
@@ -1076,7 +1122,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());
@@ -1115,9 +1162,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);
@@ -1166,7 +1216,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;
@@ -1183,7 +1234,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)
{
@@ -1215,8 +1269,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;
@@ -1264,7 +1323,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)
{
@@ -1290,12 +1349,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));
}