diff --git a/src/Components/Modules/News.hpp b/src/Components/Modules/News.hpp index a69aa27d..9170dcf6 100644 --- a/src/Components/Modules/News.hpp +++ b/src/Components/Modules/News.hpp @@ -14,7 +14,6 @@ namespace Components static std::thread Thread; static bool Terminate; - static bool DownloadUpdater(); static const char* GetNewsText(); }; diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 7d55671f..50b0c8fe 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -149,7 +149,7 @@ namespace Components Utils::IO::WriteFile("players/nodes.json", out.dump()); } - void Node::Add(Network::Address address) + void Node::Add(const Network::Address& address) { #ifndef DEBUG if (address.isLocal() || address.isSelf()) return; @@ -193,24 +193,23 @@ namespace Components if (WasIngame) // our last frame we were in-game and now we aren't so touch all nodes { - for (auto i = Nodes.begin(); i != Nodes.end();++i) + for (auto& entry : Nodes) { // clearing the last request and response times makes the // dispatcher think its a new node and will force a refresh - i->lastRequest.reset(); - i->lastResponse.reset(); + entry.lastRequest.reset(); + entry.lastResponse.reset(); } WasIngame = false; } static Utils::Time::Interval frameLimit; - int interval = static_cast(1000.0f / Dvar::Var("net_serverFrames").get()); + const auto interval = 1000 / ServerList::NETServerFrames.get(); if (!frameLimit.elapsed(std::chrono::milliseconds(interval))) return; frameLimit.update(); std::lock_guard _(Mutex); - Dvar::Var queryLimit("net_serverQueryLimit"); int sentRequests = 0; for (auto i = Nodes.begin(); i != Nodes.end();) @@ -220,7 +219,8 @@ namespace Components i = Nodes.erase(i); continue; } - if (sentRequests < queryLimit.get() && i->requiresRequest()) + + if (sentRequests < ServerList::NETServerQueryLimit.get() && i->requiresRequest()) { ++sentRequests; i->sendRequest(); @@ -241,7 +241,7 @@ namespace Components } } - void Node::HandleResponse(Network::Address address, const std::string& data) + void Node::HandleResponse(const Network::Address& address, const std::string& data) { Proto::Node::List list; if (!list.ParseFromString(data)) return; @@ -320,11 +320,11 @@ namespace Components break; } - auto node = Nodes.at(curNode++); + auto& node = Nodes.at(curNode++); if (node.isValid()) { - std::string* str = list.add_nodes(); + auto* str = list.add_nodes(); sockaddr addr = node.address.getSockAddr(); str->append(reinterpret_cast(&addr), sizeof(addr)); @@ -401,7 +401,7 @@ namespace Components Scheduler::Loop([] { StoreNodes(false); - }, Scheduler::Pipeline::ASYNC); + }, Scheduler::Pipeline::ASYNC, 5min); Scheduler::Loop(RunFrame, Scheduler::Pipeline::MAIN); @@ -411,15 +411,12 @@ namespace Components SendList(address); }); - // Load stored nodes - auto loadNodes = [] + Scheduler::OnGameInitialized([] { Migrate(); LoadNodePreset(); LoadNodes(); - }; - - Scheduler::OnGameInitialized(loadNodes, Scheduler::Pipeline::MAIN); + }, Scheduler::Pipeline::MAIN); Command::Add("listNodes", [](const Command::Params*) { diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index d76cdd20..d0943b43 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -36,7 +36,7 @@ namespace Components Node(); void preDestroy() override; - static void Add(Network::Address address); + static void Add(const Network::Address& address); static std::vector GetNodes(); static void RunFrame(); static void Synchronize(); @@ -46,7 +46,7 @@ namespace Components static std::vector Nodes; static bool WasIngame; - static void HandleResponse(Network::Address address, const std::string& data); + static void HandleResponse(const Network::Address& address, const std::string& data); static void SendList(const Network::Address& address); diff --git a/src/Components/Modules/ServerList.hpp b/src/Components/Modules/ServerList.hpp index a0ebfc28..a3820f14 100644 --- a/src/Components/Modules/ServerList.hpp +++ b/src/Components/Modules/ServerList.hpp @@ -54,6 +54,11 @@ namespace Components static bool GetMasterServer(const char* ip, int port, Game::netadr_t& address); static bool UseMasterServer; + static Dvar::Var UIServerSelected; + static Dvar::Var UIServerSelectedMap; + static Dvar::Var NETServerQueryLimit; + static Dvar::Var NETServerFrames; + private: enum class Column : int { @@ -150,11 +155,6 @@ namespace Components static std::vector VisibleList; - static Dvar::Var UIServerSelected; - static Dvar::Var UIServerSelectedMap; - static Dvar::Var NETServerQueryLimit; - static Dvar::Var NETServerFrames; - static bool IsServerListOpen(); }; }