diff --git a/src/Components/Modules/Bans.cpp b/src/Components/Modules/Bans.cpp index 63a78f07..17e28b39 100644 --- a/src/Components/Modules/Bans.cpp +++ b/src/Components/Modules/Bans.cpp @@ -120,11 +120,7 @@ namespace Components Logger::Error("Failed to parse bans (bans.json): %s", error.data()); } - if (!list) - { - Bans::AccessMutex.unlock(); - return; - } + if (!list) return; if (banData.is_object()) { diff --git a/src/Components/Modules/Discovery.cpp b/src/Components/Modules/Discovery.cpp index 01e14601..2e4fa8c0 100644 --- a/src/Components/Modules/Discovery.cpp +++ b/src/Components/Modules/Discovery.cpp @@ -80,7 +80,7 @@ namespace Components if (ServerList::IsOfflineList()) { - ServerList::InsertRequest(address, true); + ServerList::InsertRequest(address); } }); diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index cf6e2fed..c6527f99 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -778,7 +778,7 @@ namespace Components if (!Dedicated::IsEnabled() && entry->isDedi && ServerList::IsOnlineList() && entry->protocol == PROTOCOL) { - ServerList::InsertRequest(entry->address, true); + ServerList::InsertRequest(entry->address); } for (int i = 0; i < list.address_size(); ++i) diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 22c243cf..d242ccc5 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -179,14 +179,14 @@ namespace Components { list->clear(); - std::lock_guard _(ServerList::RefreshContainer.mutex); + std::lock_guard _(ServerList::RefreshContainer.mutex); ServerList::RefreshContainer.sendCount = 0; ServerList::RefreshContainer.sentCount = 0; for (auto server : tempList) { - ServerList::InsertRequest(server.addr, false); + ServerList::InsertRequest(server.addr); } } } @@ -387,14 +387,14 @@ namespace Components for (unsigned int i = 0; i < servers.size(); ++i) { if(!servers[i].is_string()) continue; - ServerList::InsertRequest(servers[i].string_value(), true); + ServerList::InsertRequest(servers[i].string_value()); } } } - void ServerList::InsertRequest(Network::Address address, bool acquireMutex) + void ServerList::InsertRequest(Network::Address address) { - if (acquireMutex) ServerList::RefreshContainer.mutex.lock(); + std::lock_guard _(ServerList::RefreshContainer.mutex); ServerList::Container::ServerContainer container; container.sent = false; @@ -430,13 +430,11 @@ namespace Components ++ServerList::RefreshContainer.sendCount; } - - if (acquireMutex) ServerList::RefreshContainer.mutex.unlock(); } void ServerList::Insert(Network::Address address, Utils::InfoString info) { - std::lock_guard _(ServerList::RefreshContainer.mutex); + std::lock_guard _(ServerList::RefreshContainer.mutex); for (auto i = ServerList::RefreshContainer.servers.begin(); i != ServerList::RefreshContainer.servers.end();) { @@ -731,7 +729,7 @@ namespace Components ServerList::RefreshContainer.awatingList = false; - std::lock_guard _(ServerList::RefreshContainer.mutex); + std::lock_guard _(ServerList::RefreshContainer.mutex); int offset = 0; int count = ServerList::RefreshContainer.servers.size(); @@ -751,7 +749,7 @@ namespace Components serverAddr.setPort(ntohs(entry[i].port)); serverAddr.setType(Game::NA_IP); - ServerList::InsertRequest(serverAddr, false); + ServerList::InsertRequest(serverAddr); } Logger::Print("Parsed %d servers from master\n", ServerList::RefreshContainer.servers.size() - count); diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index 92c9dc92..8c17f8b3 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -39,7 +39,7 @@ namespace Components static void Refresh(UIScript::Token); static void RefreshVisibleList(UIScript::Token); static void UpdateVisibleList(UIScript::Token); - static void InsertRequest(Network::Address address, bool acquireMutex = true); + static void InsertRequest(Network::Address address); static void Insert(Network::Address address, Utils::InfoString info); static ServerInfo* GetCurrentServer(); @@ -109,7 +109,7 @@ namespace Components Network::Address host; std::vector servers; - std::mutex mutex; + std::recursive_mutex mutex; }; static unsigned int GetServerCount();