some logging for networking

This commit is contained in:
otavepto 2024-02-17 22:22:43 +02:00
parent bf413fc12a
commit 505bec9896
2 changed files with 41 additions and 19 deletions

View File

@ -250,8 +250,10 @@ static void run_at_startup()
} }
#if defined(STEAM_WIN32) #if defined(STEAM_WIN32)
WSADATA wsaData; WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR) if (WSAStartup(MAKEWORD(2, 2), &wsaData) != NO_ERROR) {
PRINT_DEBUG("Networking WSAStartup error\n");
return; return;
}
for (int i = 0; i < 10; ++i) { for (int i = 0; i < 10; ++i) {
//hack: the game Full Mojo Rampage calls WSACleanup on startup so we call WSAStartup a few times so it doesn't get deallocated. //hack: the game Full Mojo Rampage calls WSACleanup on startup so we call WSAStartup a few times so it doesn't get deallocated.
@ -841,7 +843,7 @@ Networking::Networking(CSteamID id, uint32 appid, uint16 port, std::set<IP_PORT>
PRINT_DEBUG("TCP: could not initialize %i\n", get_last_error()); PRINT_DEBUG("TCP: could not initialize %i\n", get_last_error());
} }
if (curl_global_init(CURL_GLOBAL_NOTHING) == 0) { if (curl_global_init(CURL_GLOBAL_ALL) == 0) {
PRINT_DEBUG("CURL successful\n"); PRINT_DEBUG("CURL successful\n");
} else { } else {
PRINT_DEBUG("CURL: could not initialize\n"); PRINT_DEBUG("CURL: could not initialize\n");

View File

@ -340,7 +340,7 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *
{ {
long long latency = 10; long long latency = 10;
if (!(g->ip() < 0) && !(g->query_port() < 0)) { if (!(g->ip() < 0) && !(g->query_port() < 0)) {
unsigned char ip[4]; unsigned char ip[4]{};
char newip[24]; char newip[24];
ip[0] = g->ip() & 0xFF; ip[0] = g->ip() & 0xFF;
ip[1] = (g->ip() >> 8) & 0xFF; ip[1] = (g->ip() >> 8) & 0xFF;
@ -348,10 +348,11 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *
ip[3] = (g->ip() >> 24) & 0xFF; ip[3] = (g->ip() >> 24) & 0xFF;
snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]);
PRINT_DEBUG(" server_details() connecting to ssq server on %s:%u\n", newip, g->query_port());
SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port()); SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port());
if (ssq != NULL && ssq_server_eok(ssq)) { if (ssq != NULL && ssq_server_eok(ssq)) {
ssq_server_timeout(ssq, SSQ_TIMEOUT_RECV, 1200); PRINT_DEBUG(" server_details() ssq server connection ok\n");
ssq_server_timeout(ssq, SSQ_TIMEOUT_SEND, 1200); ssq_server_timeout(ssq, (SSQ_TIMEOUT_SELECTOR)(SSQ_TIMEOUT_RECV | SSQ_TIMEOUT_SEND), 1200);
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now(); std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
A2S_INFO *ssq_a2s_info = ssq_info(ssq); A2S_INFO *ssq_a2s_info = ssq_info(ssq);
@ -359,6 +360,7 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *
latency = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count(); latency = std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
if (ssq_server_eok(ssq)) { if (ssq_server_eok(ssq)) {
PRINT_DEBUG(" server_details() ssq server info ok\n");
if (ssq_info_has_steamid(ssq_a2s_info)) g->set_id(ssq_a2s_info->steamid); if (ssq_info_has_steamid(ssq_a2s_info)) g->set_id(ssq_a2s_info->steamid);
g->set_game_description(ssq_a2s_info->game); g->set_game_description(ssq_a2s_info->game);
g->set_mod_dir(ssq_a2s_info->folder); g->set_mod_dir(ssq_a2s_info->folder);
@ -387,9 +389,13 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *
if (ssq_info_has_gameid(ssq_a2s_info)) g->set_appid(ssq_a2s_info->gameid); if (ssq_info_has_gameid(ssq_a2s_info)) g->set_appid(ssq_a2s_info->gameid);
else g->set_appid(ssq_a2s_info->id); else g->set_appid(ssq_a2s_info->id);
g->set_offline(false); g->set_offline(false);
} else {
PRINT_DEBUG(" server_details() ssq server info failed: %s\n", ssq_server_emsg(ssq));
} }
if (ssq_a2s_info != NULL) ssq_info_free(ssq_a2s_info); if (ssq_a2s_info != NULL) ssq_info_free(ssq_a2s_info);
} else {
PRINT_DEBUG(" server_details() ssq server connection failed: %s\n", (ssq ? ssq_server_emsg(ssq) : "NULL instance"));
} }
if (ssq != NULL) ssq_server_free(ssq); if (ssq != NULL) ssq_server_free(ssq);
@ -422,16 +428,18 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *
server->m_nServerVersion = g->version(); server->m_nServerVersion = g->version();
server->SetName(g->server_name().c_str()); server->SetName(g->server_name().c_str());
server->m_steamID = CSteamID((uint64)g->id()); server->m_steamID = CSteamID((uint64)g->id());
PRINT_DEBUG("Steam_Matchmaking_Servers::server_details " "%" PRIu64 "\n", g->id()); PRINT_DEBUG(" Steam_Matchmaking_Servers::server_details " "%" PRIu64 "\n", g->id());
strncpy(server->m_szGameTags, g->tags().c_str(), k_cbMaxGameServerTags - 1); memset(server->m_szGameTags, 0, sizeof(server->m_szGameTags));
server->m_szGameTags[k_cbMaxGameServerTags - 1] = 0; g->tags().copy(server->m_szGameTags, sizeof(server->m_szGameTags) - 1);
// strncpy(server->m_szGameTags, g->tags().c_str(), k_cbMaxGameServerTags - 1);
// server->m_szGameTags[k_cbMaxGameServerTags - 1] = 0;
} }
void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r) void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r)
{ {
if (!(g->ip() < 0) && !(g->query_port() < 0)) { if (!(g->ip() < 0) && !(g->query_port() < 0)) {
unsigned char ip[4]; unsigned char ip[4]{};
char newip[24]; char newip[24];
ip[0] = g->ip() & 0xFF; ip[0] = g->ip() & 0xFF;
ip[1] = (g->ip() >> 8) & 0xFF; ip[1] = (g->ip() >> 8) & 0xFF;
@ -439,33 +447,39 @@ void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matc
ip[3] = (g->ip() >> 24) & 0xFF; ip[3] = (g->ip() >> 24) & 0xFF;
snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]);
PRINT_DEBUG(" server_details_players() connecting to ssq server on %s:%u\n", newip, g->query_port());
SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port()); SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port());
if (ssq != NULL && ssq_server_eok(ssq)) { if (ssq != NULL && ssq_server_eok(ssq)) {
ssq_server_timeout(ssq, SSQ_TIMEOUT_RECV, 1200); PRINT_DEBUG(" server_details_players() ssq server connection ok\n");
ssq_server_timeout(ssq, SSQ_TIMEOUT_SEND, 1200); ssq_server_timeout(ssq, (SSQ_TIMEOUT_SELECTOR)(SSQ_TIMEOUT_RECV | SSQ_TIMEOUT_SEND), 1200);
uint8_t ssq_a2s_player_count; uint8_t ssq_a2s_player_count = 0;
A2S_PLAYER *ssq_a2s_player = ssq_player(ssq, &ssq_a2s_player_count); A2S_PLAYER *ssq_a2s_player = ssq_player(ssq, &ssq_a2s_player_count);
if (ssq_server_eok(ssq)) { if (ssq_server_eok(ssq)) {
PRINT_DEBUG(" server_details_players() ssq server players ok\n");
for (int i = 0; i < ssq_a2s_player_count; i++) { for (int i = 0; i < ssq_a2s_player_count; i++) {
r->players_response->AddPlayerToList(ssq_a2s_player[i].name, ssq_a2s_player[i].score, ssq_a2s_player[i].duration); r->players_response->AddPlayerToList(ssq_a2s_player[i].name, ssq_a2s_player[i].score, ssq_a2s_player[i].duration);
} }
} else {
PRINT_DEBUG(" server_details_players() ssq server players failed: %s\n", ssq_server_emsg(ssq));
} }
if (ssq_a2s_player != NULL) ssq_player_free(ssq_a2s_player, ssq_a2s_player_count); if (ssq_a2s_player != NULL) ssq_player_free(ssq_a2s_player, ssq_a2s_player_count);
} else {
PRINT_DEBUG(" server_details_players() ssq server connection failed: %s\n", (ssq ? ssq_server_emsg(ssq) : "NULL instance"));
} }
if (ssq != NULL) ssq_server_free(ssq); if (ssq != NULL) ssq_server_free(ssq);
} }
PRINT_DEBUG("Steam_Matchmaking_Servers::server_details_players " "%" PRIu64 "\n", g->id()); PRINT_DEBUG(" Steam_Matchmaking_Servers::server_details_players " "%" PRIu64 "\n", g->id());
} }
void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r) void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r)
{ {
if (!(g->ip() < 0) && !(g->query_port() < 0)) { if (!(g->ip() < 0) && !(g->query_port() < 0)) {
unsigned char ip[4]; unsigned char ip[4]{};
char newip[24]; char newip[24];
ip[0] = g->ip() & 0xFF; ip[0] = g->ip() & 0xFF;
ip[1] = (g->ip() >> 8) & 0xFF; ip[1] = (g->ip() >> 8) & 0xFF;
@ -473,27 +487,32 @@ void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchm
ip[3] = (g->ip() >> 24) & 0xFF; ip[3] = (g->ip() >> 24) & 0xFF;
snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]); snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip[3], ip[2], ip[1], ip[0]);
PRINT_DEBUG(" server_details_rules() connecting to ssq server on %s:%u\n", newip, g->query_port());
SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port()); SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port());
if (ssq != NULL && ssq_server_eok(ssq)) { if (ssq != NULL && ssq_server_eok(ssq)) {
ssq_server_timeout(ssq, SSQ_TIMEOUT_RECV, 1200); ssq_server_timeout(ssq, (SSQ_TIMEOUT_SELECTOR)(SSQ_TIMEOUT_RECV | SSQ_TIMEOUT_SEND), 1200);
ssq_server_timeout(ssq, SSQ_TIMEOUT_SEND, 1200);
uint16_t ssq_a2s_rules_count; uint16_t ssq_a2s_rules_count = 0;
A2S_RULES *ssq_a2s_rules = ssq_rules(ssq, &ssq_a2s_rules_count); A2S_RULES *ssq_a2s_rules = ssq_rules(ssq, &ssq_a2s_rules_count);
if (ssq_server_eok(ssq)) { if (ssq_server_eok(ssq)) {
PRINT_DEBUG(" server_details_rules() ssq server rules ok\n");
for (int i = 0; i < ssq_a2s_rules_count; i++) { for (int i = 0; i < ssq_a2s_rules_count; i++) {
r->rules_response->RulesResponded(ssq_a2s_rules[i].name, ssq_a2s_rules[i].value); r->rules_response->RulesResponded(ssq_a2s_rules[i].name, ssq_a2s_rules[i].value);
} }
} else {
PRINT_DEBUG(" server_details_rules() ssq server rules failed: %s\n", ssq_server_emsg(ssq));
} }
if (ssq_a2s_rules != NULL) ssq_rules_free(ssq_a2s_rules, ssq_a2s_rules_count); if (ssq_a2s_rules != NULL) ssq_rules_free(ssq_a2s_rules, ssq_a2s_rules_count);
} else {
PRINT_DEBUG(" server_details_rules() ssq server connection failed: %s\n", (ssq ? ssq_server_emsg(ssq) : "NULL instance"));
} }
if (ssq != NULL) ssq_server_free(ssq); if (ssq != NULL) ssq_server_free(ssq);
} }
PRINT_DEBUG("Steam_Matchmaking_Servers::server_details_rules " "%" PRIu64 "\n", g->id()); PRINT_DEBUG(" Steam_Matchmaking_Servers::server_details_rules " "%" PRIu64 "\n", g->id());
} }
// Get details on a given server in the list, you can get the valid range of index // Get details on a given server in the list, you can get the valid range of index
@ -597,7 +616,8 @@ void Steam_Matchmaking_Servers::RefreshServer( HServerListRequest hRequest, int
static HServerQuery new_server_query() static HServerQuery new_server_query()
{ {
static int a; std::lock_guard<std::recursive_mutex> lock(global_mutex);
static int a = 0;
++a; ++a;
if (!a) ++a; if (!a) ++a;
return a; return a;