diff --git a/src/client/steam/interfaces/matchmaking_servers.cpp b/src/client/steam/interfaces/matchmaking_servers.cpp index 594689ce..924d7f62 100644 --- a/src/client/steam/interfaces/matchmaking_servers.cpp +++ b/src/client/steam/interfaces/matchmaking_servers.cpp @@ -28,6 +28,13 @@ namespace steam ::utils::concurrency::container queried_servers{}; std::atomic current_response{}; + template + void copy_safe(T& dest, const char* in) + { + ::utils::string::copy(dest, in); + ::utils::string::strip_material(dest, dest, std::extent::value); + } + gameserveritem_t create_server_item(const game::netadr_t& address, const ::utils::info_string& info, const uint32_t ping, const bool success) { @@ -40,9 +47,11 @@ namespace steam server.m_nPing = static_cast(ping); server.m_bHadSuccessfulResponse = success; server.m_bDoNotRefresh = false; - ::utils::string::copy(server.m_szGameDir, ""); - ::utils::string::copy(server.m_szMap, info.get("mapname").data()); - ::utils::string::copy(server.m_szGameDescription, info.get("description").data()); + + copy_safe(server.m_szGameDir, ""); + copy_safe(server.m_szMap, info.get("mapname").data()); + copy_safe(server.m_szGameDescription, info.get("description").data()); + server.m_nAppID = (sub_protocol == SUB_PROTOCOL || sub_protocol == (SUB_PROTOCOL - 1)) ? 311210 : 0; server.m_nPlayers = atoi(info.get("clients").data()); server.m_nMaxPlayers = atoi(info.get("sv_maxclients").data()); @@ -51,7 +60,8 @@ namespace steam server.m_bSecure = true; server.m_ulTimeLastPlayed = 0; server.m_nServerVersion = 1000; - ::utils::string::copy(server.m_szServerName, info.get("hostname").data()); + + copy_safe(server.m_szServerName, info.get("hostname").data()); const auto playmode = info.get("playmode"); const auto mode = game::eModes(std::atoi(playmode.data())); @@ -66,7 +76,8 @@ namespace steam atoi(info.get("bots").data()), info.get("modname").data()); - ::utils::string::copy(server.m_szGameTags, tags); + copy_safe(server.m_szGameTags, tags); + server.m_steamID.bits = strtoull(info.get("xuid").data(), nullptr, 16); return server; diff --git a/src/common/utils/string.cpp b/src/common/utils/string.cpp index 64a1215e..2421e0c3 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -1,7 +1,8 @@ #include "string.hpp" -#include -#include #include +#include +#include +#include #include "nt.hpp" @@ -107,11 +108,12 @@ namespace utils::string void strip(const char* in, char* out, size_t max) { + assert(max); if (!in || !out) return; max--; size_t current = 0; - while (*in != 0 && current < max) + while (*in != '\0' && current < max) { const auto color_index = (*(in + 1) - 48) >= 0xC ? 7 : (*(in + 1) - 48); @@ -132,6 +134,25 @@ namespace utils::string *out = '\0'; } + void strip_material(const char* in, char* out, size_t max) + { + assert(max); + if (!in || !out) return; + + size_t i = 0; + while (*in != '\0' && i < max - 1) + { + if (*in != '$' && *in != '{' && *in != '}') + { + *out++ = *in; + i++; + } + in++; + } + + *out = '\0'; + } + std::string convert(const std::wstring& wstr) { std::string result; diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index d3d798dd..c58753dc 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -89,6 +89,7 @@ namespace utils::string std::string get_clipboard_data(); void strip(const char* in, char* out, size_t max); + void strip_material(const char* in, char* out, size_t max); std::string convert(const std::wstring& wstr); std::wstring convert(const std::string& str);