From 3d7e310a3253ad41707217e77c62f1d8dcbc3a8b Mon Sep 17 00:00:00 2001 From: GeckoEidechse <40122905+GeckoEidechse@users.noreply.github.com> Date: Sat, 26 Nov 2022 10:33:39 +0100 Subject: Parse and expose region field from JSON server list (#232) * Add parsing region field from JSON server list * Add function to read server region from Squirrel * Update logic to post-refactor code * Make region field optional --- NorthstarDLL/masterserver.cpp | 6 ++++++ NorthstarDLL/masterserver.h | 2 ++ NorthstarDLL/scriptserverbrowser.cpp | 20 ++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/NorthstarDLL/masterserver.cpp b/NorthstarDLL/masterserver.cpp index fc747e5d..2e1c5321 100644 --- a/NorthstarDLL/masterserver.cpp +++ b/NorthstarDLL/masterserver.cpp @@ -30,6 +30,7 @@ RemoteServerInfo::RemoteServerInfo( const char* newDescription, const char* newMap, const char* newPlaylist, + const char* newRegion, int newPlayerCount, int newMaxPlayers, bool newRequiresPassword) @@ -45,6 +46,9 @@ RemoteServerInfo::RemoteServerInfo( strncpy_s((char*)map, sizeof(map), newMap, sizeof(map) - 1); strncpy_s((char*)playlist, sizeof(playlist), newPlaylist, sizeof(playlist) - 1); + strncpy((char*)region, newRegion, sizeof(region)); + region[sizeof(region) - 1] = 0; + playerCount = newPlayerCount; maxPlayers = newMaxPlayers; } @@ -256,6 +260,7 @@ void MasterServerManager::RequestServerList() serverObj["description"].GetString(), serverObj["map"].GetString(), serverObj["playlist"].GetString(), + (serverObj.HasMember("region") && serverObj["region"].IsString()) ? serverObj["region"].GetString() : "", serverObj["playerCount"].GetInt(), serverObj["maxPlayers"].GetInt(), serverObj["hasPassword"].IsTrue()); @@ -273,6 +278,7 @@ void MasterServerManager::RequestServerList() serverObj["description"].GetString(), serverObj["map"].GetString(), serverObj["playlist"].GetString(), + (serverObj.HasMember("region") && serverObj["region"].IsString()) ? serverObj["region"].GetString() : "", serverObj["playerCount"].GetInt(), serverObj["maxPlayers"].GetInt(), serverObj["hasPassword"].IsTrue()); diff --git a/NorthstarDLL/masterserver.h b/NorthstarDLL/masterserver.h index eb784002..4e649fae 100644 --- a/NorthstarDLL/masterserver.h +++ b/NorthstarDLL/masterserver.h @@ -27,6 +27,7 @@ class RemoteServerInfo std::string description; char map[32]; char playlist[16]; + char region[32]; std::vector requiredMods; int playerCount; @@ -42,6 +43,7 @@ class RemoteServerInfo const char* newDescription, const char* newMap, const char* newPlaylist, + const char* newRegion, int newPlayerCount, int newMaxPlayers, bool newRequiresPassword); diff --git a/NorthstarDLL/scriptserverbrowser.cpp b/NorthstarDLL/scriptserverbrowser.cpp index e6066954..05f83269 100644 --- a/NorthstarDLL/scriptserverbrowser.cpp +++ b/NorthstarDLL/scriptserverbrowser.cpp @@ -217,6 +217,26 @@ ADD_SQFUNC("int", NSGetServerRequiredModsCount, "int serverIndex", "", ScriptCon return SQRESULT_NOTNULL; } +ADD_SQFUNC("string", NSGetServerRegion, "int serverIndex", "", ScriptContext::UI) +{ + SQInteger serverIndex = g_pSquirrel->getinteger(sqvm, 1); + + if (serverIndex >= g_pMasterServerManager->m_vRemoteServers.size()) + { + g_pSquirrel->raiseerror( + sqvm, + fmt::format( + "Tried to get region of server index {} when only {} servers are available", + serverIndex, + g_pMasterServerManager->m_vRemoteServers.size()) + .c_str()); + return SQRESULT_ERROR; + } + + g_pSquirrel->pushstring(sqvm, g_pMasterServerManager->m_vRemoteServers[serverIndex].region, -1); + return SQRESULT_NOTNULL; +} + ADD_SQFUNC("string", NSGetServerRequiredModName, "int serverIndex, int modIndex", "", ScriptContext::UI) { SQInteger serverIndex = g_pSquirrel->getinteger(sqvm, 1); -- cgit v1.2.3