diff --git a/src/Components/Modules/Bots.cpp b/src/Components/Modules/Bots.cpp index e8634b83..15e36cfb 100644 --- a/src/Components/Modules/Bots.cpp +++ b/src/Components/Modules/Bots.cpp @@ -71,7 +71,7 @@ namespace Components { "9", 33554432 }, }; - unsigned int Bots::GetClientNum(const Game::client_s* cl) + unsigned int Bots::GetClientNum(Game::client_s* cl) { unsigned int num; diff --git a/src/Components/Modules/Bots.hpp b/src/Components/Modules/Bots.hpp index 6b1efd3c..ee8381aa 100644 --- a/src/Components/Modules/Bots.hpp +++ b/src/Components/Modules/Bots.hpp @@ -7,7 +7,7 @@ namespace Components public: Bots(); ~Bots(); - static unsigned int GetClientNum(const Game::client_s*); + static unsigned int GetClientNum(Game::client_s*); static bool IsValidClientNum(unsigned int); private: diff --git a/src/Components/Modules/Chat.cpp b/src/Components/Modules/Chat.cpp index c10df623..07715101 100644 --- a/src/Components/Modules/Chat.cpp +++ b/src/Components/Modules/Chat.cpp @@ -8,10 +8,13 @@ namespace Components bool Chat::SendChat; + std::mutex Chat::AccessMutex; std::unordered_set Chat::MuteList; const char* Chat::EvaluateSay(char* text, Game::gentity_t* player) { + std::lock_guard _(Chat::AccessMutex); + Chat::SendChat = true; if (text[1] == '/') @@ -205,12 +208,14 @@ namespace Components void Chat::MuteClient(const Game::client_t* client) { + std::lock_guard _(Chat::AccessMutex); + if (Chat::MuteList.find(client->steamID) == Chat::MuteList.end()) { Chat::MuteList.insert(client->steamID); Logger::Print("%s was muted\n", client->name); - Game::SV_GameSendServerCommand(Bots::GetClientNum(client), 0, + Game::SV_GameSendServerCommand(client->gentity->s.number, 0, Utils::String::VA("%c \"You were muted\"", 0x65)); return; } @@ -222,13 +227,23 @@ namespace Components void Chat::UnmuteClient(const Game::client_t* client) { - Chat::MuteList.erase(client->steamID); + Chat::UnmuteInternal(client->steamID); Logger::Print("%s was unmuted\n", client->name); - Game::SV_GameSendServerCommand(Bots::GetClientNum(client), 0, + Game::SV_GameSendServerCommand(client->gentity->s.number, 0, Utils::String::VA("%c \"You were unmuted\"", 0x65)); } + void Chat::UnmuteInternal(const std::uint64_t id, bool everyone) + { + std::lock_guard _(Chat::AccessMutex); + + if (everyone) + Chat::MuteList.clear(); + else + Chat::MuteList.erase(id); + } + void Chat::AddChatCommands() { Command::AddSV("muteClient", [](Command::Params* params) @@ -279,12 +294,12 @@ namespace Components if (params->get(1) == "all"s) { Logger::Print("All players were unmuted\n"); - Chat::MuteList.clear(); + Chat::UnmuteInternal(0, true); } else { - const auto SteamID = std::strtoull(params->get(1), nullptr, 16); - Chat::MuteList.erase(SteamID); + const auto steamId = std::strtoull(params->get(1), nullptr, 16); + Chat::UnmuteInternal(steamId); } }); } diff --git a/src/Components/Modules/Chat.hpp b/src/Components/Modules/Chat.hpp index 72a564db..62bc36aa 100644 --- a/src/Components/Modules/Chat.hpp +++ b/src/Components/Modules/Chat.hpp @@ -16,6 +16,7 @@ namespace Components static bool SendChat; + static std::mutex AccessMutex; static std::unordered_set MuteList; static const char* EvaluateSay(char* text, Game::gentity_t* player); @@ -29,6 +30,7 @@ namespace Components static void MuteClient(const Game::client_t* client); static void UnmuteClient(const Game::client_t* client); + static void UnmuteInternal(const std::uint64_t id, bool everyone = false); static void AddChatCommands(); }; }