diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index 48e26c6e..f033d885 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -5,6 +5,8 @@ namespace Components std::recursive_mutex Node::Mutex; std::vector Node::Nodes; + bool Node::wasIngame; + bool Node::Entry::isValid() { return (this->lastResponse.has_value() && !this->lastResponse->elapsed(NODE_HALFLIFE * 2)); @@ -14,7 +16,7 @@ namespace Components { if (!this->lastResponse.has_value()) { - if (this->lastRequest.has_value() && this->lastRequest->elapsed(NODE_HALFLIFE) && this->creationPoint.elapsed(NODE_HALFLIFE)) + if (this->lastRequest.has_value() && this->lastRequest->elapsed(NODE_HALFLIFE)) { return true; } @@ -155,6 +157,24 @@ namespace Components { if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get()) return; + if (Game::CL_IsCgameInitialized()) + { + wasIngame = true; + return; // don't run while ingame because it can still cause lag spikes on lower end PCs + } + + if (wasIngame) // our last frame we were ingame and now we aren't so touch all nodes + { + for (auto i = Node::Nodes.begin(); i != Node::Nodes.end();++i) + { + // 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(); + } + wasIngame = false; + } + static Utils::Time::Interval frameLimit; int interval = static_cast(1000.0f / Dvar::Var("net_serverFrames").get()); if (!frameLimit.elapsed(std::chrono::milliseconds(interval))) return; diff --git a/src/Components/Modules/Node.hpp b/src/Components/Modules/Node.hpp index ca925db8..ac6ce353 100644 --- a/src/Components/Modules/Node.hpp +++ b/src/Components/Modules/Node.hpp @@ -27,7 +27,6 @@ namespace Components std::optional lastRequest; std::optional lastResponse; - Utils::Time::Point creationPoint; bool isValid(); bool isDead(); @@ -50,6 +49,7 @@ namespace Components private: static std::recursive_mutex Mutex; static std::vector Nodes; + static bool wasIngame; static void HandleResponse(Network::Address address, std::string data);