diff --git a/src/Components/Modules/Auth.cpp b/src/Components/Modules/Auth.cpp index e090e1bb..3c06bf72 100644 --- a/src/Components/Modules/Auth.cpp +++ b/src/Components/Modules/Auth.cpp @@ -8,7 +8,8 @@ namespace Components Utils::Cryptography::Token Auth::ComputeToken; Utils::Cryptography::ECC::Key Auth::GuidKey; - std::vector Auth::BannedUids = { + std::vector Auth::BannedUids = + { 0xf4d2c30b712ac6e3, 0xf7e33c4081337fa3, 0x6f5597f103cc50e9 @@ -179,8 +180,8 @@ namespace Components Utils::InfoString infostr(params[2]); // Read the required data - std::string steamId = infostr.get("xuid"); - std::string challenge = infostr.get("challenge"); + const auto& steamId = infostr.get("xuid"); + const auto& challenge = infostr.get("challenge"); if (steamId.empty() || challenge.empty()) { @@ -189,12 +190,12 @@ namespace Components } // Parse the id - unsigned __int64 xuid = strtoull(steamId.data(), nullptr, 16); + const auto xuid = strtoull(steamId.data(), nullptr, 16); SteamID guid; guid.bits = xuid; - if (Bans::IsBanned({ guid, address.getIP() })) + if (Bans::IsBanned({guid, address.getIP()})) { Network::Send(address, "error\nEXE_ERR_BANNED_PERM"); return; @@ -223,8 +224,8 @@ namespace Components } // Verify the security level - uint32_t ourLevel = static_cast(Dvar::Var("sv_securityLevel").get()); - uint32_t userLevel = Auth::GetZeroBits(connectData.token(), connectData.publickey()); + auto ourLevel = Dvar::Var("sv_securityLevel").get(); + auto userLevel = Auth::GetZeroBits(connectData.token(), connectData.publickey()); if (userLevel < ourLevel) { diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index 15e36cfb..f6b5061e 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -96,7 +96,7 @@ namespace Components if (bots.exists()) { - std::vector names = Utils::String::Explode(bots.getBuffer(), '\n'); + std::vector names = Utils::String::Split(bots.getBuffer(), '\n'); for (auto name : names) { diff --git a/src/Components/Modules/Changelog.cpp b/src/Components/Modules/Changelog.cpp index 059ef0bb..b88513a1 100644 --- a/src/Components/Modules/Changelog.cpp +++ b/src/Components/Modules/Changelog.cpp @@ -19,7 +19,7 @@ namespace Components data = "^1Unable to get changelog."; } - Changelog::Lines = Utils::String::Explode(data, '\n'); + Changelog::Lines = Utils::String::Split(data, '\n'); for (auto& line : Changelog::Lines) { diff --git a/src/Components/Modules/Dedicated.cpp b/src/Components/Modules/Dedicated.cpp index dc856792..6414aeda 100644 --- a/src/Components/Modules/Dedicated.cpp +++ b/src/Components/Modules/Dedicated.cpp @@ -124,7 +124,7 @@ namespace Components { auto rotation = Dvar::Var("sv_mapRotation").get(); - const auto tokens = Utils::String::Explode(rotation, ' '); + const auto tokens = Utils::String::Split(rotation, ' '); std::vector> mapRotationPair; for (auto i = 0u; i < (tokens.size() - 1); i += 2) @@ -207,7 +207,7 @@ namespace Components auto rotation = Dvar::Var("sv_mapRotationCurrent").get(); - auto tokens = Utils::String::Explode(rotation, ' '); + auto tokens = Utils::String::Split(rotation, ' '); for (unsigned int i = 0; i < (tokens.size() - 1); i += 2) { diff --git a/src/Components/Modules/Maps.cpp b/src/Components/Modules/Maps.cpp index a6081034..7a91f2ef 100644 --- a/src/Components/Modules/Maps.cpp +++ b/src/Components/Modules/Maps.cpp @@ -357,7 +357,7 @@ namespace Components { if (arena->keys[j] == "dependency"s) { - return Utils::String::Explode(arena->values[j], ' '); + return Utils::String::Split(arena->values[j], ' '); } } } diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 2d60d147..bc1af6dc 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -60,7 +60,7 @@ namespace Components std::string nodes = Utils::Cache::GetFile("/iw4/nodes.txt"); if (nodes.empty()) return; - auto nodeList = Utils::String::Explode(nodes, '\n'); + auto nodeList = Utils::String::Split(nodes, '\n'); for (auto& node : nodeList) { Utils::String::Replace(node, "\r", ""); diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index 04f08bb5..bfd9281d 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -264,7 +264,7 @@ namespace Components Dvar::Var("uiSi_ModName").set(info.get("fs_game").data() + 5); } - auto lines = Utils::String::Explode(data, '\n'); + auto lines = Utils::String::Split(data, '\n'); if (lines.size() <= 1) return; diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 166f444f..ce43bdc7 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -539,8 +539,8 @@ namespace Components bool ServerList::CompareVersion(const std::string& version1, const std::string& version2) { - std::vector subVersions1 = Utils::String::Explode(version1, '.'); - std::vector subVersions2 = Utils::String::Explode(version2, '.'); + std::vector subVersions1 = Utils::String::Split(version1, '.'); + std::vector subVersions2 = Utils::String::Split(version2, '.'); while (subVersions1.size() >= 3) subVersions1.pop_back(); while (subVersions2.size() >= 3) subVersions2.pop_back(); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 9e7b7132..d6b83c52 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -283,7 +283,7 @@ namespace Game typedef dvar_t* (__cdecl * Dvar_FindVar_t)(const char *dvarName); extern Dvar_FindVar_t Dvar_FindVar; - typedef char* (__cdecl* Dvar_InfoString_Big_t)(int typeMask); + typedef char* (__cdecl * Dvar_InfoString_Big_t)(int bit); extern Dvar_InfoString_Big_t Dvar_InfoString_Big; typedef dvar_t* (__cdecl * Dvar_SetCommand_t)(const char* name, const char* value); diff --git a/src/Utils/CSV.cpp b/src/Utils/CSV.cpp index 0b0a02d1..efcfcd28 100644 --- a/src/Utils/CSV.cpp +++ b/src/Utils/CSV.cpp @@ -71,7 +71,7 @@ namespace Utils if (!buffer.empty()) { - auto rows = Utils::String::Explode(buffer, '\n'); + auto rows = Utils::String::Split(buffer, '\n'); for (auto& row : rows) { diff --git a/src/Utils/InfoString.cpp b/src/Utils/InfoString.cpp index 09126843..ba861dac 100644 --- a/src/Utils/InfoString.cpp +++ b/src/Utils/InfoString.cpp @@ -9,9 +9,10 @@ namespace Utils std::string InfoString::get(const std::string& key) { - if (this->keyValuePairs.find(key) != this->keyValuePairs.end()) + const auto value = this->keyValuePairs.find(key); + if (value != this->keyValuePairs.end()) { - return this->keyValuePairs[key]; + return value->second; } return ""; @@ -24,11 +25,13 @@ namespace Utils buffer = buffer.substr(1); } - std::vector KeyValues = Utils::String::Explode(buffer, '\\'); + auto KeyValues = Utils::String::Split(buffer, '\\'); - for (unsigned int i = 0; i < (KeyValues.size() - 1); i += 2) + for (size_t i = 0; !KeyValues.empty() && i < (KeyValues.size() - 1); i += 2) { - this->keyValuePairs[KeyValues[i]] = KeyValues[i + 1]; + const auto& key = KeyValues[i]; + const auto& value = KeyValues[i + 1]; + this->keyValuePairs[key] = value; } } @@ -36,16 +39,16 @@ namespace Utils { std::string infoString; - bool first = true; + auto first = true; - for (auto i = this->keyValuePairs.begin(); i != this->keyValuePairs.end(); ++i) + for (const auto& [key, value] : this->keyValuePairs) { if (first) first = false; else infoString.append("\\"); - infoString.append(i->first); // Key + infoString.append(key); infoString.append("\\"); - infoString.append(i->second); // Value + infoString.append(value); } return infoString; @@ -53,9 +56,9 @@ namespace Utils void InfoString::dump() { - for (auto i = this->keyValuePairs.begin(); i != this->keyValuePairs.end(); ++i) + for (const auto& [key, value] : this->keyValuePairs) { - OutputDebugStringA(Utils::String::VA("%s: %s", i->first.data(), i->second.data())); + OutputDebugStringA(Utils::String::VA("%s: %s\n", key.data(), value.data())); } } diff --git a/src/Utils/InfoString.hpp b/src/Utils/InfoString.hpp index d83edde8..f63c6714 100644 --- a/src/Utils/InfoString.hpp +++ b/src/Utils/InfoString.hpp @@ -7,11 +7,9 @@ namespace Utils public: InfoString() {}; InfoString(const std::string& buffer) : InfoString() { this->parse(buffer); }; - InfoString(const InfoString &obj) : keyValuePairs(obj.keyValuePairs) {}; void set(const std::string& key, const std::string& value); std::string get(const std::string& key); - std::string build(); void dump(); diff --git a/src/Utils/String.cpp b/src/Utils/String.cpp index ca2d0664..67d35006 100644 --- a/src/Utils/String.cpp +++ b/src/Utils/String.cpp @@ -62,25 +62,18 @@ namespace Utils return str; } - std::vector Explode(const std::string& str, char delim) + std::vector Split(const std::string& str, const char delim) { - std::vector result; - std::istringstream iss(str); + std::stringstream ss(str); + std::string item; + std::vector elems; - for (std::string token; std::getline(iss, token, delim);) + while (std::getline(ss, item, delim)) { - std::string _entry = std::move(token); - - // Remove trailing 0x0 bytes - while (_entry.size() && !_entry.back()) - { - _entry = _entry.substr(0, _entry.size() - 1); - } - - result.push_back(_entry); + elems.push_back(item); // elems.push_back(std::move(item)); // if C++11 (based on comment from S1x) } - return result; + return elems; } void Replace(std::string &string, const std::string& find, const std::string& replace) diff --git a/src/Utils/String.hpp b/src/Utils/String.hpp index 2b0ed6d1..3beed27e 100644 --- a/src/Utils/String.hpp +++ b/src/Utils/String.hpp @@ -78,7 +78,7 @@ namespace Utils std::string ToLower(std::string input); std::string ToUpper(std::string input); bool EndsWith(const std::string& haystack, const std::string& needle); - std::vector Explode(const std::string& str, char delim); + std::vector Split(const std::string& str, const char delim); void Replace(std::string &string, const std::string& find, const std::string& replace); bool StartsWith(const std::string& haystack, const std::string& needle); std::string <rim(std::string &s);