diff --git a/CHANGELOG.md b/CHANGELOG.md index 424f3859..005de259 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -187,7 +187,7 @@ The format is based on [Keep a Changelog v0.3.0](http://keepachangelog.com/en/0. - Fixed slow motion during final killcams (#111 - #107) - Fixed sound issue that causes the game to freeze (#106) - Fixed issue where materials strings found in hostnames, player names, chat etc. caused the game to crash (#113) -- Fixed issue with servers displaying an invalid player count (#144) +- Fixed issue with servers displaying an invalid player count (#113) ### Known issues diff --git a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp index 6838ae44..d70c9aaa 100644 --- a/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp +++ b/src/Components/Modules/AssetInterfaces/Isnd_alias_list_t.cpp @@ -5,10 +5,10 @@ namespace Assets { void Isnd_alias_list_t::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) { - Components::FileSystem::File aliasFile(Utils::String::VA("sounds/%s", name.c_str())); + Components::FileSystem::File aliasFile(Utils::String::VA("sounds/%s.json", name.data())); if (!aliasFile.exists()) { - header->sound = Components::AssetHandler::FindOriginalAsset(this->getType(), name.c_str()).sound; + header->sound = Components::AssetHandler::FindOriginalAsset(this->getType(), name.data()).sound; return; } @@ -19,7 +19,6 @@ namespace Assets return; } - std::string errors; nlohmann::json infoData = nlohmann::json::parse(aliasFile.getBuffer()); nlohmann::json aliasesContainer = infoData["head"]; diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index 294bf512..1457f85d 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -151,7 +151,8 @@ namespace Components if (idEntry.is_string()) { SteamID id; - id.bits = strtoull(idEntry.get().data(), nullptr, 16); + auto guid = idEntry.get(); + id.bits = std::strtoull(guid.data(), nullptr, 16); list->idList.push_back(id); } diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index 45f11e40..6707ef22 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -20,13 +20,10 @@ namespace Components { case 0: return Utils::String::VA("%d", index); - case 1: return ServerInfo::PlayerContainer.playerList[index].name.data(); - case 2: return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].score); - case 3: return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].ping); default: @@ -130,17 +127,16 @@ namespace Components Utils::InfoString ServerInfo::GetInfo() { - int maxclientCount = *Game::svs_clientCount; + auto maxClientCount = *Game::svs_clientCount; - if (!maxclientCount) + if (!maxClientCount) { - maxclientCount = Dvar::Var("party_maxplayers").get(); - //maxclientCount = Game::Party_GetMaxPlayers(*Game::partyIngame); + maxClientCount = Dvar::Var("party_maxplayers").get(); } - Utils::InfoString info(Game::Dvar_InfoString_Big(1024)); + Utils::InfoString info(Game::Dvar_InfoString_Big(Game::DVAR_SERVERINFO)); info.set("gamename", "IW4"); - info.set("sv_maxclients", Utils::String::VA("%i", maxclientCount)); + info.set("sv_maxclients", Utils::String::VA("%i", maxClientCount)); info.set("protocol", Utils::String::VA("%i", PROTOCOL)); info.set("shortversion", SHORTVERSION); info.set("mapname", Dvar::Var("mapname").get()); @@ -231,84 +227,83 @@ namespace Components Network::OnPacket("statusResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data) { - if (ServerInfo::PlayerContainer.target == address) + if (ServerInfo::PlayerContainer.target != address) { - Utils::InfoString info(data.substr(0, data.find_first_of("\n"))); + return; + } - Dvar::Var("uiSi_ServerName").set(info.get("sv_hostname")); - Dvar::Var("uiSi_MaxClients").set(info.get("sv_maxclients")); - Dvar::Var("uiSi_Version").set(info.get("shortversion")); - Dvar::Var("uiSi_SecurityLevel").set(info.get("sv_securityLevel")); - Dvar::Var("uiSi_isPrivate").set(info.get("isPrivate") == "0" ? "@MENU_NO" : "@MENU_YES"); - Dvar::Var("uiSi_Hardcore").set(info.get("g_hardcore") == "0" ? "@MENU_DISABLED" : "@MENU_ENABLED"); - Dvar::Var("uiSi_KillCam").set(info.get("scr_game_allowkillcam") == "0" ? "@MENU_NO" : "@MENU_YES"); - Dvar::Var("uiSi_MapName").set(info.get("mapname")); - Dvar::Var("uiSi_MapNameLoc").set(Game::UI_LocalizeMapName(info.get("mapname").data())); - Dvar::Var("uiSi_GameType").set(Game::UI_LocalizeGameType(info.get("g_gametype").data())); - Dvar::Var("uiSi_ModName").set(""); + const Utils::InfoString info(data.substr(0, data.find_first_of("\n"))); - switch (atoi(info.get("scr_team_fftype").data())) + Dvar::Var("uiSi_ServerName").set(info.get("sv_hostname")); + Dvar::Var("uiSi_MaxClients").set(info.get("sv_maxclients")); + Dvar::Var("uiSi_Version").set(info.get("shortversion")); + Dvar::Var("uiSi_SecurityLevel").set(info.get("sv_securityLevel")); + Dvar::Var("uiSi_isPrivate").set(info.get("isPrivate") == "0" ? "@MENU_NO" : "@MENU_YES"); + Dvar::Var("uiSi_Hardcore").set(info.get("g_hardcore") == "0" ? "@MENU_DISABLED" : "@MENU_ENABLED"); + Dvar::Var("uiSi_KillCam").set(info.get("scr_game_allowkillcam") == "0" ? "@MENU_NO" : "@MENU_YES"); + Dvar::Var("uiSi_MapName").set(info.get("mapname")); + Dvar::Var("uiSi_MapNameLoc").set(Game::UI_LocalizeMapName(info.get("mapname").data())); + Dvar::Var("uiSi_GameType").set(Game::UI_LocalizeGameType(info.get("g_gametype").data())); + Dvar::Var("uiSi_ModName").set(""); + + switch (atoi(info.get("scr_team_fftype").data())) + { + default: + Dvar::Var("uiSi_ffType").set("@MENU_DISABLED"); + break; + case 1: + Dvar::Var("uiSi_ffType").set("@MENU_ENABLED"); + break; + case 2: + Dvar::Var("uiSi_ffType").set("@MPUI_RULES_REFLECT"); + break; + case 3: + Dvar::Var("uiSi_ffType").set("@MPUI_RULES_SHARED"); + break; + } + + if (info.get("fs_game").size() > 5) + { + Dvar::Var("uiSi_ModName").set(info.get("fs_game").data() + 5); + } + + auto lines = Utils::String::Split(data, '\n'); + + if (lines.size() <= 1) return; + + for (std::size_t i = 1; i < lines.size(); ++i) + { + ServerInfo::Container::Player player; + + std::string currentData = lines[i]; + + if (currentData.size() < 3) continue; + + // Insert score + player.score = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); + + // Remove score + currentData = currentData.substr(currentData.find_first_of(" ") + 1); + + // Insert ping + player.ping = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); + + // Remove ping + currentData = currentData.substr(currentData.find_first_of(" ") + 1); + + if (currentData[0] == '\"') { - default: - Dvar::Var("uiSi_ffType").set("@MENU_DISABLED"); - break; - - case 1: - Dvar::Var("uiSi_ffType").set("@MENU_ENABLED"); - break; - - case 2: - Dvar::Var("uiSi_ffType").set("@MPUI_RULES_REFLECT"); - break; - - case 3: - Dvar::Var("uiSi_ffType").set("@MPUI_RULES_SHARED"); - break; + currentData = currentData.substr(1); } - if (info.get("fs_game").size() > 5) + if (currentData.back() == '\"') { - Dvar::Var("uiSi_ModName").set(info.get("fs_game").data() + 5); + currentData.pop_back(); } - auto lines = Utils::String::Split(data, '\n'); + player.name = currentData; - if (lines.size() <= 1) return; - - for (unsigned int i = 1; i < lines.size(); ++i) - { - ServerInfo::Container::Player player; - - std::string currentData = lines[i]; - - if (currentData.size() < 3) continue; - - // Insert score - player.score = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); - - // Remove score - currentData = currentData.substr(currentData.find_first_of(" ") + 1); - - // Insert ping - player.ping = atoi(currentData.substr(0, currentData.find_first_of(" ")).data()); - - // Remove ping - currentData = currentData.substr(currentData.find_first_of(" ") + 1); - - if (currentData[0] == '\"') - { - currentData = currentData.substr(1); - } - - if (currentData.back() == '\"') - { - currentData.pop_back(); - } - - player.name = currentData; - - ServerInfo::PlayerContainer.playerList.push_back(player); - } + ServerInfo::PlayerContainer.playerList.push_back(player); } }); } diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index e9d724c4..00ef76a7 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -312,7 +312,6 @@ namespace Components void ServerList::StoreFavourite(const std::string& server) { - //json11::Json::parse() std::vector servers; if (Utils::IO::FileExists("players/favourites.json")) @@ -327,7 +326,7 @@ namespace Components return; } - nlohmann::json::array_t storedServers = object; + nlohmann::json::array_t storedServers = object; for (unsigned int i = 0; i < storedServers.size(); ++i) { @@ -540,15 +539,12 @@ namespace Components ) { auto lList = ServerList::GetList(); - if (lList) { lList->push_back(server); ServerList::RefreshVisibleListInternal(UIScript::Token()); } } - - break; } else { diff --git a/src/Components/Modules/Theatre.cpp b/src/Components/Modules/Theatre.cpp index 44e1554b..e7d0fa41 100644 --- a/src/Components/Modules/Theatre.cpp +++ b/src/Components/Modules/Theatre.cpp @@ -206,7 +206,8 @@ namespace Components info.gametype = metaObject["gametype"].get(); info.mapname = metaObject["mapname"].get(); info.length = metaObject["length"].get(); - info.timeStamp = _atoi64(metaObject["timestamp"].get().data()); + auto timestamp = metaObject["timestamp"].get(); + info.timeStamp = _atoi64(timestamp.data()); Theatre::Demos.push_back(info); } diff --git a/src/Utils/InfoString.cpp b/src/Utils/InfoString.cpp index 534c7f75..9eb8c37b 100644 --- a/src/Utils/InfoString.cpp +++ b/src/Utils/InfoString.cpp @@ -76,6 +76,6 @@ namespace Utils nlohmann::json InfoString::to_json() const { - return {this->keyValuePairs}; + return this->keyValuePairs; } }