Merge pull request #409 from diamante0018/fixes-json

Fixes for JSON
This commit is contained in:
Dss0 2022-08-04 11:32:59 +02:00 committed by GitHub
commit 7808e9a90c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 89 deletions

View File

@ -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 slow motion during final killcams (#111 - #107)
- Fixed sound issue that causes the game to freeze (#106) - 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 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 ### Known issues

View File

@ -5,10 +5,10 @@ namespace Assets
{ {
void Isnd_alias_list_t::load(Game::XAssetHeader* header, const std::string& name, Components::ZoneBuilder::Zone* builder) 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()) 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; return;
} }
@ -19,7 +19,6 @@ namespace Assets
return; return;
} }
std::string errors;
nlohmann::json infoData = nlohmann::json::parse(aliasFile.getBuffer()); nlohmann::json infoData = nlohmann::json::parse(aliasFile.getBuffer());
nlohmann::json aliasesContainer = infoData["head"]; nlohmann::json aliasesContainer = infoData["head"];

View File

@ -151,7 +151,8 @@ namespace Components
if (idEntry.is_string()) if (idEntry.is_string())
{ {
SteamID id; SteamID id;
id.bits = strtoull(idEntry.get<std::string>().data(), nullptr, 16); auto guid = idEntry.get<std::string>();
id.bits = std::strtoull(guid.data(), nullptr, 16);
list->idList.push_back(id); list->idList.push_back(id);
} }

View File

@ -20,13 +20,10 @@ namespace Components
{ {
case 0: case 0:
return Utils::String::VA("%d", index); return Utils::String::VA("%d", index);
case 1: case 1:
return ServerInfo::PlayerContainer.playerList[index].name.data(); return ServerInfo::PlayerContainer.playerList[index].name.data();
case 2: case 2:
return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].score); return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].score);
case 3: case 3:
return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].ping); return Utils::String::VA("%d", ServerInfo::PlayerContainer.playerList[index].ping);
default: default:
@ -130,17 +127,16 @@ namespace Components
Utils::InfoString ServerInfo::GetInfo() Utils::InfoString ServerInfo::GetInfo()
{ {
int maxclientCount = *Game::svs_clientCount; auto maxClientCount = *Game::svs_clientCount;
if (!maxclientCount) if (!maxClientCount)
{ {
maxclientCount = Dvar::Var("party_maxplayers").get<int>(); maxClientCount = Dvar::Var("party_maxplayers").get<int>();
//maxclientCount = Game::Party_GetMaxPlayers(*Game::partyIngame);
} }
Utils::InfoString info(Game::Dvar_InfoString_Big(1024)); Utils::InfoString info(Game::Dvar_InfoString_Big(Game::DVAR_SERVERINFO));
info.set("gamename", "IW4"); 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("protocol", Utils::String::VA("%i", PROTOCOL));
info.set("shortversion", SHORTVERSION); info.set("shortversion", SHORTVERSION);
info.set("mapname", Dvar::Var("mapname").get<const char*>()); info.set("mapname", Dvar::Var("mapname").get<const char*>());
@ -231,9 +227,12 @@ namespace Components
Network::OnPacket("statusResponse", [](const Network::Address& address, [[maybe_unused]] const std::string& data) 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;
}
const Utils::InfoString info(data.substr(0, data.find_first_of("\n")));
Dvar::Var("uiSi_ServerName").set(info.get("sv_hostname")); Dvar::Var("uiSi_ServerName").set(info.get("sv_hostname"));
Dvar::Var("uiSi_MaxClients").set(info.get("sv_maxclients")); Dvar::Var("uiSi_MaxClients").set(info.get("sv_maxclients"));
@ -252,15 +251,12 @@ namespace Components
default: default:
Dvar::Var("uiSi_ffType").set("@MENU_DISABLED"); Dvar::Var("uiSi_ffType").set("@MENU_DISABLED");
break; break;
case 1: case 1:
Dvar::Var("uiSi_ffType").set("@MENU_ENABLED"); Dvar::Var("uiSi_ffType").set("@MENU_ENABLED");
break; break;
case 2: case 2:
Dvar::Var("uiSi_ffType").set("@MPUI_RULES_REFLECT"); Dvar::Var("uiSi_ffType").set("@MPUI_RULES_REFLECT");
break; break;
case 3: case 3:
Dvar::Var("uiSi_ffType").set("@MPUI_RULES_SHARED"); Dvar::Var("uiSi_ffType").set("@MPUI_RULES_SHARED");
break; break;
@ -275,7 +271,7 @@ namespace Components
if (lines.size() <= 1) return; if (lines.size() <= 1) return;
for (unsigned int i = 1; i < lines.size(); ++i) for (std::size_t i = 1; i < lines.size(); ++i)
{ {
ServerInfo::Container::Player player; ServerInfo::Container::Player player;
@ -309,7 +305,6 @@ namespace Components
ServerInfo::PlayerContainer.playerList.push_back(player); ServerInfo::PlayerContainer.playerList.push_back(player);
} }
}
}); });
} }

View File

@ -312,7 +312,6 @@ namespace Components
void ServerList::StoreFavourite(const std::string& server) void ServerList::StoreFavourite(const std::string& server)
{ {
//json11::Json::parse()
std::vector<std::string> servers; std::vector<std::string> servers;
if (Utils::IO::FileExists("players/favourites.json")) if (Utils::IO::FileExists("players/favourites.json"))
@ -540,15 +539,12 @@ namespace Components
) )
{ {
auto lList = ServerList::GetList(); auto lList = ServerList::GetList();
if (lList) if (lList)
{ {
lList->push_back(server); lList->push_back(server);
ServerList::RefreshVisibleListInternal(UIScript::Token()); ServerList::RefreshVisibleListInternal(UIScript::Token());
} }
} }
break;
} }
else else
{ {

View File

@ -206,7 +206,8 @@ namespace Components
info.gametype = metaObject["gametype"].get<std::string>(); info.gametype = metaObject["gametype"].get<std::string>();
info.mapname = metaObject["mapname"].get<std::string>(); info.mapname = metaObject["mapname"].get<std::string>();
info.length = metaObject["length"].get<int>(); info.length = metaObject["length"].get<int>();
info.timeStamp = _atoi64(metaObject["timestamp"].get<std::string>().data()); auto timestamp = metaObject["timestamp"].get<std::string>();
info.timeStamp = _atoi64(timestamp.data());
Theatre::Demos.push_back(info); Theatre::Demos.push_back(info);
} }

View File

@ -76,6 +76,6 @@ namespace Utils
nlohmann::json InfoString::to_json() const nlohmann::json InfoString::to_json() const
{ {
return {this->keyValuePairs}; return this->keyValuePairs;
} }
} }