aboutsummaryrefslogtreecommitdiff
path: root/NorthstarDedicatedTest/masterserver.cpp
diff options
context:
space:
mode:
authorKawe Mazidjatari <48657826+Mauler125@users.noreply.github.com>2022-02-23 22:27:08 +0100
committerGitHub <noreply@github.com>2022-02-23 18:27:08 -0300
commit4f28a07d0562ca905bbcdb010b69604c330194bb (patch)
tree32ce0e8b0eff10cba6944a561e3538931a6033b6 /NorthstarDedicatedTest/masterserver.cpp
parent8c9f34283f8670dda98959d0785d682e6f652a93 (diff)
downloadNorthstarLauncher-4f28a07d0562ca905bbcdb010b69604c330194bb.tar.gz
NorthstarLauncher-4f28a07d0562ca905bbcdb010b69604c330194bb.zip
ConVar class rebuild (#90)
* Implement CCvar class with mapped out vtable funcs * Rebuilded ConVar class + code overhaul to use new system * ConVar class is now properly mapped out for r2 (0x80 in size). * Reimplemented and exposed all frequently used ConVar class methods to the SDK. * Implement frequently used CCvar class methods. * Implement all CCVarIteratorInternal class methods. * Performed additional cleanup over the SDK to use new system instead. * ConVar class improvements + rebuilded ConCommand struct * Fix actual struct size for ConCommand
Diffstat (limited to 'NorthstarDedicatedTest/masterserver.cpp')
-rw-r--r--NorthstarDedicatedTest/masterserver.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/NorthstarDedicatedTest/masterserver.cpp b/NorthstarDedicatedTest/masterserver.cpp
index cfb92409..b08ebb90 100644
--- a/NorthstarDedicatedTest/masterserver.cpp
+++ b/NorthstarDedicatedTest/masterserver.cpp
@@ -105,8 +105,8 @@ std::string unescape_unicode(const std::string& str)
void UpdateServerInfoFromUnicodeToUTF8()
{
- g_MasterServerManager->ns_auth_srvName = unescape_unicode(Cvar_ns_server_name->m_pszString);
- g_MasterServerManager->ns_auth_srvDesc = unescape_unicode(Cvar_ns_server_desc->m_pszString);
+ g_MasterServerManager->ns_auth_srvName = unescape_unicode(Cvar_ns_server_name->GetString());
+ g_MasterServerManager->ns_auth_srvDesc = unescape_unicode(Cvar_ns_server_desc->GetString());
}
const char* HttplibErrorToString(httplib::Error error)
@@ -214,7 +214,7 @@ void MasterServerManager::AuthenticateOriginWithMasterServer(char* uid, char* or
std::string readBuffer;
curl_easy_setopt(
curl, CURLOPT_URL,
- fmt::format("{}/client/origin_auth?id={}&token={}", Cvar_ns_masterserver_hostname->m_pszString, uidStr, tokenStr).c_str());
+ 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);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
@@ -283,13 +283,13 @@ void MasterServerManager::RequestServerList()
m_requestingServerList = true;
m_scriptRequestingServerList = true;
- spdlog::info("Requesting server list from {}", Cvar_ns_masterserver_hostname->m_pszString);
+ spdlog::info("Requesting server list from {}", Cvar_ns_masterserver_hostname->GetString());
CURL* curl = curl_easy_init();
SetCommonHttpClientOptions(curl);
std::string readBuffer;
- curl_easy_setopt(curl, CURLOPT_URL, fmt::format("{}/client/servers", Cvar_ns_masterserver_hostname->m_pszString).c_str());
+ curl_easy_setopt(curl, CURLOPT_URL, fmt::format("{}/client/servers", Cvar_ns_masterserver_hostname->GetString()).c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
@@ -437,7 +437,7 @@ void MasterServerManager::RequestMainMenuPromos()
std::string readBuffer;
curl_easy_setopt(
- curl, CURLOPT_URL, fmt::format("{}/client/mainmenupromos", Cvar_ns_masterserver_hostname->m_pszString).c_str());
+ curl, CURLOPT_URL, fmt::format("{}/client/mainmenupromos", Cvar_ns_masterserver_hostname->GetString()).c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
@@ -555,7 +555,7 @@ void MasterServerManager::AuthenticateWithOwnServer(char* uid, char* playerToken
std::string readBuffer;
curl_easy_setopt(
curl, CURLOPT_URL,
- fmt::format("{}/client/auth_with_self?id={}&playerToken={}", Cvar_ns_masterserver_hostname->m_pszString, uidStr, tokenStr)
+ fmt::format("{}/client/auth_with_self?id={}&playerToken={}", Cvar_ns_masterserver_hostname->GetString(), uidStr, tokenStr)
.c_str());
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, CurlWriteToStringBufferCallback);
@@ -696,7 +696,7 @@ void MasterServerManager::AuthenticateWithServer(char* uid, char* playerToken, c
curl_easy_setopt(
curl, CURLOPT_URL,
fmt::format(
- "{}/client/auth_with_server?id={}&playerToken={}&server={}&password={}", Cvar_ns_masterserver_hostname->m_pszString,
+ "{}/client/auth_with_server?id={}&playerToken={}&server={}&password={}", Cvar_ns_masterserver_hostname->GetString(),
uidStr, tokenStr, serverIdStr, escapedPassword)
.c_str());
@@ -777,10 +777,10 @@ void MasterServerManager::AuthenticateWithServer(char* uid, char* playerToken, c
void MasterServerManager::AddSelfToServerList(
int port, int authPort, char* name, char* description, char* map, char* playlist, int maxPlayers, char* password)
{
- if (!Cvar_ns_report_server_to_masterserver->m_nValue)
+ if (!Cvar_ns_report_server_to_masterserver->GetBool())
return;
- if (!Cvar_ns_report_sp_server_to_masterserver->m_nValue && !strncmp(map, "sp_", 3))
+ if (!Cvar_ns_report_sp_server_to_masterserver->GetBool() && !strncmp(map, "sp_", 3))
{
m_bRequireClientAuth = false;
return;
@@ -830,7 +830,7 @@ void MasterServerManager::AddSelfToServerList(
curl, CURLOPT_URL,
fmt::format(
"{}/server/add_server?port={}&authPort={}&name={}&description={}&map={}&playlist={}&maxPlayers={}&password={}",
- Cvar_ns_masterserver_hostname->m_pszString, port, authPort, nameEscaped, descEscaped, mapEscaped, playlistEscaped,
+ Cvar_ns_masterserver_hostname->GetString(), port, authPort, nameEscaped, descEscaped, mapEscaped, playlistEscaped,
maxPlayers, passwordEscaped)
.c_str());
@@ -915,7 +915,7 @@ void MasterServerManager::AddSelfToServerList(
char* escapedDescNew = curl_easy_escape(curl, g_MasterServerManager->ns_auth_srvDesc.c_str(), NULL);
char* escapedMapNew = curl_easy_escape(curl, g_pHostState->m_levelName, NULL);
char* escapedPlaylistNew = curl_easy_escape(curl, GetCurrentPlaylistName(), NULL);
- char* escapedPasswordNew = curl_easy_escape(curl, Cvar_ns_server_password->m_pszString, NULL);
+ char* escapedPasswordNew = curl_easy_escape(curl, Cvar_ns_server_password->GetString(), NULL);
int maxPlayers = 6;
char* maxPlayersVar = GetCurrentPlaylistVar("max_players", false);
@@ -928,8 +928,8 @@ void MasterServerManager::AddSelfToServerList(
"{}/server/"
"update_values?id={}&port={}&authPort={}&name={}&description={}&map={}&playlist={}&playerCount={}&"
"maxPlayers={}&password={}",
- Cvar_ns_masterserver_hostname->m_pszString, m_ownServerId, Cvar_hostport->m_nValue,
- Cvar_ns_player_auth_port->m_nValue, escapedNameNew, escapedDescNew, escapedMapNew,
+ 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());
@@ -1026,7 +1026,7 @@ void MasterServerManager::UpdateServerMapAndPlaylist(char* map, char* playlist,
curl_easy_setopt(
curl, CURLOPT_URL,
fmt::format(
- "{}/server/update_values?id={}&map={}&playlist={}&maxPlayers={}", Cvar_ns_masterserver_hostname->m_pszString,
+ "{}/server/update_values?id={}&map={}&playlist={}&maxPlayers={}", Cvar_ns_masterserver_hostname->GetString(),
m_ownServerId, mapEscaped, playlistEscaped, maxPlayers)
.c_str());
@@ -1066,7 +1066,7 @@ void MasterServerManager::UpdateServerPlayerCount(int playerCount)
curl_easy_setopt(
curl, CURLOPT_URL,
fmt::format(
- "{}/server/update_values?id={}&playerCount={}", Cvar_ns_masterserver_hostname->m_pszString, m_ownServerId, playerCount)
+ "{}/server/update_values?id={}&playerCount={}", Cvar_ns_masterserver_hostname->GetString(), m_ownServerId, playerCount)
.c_str());
CURLcode result = curl_easy_perform(curl);
@@ -1105,7 +1105,7 @@ void MasterServerManager::WritePlayerPersistentData(char* playerId, char* pdata,
curl_easy_setopt(
curl, CURLOPT_URL,
fmt::format(
- "{}/accounts/write_persistence?id={}&serverId={}", Cvar_ns_masterserver_hostname->m_pszString, strPlayerId,
+ "{}/accounts/write_persistence?id={}&serverId={}", Cvar_ns_masterserver_hostname->GetString(), strPlayerId,
m_ownServerId)
.c_str());
curl_easy_setopt(curl, CURLOPT_POST, 1L);
@@ -1140,7 +1140,7 @@ void MasterServerManager::WritePlayerPersistentData(char* playerId, char* pdata,
void MasterServerManager::RemoveSelfFromServerList()
{
// dont call this if we don't have a server id
- if (!*m_ownServerId || !Cvar_ns_report_server_to_masterserver->m_nValue)
+ if (!*m_ownServerId || !Cvar_ns_report_server_to_masterserver->GetBool())
return;
std::thread requestThread(
@@ -1155,7 +1155,7 @@ void MasterServerManager::RemoveSelfFromServerList()
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
curl_easy_setopt(
curl, CURLOPT_URL,
- fmt::format("{}/server/remove_server?id={}", Cvar_ns_masterserver_hostname->m_pszString, m_ownServerId).c_str());
+ fmt::format("{}/server/remove_server?id={}", Cvar_ns_masterserver_hostname->GetString(), m_ownServerId).c_str());
CURLcode result = curl_easy_perform(curl);
@@ -1197,14 +1197,14 @@ void CHostState__State_NewGameHook(CHostState* hostState)
maxPlayers = std::stoi(maxPlayersVar);
// Copy new server name cvar to source
- Cvar_hostname->m_pszString = Cvar_ns_server_name->m_pszString;
- Cvar_hostname->m_StringLength = Cvar_ns_server_name->m_StringLength;
+ Cvar_hostname->SetValue(Cvar_ns_server_name->GetString());
// This calls the function that converts unicode strings from servername and serverdesc to UTF-8
UpdateServerInfoFromUnicodeToUTF8();
g_MasterServerManager->AddSelfToServerList(
- Cvar_hostport->m_nValue, Cvar_ns_player_auth_port->m_nValue, Cvar_ns_server_name->m_pszString, Cvar_ns_server_desc->m_pszString,
- hostState->m_levelName, (char*)GetCurrentPlaylistName(), maxPlayers, Cvar_ns_server_password->m_pszString);
+ 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;
}
@@ -1255,15 +1255,15 @@ MasterServerManager::MasterServerManager() : m_pendingConnectionInfo{}, m_ownSer
void InitialiseSharedMasterServer(HMODULE baseAddress)
{
- Cvar_ns_masterserver_hostname = RegisterConVar("ns_masterserver_hostname", "127.0.0.1", FCVAR_NONE, "");
+ Cvar_ns_masterserver_hostname = new ConVar("ns_masterserver_hostname", "127.0.0.1", FCVAR_NONE, "");
// unfortunately lib doesn't let us specify a port and still have https work
- // Cvar_ns_masterserver_port = RegisterConVar("ns_masterserver_port", "8080", FCVAR_NONE, "");
+ // Cvar_ns_masterserver_port = new ConVar("ns_masterserver_port", "8080", FCVAR_NONE, "");
- Cvar_ns_server_name = RegisterConVar("ns_server_name", "Unnamed Northstar Server", FCVAR_GAMEDLL, "");
- Cvar_ns_server_desc = RegisterConVar("ns_server_desc", "Default server description", FCVAR_GAMEDLL, "");
- Cvar_ns_server_password = RegisterConVar("ns_server_password", "", FCVAR_GAMEDLL, "");
- Cvar_ns_report_server_to_masterserver = RegisterConVar("ns_report_server_to_masterserver", "1", FCVAR_GAMEDLL, "");
- Cvar_ns_report_sp_server_to_masterserver = RegisterConVar("ns_report_sp_server_to_masterserver", "0", FCVAR_GAMEDLL, "");
+ Cvar_ns_server_name = new ConVar("ns_server_name", "Unnamed Northstar Server", FCVAR_GAMEDLL, "");
+ Cvar_ns_server_desc = new ConVar("ns_server_desc", "Default server description", FCVAR_GAMEDLL, "");
+ Cvar_ns_server_password = new ConVar("ns_server_password", "", FCVAR_GAMEDLL, "");
+ Cvar_ns_report_server_to_masterserver = new ConVar("ns_report_server_to_masterserver", "1", FCVAR_GAMEDLL, "");
+ Cvar_ns_report_sp_server_to_masterserver = new ConVar("ns_report_sp_server_to_masterserver", "0", FCVAR_GAMEDLL, "");
Cvar_hostname = *(ConVar**)((char*)baseAddress + 0x1315bae8);