diff --git a/dll/dll/steam_matchmaking_servers.h b/dll/dll/steam_matchmaking_servers.h index 91248893..20da051e 100644 --- a/dll/dll/steam_matchmaking_servers.h +++ b/dll/dll/steam_matchmaking_servers.h @@ -234,6 +234,4 @@ public: void RunCallbacks(); void Callback(Common_Message *msg); void server_details(Gameserver *g, gameserveritem_t *server); - void server_details_players(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r); - void server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r); }; diff --git a/dll/dll/steam_user.h b/dll/dll/steam_user.h index c8bd1bf8..4d77ab5f 100644 --- a/dll/dll/steam_user.h +++ b/dll/dll/steam_user.h @@ -385,7 +385,7 @@ void AdvertiseGame( CSteamID steamIDGameServer, uint32 unIPServer, uint16 usPort server->set_port(usPortServer); server->set_query_port(usPortServer); server->set_appid(settings->get_local_game_id().ToUint64()); - server->set_type(eFriendsServer); + server->set_type(eLANServer); Common_Message msg; msg.set_allocated_gameserver(server); msg.set_source_id(settings->get_local_steam_id().ConvertToUint64()); diff --git a/dll/steam_matchmaking_servers.cpp b/dll/steam_matchmaking_servers.cpp index 10846a96..c056c9a4 100644 --- a/dll/steam_matchmaking_servers.cpp +++ b/dll/steam_matchmaking_servers.cpp @@ -33,7 +33,7 @@ Steam_Matchmaking_Servers::Steam_Matchmaking_Servers(class Settings *settings, c this->network->setCallback(CALLBACK_ID_GAMESERVER, (uint64) 0, &network_callback, this); } -static int server_list_request; +static int server_list_request = 0; HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse, EMatchMakingType type) { @@ -42,7 +42,7 @@ HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, IS ++server_list_request; HServerListRequest id = (char *)0 + server_list_request; // (char *)0 silences the compiler warning - struct Steam_Matchmaking_Request request; + struct Steam_Matchmaking_Request request{}; request.appid = iApp; request.callbacks = pRequestServersResponse; request.old_callbacks = NULL; @@ -145,7 +145,7 @@ HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, IS HServerListRequest Steam_Matchmaking_Servers::RequestInternetServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("Steam_Matchmaking_Servers::RequestInternetServerList\n"); - return RequestServerList(iApp, pRequestServersResponse, eInternetServer); + return RequestServerList(iApp, pRequestServersResponse, eLANServer); } HServerListRequest Steam_Matchmaking_Servers::RequestLANServerList( AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse ) @@ -157,25 +157,25 @@ HServerListRequest Steam_Matchmaking_Servers::RequestLANServerList( AppId_t iApp HServerListRequest Steam_Matchmaking_Servers::RequestFriendsServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("Steam_Matchmaking_Servers::RequestFriendsServerList\n"); - return RequestServerList(iApp, pRequestServersResponse, eFriendsServer); + return RequestServerList(iApp, pRequestServersResponse, eLANServer); } HServerListRequest Steam_Matchmaking_Servers::RequestFavoritesServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("Steam_Matchmaking_Servers::RequestFavoritesServerList\n"); - return RequestServerList(iApp, pRequestServersResponse, eFavoritesServer); + return RequestServerList(iApp, pRequestServersResponse, eLANServer); } HServerListRequest Steam_Matchmaking_Servers::RequestHistoryServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("Steam_Matchmaking_Servers::RequestHistoryServerList\n"); - return RequestServerList(iApp, pRequestServersResponse, eHistoryServer); + return RequestServerList(iApp, pRequestServersResponse, eLANServer); } HServerListRequest Steam_Matchmaking_Servers::RequestSpectatorServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse ) { PRINT_DEBUG("Steam_Matchmaking_Servers::RequestSpectatorServerList\n"); - return RequestServerList(iApp, pRequestServersResponse, eSpectatorServer); + return RequestServerList(iApp, pRequestServersResponse, eLANServer); } void Steam_Matchmaking_Servers::RequestOldServerList(AppId_t iApp, ISteamMatchmakingServerListResponse001 *pRequestServersResponse, EMatchMakingType type) @@ -184,22 +184,22 @@ void Steam_Matchmaking_Servers::RequestOldServerList(AppId_t iApp, ISteamMatchma std::lock_guard lock(global_mutex); auto g = std::begin(requests); while (g != std::end(requests)) { - if (g->id == ((void *)type)) { + if (g->id == (void *)type) { return; } ++g; } - struct Steam_Matchmaking_Request request; + struct Steam_Matchmaking_Request request{}; request.appid = iApp; request.callbacks = NULL; request.old_callbacks = pRequestServersResponse; request.cancelled = false; request.completed = false; request.type = type; + request.id = (void *)type; requests.push_back(request); - requests[requests.size() - 1].id = (void *)type; } void Steam_Matchmaking_Servers::RequestInternetServerList( AppId_t iApp, MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse001 *pRequestServersResponse ) @@ -338,85 +338,15 @@ void Steam_Matchmaking_Servers::ReleaseRequest( HServerListRequest hServerListRe void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *server) { - long long latency = 10; - if (!(g->ip() < 0) && !(g->query_port() < 0)) { - unsigned char ip[4]{}; - char newip[24]; - ip[0] = g->ip() & 0xFF; - ip[1] = (g->ip() >> 8) & 0xFF; - ip[2] = (g->ip() >> 16) & 0xFF; - ip[3] = (g->ip() >> 24) & 0xFF; - 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()); - if (ssq != NULL && ssq_server_eok(ssq)) { - PRINT_DEBUG(" server_details() ssq server connection ok\n"); - 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(); - A2S_INFO *ssq_a2s_info = ssq_info(ssq); - std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now(); - latency = std::chrono::duration_cast(t2 - t1).count(); - - 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); - g->set_game_description(ssq_a2s_info->game); - g->set_mod_dir(ssq_a2s_info->folder); - if (ssq_a2s_info->server_type == A2S_SERVER_TYPE_DEDICATED) g->set_dedicated_server(true); - else if (ssq_a2s_info->server_type == A2S_SERVER_TYPE_STV_RELAY) g->set_dedicated_server(true); - else g->set_dedicated_server(false); - g->set_max_player_count(ssq_a2s_info->max_players); - g->set_bot_player_count(ssq_a2s_info->bots); - g->set_server_name(ssq_a2s_info->name); - g->set_map_name(ssq_a2s_info->map); - if (ssq_a2s_info->visibility) g->set_password_protected(true); - else g->set_password_protected(false); - if (ssq_info_has_stv(ssq_a2s_info)) { - g->set_spectator_port(ssq_a2s_info->stv_port); - g->set_spectator_server_name(ssq_a2s_info->stv_name); - } - //g->set_tags(ssq_a2s_info->keywords); - //g->set_gamedata(); - //g->set_region(); - g->set_product(ssq_a2s_info->game); - if (ssq_a2s_info->vac) g->set_secure(true); - else g->set_secure(false); - g->set_num_players(ssq_a2s_info->players); - g->set_version(std::stoull(ssq_a2s_info->version, NULL, 0)); - if (ssq_info_has_port(ssq_a2s_info)) g->set_port(ssq_a2s_info->port); - if (ssq_info_has_gameid(ssq_a2s_info)) g->set_appid(ssq_a2s_info->gameid); - else g->set_appid(ssq_a2s_info->id); - 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); - } 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); - } - uint16 query_port = g->query_port(); if (g->query_port() == 0xFFFF) { query_port = g->port(); } server->m_NetAdr.Init(g->ip(), query_port, g->port()); - server->m_nPing = latency; + server->m_nPing = 10; //TODO server->m_bHadSuccessfulResponse = true; server->m_bDoNotRefresh = false; - strncpy(server->m_szGameDir, g->mod_dir().c_str(), k_cbMaxGameServerGameDir - 1); - strncpy(server->m_szMap, g->map_name().c_str(), k_cbMaxGameServerMapName - 1); - strncpy(server->m_szGameDescription, g->game_description().c_str(), k_cbMaxGameServerGameDescription - 1); - - server->m_szGameDir[k_cbMaxGameServerGameDir - 1] = 0; - server->m_szMap[k_cbMaxGameServerMapName - 1] = 0; - server->m_szGameDescription[k_cbMaxGameServerGameDescription - 1] = 0; server->m_nAppID = g->appid(); server->m_nPlayers = g->num_players(); @@ -428,91 +358,20 @@ void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t * server->m_nServerVersion = g->version(); server->SetName(g->server_name().c_str()); server->m_steamID = CSteamID((uint64)g->id()); - PRINT_DEBUG(" Steam_Matchmaking_Servers::server_details " "%" PRIu64 "\n", g->id()); + + memset(server->m_szGameDir, 0, sizeof(server->m_szGameDir)); + g->mod_dir().copy(server->m_szGameDir, sizeof(server->m_szGameDir) - 1); + + memset(server->m_szMap, 0, sizeof(server->m_szMap)); + g->map_name().copy(server->m_szMap, sizeof(server->m_szMap) - 1); + + memset(server->m_szGameDescription, 0, sizeof(server->m_szGameDescription)); + g->game_description().copy(server->m_szGameDescription, sizeof(server->m_szGameDescription) - 1); memset(server->m_szGameTags, 0, sizeof(server->m_szGameTags)); 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) -{ - if (!(g->ip() < 0) && !(g->query_port() < 0)) { - unsigned char ip[4]{}; - char newip[24]; - ip[0] = g->ip() & 0xFF; - ip[1] = (g->ip() >> 8) & 0xFF; - ip[2] = (g->ip() >> 16) & 0xFF; - ip[3] = (g->ip() >> 24) & 0xFF; - 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()); - if (ssq != NULL && ssq_server_eok(ssq)) { - PRINT_DEBUG(" server_details_players() ssq server connection ok\n"); - ssq_server_timeout(ssq, (SSQ_TIMEOUT_SELECTOR)(SSQ_TIMEOUT_RECV | SSQ_TIMEOUT_SEND), 1200); - - uint8_t ssq_a2s_player_count = 0; - A2S_PLAYER *ssq_a2s_player = ssq_player(ssq, &ssq_a2s_player_count); - - 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++) { - 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); - } 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); - } - - 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) -{ - if (!(g->ip() < 0) && !(g->query_port() < 0)) { - unsigned char ip[4]{}; - char newip[24]; - ip[0] = g->ip() & 0xFF; - ip[1] = (g->ip() >> 8) & 0xFF; - ip[2] = (g->ip() >> 16) & 0xFF; - ip[3] = (g->ip() >> 24) & 0xFF; - 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()); - if (ssq != NULL && ssq_server_eok(ssq)) { - ssq_server_timeout(ssq, (SSQ_TIMEOUT_SELECTOR)(SSQ_TIMEOUT_RECV | SSQ_TIMEOUT_SEND), 1200); - - uint16_t ssq_a2s_rules_count = 0; - A2S_RULES *ssq_a2s_rules = ssq_rules(ssq, &ssq_a2s_rules_count); - - 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++) { - 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); - } 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); - } - - PRINT_DEBUG(" Steam_Matchmaking_Servers::server_details_rules " "%" PRIu64 "\n", g->id()); + PRINT_DEBUG(" Steam_Matchmaking_Servers::server_details " "%" PRIu64 "\n", g->id()); } // Get details on a given server in the list, you can get the valid range of index @@ -709,7 +568,7 @@ void Steam_Matchmaking_Servers::RunCallbacks() r.gameservers_filtered.clear(); for (auto &g : gameservers) { - PRINT_DEBUG("Steam_Matchmaking_Servers::game_server_check %u %u\n", g.server.appid(), r.appid); + PRINT_DEBUG("Steam_Matchmaking_Servers::game_server_check %u==%u | %i==%i\n", g.server.appid(), r.appid, (int)g.type, (int)r.type); if ((g.server.appid() == r.appid) && (g.type == r.type)) { PRINT_DEBUG("Steam_Matchmaking_Servers::REQUESTS server found\n"); r.gameservers_filtered.push_back(g); @@ -778,13 +637,31 @@ void Steam_Matchmaking_Servers::RunCallbacks() if (query_port == r.port && g.server.ip() == r.ip) { if (r.rules_response) { - server_details_rules(&(g.server), &r); + int number_rules = (int)g.server.values().size(); + PRINT_DEBUG("Steam_Matchmaking_Servers rules: %i\n", number_rules); + auto rule = g.server.values().begin(); + for (int i = 0; i < number_rules; ++i) { + PRINT_DEBUG("Steam_Matchmaking_Servers RULE '%s' '%s'\n", rule->first.c_str(), rule->second.c_str()); + r.rules_response->RulesResponded(rule->first.c_str(), rule->second.c_str()); + ++rule; + } + r.rules_response->RulesRefreshComplete(); r.rules_response = NULL; } if (r.players_response) { - server_details_players(&(g.server), &r); + uint32_t number_players = g.server.num_players(); + PRINT_DEBUG("Steam_Matchmaking_Servers players: %i\n", number_players); + // const auto &players = get_steam_client()->steam_gameserver->get_players(); + // auto &player = players->begin(); + + // for (int i = 0; i < number_players && i < players->size(); i++) { + // float playtime = static_cast(std::chrono::duration_cast(std::chrono::steady_clock::now() - player->second.join_time).count()); + // PRINT_DEBUG("Steam_Matchmaking_Servers PLAYER [%u] '%s' %u %f\n", i, player->second.name.c_str(), player->second.score, playtime); + // r.players_response->AddPlayerToList(player->second.name.c_str(), player->second.score, playtime); + // ++player; + // } r.players_response->PlayersRefreshComplete(); r.players_response = NULL; } @@ -807,7 +684,7 @@ void Steam_Matchmaking_Servers::RunCallbacks() void Steam_Matchmaking_Servers::Callback(Common_Message *msg) { if (msg->has_gameserver() && msg->gameserver().type() != eFriendsServer) { - PRINT_DEBUG("Steam_Matchmaking_Servers::got SERVER " "%" PRIu64 ", offline:%u\n", msg->gameserver().id(), msg->gameserver().offline()); + PRINT_DEBUG("Steam_Matchmaking_Servers got SERVER " "%" PRIu64 ", offline:%u\n", msg->gameserver().id(), msg->gameserver().offline()); if (msg->gameserver().offline()) { for (auto &g : gameservers) { if (g.server.id() == msg->gameserver().id()) { @@ -840,6 +717,7 @@ void Steam_Matchmaking_Servers::Callback(Common_Message *msg) } if (msg->has_gameserver() && msg->gameserver().type() == eFriendsServer) { + PRINT_DEBUG("Steam_Matchmaking_Servers got eFriendsServer SERVER " "%" PRIu64 "\n", msg->gameserver().id()); bool addserver = true; for (auto &g : gameservers_friends) { if (g.source_id == msg->source_id()) {