maint(node): cleanup node system
This commit is contained in:
parent
35a02879ed
commit
7c05b151b7
@ -14,7 +14,6 @@ namespace Components
|
|||||||
static std::thread Thread;
|
static std::thread Thread;
|
||||||
|
|
||||||
static bool Terminate;
|
static bool Terminate;
|
||||||
static bool DownloadUpdater();
|
|
||||||
|
|
||||||
static const char* GetNewsText();
|
static const char* GetNewsText();
|
||||||
};
|
};
|
||||||
|
@ -149,7 +149,7 @@ namespace Components
|
|||||||
Utils::IO::WriteFile("players/nodes.json", out.dump());
|
Utils::IO::WriteFile("players/nodes.json", out.dump());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::Add(Network::Address address)
|
void Node::Add(const Network::Address& address)
|
||||||
{
|
{
|
||||||
#ifndef DEBUG
|
#ifndef DEBUG
|
||||||
if (address.isLocal() || address.isSelf()) return;
|
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
|
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
|
// clearing the last request and response times makes the
|
||||||
// dispatcher think its a new node and will force a refresh
|
// dispatcher think its a new node and will force a refresh
|
||||||
i->lastRequest.reset();
|
entry.lastRequest.reset();
|
||||||
i->lastResponse.reset();
|
entry.lastResponse.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
WasIngame = false;
|
WasIngame = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static Utils::Time::Interval frameLimit;
|
static Utils::Time::Interval frameLimit;
|
||||||
int interval = static_cast<int>(1000.0f / Dvar::Var("net_serverFrames").get<int>());
|
const auto interval = 1000 / ServerList::NETServerFrames.get<int>();
|
||||||
if (!frameLimit.elapsed(std::chrono::milliseconds(interval))) return;
|
if (!frameLimit.elapsed(std::chrono::milliseconds(interval))) return;
|
||||||
frameLimit.update();
|
frameLimit.update();
|
||||||
|
|
||||||
std::lock_guard _(Mutex);
|
std::lock_guard _(Mutex);
|
||||||
Dvar::Var queryLimit("net_serverQueryLimit");
|
|
||||||
|
|
||||||
int sentRequests = 0;
|
int sentRequests = 0;
|
||||||
for (auto i = Nodes.begin(); i != Nodes.end();)
|
for (auto i = Nodes.begin(); i != Nodes.end();)
|
||||||
@ -220,7 +219,8 @@ namespace Components
|
|||||||
i = Nodes.erase(i);
|
i = Nodes.erase(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (sentRequests < queryLimit.get<int>() && i->requiresRequest())
|
|
||||||
|
if (sentRequests < ServerList::NETServerQueryLimit.get<int>() && i->requiresRequest())
|
||||||
{
|
{
|
||||||
++sentRequests;
|
++sentRequests;
|
||||||
i->sendRequest();
|
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;
|
Proto::Node::List list;
|
||||||
if (!list.ParseFromString(data)) return;
|
if (!list.ParseFromString(data)) return;
|
||||||
@ -320,11 +320,11 @@ namespace Components
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto node = Nodes.at(curNode++);
|
auto& node = Nodes.at(curNode++);
|
||||||
|
|
||||||
if (node.isValid())
|
if (node.isValid())
|
||||||
{
|
{
|
||||||
std::string* str = list.add_nodes();
|
auto* str = list.add_nodes();
|
||||||
|
|
||||||
sockaddr addr = node.address.getSockAddr();
|
sockaddr addr = node.address.getSockAddr();
|
||||||
str->append(reinterpret_cast<char*>(&addr), sizeof(addr));
|
str->append(reinterpret_cast<char*>(&addr), sizeof(addr));
|
||||||
@ -401,7 +401,7 @@ namespace Components
|
|||||||
Scheduler::Loop([]
|
Scheduler::Loop([]
|
||||||
{
|
{
|
||||||
StoreNodes(false);
|
StoreNodes(false);
|
||||||
}, Scheduler::Pipeline::ASYNC);
|
}, Scheduler::Pipeline::ASYNC, 5min);
|
||||||
|
|
||||||
Scheduler::Loop(RunFrame, Scheduler::Pipeline::MAIN);
|
Scheduler::Loop(RunFrame, Scheduler::Pipeline::MAIN);
|
||||||
|
|
||||||
@ -411,15 +411,12 @@ namespace Components
|
|||||||
SendList(address);
|
SendList(address);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Load stored nodes
|
Scheduler::OnGameInitialized([]
|
||||||
auto loadNodes = []
|
|
||||||
{
|
{
|
||||||
Migrate();
|
Migrate();
|
||||||
LoadNodePreset();
|
LoadNodePreset();
|
||||||
LoadNodes();
|
LoadNodes();
|
||||||
};
|
}, Scheduler::Pipeline::MAIN);
|
||||||
|
|
||||||
Scheduler::OnGameInitialized(loadNodes, Scheduler::Pipeline::MAIN);
|
|
||||||
|
|
||||||
Command::Add("listNodes", [](const Command::Params*)
|
Command::Add("listNodes", [](const Command::Params*)
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ namespace Components
|
|||||||
Node();
|
Node();
|
||||||
void preDestroy() override;
|
void preDestroy() override;
|
||||||
|
|
||||||
static void Add(Network::Address address);
|
static void Add(const Network::Address& address);
|
||||||
static std::vector<Entry> GetNodes();
|
static std::vector<Entry> GetNodes();
|
||||||
static void RunFrame();
|
static void RunFrame();
|
||||||
static void Synchronize();
|
static void Synchronize();
|
||||||
@ -46,7 +46,7 @@ namespace Components
|
|||||||
static std::vector<Entry> Nodes;
|
static std::vector<Entry> Nodes;
|
||||||
static bool WasIngame;
|
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);
|
static void SendList(const Network::Address& address);
|
||||||
|
|
||||||
|
@ -54,6 +54,11 @@ namespace Components
|
|||||||
static bool GetMasterServer(const char* ip, int port, Game::netadr_t& address);
|
static bool GetMasterServer(const char* ip, int port, Game::netadr_t& address);
|
||||||
static bool UseMasterServer;
|
static bool UseMasterServer;
|
||||||
|
|
||||||
|
static Dvar::Var UIServerSelected;
|
||||||
|
static Dvar::Var UIServerSelectedMap;
|
||||||
|
static Dvar::Var NETServerQueryLimit;
|
||||||
|
static Dvar::Var NETServerFrames;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum class Column : int
|
enum class Column : int
|
||||||
{
|
{
|
||||||
@ -150,11 +155,6 @@ namespace Components
|
|||||||
|
|
||||||
static std::vector<unsigned int> VisibleList;
|
static std::vector<unsigned int> VisibleList;
|
||||||
|
|
||||||
static Dvar::Var UIServerSelected;
|
|
||||||
static Dvar::Var UIServerSelectedMap;
|
|
||||||
static Dvar::Var NETServerQueryLimit;
|
|
||||||
static Dvar::Var NETServerFrames;
|
|
||||||
|
|
||||||
static bool IsServerListOpen();
|
static bool IsServerListOpen();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user