[Node] Introduce dvar to control server query rate
This commit is contained in:
parent
902d40188f
commit
d3930ce19a
@ -39,6 +39,7 @@ namespace Components
|
|||||||
|
|
||||||
Session::Send(this->address, "nodeListRequest");
|
Session::Send(this->address, "nodeListRequest");
|
||||||
Node::SendList(this->address);
|
Node::SendList(this->address);
|
||||||
|
NODE_LOG("Sent request to %s\n", this->address.getCString());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Node::Entry::reset()
|
void Node::Entry::reset()
|
||||||
@ -154,7 +155,13 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get<bool>()) return;
|
if (Dedicated::IsEnabled() && Dvar::Var("sv_lanOnly").get<bool>()) return;
|
||||||
|
|
||||||
|
static Utils::Time::Interval frameLimit;
|
||||||
|
int interval = static_cast<int>(1000.0f / Dvar::Var("net_serverFrames").get<int>());
|
||||||
|
if (!frameLimit.elapsed(std::chrono::milliseconds(interval))) return;
|
||||||
|
frameLimit.update();
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> _(Node::Mutex);
|
std::lock_guard<std::recursive_mutex> _(Node::Mutex);
|
||||||
|
Dvar::Var queryLimit("net_serverQueryLimit");
|
||||||
|
|
||||||
int sentRequests = 0;
|
int sentRequests = 0;
|
||||||
for (auto i = Node::Nodes.begin(); i != Node::Nodes.end();)
|
for (auto i = Node::Nodes.begin(); i != Node::Nodes.end();)
|
||||||
@ -164,7 +171,7 @@ namespace Components
|
|||||||
i = Node::Nodes.erase(i);
|
i = Node::Nodes.erase(i);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (sentRequests < NODE_REQUEST_LIMIT && i->requiresRequest())
|
else if (sentRequests < queryLimit.get<int>() && i->requiresRequest())
|
||||||
{
|
{
|
||||||
++sentRequests;
|
++sentRequests;
|
||||||
i->sendRequest();
|
i->sendRequest();
|
||||||
@ -191,6 +198,8 @@ namespace Components
|
|||||||
Proto::Node::List list;
|
Proto::Node::List list;
|
||||||
if (!list.ParseFromString(data)) return;
|
if (!list.ParseFromString(data)) return;
|
||||||
|
|
||||||
|
NODE_LOG("Received response from %s\n", address.getCString());
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> _(Node::Mutex);
|
std::lock_guard<std::recursive_mutex> _(Node::Mutex);
|
||||||
|
|
||||||
for (int i = 0; i < list.nodes_size(); ++i)
|
for (int i = 0; i < list.nodes_size(); ++i)
|
||||||
@ -207,8 +216,13 @@ namespace Components
|
|||||||
{
|
{
|
||||||
if (!Dedicated::IsEnabled() && ServerList::IsOnlineList() && list.protocol() == PROTOCOL)
|
if (!Dedicated::IsEnabled() && ServerList::IsOnlineList() && list.protocol() == PROTOCOL)
|
||||||
{
|
{
|
||||||
|
NODE_LOG("Inserting %s into the serverlist\n", address.getCString());
|
||||||
ServerList::InsertRequest(address);
|
ServerList::InsertRequest(address);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NODE_LOG("Dropping serverlist insertion for %s\n", address.getCString());
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& node : Node::Nodes)
|
for (auto& node : Node::Nodes)
|
||||||
{
|
{
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
|
#define NODE_HALFLIFE (3 * 60 * 1000) //3min
|
||||||
#define NODE_REQUEST_LIMIT 3
|
|
||||||
|
#ifdef NODE_LOG_MESSAGES
|
||||||
|
#define NODE_LOG(x, ...) Logger::Print(x, __VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define NODE_LOG(x, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Components
|
namespace Components
|
||||||
{
|
{
|
||||||
|
@ -610,6 +610,11 @@ namespace Components
|
|||||||
|
|
||||||
void ServerList::Frame()
|
void ServerList::Frame()
|
||||||
{
|
{
|
||||||
|
static Utils::Time::Interval frameLimit;
|
||||||
|
int interval = static_cast<int>(1000.0f / Dvar::Var("net_serverFrames").get<int>());
|
||||||
|
if (!frameLimit.elapsed(std::chrono::milliseconds(interval))) return;
|
||||||
|
frameLimit.update();
|
||||||
|
|
||||||
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
|
std::lock_guard<std::recursive_mutex> _(ServerList::RefreshContainer.mutex);
|
||||||
|
|
||||||
if (ServerList::RefreshContainer.awatingList)
|
if (ServerList::RefreshContainer.awatingList)
|
||||||
@ -623,17 +628,15 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send requests to 10 servers each frame
|
int requestLimit = Dvar::Var("net_serverQueryLimit").get<int>();
|
||||||
int SendServers = 10;
|
for (unsigned int i = 0; i < ServerList::RefreshContainer.servers.size() && requestLimit > 0; ++i)
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ServerList::RefreshContainer.servers.size(); ++i)
|
|
||||||
{
|
{
|
||||||
ServerList::Container::ServerContainer* server = &ServerList::RefreshContainer.servers[i];
|
ServerList::Container::ServerContainer* server = &ServerList::RefreshContainer.servers[i];
|
||||||
if (server->sent) continue;
|
if (server->sent) continue;
|
||||||
|
|
||||||
// Found server we can send a request to
|
// Found server we can send a request to
|
||||||
server->sent = true;
|
server->sent = true;
|
||||||
SendServers--;
|
requestLimit--;
|
||||||
|
|
||||||
server->sendTime = Game::Sys_Milliseconds();
|
server->sendTime = Game::Sys_Milliseconds();
|
||||||
server->challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
server->challenge = Utils::Cryptography::Rand::GenerateChallenge();
|
||||||
@ -644,8 +647,6 @@ namespace Components
|
|||||||
|
|
||||||
// Display in the menu, like in COD4
|
// Display in the menu, like in COD4
|
||||||
//Localization::Set("MPUI_SERVERQUERIED", Utils::String::VA("Sent requests: %d/%d", ServerList::RefreshContainer.sentCount, ServerList::RefreshContainer.sendCount));
|
//Localization::Set("MPUI_SERVERQUERIED", Utils::String::VA("Sent requests: %d/%d", ServerList::RefreshContainer.sentCount, ServerList::RefreshContainer.sendCount));
|
||||||
|
|
||||||
if (SendServers <= 0) break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ServerList::UpdateVisibleInfo();
|
ServerList::UpdateVisibleInfo();
|
||||||
@ -725,6 +726,9 @@ namespace Components
|
|||||||
{
|
{
|
||||||
Dvar::Register<bool>("ui_serverSelected", false, Game::dvar_flag::DVAR_FLAG_NONE, "Whether a server has been selected in the serverlist");
|
Dvar::Register<bool>("ui_serverSelected", false, Game::dvar_flag::DVAR_FLAG_NONE, "Whether a server has been selected in the serverlist");
|
||||||
Dvar::Register<const char*>("ui_serverSelectedMap", "mp_afghan", Game::dvar_flag::DVAR_FLAG_NONE, "Map of the selected server");
|
Dvar::Register<const char*>("ui_serverSelectedMap", "mp_afghan", Game::dvar_flag::DVAR_FLAG_NONE, "Map of the selected server");
|
||||||
|
|
||||||
|
Dvar::Register<int>("net_serverQueryLimit", 3, 1, 10, Dedicated::IsEnabled() ? 0 : Game::dvar_flag::DVAR_FLAG_SAVED, "Amount of server queries per frame");
|
||||||
|
Dvar::Register<int>("net_serverFrames", 60, 1, 1000, Dedicated::IsEnabled() ? 0 : Game::dvar_flag::DVAR_FLAG_SAVED, "Amount of server query frames per second");
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fix ui_netsource dvar
|
// Fix ui_netsource dvar
|
||||||
|
Loading…
Reference in New Issue
Block a user