diff --git a/src/client/component/party.cpp b/src/client/component/party.cpp index 7328bc94..8549e67e 100644 --- a/src/client/component/party.cpp +++ b/src/client/component/party.cpp @@ -7,6 +7,7 @@ #include "scheduler.hpp" #include +#include #include #include #include @@ -127,7 +128,7 @@ namespace party host.info.netAdr = addr; host.info.xuid = xuid; - strcpy_s(host.info.name, hostname.data()); + utils::string::copy(host.info.name, hostname.data()); host.lobbyType = game::LOBBY_TYPE_PRIVATE; host.lobbyParams.networkMode = game::LOBBY_NETWORKMODE_LIVE; diff --git a/src/client/game/demonware/byte_buffer.cpp b/src/client/game/demonware/byte_buffer.cpp index af5bee9a..906b521f 100644 --- a/src/client/game/demonware/byte_buffer.cpp +++ b/src/client/game/demonware/byte_buffer.cpp @@ -1,5 +1,6 @@ #include #include "byte_buffer.hpp" +#include namespace demonware { @@ -90,7 +91,7 @@ namespace demonware { if (!this->read_data_type(16)) return false; - strcpy_s(output, length, const_cast(this->buffer_.data()) + this->current_byte_); + utils::string::copy(output, static_cast(length), const_cast(this->buffer_.data()) + this->current_byte_); this->current_byte_ += strlen(output) + 1; return true; diff --git a/src/client/steam/interfaces/matchmaking_servers.cpp b/src/client/steam/interfaces/matchmaking_servers.cpp index e9029ef8..8f772b65 100644 --- a/src/client/steam/interfaces/matchmaking_servers.cpp +++ b/src/client/steam/interfaces/matchmaking_servers.cpp @@ -38,9 +38,9 @@ namespace steam server.m_nPing = static_cast(ping); server.m_bHadSuccessfulResponse = success; server.m_bDoNotRefresh = false; - strcpy_s(server.m_szGameDir, ""); - strcpy_s(server.m_szMap, info.get("mapname").data()); - strcpy_s(server.m_szGameDescription, info.get("description").data()); + ::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()); server.m_nAppID = 311210; server.m_nPlayers = atoi(info.get("clients").data()); server.m_nMaxPlayers = atoi(info.get("sv_maxclients").data()); @@ -49,7 +49,7 @@ namespace steam server.m_bSecure = true; server.m_ulTimeLastPlayed = 0; server.m_nServerVersion = 1000; - strcpy_s(server.m_szServerName, info.get("hostname").data()); + ::utils::string::copy(server.m_szServerName, info.get("hostname").data()); const auto playmode = info.get("playmode"); const auto mode = game::eModes(std::atoi(playmode.data())); @@ -60,7 +60,7 @@ namespace steam info.get("dedicated") == "1" ? "true" : "false", mode == game::MODE_ZOMBIES ? "true" : "false", server.m_nPlayers); - strcpy_s(server.m_szGameTags, tags); + ::utils::string::copy(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 3313eca9..cf030dd4 100644 --- a/src/common/utils/string.cpp +++ b/src/common/utils/string.cpp @@ -174,4 +174,23 @@ namespace utils::string return str; } + + void copy(char* dest, const size_t max_size, const char* src) + { + for (size_t i = 0;; ++i) + { + if (i + 1 == max_size) + { + dest[i] = 0; + break; + } + + dest[i] = src[i]; + + if (!src[i]) + { + break; + } + } + } } diff --git a/src/common/utils/string.hpp b/src/common/utils/string.hpp index edc5cc1b..6a2cdc76 100644 --- a/src/common/utils/string.hpp +++ b/src/common/utils/string.hpp @@ -94,4 +94,12 @@ namespace utils::string std::wstring convert(const std::string& str); std::string replace(std::string str, const std::string& from, const std::string& to); + + void copy(char* dest, size_t max_size, const char* src); + + template + void copy(char (&dest)[Size], const char* src) + { + copy(dest, Size, src); + } }