Add delay to matchmaking servers direct ip requests.

merge-requests/30/head
Mr_Goldberg 2020-02-24 15:05:51 -05:00
parent 2204de7ce4
commit f62a2e4566
No known key found for this signature in database
GPG Key ID: 8597D87419DEF278
2 changed files with 16 additions and 2 deletions

View File

@ -338,6 +338,7 @@ HServerQuery Steam_Matchmaking_Servers::PingServer( uint32 unIP, uint16 usPort,
r.ip = unIP; r.ip = unIP;
r.port = usPort; r.port = usPort;
r.ping_response = pRequestServersResponse; r.ping_response = pRequestServersResponse;
r.created = std::chrono::high_resolution_clock::now();
direct_ip_requests.push_back(r); direct_ip_requests.push_back(r);
return r.id; return r.id;
} }
@ -352,6 +353,7 @@ HServerQuery Steam_Matchmaking_Servers::PlayerDetails( uint32 unIP, uint16 usPor
r.ip = unIP; r.ip = unIP;
r.port = usPort; r.port = usPort;
r.players_response = pRequestServersResponse; r.players_response = pRequestServersResponse;
r.created = std::chrono::high_resolution_clock::now();
direct_ip_requests.push_back(r); direct_ip_requests.push_back(r);
return r.id; return r.id;
} }
@ -367,6 +369,7 @@ HServerQuery Steam_Matchmaking_Servers::ServerRules( uint32 unIP, uint16 usPort,
r.ip = unIP; r.ip = unIP;
r.port = usPort; r.port = usPort;
r.rules_response = pRequestServersResponse; r.rules_response = pRequestServersResponse;
r.created = std::chrono::high_resolution_clock::now();
direct_ip_requests.push_back(r); direct_ip_requests.push_back(r);
return r.id; return r.id;
} }
@ -439,8 +442,16 @@ void Steam_Matchmaking_Servers::RunCallbacks()
} }
} }
std::vector <struct Steam_Matchmaking_Servers_Direct_IP_Request> direct_ip_requests_temp = direct_ip_requests; std::vector <struct Steam_Matchmaking_Servers_Direct_IP_Request> direct_ip_requests_temp;
direct_ip_requests.clear(); auto dip = std::begin(direct_ip_requests);
while (dip != std::end(direct_ip_requests)) {
if (check_timedout(dip->created, DIRECT_IP_DELAY)) {
direct_ip_requests_temp.push_back(*dip);
dip = direct_ip_requests.erase(dip);
} else {
++dip;
}
}
for (auto &r : direct_ip_requests_temp) { for (auto &r : direct_ip_requests_temp) {
PRINT_DEBUG("dip request: %lu:%hu\n", r.ip, r.port); PRINT_DEBUG("dip request: %lu:%hu\n", r.ip, r.port);
@ -486,6 +497,7 @@ void Steam_Matchmaking_Servers::RunCallbacks()
void Steam_Matchmaking_Servers::Callback(Common_Message *msg) void Steam_Matchmaking_Servers::Callback(Common_Message *msg)
{ {
if (msg->has_gameserver()) { if (msg->has_gameserver()) {
PRINT_DEBUG("got SERVER %llu, offline:%u\n", msg->gameserver().id(), msg->gameserver().offline());
if (msg->gameserver().offline()) { if (msg->gameserver().offline()) {
for (auto &g : gameservers) { for (auto &g : gameservers) {
if (g.server.id() == msg->gameserver().id()) { if (g.server.id() == msg->gameserver().id()) {

View File

@ -18,12 +18,14 @@
#include "base.h" #include "base.h"
#define SERVER_TIMEOUT 10.0 #define SERVER_TIMEOUT 10.0
#define DIRECT_IP_DELAY 0.05
struct Steam_Matchmaking_Servers_Direct_IP_Request { struct Steam_Matchmaking_Servers_Direct_IP_Request {
HServerQuery id; HServerQuery id;
uint32 ip; uint32 ip;
uint16 port; uint16 port;
std::chrono::high_resolution_clock::time_point created;
ISteamMatchmakingRulesResponse *rules_response = NULL; ISteamMatchmakingRulesResponse *rules_response = NULL;
ISteamMatchmakingPlayersResponse *players_response = NULL; ISteamMatchmakingPlayersResponse *players_response = NULL;
ISteamMatchmakingPingResponse *ping_response = NULL; ISteamMatchmakingPingResponse *ping_response = NULL;