diff --git a/src/Components/Modules/AssetInterfaces/IMaterial.cpp b/src/Components/Modules/AssetInterfaces/IMaterial.cpp index 39e95fc9..7e875f52 100644 --- a/src/Components/Modules/AssetInterfaces/IMaterial.cpp +++ b/src/Components/Modules/AssetInterfaces/IMaterial.cpp @@ -307,7 +307,7 @@ namespace Assets { std::vector textureList; - for (auto texture : textures.array_items()) + for (auto& texture : textures.array_items()) { if (!texture.is_array()) continue; if (textureList.size() >= 0xFF) break; diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index c6527f99..114e4471 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -14,7 +14,7 @@ namespace Components if (nodes.empty()) return; auto nodeList = Utils::String::Explode(nodes, '\n'); - for (auto node : nodeList) + for (auto& node : nodeList) { Utils::String::Replace(node, "\r", ""); node = Utils::String::Trim(node); @@ -71,7 +71,7 @@ namespace Components //list.set_is_dedi(Dedicated::IsDedicated()); std::lock_guard _(Node::NodeMutex); - for (auto node : Node::Nodes) + for (auto& node : Node::Nodes) { if (node.state == Node::STATE_VALID && node.registered) { @@ -114,7 +114,7 @@ namespace Components unsigned int count = 0; std::lock_guard _(Node::NodeMutex); - for (auto node : Node::Nodes) + for (auto& node : Node::Nodes) { if (node.state == Node::STATE_VALID) { @@ -416,7 +416,7 @@ namespace Components packet.set_signature(Utils::Cryptography::ECC::SignMessage(Node::SignatureKey, challenge)); std::lock_guard _(Node::NodeMutex); - for (auto node : Node::Nodes) + for (auto& node : Node::Nodes) { Network::SendCommand(node.address, "nodeDeregister", packet.SerializeAsString()); } @@ -846,7 +846,7 @@ namespace Components Logger::Print("Nodes: %d (%d)\n", Node::Nodes.size(), Node::GetValidNodeCount()); std::lock_guard _(Node::NodeMutex); - for (auto node : Node::Nodes) + for (auto& node : Node::Nodes) { Logger::Print("%s\t(%s)\n", node.address.getCString(), Node::GetStateName(node.state)); } @@ -894,6 +894,33 @@ namespace Components Node::LoadNodeRemotePreset(); }).detach(); }); + + if (Dedicated::IsEnabled()) + { + Network::Handle("getServersRequest", [](Network::Address target, std::string) + { + std::string data; + + { + std::lock_guard _(Node::NodeMutex); + for (auto& node : Node::Nodes) + { + if (node.state == Node::STATE_VALID && node.isDedi) + { + Game::netIP_t ip = node.address.getIP(); + unsigned short port = htons(node.address.getPort()); + data.append(reinterpret_cast(&ip.full), 4); + data.append(reinterpret_cast(&port), 2); + data.append("\\"); + } + } + + data.append("EOT"); + } + + Network::SendCommand(target, "getServersResponse", data); + }); + } } Node::~Node() diff --git a/src/Components/Modules/ServerList.cpp b/src/Components/Modules/ServerList.cpp index 69262661..a3168e47 100644 --- a/src/Components/Modules/ServerList.cpp +++ b/src/Components/Modules/ServerList.cpp @@ -184,7 +184,7 @@ namespace Components ServerList::RefreshContainer.sendCount = 0; ServerList::RefreshContainer.sentCount = 0; - for (auto server : tempList) + for (auto& server : tempList) { ServerList::InsertRequest(server.addr); } @@ -255,11 +255,13 @@ namespace Components if (list) list->clear(); ServerList::VisibleList.clear(); - ServerList::RefreshContainer.mutex.lock(); - ServerList::RefreshContainer.servers.clear(); - ServerList::RefreshContainer.sendCount = 0; - ServerList::RefreshContainer.sentCount = 0; - ServerList::RefreshContainer.mutex.unlock(); + + { + std::lock_guard _(ServerList::RefreshContainer.mutex); + ServerList::RefreshContainer.servers.clear(); + ServerList::RefreshContainer.sendCount = 0; + ServerList::RefreshContainer.sentCount = 0; + } if (ServerList::IsOfflineList()) { @@ -417,7 +419,7 @@ namespace Components auto list = ServerList::GetList(); if (list) { - for (auto server : *list) + for (auto& server : *list) { if (server.addr == container.target) { @@ -604,8 +606,7 @@ namespace Components void ServerList::Frame() { - // This is bad practice and might even cause undefined behaviour! - if (!ServerList::RefreshContainer.mutex.try_lock()) return; + std::lock_guard _(ServerList::RefreshContainer.mutex); if (ServerList::RefreshContainer.awatingList) { @@ -644,8 +645,6 @@ namespace Components } ServerList::UpdateVisibleInfo(); - - ServerList::RefreshContainer.mutex.unlock(); } void ServerList::UpdateSource() @@ -865,9 +864,10 @@ namespace Components ServerList::FavouriteList.clear(); ServerList::VisibleList.clear(); - ServerList::RefreshContainer.mutex.lock(); - ServerList::RefreshContainer.awatingList = false; - ServerList::RefreshContainer.servers.clear(); - ServerList::RefreshContainer.mutex.unlock(); + { + std::lock_guard _(ServerList::RefreshContainer.mutex); + ServerList::RefreshContainer.awatingList = false; + ServerList::RefreshContainer.servers.clear(); + } } } diff --git a/src/Utils/CSV.cpp b/src/Utils/CSV.cpp index b69440ac..31d4282e 100644 --- a/src/Utils/CSV.cpp +++ b/src/Utils/CSV.cpp @@ -10,16 +10,6 @@ namespace Utils CSV::~CSV() { - for (auto row : this->dataMap) - { - for (auto entry : row) - { - entry.clear(); - } - - row.clear(); - } - this->dataMap.clear(); } @@ -84,7 +74,7 @@ namespace Utils { auto rows = Utils::String::Explode(buffer, '\n'); - for (auto row : rows) + for (auto& row : rows) { this->parseRow(row, allowComments); } diff --git a/src/Utils/Memory.hpp b/src/Utils/Memory.hpp index 0fb8e148..7d7efe8e 100644 --- a/src/Utils/Memory.hpp +++ b/src/Utils/Memory.hpp @@ -34,7 +34,7 @@ namespace Utils this->refMemory.clear(); - for (auto data : this->pool) + for (auto& data : this->pool) { Memory::Free(data); } diff --git a/src/Utils/Utils.hpp b/src/Utils/Utils.hpp index 050158ae..6c0bcbe4 100644 --- a/src/Utils/Utils.hpp +++ b/src/Utils/Utils.hpp @@ -92,7 +92,7 @@ namespace Utils std::vector> copiedSlots; Utils::Merge(&copiedSlots, this->slots); - for (auto slot : copiedSlots) + for (auto& slot : copiedSlots) { if (slot) { diff --git a/src/Utils/WebIO.cpp b/src/Utils/WebIO.cpp index b1aee4b1..3b928d34 100644 --- a/src/Utils/WebIO.cpp +++ b/src/Utils/WebIO.cpp @@ -435,7 +435,7 @@ namespace Utils for (auto file : list) this->deleteFile(file); this->listDirectories(".", list); - for (auto dir : list) this->deleteDirectory(dir); + for (auto& dir : list) this->deleteDirectory(dir); this->setDirectory(tempDir);