From f62a2e456677af9fc66bbb01d8965d189df00ebe Mon Sep 17 00:00:00 2001 From: Mr_Goldberg Date: Mon, 24 Feb 2020 15:05:51 -0500 Subject: [PATCH] Add delay to matchmaking servers direct ip requests. --- dll/steam_matchmaking_servers.cpp | 16 ++++++++++++++-- dll/steam_matchmaking_servers.h | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dll/steam_matchmaking_servers.cpp b/dll/steam_matchmaking_servers.cpp index 72cdb015..70351b12 100644 --- a/dll/steam_matchmaking_servers.cpp +++ b/dll/steam_matchmaking_servers.cpp @@ -338,6 +338,7 @@ HServerQuery Steam_Matchmaking_Servers::PingServer( uint32 unIP, uint16 usPort, r.ip = unIP; r.port = usPort; r.ping_response = pRequestServersResponse; + r.created = std::chrono::high_resolution_clock::now(); direct_ip_requests.push_back(r); return r.id; } @@ -352,6 +353,7 @@ HServerQuery Steam_Matchmaking_Servers::PlayerDetails( uint32 unIP, uint16 usPor r.ip = unIP; r.port = usPort; r.players_response = pRequestServersResponse; + r.created = std::chrono::high_resolution_clock::now(); direct_ip_requests.push_back(r); return r.id; } @@ -367,6 +369,7 @@ HServerQuery Steam_Matchmaking_Servers::ServerRules( uint32 unIP, uint16 usPort, r.ip = unIP; r.port = usPort; r.rules_response = pRequestServersResponse; + r.created = std::chrono::high_resolution_clock::now(); direct_ip_requests.push_back(r); return r.id; } @@ -439,8 +442,16 @@ void Steam_Matchmaking_Servers::RunCallbacks() } } - std::vector direct_ip_requests_temp = direct_ip_requests; - direct_ip_requests.clear(); + std::vector direct_ip_requests_temp; + 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) { 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) { if (msg->has_gameserver()) { + PRINT_DEBUG("got SERVER %llu, offline:%u\n", msg->gameserver().id(), msg->gameserver().offline()); if (msg->gameserver().offline()) { for (auto &g : gameservers) { if (g.server.id() == msg->gameserver().id()) { diff --git a/dll/steam_matchmaking_servers.h b/dll/steam_matchmaking_servers.h index 2ad51fc7..71e2a575 100644 --- a/dll/steam_matchmaking_servers.h +++ b/dll/steam_matchmaking_servers.h @@ -18,12 +18,14 @@ #include "base.h" #define SERVER_TIMEOUT 10.0 +#define DIRECT_IP_DELAY 0.05 struct Steam_Matchmaking_Servers_Direct_IP_Request { HServerQuery id; uint32 ip; uint16 port; + std::chrono::high_resolution_clock::time_point created; ISteamMatchmakingRulesResponse *rules_response = NULL; ISteamMatchmakingPlayersResponse *players_response = NULL; ISteamMatchmakingPingResponse *ping_response = NULL;