NetworkSystem: rename NetGameServer_t member vars

This commit is contained in:
Kawe Mazidjatari 2024-01-24 23:40:58 +01:00
parent 1410ecd79c
commit 39d16fa4d7
6 changed files with 93 additions and 88 deletions

View File

@ -93,7 +93,7 @@ namespace VScriptCode
return SQ_OK; return SQ_OK;
} }
if (serverListing.m_svHostName.empty()) if (serverListing.name.empty())
{ {
if (hiddenServerRequestMessage.empty()) if (hiddenServerRequestMessage.empty())
{ {
@ -108,7 +108,7 @@ namespace VScriptCode
} }
else else
{ {
hiddenServerRequestMessage = Format("Found server: %s", serverListing.m_svHostName.c_str()); hiddenServerRequestMessage = Format("Found server: %s", serverListing.name.c_str());
sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1); sq_pushstring(v, hiddenServerRequestMessage.c_str(), -1);
} }
@ -128,7 +128,7 @@ namespace VScriptCode
return SQ_ERROR; return SQ_ERROR;
} }
const string& serverName = g_ServerListManager.m_vServerList[iServer].m_svHostName; const string& serverName = g_ServerListManager.m_vServerList[iServer].name;
sq_pushstring(v, serverName.c_str(), -1); sq_pushstring(v, serverName.c_str(), -1);
return SQ_OK; return SQ_OK;
@ -147,7 +147,7 @@ namespace VScriptCode
return SQ_ERROR; return SQ_ERROR;
} }
const string& serverDescription = g_ServerListManager.m_vServerList[iServer].m_svDescription; const string& serverDescription = g_ServerListManager.m_vServerList[iServer].description;
sq_pushstring(v, serverDescription.c_str(), -1); sq_pushstring(v, serverDescription.c_str(), -1);
return SQ_OK; return SQ_OK;
@ -166,7 +166,7 @@ namespace VScriptCode
return SQ_ERROR; return SQ_ERROR;
} }
const string& svServerMapName = g_ServerListManager.m_vServerList[iServer].m_svHostMap; const string& svServerMapName = g_ServerListManager.m_vServerList[iServer].map;
sq_pushstring(v, svServerMapName.c_str(), -1); sq_pushstring(v, svServerMapName.c_str(), -1);
return SQ_OK; return SQ_OK;
@ -185,7 +185,7 @@ namespace VScriptCode
return SQ_ERROR; return SQ_ERROR;
} }
const string& serverPlaylist = g_ServerListManager.m_vServerList[iServer].m_svPlaylist; const string& serverPlaylist = g_ServerListManager.m_vServerList[iServer].playlist;
sq_pushstring(v, serverPlaylist.c_str(), -1); sq_pushstring(v, serverPlaylist.c_str(), -1);
return SQ_OK; return SQ_OK;
@ -204,7 +204,7 @@ namespace VScriptCode
return SQ_ERROR; return SQ_ERROR;
} }
const SQInteger playerCount = g_ServerListManager.m_vServerList[iServer].m_nPlayerCount; const SQInteger playerCount = g_ServerListManager.m_vServerList[iServer].numPlayers;
sq_pushinteger(v, playerCount); sq_pushinteger(v, playerCount);
return SQ_OK; return SQ_OK;
@ -223,7 +223,7 @@ namespace VScriptCode
return SQ_ERROR; return SQ_ERROR;
} }
const SQInteger maxPlayers = g_ServerListManager.m_vServerList[iServer].m_nMaxPlayers; const SQInteger maxPlayers = g_ServerListManager.m_vServerList[iServer].maxPlayers;
sq_pushinteger(v, maxPlayers); sq_pushinteger(v, maxPlayers);
return SQ_OK; return SQ_OK;
@ -345,8 +345,8 @@ namespace VScriptCode
const NetGameServer_t& gameServer = g_ServerListManager.m_vServerList[iServer]; const NetGameServer_t& gameServer = g_ServerListManager.m_vServerList[iServer];
g_ServerListManager.ConnectToServer(gameServer.m_svIpAddress, gameServer.m_nGamePort, g_ServerListManager.ConnectToServer(gameServer.address, gameServer.port,
gameServer.m_svEncryptionKey); gameServer.netKey);
return SQ_OK; return SQ_OK;
} }
@ -367,7 +367,7 @@ namespace VScriptCode
bool result = g_MasterServer.GetServerByToken(netListing, hiddenServerRequestMessage, privateToken); // Send token connect request. bool result = g_MasterServer.GetServerByToken(netListing, hiddenServerRequestMessage, privateToken); // Send token connect request.
if (result) if (result)
{ {
g_ServerListManager.ConnectToServer(netListing.m_svIpAddress, netListing.m_nGamePort, netListing.m_svEncryptionKey); g_ServerListManager.ConnectToServer(netListing.address, netListing.port, netListing.netKey);
} }
else else
{ {

View File

@ -45,10 +45,10 @@ namespace VScriptCode
// Adjust browser settings. // Adjust browser settings.
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex); std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
g_ServerListManager.m_Server.m_svHostName = serverName; g_ServerListManager.m_Server.name = serverName;
g_ServerListManager.m_Server.m_svDescription = serverDescription; g_ServerListManager.m_Server.description = serverDescription;
g_ServerListManager.m_Server.m_svHostMap = serverMapName; g_ServerListManager.m_Server.map = serverMapName;
g_ServerListManager.m_Server.m_svPlaylist = serverPlaylist; g_ServerListManager.m_Server.playlist = serverPlaylist;
g_ServerListManager.m_ServerVisibility = eServerVisibility; g_ServerListManager.m_ServerVisibility = eServerVisibility;
// Launch server. // Launch server.

View File

@ -292,12 +292,12 @@ void CBrowser::BrowserPanel(void)
g_ServerListManager.m_Mutex.lock(); g_ServerListManager.m_Mutex.lock();
for (const NetGameServer_t& server : g_ServerListManager.m_vServerList) for (const NetGameServer_t& server : g_ServerListManager.m_vServerList)
{ {
const char* pszHostName = server.m_svHostName.c_str(); const char* pszHostName = server.name.c_str();
const char* pszHostMap = server.m_svHostMap.c_str(); const char* pszHostMap = server.map.c_str();
const char* pszPlaylist = server.m_svPlaylist.c_str(); const char* pszPlaylist = server.playlist.c_str();
char pszHostPort[32]; char pszHostPort[32];
sprintf(pszHostPort, "%d", server.m_nGamePort); sprintf(pszHostPort, "%d", server.port);
if (m_imServerBrowserFilter.PassFilter(pszHostName) if (m_imServerBrowserFilter.PassFilter(pszHostName)
|| m_imServerBrowserFilter.PassFilter(pszHostMap) || m_imServerBrowserFilter.PassFilter(pszHostMap)
@ -313,18 +313,18 @@ void CBrowser::BrowserPanel(void)
ImGui::Text("%s", pszPlaylist); ImGui::Text("%s", pszPlaylist);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("%s", Format("%3d/%3d", server.m_nPlayerCount, server.m_nMaxPlayers).c_str()); ImGui::Text("%s", Format("%3d/%3d", server.numPlayers, server.maxPlayers).c_str());
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::Text("%s", pszHostPort); ImGui::Text("%s", pszHostPort);
ImGui::TableNextColumn(); ImGui::TableNextColumn();
string svConnectBtn = "Connect##"; string svConnectBtn = "Connect##";
svConnectBtn.append(server.m_svHostName + server.m_svIpAddress + server.m_svHostMap); svConnectBtn.append(server.name + server.address + server.map);
if (ImGui::Button(svConnectBtn.c_str())) if (ImGui::Button(svConnectBtn.c_str()))
{ {
g_ServerListManager.ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey); g_ServerListManager.ConnectToServer(server.address, server.port, server.netKey);
} }
} }
} }
@ -441,10 +441,10 @@ void CBrowser::HiddenServersModal(void)
NetGameServer_t server; NetGameServer_t server;
bool result = g_MasterServer.GetServerByToken(server, m_svHiddenServerRequestMessage, m_svHiddenServerToken); // Send token connect request. bool result = g_MasterServer.GetServerByToken(server, m_svHiddenServerRequestMessage, m_svHiddenServerToken); // Send token connect request.
if (result && !server.m_svHostName.empty()) if (result && !server.name.empty())
{ {
g_ServerListManager.ConnectToServer(server.m_svIpAddress, server.m_nGamePort, server.m_svEncryptionKey); // Connect to the server g_ServerListManager.ConnectToServer(server.address, server.port, server.netKey); // Connect to the server
m_svHiddenServerRequestMessage = Format("Found server: %s", server.m_svHostName.c_str()); m_svHiddenServerRequestMessage = Format("Found server: %s", server.name.c_str());
m_ivHiddenServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f); m_ivHiddenServerMessageColor = ImVec4(0.00f, 1.00f, 0.00f, 1.00f);
ImGui::CloseCurrentPopup(); ImGui::CloseCurrentPopup();
} }
@ -499,18 +499,18 @@ void CBrowser::HostPanel(void)
#ifndef CLIENT_DLL #ifndef CLIENT_DLL
std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex); std::lock_guard<std::mutex> l(g_ServerListManager.m_Mutex);
ImGui::InputTextWithHint("##ServerHost_ServerName", "Server name (required)", &g_ServerListManager.m_Server.m_svHostName); ImGui::InputTextWithHint("##ServerHost_ServerName", "Server name (required)", &g_ServerListManager.m_Server.name);
ImGui::InputTextWithHint("##ServerHost_ServerDesc", "Server description (optional)", &g_ServerListManager.m_Server.m_svDescription); ImGui::InputTextWithHint("##ServerHost_ServerDesc", "Server description (optional)", &g_ServerListManager.m_Server.description);
ImGui::Spacing(); ImGui::Spacing();
if (ImGui::BeginCombo("Mode", g_ServerListManager.m_Server.m_svPlaylist.c_str())) if (ImGui::BeginCombo("Mode", g_ServerListManager.m_Server.playlist.c_str()))
{ {
g_PlaylistsVecMutex.lock(); g_PlaylistsVecMutex.lock();
for (const string& svPlaylist : g_vAllPlaylists) for (const string& svPlaylist : g_vAllPlaylists)
{ {
if (ImGui::Selectable(svPlaylist.c_str(), svPlaylist == g_ServerListManager.m_Server.m_svPlaylist)) if (ImGui::Selectable(svPlaylist.c_str(), svPlaylist == g_ServerListManager.m_Server.playlist))
{ {
g_ServerListManager.m_Server.m_svPlaylist = svPlaylist; g_ServerListManager.m_Server.playlist = svPlaylist;
} }
} }
@ -518,7 +518,7 @@ void CBrowser::HostPanel(void)
ImGui::EndCombo(); ImGui::EndCombo();
} }
if (ImGui::BeginCombo("Map", g_ServerListManager.m_Server.m_svHostMap.c_str())) if (ImGui::BeginCombo("Map", g_ServerListManager.m_Server.map.c_str()))
{ {
g_InstalledMapsMutex.lock(); g_InstalledMapsMutex.lock();
@ -527,9 +527,9 @@ void CBrowser::HostPanel(void)
const CUtlString& mapName = g_InstalledMaps[i]; const CUtlString& mapName = g_InstalledMaps[i];
if (ImGui::Selectable(mapName.String(), if (ImGui::Selectable(mapName.String(),
mapName.IsEqual_CaseInsensitive(g_ServerListManager.m_Server.m_svHostMap.c_str()))) mapName.IsEqual_CaseInsensitive(g_ServerListManager.m_Server.map.c_str())))
{ {
g_ServerListManager.m_Server.m_svHostMap = mapName.String(); g_ServerListManager.m_Server.map = mapName.String();
} }
} }
@ -574,24 +574,24 @@ void CBrowser::HostPanel(void)
{ {
m_svHostRequestMessage.clear(); m_svHostRequestMessage.clear();
bool bEnforceField = g_ServerListManager.m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_ServerListManager.m_Server.m_svHostName.empty(); bool bEnforceField = g_ServerListManager.m_ServerVisibility == EServerVisibility_t::OFFLINE ? true : !g_ServerListManager.m_Server.name.empty();
if (bEnforceField && !g_ServerListManager.m_Server.m_svPlaylist.empty() && !g_ServerListManager.m_Server.m_svHostMap.empty()) if (bEnforceField && !g_ServerListManager.m_Server.playlist.empty() && !g_ServerListManager.m_Server.map.empty())
{ {
g_ServerListManager.LaunchServer(bServerActive); // Launch server. g_ServerListManager.LaunchServer(bServerActive); // Launch server.
} }
else else
{ {
if (g_ServerListManager.m_Server.m_svHostName.empty()) if (g_ServerListManager.m_Server.name.empty())
{ {
m_svHostRequestMessage = "Server name is required."; m_svHostRequestMessage = "Server name is required.";
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
} }
else if (g_ServerListManager.m_Server.m_svPlaylist.empty()) else if (g_ServerListManager.m_Server.playlist.empty())
{ {
m_svHostRequestMessage = "Playlist is required."; m_svHostRequestMessage = "Playlist is required.";
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
} }
else if (g_ServerListManager.m_Server.m_svHostMap.empty()) else if (g_ServerListManager.m_Server.map.empty())
{ {
m_svHostRequestMessage = "Level name is required."; m_svHostRequestMessage = "Level name is required.";
m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f); m_HostRequestMessageColor = ImVec4(1.00f, 0.00f, 0.00f, 1.00f);
@ -629,7 +629,7 @@ void CBrowser::HostPanel(void)
if (ImGui::Button("Change level", ImVec2(ImGui::GetWindowContentRegionWidth(), 32))) if (ImGui::Button("Change level", ImVec2(ImGui::GetWindowContentRegionWidth(), 32)))
{ {
if (!g_ServerListManager.m_Server.m_svHostMap.empty()) if (!g_ServerListManager.m_Server.map.empty())
{ {
g_ServerListManager.LaunchServer(bServerActive); g_ServerListManager.LaunchServer(bServerActive);
} }
@ -727,10 +727,10 @@ void CBrowser::UpdateHostingStatus(void)
{ {
case EServerVisibility_t::HIDDEN: case EServerVisibility_t::HIDDEN:
g_ServerListManager.m_Server.m_bHidden = true; g_ServerListManager.m_Server.hidden = true;
break; break;
case EServerVisibility_t::PUBLIC: case EServerVisibility_t::PUBLIC:
g_ServerListManager.m_Server.m_bHidden = false; g_ServerListManager.m_Server.hidden = false;
break; break;
default: default:
break; break;
@ -741,9 +741,9 @@ void CBrowser::UpdateHostingStatus(void)
std::lock_guard<std::mutex> f(g_ServerListManager.m_Mutex); std::lock_guard<std::mutex> f(g_ServerListManager.m_Mutex);
NetGameServer_t netGameServer NetGameServer_t netGameServer
{ {
g_ServerListManager.m_Server.m_svHostName, g_ServerListManager.m_Server.name,
g_ServerListManager.m_Server.m_svDescription, g_ServerListManager.m_Server.description,
g_ServerListManager.m_Server.m_bHidden, g_ServerListManager.m_Server.hidden,
g_pHostState->m_levelName, g_pHostState->m_levelName,
v_Playlists_GetCurrent(), v_Playlists_GetCurrent(),
hostip->GetString(), hostip->GetString(),

View File

@ -67,17 +67,17 @@ void CServerListManager::LaunchServer(const bool bChangeLevel) const
} }
Msg(eDLL_T::ENGINE, "Starting server with name: \"%s\" map: \"%s\" playlist: \"%s\"\n", Msg(eDLL_T::ENGINE, "Starting server with name: \"%s\" map: \"%s\" playlist: \"%s\"\n",
m_Server.m_svHostName.c_str(), m_Server.m_svHostMap.c_str(), m_Server.m_svPlaylist.c_str()); m_Server.name.c_str(), m_Server.map.c_str(), m_Server.playlist.c_str());
/* /*
* Playlist gets parsed in two instances, first in Playlists_Parse() with all the necessary * Playlist gets parsed in two instances, first in Playlists_Parse() with all the necessary
* values. Then when you would normally call launchplaylist which calls StartPlaylist it would cmd * values. Then when you would normally call launchplaylist which calls StartPlaylist it would cmd
* call mp_gamemode which parses the gamemode specific part of the playlist.. * call mp_gamemode which parses the gamemode specific part of the playlist..
*/ */
v_Playlists_Parse(m_Server.m_svPlaylist.c_str()); v_Playlists_Parse(m_Server.playlist.c_str());
mp_gamemode->SetValue(m_Server.m_svPlaylist.c_str()); mp_gamemode->SetValue(m_Server.playlist.c_str());
ProcessCommand(Format("%s \"%s\"", bChangeLevel ? "changelevel" : "map", m_Server.m_svHostMap.c_str()).c_str()); ProcessCommand(Format("%s \"%s\"", bChangeLevel ? "changelevel" : "map", m_Server.map.c_str()).c_str());
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View File

@ -177,19 +177,19 @@ bool CPylon::PostServerHost(string& outMessage, string& outToken, string& outHos
rapidjson::Document::AllocatorType& allocator = requestJson.GetAllocator(); rapidjson::Document::AllocatorType& allocator = requestJson.GetAllocator();
requestJson.AddMember("name", rapidjson::Value(netGameServer.m_svHostName.c_str(), allocator), allocator); requestJson.AddMember("name", rapidjson::Value(netGameServer.name.c_str(), allocator), allocator);
requestJson.AddMember("description", rapidjson::Value(netGameServer.m_svDescription.c_str(), allocator), allocator); requestJson.AddMember("description", rapidjson::Value(netGameServer.description.c_str(), allocator), allocator);
requestJson.AddMember("hidden", netGameServer.m_bHidden, allocator); requestJson.AddMember("hidden", netGameServer.hidden, allocator);
requestJson.AddMember("map", rapidjson::Value(netGameServer.m_svHostMap.c_str(), allocator), allocator); requestJson.AddMember("map", rapidjson::Value(netGameServer.map.c_str(), allocator), allocator);
requestJson.AddMember("playlist", rapidjson::Value(netGameServer.m_svPlaylist.c_str(), allocator), allocator); requestJson.AddMember("playlist", rapidjson::Value(netGameServer.playlist.c_str(), allocator), allocator);
requestJson.AddMember("ip", rapidjson::Value(netGameServer.m_svIpAddress.c_str(), allocator), allocator); requestJson.AddMember("ip", rapidjson::Value(netGameServer.address.c_str(), allocator), allocator);
requestJson.AddMember("port", netGameServer.m_nGamePort, allocator); requestJson.AddMember("port", netGameServer.port, allocator);
requestJson.AddMember("key", rapidjson::Value(netGameServer.m_svEncryptionKey.c_str(), allocator), allocator); requestJson.AddMember("key", rapidjson::Value(netGameServer.netKey.c_str(), allocator), allocator);
requestJson.AddMember("checksum", netGameServer.m_nRemoteChecksum, allocator); requestJson.AddMember("checksum", netGameServer.checksum, allocator);
requestJson.AddMember("version", rapidjson::Value(netGameServer.m_svSDKVersion.c_str(), allocator), allocator); requestJson.AddMember("version", rapidjson::Value(netGameServer.versionId.c_str(), allocator), allocator);
requestJson.AddMember("playerCount", netGameServer.m_nPlayerCount, allocator); requestJson.AddMember("playerCount", netGameServer.numPlayers, allocator);
requestJson.AddMember("maxPlayers", netGameServer.m_nMaxPlayers, allocator); requestJson.AddMember("maxPlayers", netGameServer.maxPlayers, allocator);
requestJson.AddMember("timeStamp", netGameServer.m_nTimeStamp, allocator); requestJson.AddMember("timeStamp", netGameServer.timeStamp, allocator);
rapidjson::Document responseJson; rapidjson::Document responseJson;
CURLINFO status; CURLINFO status;
@ -199,7 +199,7 @@ bool CPylon::PostServerHost(string& outMessage, string& outToken, string& outHos
return false; return false;
} }
if (netGameServer.m_bHidden) if (netGameServer.hidden)
{ {
if (!responseJson.HasMember("token") || !responseJson["token"].IsString()) if (!responseJson.HasMember("token") || !responseJson["token"].IsString())
{ {

View File

@ -1,35 +1,40 @@
#pragma once #pragma once
//struct NetGameMod_t
//{
// string m_svPackage;
// int m_nNumber;
// bool m_bRequired;
// string m_svDownloadLink;
//
// //NLOHMANN_DEFINE_TYPE_INTRUSIVE(NetGameMod_t, m_svPackage, m_nNumber, m_bRequired, m_svDownloadLink)
//};
struct NetGameServer_t struct NetGameServer_t
{ {
string m_svHostName; // the name and description of this listing, which will be display to the
string m_svDescription; // client's server browser
bool m_bHidden; string name;
string description;
string m_svHostMap = "mp_lobby"; // whether or not this is a visible 'public' gameserver; this is only used
string m_svPlaylist = "dev_default"; // on the masterserver to determine whether or not to broadcast your
// listing from there
bool hidden = true;
string m_svIpAddress; // the level and playlist of the server, which will be display to the
int m_nGamePort; // client's server browser
string m_svEncryptionKey; string map = "mp_lobby";
string playlist = "dev_default";
unsigned int m_nRemoteChecksum; // the address and port of the server, validated and set from the
string m_svSDKVersion; // masterserver
string address;
int port = NULL;
int m_nPlayerCount; // the base64 net key used to decrypt game packets, the client has to
int m_nMaxPlayers; // install this before issuing a connectionless packet
int64_t m_nTimeStamp = -1; string netKey;
//vector<NetGameMod_t> m_vMods; // version identifiers used to check if the gameserver and gameclient are
// compatible with each other
unsigned int checksum = NULL;
string versionId;
// current amount of players, and the maximum allowed for this gameserver
int numPlayers = NULL;
int maxPlayers = NULL;
// the issue time of this listing
int64_t timeStamp = -1;
}; };