2019-04-13 12:21:56 -04:00
|
|
|
/* Copyright (C) 2019 Mr Goldberg
|
|
|
|
This file is part of the Goldberg Emulator
|
|
|
|
|
|
|
|
The Goldberg Emulator is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 3 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
The Goldberg Emulator is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with the Goldberg Emulator; if not, see
|
|
|
|
<http://www.gnu.org/licenses/>. */
|
|
|
|
|
2024-02-28 22:41:04 +02:00
|
|
|
#include "dll/dll.h"
|
2019-04-13 12:21:56 -04:00
|
|
|
|
|
|
|
|
|
|
|
static void network_callback(void *object, Common_Message *msg)
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("steam_matchmaking_servers_callback");
|
2019-04-13 12:21:56 -04:00
|
|
|
|
|
|
|
Steam_Matchmaking_Servers *obj = (Steam_Matchmaking_Servers *)object;
|
|
|
|
obj->Callback(msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
Steam_Matchmaking_Servers::Steam_Matchmaking_Servers(class Settings *settings, class Networking *network)
|
|
|
|
{
|
|
|
|
this->settings = settings;
|
|
|
|
this->network = network;
|
|
|
|
this->network->setCallback(CALLBACK_ID_GAMESERVER, (uint64) 0, &network_callback, this);
|
|
|
|
}
|
|
|
|
|
2024-03-23 17:01:27 +02:00
|
|
|
Steam_Matchmaking_Servers::~Steam_Matchmaking_Servers()
|
|
|
|
{
|
|
|
|
this->network->rmCallback(CALLBACK_ID_GAMESERVER, (uint64) 0, &network_callback, this);
|
|
|
|
}
|
|
|
|
|
2024-02-28 00:12:47 +02:00
|
|
|
static int server_list_request = 0;
|
2019-04-13 12:21:56 -04:00
|
|
|
|
2024-02-27 21:17:53 +02:00
|
|
|
HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse, EMatchMakingType type)
|
2019-04-13 12:21:56 -04:00
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%u %p, %i", iApp, pRequestServersResponse, (int)type);
|
2019-04-13 12:21:56 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
2024-01-20 03:32:01 +02:00
|
|
|
++server_list_request;
|
|
|
|
HServerListRequest id = (char *)0 + server_list_request; // (char *)0 silences the compiler warning
|
|
|
|
|
2024-02-29 02:38:51 +02:00
|
|
|
if (settings->matchmaking_server_list_always_lan_type) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("forcing request type to LAN");
|
2024-02-29 02:38:51 +02:00
|
|
|
type = EMatchMakingType::eLANServer;
|
|
|
|
}
|
|
|
|
|
2024-02-28 00:12:47 +02:00
|
|
|
struct Steam_Matchmaking_Request request{};
|
2019-04-13 12:21:56 -04:00
|
|
|
request.appid = iApp;
|
|
|
|
request.callbacks = pRequestServersResponse;
|
2022-07-31 15:49:45 -04:00
|
|
|
request.old_callbacks = NULL;
|
2019-04-13 12:21:56 -04:00
|
|
|
request.cancelled = false;
|
|
|
|
request.completed = false;
|
2024-02-27 21:17:53 +02:00
|
|
|
request.type = type;
|
2024-01-20 03:32:01 +02:00
|
|
|
request.id = id;
|
2019-04-13 12:21:56 -04:00
|
|
|
requests.push_back(request);
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("id: %p", id);
|
2024-02-27 21:17:53 +02:00
|
|
|
|
2024-02-29 02:38:51 +02:00
|
|
|
if (type == eLANServer) return id;
|
2024-02-27 21:17:53 +02:00
|
|
|
|
|
|
|
if (type == eFriendsServer) {
|
|
|
|
for (auto &g : gameservers_friends) {
|
|
|
|
if (g.source_id != settings->get_local_steam_id().ConvertToUint64()) {
|
|
|
|
Gameserver server;
|
|
|
|
server.set_ip(g.ip);
|
|
|
|
server.set_port(g.port);
|
|
|
|
server.set_query_port(g.port);
|
|
|
|
server.set_appid(iApp);
|
|
|
|
|
|
|
|
struct Steam_Matchmaking_Servers_Gameserver g2;
|
|
|
|
g2.last_recv = std::chrono::high_resolution_clock::now();
|
|
|
|
g2.server = server;
|
|
|
|
g2.type = type;
|
|
|
|
gameservers.push_back(g2);
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" eFriendsServer SERVER ADDED");
|
2024-02-27 21:17:53 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string file_path;
|
|
|
|
unsigned long long file_size;
|
|
|
|
if (type == eInternetServer || type == eSpectatorServer) {
|
2024-04-16 22:58:05 +02:00
|
|
|
file_path = Local_Storage::get_user_appdata_path() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + PATH_SEPARATOR + "serverbrowser.txt";
|
2024-02-27 21:17:53 +02:00
|
|
|
file_size = file_size_(file_path);
|
|
|
|
} else if (type == eFavoritesServer) {
|
2024-04-16 22:58:05 +02:00
|
|
|
file_path = Local_Storage::get_user_appdata_path() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + PATH_SEPARATOR + "serverbrowser_favorites.txt";
|
2024-02-27 21:17:53 +02:00
|
|
|
file_size = file_size_(file_path);
|
|
|
|
} else if (type == eHistoryServer) {
|
2024-04-16 22:58:05 +02:00
|
|
|
file_path = Local_Storage::get_user_appdata_path() + "7" + PATH_SEPARATOR + Local_Storage::remote_storage_folder + PATH_SEPARATOR + "serverbrowser_history.txt";
|
2024-02-27 21:17:53 +02:00
|
|
|
file_size = file_size_(file_path);
|
|
|
|
}
|
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("list file '%s' [%llu bytes]", file_path.c_str(), file_size);
|
2024-04-10 12:27:37 +02:00
|
|
|
std::string list{};
|
2024-02-27 21:17:53 +02:00
|
|
|
if (file_size) {
|
|
|
|
list.resize(file_size);
|
2024-04-10 12:27:37 +02:00
|
|
|
Local_Storage::get_file_data(file_path, (char *)&list[0], file_size, 0);
|
2024-02-27 21:17:53 +02:00
|
|
|
} else {
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2024-04-10 12:27:37 +02:00
|
|
|
std::istringstream list_ss(list);
|
2024-02-27 21:17:53 +02:00
|
|
|
std::string list_ip;
|
|
|
|
while (std::getline(list_ss, list_ip)) {
|
2024-04-10 07:59:40 +02:00
|
|
|
if (list_ip.length() <= 0) continue;
|
2024-02-27 21:17:53 +02:00
|
|
|
|
|
|
|
unsigned int byte4, byte3, byte2, byte1, byte0;
|
|
|
|
uint32 ip_int;
|
|
|
|
uint16 port_int;
|
|
|
|
char newip[24];
|
|
|
|
if (sscanf(list_ip.c_str(), "%u.%u.%u.%u:%u", &byte3, &byte2, &byte1, &byte0, &byte4) == 5) {
|
|
|
|
ip_int = (byte3 << 24) + (byte2 << 16) + (byte1 << 8) + byte0;
|
|
|
|
port_int = byte4;
|
|
|
|
|
|
|
|
unsigned char ip_tmp[4];
|
|
|
|
ip_tmp[0] = ip_int & 0xFF;
|
|
|
|
ip_tmp[1] = (ip_int >> 8) & 0xFF;
|
|
|
|
ip_tmp[2] = (ip_int >> 16) & 0xFF;
|
|
|
|
ip_tmp[3] = (ip_int >> 24) & 0xFF;
|
|
|
|
snprintf(newip, sizeof(newip), "%d.%d.%d.%d", ip_tmp[3], ip_tmp[2], ip_tmp[1], ip_tmp[0]);
|
|
|
|
} else {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gameserver server;
|
|
|
|
server.set_ip(ip_int);
|
|
|
|
server.set_port(port_int);
|
|
|
|
server.set_query_port(port_int);
|
|
|
|
server.set_appid(iApp);
|
|
|
|
|
|
|
|
struct Steam_Matchmaking_Servers_Gameserver g;
|
|
|
|
g.last_recv = std::chrono::high_resolution_clock::now();
|
|
|
|
g.server = server;
|
|
|
|
g.type = type;
|
|
|
|
gameservers.push_back(g);
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" SERVER ADDED");
|
2024-02-27 21:17:53 +02:00
|
|
|
|
|
|
|
list_ip = "";
|
|
|
|
}
|
|
|
|
|
2019-04-13 12:21:56 -04:00
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2024-02-27 21:17:53 +02:00
|
|
|
// Request a new list of servers of a particular type. These calls each correspond to one of the EMatchMakingType values.
|
|
|
|
// Each call allocates a new asynchronous request object.
|
|
|
|
// Request object must be released by calling ReleaseRequest( hServerListRequest )
|
|
|
|
HServerListRequest Steam_Matchmaking_Servers::RequestInternetServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-02-29 01:16:01 +02:00
|
|
|
return RequestServerList(iApp, pRequestServersResponse, eInternetServer);
|
2024-02-27 21:17:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
HServerListRequest Steam_Matchmaking_Servers::RequestLANServerList( AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-02-27 21:17:53 +02:00
|
|
|
return RequestServerList(iApp, pRequestServersResponse, eLANServer);
|
|
|
|
}
|
|
|
|
|
2019-04-13 12:21:56 -04:00
|
|
|
HServerListRequest Steam_Matchmaking_Servers::RequestFriendsServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-02-29 01:16:01 +02:00
|
|
|
return RequestServerList(iApp, pRequestServersResponse, eFriendsServer);
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HServerListRequest Steam_Matchmaking_Servers::RequestFavoritesServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-02-29 01:16:01 +02:00
|
|
|
return RequestServerList(iApp, pRequestServersResponse, eFavoritesServer);
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HServerListRequest Steam_Matchmaking_Servers::RequestHistoryServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-02-29 01:16:01 +02:00
|
|
|
return RequestServerList(iApp, pRequestServersResponse, eHistoryServer);
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HServerListRequest Steam_Matchmaking_Servers::RequestSpectatorServerList( AppId_t iApp, STEAM_ARRAY_COUNT(nFilters) MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-02-29 01:16:01 +02:00
|
|
|
return RequestServerList(iApp, pRequestServersResponse, eSpectatorServer);
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
|
2024-02-29 01:16:01 +02:00
|
|
|
// old server list request
|
|
|
|
|
2022-07-31 15:49:45 -04:00
|
|
|
void Steam_Matchmaking_Servers::RequestOldServerList(AppId_t iApp, ISteamMatchmakingServerListResponse001 *pRequestServersResponse, EMatchMakingType type)
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%u", iApp);
|
2022-07-31 15:49:45 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
auto g = std::begin(requests);
|
|
|
|
while (g != std::end(requests)) {
|
2024-02-28 00:12:47 +02:00
|
|
|
if (g->id == (void *)type) {
|
2022-07-31 15:49:45 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
++g;
|
|
|
|
}
|
|
|
|
|
2024-02-28 00:12:47 +02:00
|
|
|
struct Steam_Matchmaking_Request request{};
|
2022-07-31 15:49:45 -04:00
|
|
|
request.appid = iApp;
|
|
|
|
request.callbacks = NULL;
|
|
|
|
request.old_callbacks = pRequestServersResponse;
|
|
|
|
request.cancelled = false;
|
|
|
|
request.completed = false;
|
2024-02-27 21:17:53 +02:00
|
|
|
request.type = type;
|
2024-02-28 00:12:47 +02:00
|
|
|
request.id = (void *)type;
|
2022-07-31 15:49:45 -04:00
|
|
|
requests.push_back(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::RequestInternetServerList( AppId_t iApp, MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse001 *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("old");
|
2022-07-31 15:49:45 -04:00
|
|
|
//TODO
|
|
|
|
RequestOldServerList(iApp, pRequestServersResponse, eInternetServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::RequestLANServerList( AppId_t iApp, ISteamMatchmakingServerListResponse001 *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("old");
|
2022-07-31 15:49:45 -04:00
|
|
|
//TODO
|
|
|
|
RequestOldServerList(iApp, pRequestServersResponse, eLANServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::RequestFriendsServerList( AppId_t iApp, MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse001 *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("old");
|
2022-07-31 15:49:45 -04:00
|
|
|
//TODO
|
|
|
|
RequestOldServerList(iApp, pRequestServersResponse, eFriendsServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::RequestFavoritesServerList( AppId_t iApp, MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse001 *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("old");
|
2022-07-31 15:49:45 -04:00
|
|
|
//TODO
|
|
|
|
RequestOldServerList(iApp, pRequestServersResponse, eFavoritesServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::RequestHistoryServerList( AppId_t iApp, MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse001 *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("old");
|
2022-07-31 15:49:45 -04:00
|
|
|
//TODO
|
|
|
|
RequestOldServerList(iApp, pRequestServersResponse, eHistoryServer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::RequestSpectatorServerList( AppId_t iApp, MatchMakingKeyValuePair_t **ppchFilters, uint32 nFilters, ISteamMatchmakingServerListResponse001 *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("old");
|
2022-07-31 15:49:45 -04:00
|
|
|
//TODO
|
|
|
|
RequestOldServerList(iApp, pRequestServersResponse, eSpectatorServer);
|
|
|
|
}
|
|
|
|
|
2019-04-13 12:21:56 -04:00
|
|
|
|
|
|
|
// Releases the asynchronous request object and cancels any pending query on it if there's a pending query in progress.
|
|
|
|
// RefreshComplete callback is not posted when request is released.
|
|
|
|
void Steam_Matchmaking_Servers::ReleaseRequest( HServerListRequest hServerListRequest )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%p", hServerListRequest);
|
2019-04-13 12:21:56 -04:00
|
|
|
auto g = std::begin(requests);
|
|
|
|
while (g != std::end(requests)) {
|
|
|
|
if (g->id == hServerListRequest) {
|
|
|
|
//NOTE: some garbage games release the request before getting server details from it.
|
|
|
|
// g = requests.erase(g);
|
|
|
|
// } else {
|
|
|
|
//TODO: eventually delete the released request.
|
|
|
|
g->cancelled = true;
|
|
|
|
g->released = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
++g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* the filter operation codes that go in the key part of MatchMakingKeyValuePair_t should be one of these:
|
|
|
|
|
|
|
|
"map"
|
|
|
|
- Server passes the filter if the server is playing the specified map.
|
|
|
|
"gamedataand"
|
|
|
|
- Server passes the filter if the server's game data (ISteamGameServer::SetGameData) contains all of the
|
|
|
|
specified strings. The value field is a comma-delimited list of strings to match.
|
|
|
|
"gamedataor"
|
|
|
|
- Server passes the filter if the server's game data (ISteamGameServer::SetGameData) contains at least one of the
|
|
|
|
specified strings. The value field is a comma-delimited list of strings to match.
|
|
|
|
"gamedatanor"
|
|
|
|
- Server passes the filter if the server's game data (ISteamGameServer::SetGameData) does not contain any
|
|
|
|
of the specified strings. The value field is a comma-delimited list of strings to check.
|
|
|
|
"gametagsand"
|
|
|
|
- Server passes the filter if the server's game tags (ISteamGameServer::SetGameTags) contains all
|
|
|
|
of the specified strings. The value field is a comma-delimited list of strings to check.
|
|
|
|
"gametagsnor"
|
|
|
|
- Server passes the filter if the server's game tags (ISteamGameServer::SetGameTags) does not contain any
|
|
|
|
of the specified strings. The value field is a comma-delimited list of strings to check.
|
|
|
|
"and" (x1 && x2 && ... && xn)
|
|
|
|
"or" (x1 || x2 || ... || xn)
|
|
|
|
"nand" !(x1 && x2 && ... && xn)
|
|
|
|
"nor" !(x1 || x2 || ... || xn)
|
|
|
|
- Performs Boolean operation on the following filters. The operand to this filter specifies
|
|
|
|
the "size" of the Boolean inputs to the operation, in Key/value pairs. (The keyvalue
|
|
|
|
pairs must immediately follow, i.e. this is a prefix logical operator notation.)
|
|
|
|
In the simplest case where Boolean expressions are not nested, this is simply
|
|
|
|
the number of operands.
|
|
|
|
|
|
|
|
For example, to match servers on a particular map or with a particular tag, would would
|
|
|
|
use these filters.
|
|
|
|
|
|
|
|
( server.map == "cp_dustbowl" || server.gametags.contains("payload") )
|
|
|
|
"or", "2"
|
|
|
|
"map", "cp_dustbowl"
|
|
|
|
"gametagsand", "payload"
|
|
|
|
|
|
|
|
If logical inputs are nested, then the operand specifies the size of the entire
|
|
|
|
"length" of its operands, not the number of immediate children.
|
|
|
|
|
|
|
|
( server.map == "cp_dustbowl" || ( server.gametags.contains("payload") && !server.gametags.contains("payloadrace") ) )
|
|
|
|
"or", "4"
|
|
|
|
"map", "cp_dustbowl"
|
|
|
|
"and", "2"
|
|
|
|
"gametagsand", "payload"
|
|
|
|
"gametagsnor", "payloadrace"
|
|
|
|
|
|
|
|
Unary NOT can be achieved using either "nand" or "nor" with a single operand.
|
|
|
|
|
|
|
|
"addr"
|
|
|
|
- Server passes the filter if the server's query address matches the specified IP or IP:port.
|
|
|
|
"gameaddr"
|
|
|
|
- Server passes the filter if the server's game address matches the specified IP or IP:port.
|
|
|
|
|
|
|
|
The following filter operations ignore the "value" part of MatchMakingKeyValuePair_t
|
|
|
|
|
|
|
|
"dedicated"
|
|
|
|
- Server passes the filter if it passed true to SetDedicatedServer.
|
|
|
|
"secure"
|
|
|
|
- Server passes the filter if the server is VAC-enabled.
|
|
|
|
"notfull"
|
|
|
|
- Server passes the filter if the player count is less than the reported max player count.
|
|
|
|
"hasplayers"
|
|
|
|
- Server passes the filter if the player count is greater than zero.
|
|
|
|
"noplayers"
|
|
|
|
- Server passes the filter if it doesn't have any players.
|
|
|
|
"linux"
|
|
|
|
- Server passes the filter if it's a linux server
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::server_details(Gameserver *g, gameserveritem_t *server)
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG_ENTRY();
|
2024-03-25 03:46:13 +02:00
|
|
|
constexpr const static int MIN_LATENCY = 2;
|
|
|
|
|
|
|
|
int latency = MIN_LATENCY;
|
2024-02-29 01:16:01 +02:00
|
|
|
|
|
|
|
if (settings->matchmaking_server_details_via_source_query && !(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]);
|
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" connecting to ssq server on %s:%u", newip, g->query_port());
|
2024-02-29 01:16:01 +02:00
|
|
|
SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port());
|
|
|
|
if (ssq != NULL && ssq_server_eok(ssq)) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server connection ok");
|
2024-02-29 01:16:01 +02:00
|
|
|
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 = (int)std::chrono::duration_cast<std::chrono::milliseconds>(t2 - t1).count();
|
2024-03-25 03:46:13 +02:00
|
|
|
|
|
|
|
// TODO I don't know if low latency is problematic or not, hence this artificial latency
|
|
|
|
if (latency < MIN_LATENCY) latency = MIN_LATENCY;
|
2024-02-29 01:16:01 +02:00
|
|
|
|
|
|
|
if (ssq_server_eok(ssq)) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server info ok");
|
2024-02-29 01:16:01 +02:00
|
|
|
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 {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server info failed: %s", ssq_server_emsg(ssq));
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ssq_a2s_info != NULL) ssq_info_free(ssq_a2s_info);
|
|
|
|
} else {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server connection failed: %s", (ssq ? ssq_server_emsg(ssq) : "NULL instance"));
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ssq != NULL) ssq_server_free(ssq);
|
|
|
|
}
|
|
|
|
|
2019-04-13 12:21:56 -04:00
|
|
|
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());
|
2024-02-29 01:16:01 +02:00
|
|
|
server->m_nPing = latency;
|
2019-04-13 12:21:56 -04:00
|
|
|
server->m_bHadSuccessfulResponse = true;
|
|
|
|
server->m_bDoNotRefresh = false;
|
|
|
|
|
|
|
|
server->m_nAppID = g->appid();
|
|
|
|
server->m_nPlayers = g->num_players();
|
|
|
|
server->m_nMaxPlayers = g->max_player_count();
|
|
|
|
server->m_nBotPlayers = g->bot_player_count();
|
|
|
|
server->m_bPassword = g->password_protected();
|
|
|
|
server->m_bSecure = g->secure();
|
|
|
|
server->m_ulTimeLastPlayed = 0;
|
|
|
|
server->m_nServerVersion = g->version();
|
|
|
|
server->SetName(g->server_name().c_str());
|
|
|
|
server->m_steamID = CSteamID((uint64)g->id());
|
2024-02-28 00:12:47 +02:00
|
|
|
|
|
|
|
memset(server->m_szGameDir, 0, sizeof(server->m_szGameDir));
|
|
|
|
g->mod_dir().copy(server->m_szGameDir, sizeof(server->m_szGameDir) - 1);
|
2024-02-27 21:17:53 +02:00
|
|
|
|
2024-02-28 00:12:47 +02:00
|
|
|
memset(server->m_szMap, 0, sizeof(server->m_szMap));
|
|
|
|
g->map_name().copy(server->m_szMap, sizeof(server->m_szMap) - 1);
|
2024-02-27 21:17:53 +02:00
|
|
|
|
2024-02-28 00:12:47 +02:00
|
|
|
memset(server->m_szGameDescription, 0, sizeof(server->m_szGameDescription));
|
|
|
|
g->game_description().copy(server->m_szGameDescription, sizeof(server->m_szGameDescription) - 1);
|
2024-02-27 21:17:53 +02:00
|
|
|
|
2024-02-28 00:12:47 +02:00
|
|
|
memset(server->m_szGameTags, 0, sizeof(server->m_szGameTags));
|
|
|
|
g->tags().copy(server->m_szGameTags, sizeof(server->m_szGameTags) - 1);
|
2024-02-27 21:17:53 +02:00
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" " "%" PRIu64 "", g->id());
|
2023-08-21 06:58:55 +03:00
|
|
|
}
|
|
|
|
|
2024-02-29 01:16:01 +02:00
|
|
|
void Steam_Matchmaking_Servers::server_details_players(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r)
|
|
|
|
{
|
|
|
|
if (settings->matchmaking_server_details_via_source_query && !(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]);
|
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" connecting to ssq server on %s:%u", newip, g->query_port());
|
2024-02-29 01:16:01 +02:00
|
|
|
SSQ_SERVER *ssq = ssq_server_new(newip, g->query_port());
|
|
|
|
if (ssq != NULL && ssq_server_eok(ssq)) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server connection ok");
|
2024-02-29 01:16:01 +02:00
|
|
|
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)) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server players ok");
|
2024-02-29 01:16:01 +02:00
|
|
|
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 {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server players failed: %s", ssq_server_emsg(ssq));
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ssq_a2s_player != NULL) ssq_player_free(ssq_a2s_player, ssq_a2s_player_count);
|
|
|
|
} else {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server connection failed: %s", (ssq ? ssq_server_emsg(ssq) : "NULL instance"));
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ssq != NULL) ssq_server_free(ssq);
|
|
|
|
} else if (!settings->matchmaking_server_details_via_source_query) { // original behavior
|
|
|
|
uint32_t number_players = g->num_players();
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" players: %u", number_players);
|
2024-02-29 01:16:01 +02:00
|
|
|
const auto &players = get_steam_client()->steam_gameserver->get_players();
|
2024-02-29 02:51:33 +02:00
|
|
|
auto player = players->cbegin();
|
2024-02-29 01:16:01 +02:00
|
|
|
for (int i = 0; i < number_players && player != players->end(); ++i, ++player) {
|
|
|
|
float playtime = static_cast<float>(std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - player->second.join_time).count());
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" PLAYER [%u] '%s' %u %f", i, player->second.name.c_str(), player->second.score, playtime);
|
2024-02-29 01:16:01 +02:00
|
|
|
r->players_response->AddPlayerToList(player->second.name.c_str(), player->second.score, playtime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" " "%" PRIu64 "", g->id());
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::server_details_rules(Gameserver *g, Steam_Matchmaking_Servers_Direct_IP_Request *r)
|
|
|
|
{
|
|
|
|
if (settings->matchmaking_server_details_via_source_query && !(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]);
|
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" connecting to ssq server on %s:%u", newip, g->query_port());
|
2024-02-29 01:16:01 +02:00
|
|
|
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)) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server rules ok");
|
2024-02-29 01:16:01 +02:00
|
|
|
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 {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server rules failed: %s", ssq_server_emsg(ssq));
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ssq_a2s_rules != NULL) ssq_rules_free(ssq_a2s_rules, ssq_a2s_rules_count);
|
|
|
|
} else {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" ssq server connection failed: %s", (ssq ? ssq_server_emsg(ssq) : "NULL instance"));
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ssq != NULL) ssq_server_free(ssq);
|
|
|
|
} else if (!settings->matchmaking_server_details_via_source_query) { // original behavior
|
|
|
|
int number_rules = (int)g->values().size();
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" rules: %i", number_rules);
|
2024-02-29 01:16:01 +02:00
|
|
|
auto rule = g->values().begin();
|
|
|
|
for (int i = 0; i < number_rules; ++i) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" RULE '%s'='%s'", rule->first.c_str(), rule->second.c_str());
|
2024-02-29 01:16:01 +02:00
|
|
|
r->rules_response->RulesResponded(rule->first.c_str(), rule->second.c_str());
|
|
|
|
++rule;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" " "%" PRIu64 "", g->id());
|
2024-02-29 01:16:01 +02:00
|
|
|
}
|
|
|
|
|
2019-04-13 12:21:56 -04:00
|
|
|
// Get details on a given server in the list, you can get the valid range of index
|
|
|
|
// values by calling GetServerCount(). You will also receive index values in
|
|
|
|
// ISteamMatchmakingServerListResponse::ServerResponded() callbacks
|
|
|
|
gameserveritem_t *Steam_Matchmaking_Servers::GetServerDetails( HServerListRequest hRequest, int iServer )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%p %i", hRequest, iServer);
|
2019-04-13 12:21:56 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
|
|
|
|
std::vector <struct Steam_Matchmaking_Servers_Gameserver> gameservers_filtered;
|
|
|
|
auto g = std::begin(requests);
|
|
|
|
while (g != std::end(requests)) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" equal? %p %p", hRequest, g->id);
|
2019-04-13 12:21:56 -04:00
|
|
|
if (g->id == hRequest) {
|
|
|
|
gameservers_filtered = g->gameservers_filtered;
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" found %zu", gameservers_filtered.size());
|
2019-04-13 12:21:56 -04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++g;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iServer >= gameservers_filtered.size() || iServer < 0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
Gameserver *gs = &gameservers_filtered[iServer].server;
|
|
|
|
gameserveritem_t *server = new gameserveritem_t(); //TODO: is the new here ok?
|
|
|
|
server_details(gs, server);
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG(" Returned server details");
|
2019-04-13 12:21:56 -04:00
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Cancel an request which is operation on the given list type. You should call this to cancel
|
|
|
|
// any in-progress requests before destructing a callback object that may have been passed
|
|
|
|
// to one of the above list request calls. Not doing so may result in a crash when a callback
|
|
|
|
// occurs on the destructed object.
|
|
|
|
// Canceling a query does not release the allocated request handle.
|
|
|
|
// The request handle must be released using ReleaseRequest( hRequest )
|
|
|
|
void Steam_Matchmaking_Servers::CancelQuery( HServerListRequest hRequest )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%p", hRequest);
|
2019-04-13 12:21:56 -04:00
|
|
|
auto g = std::begin(requests);
|
|
|
|
while (g != std::end(requests)) {
|
|
|
|
if (g->id == hRequest) {
|
|
|
|
g->cancelled = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
++g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ping every server in your list again but don't update the list of servers
|
|
|
|
// Query callback installed when the server list was requested will be used
|
|
|
|
// again to post notifications and RefreshComplete, so the callback must remain
|
|
|
|
// valid until another RefreshComplete is called on it or the request
|
|
|
|
// is released with ReleaseRequest( hRequest )
|
|
|
|
void Steam_Matchmaking_Servers::RefreshQuery( HServerListRequest hRequest )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%p", hRequest);
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns true if the list is currently refreshing its server list
|
|
|
|
bool Steam_Matchmaking_Servers::IsRefreshing( HServerListRequest hRequest )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%p", hRequest);
|
2019-04-13 12:21:56 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// How many servers in the given list, GetServerDetails above takes 0... GetServerCount() - 1
|
|
|
|
int Steam_Matchmaking_Servers::GetServerCount( HServerListRequest hRequest )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%p", hRequest);
|
2019-04-13 12:21:56 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
int size = 0;
|
|
|
|
auto g = std::begin(requests);
|
|
|
|
while (g != std::end(requests)) {
|
|
|
|
if (g->id == hRequest) {
|
|
|
|
size = g->gameservers_filtered.size();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
++g;
|
|
|
|
}
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Refresh a single server inside of a query (rather than all the servers )
|
|
|
|
void Steam_Matchmaking_Servers::RefreshServer( HServerListRequest hRequest, int iServer )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%p", hRequest);
|
2019-04-13 12:21:56 -04:00
|
|
|
//TODO
|
|
|
|
}
|
|
|
|
|
|
|
|
static HServerQuery new_server_query()
|
|
|
|
{
|
2024-02-17 22:22:43 +02:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
static int a = 0;
|
2019-04-13 12:21:56 -04:00
|
|
|
++a;
|
|
|
|
if (!a) ++a;
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Queries to individual servers directly via IP/Port
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Request updated ping time and other details from a single server
|
|
|
|
HServerQuery Steam_Matchmaking_Servers::PingServer( uint32 unIP, uint16 usPort, ISteamMatchmakingPingResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%hhu.%hhu.%hhu.%hhu:%hu", ((unsigned char *)&unIP)[3], ((unsigned char *)&unIP)[2], ((unsigned char *)&unIP)[1], ((unsigned char *)&unIP)[0], usPort);
|
2019-04-13 12:21:56 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
Steam_Matchmaking_Servers_Direct_IP_Request r;
|
|
|
|
r.id = new_server_query();
|
|
|
|
r.ip = unIP;
|
|
|
|
r.port = usPort;
|
|
|
|
r.ping_response = pRequestServersResponse;
|
2020-02-24 15:05:51 -05:00
|
|
|
r.created = std::chrono::high_resolution_clock::now();
|
2019-04-13 12:21:56 -04:00
|
|
|
direct_ip_requests.push_back(r);
|
|
|
|
return r.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Request the list of players currently playing on a server
|
|
|
|
HServerQuery Steam_Matchmaking_Servers::PlayerDetails( uint32 unIP, uint16 usPort, ISteamMatchmakingPlayersResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%hhu.%hhu.%hhu.%hhu:%hu", ((unsigned char *)&unIP)[3], ((unsigned char *)&unIP)[2], ((unsigned char *)&unIP)[1], ((unsigned char *)&unIP)[0], usPort);
|
2019-04-13 12:21:56 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
Steam_Matchmaking_Servers_Direct_IP_Request r;
|
|
|
|
r.id = new_server_query();
|
|
|
|
r.ip = unIP;
|
|
|
|
r.port = usPort;
|
|
|
|
r.players_response = pRequestServersResponse;
|
2020-02-24 15:05:51 -05:00
|
|
|
r.created = std::chrono::high_resolution_clock::now();
|
2019-04-13 12:21:56 -04:00
|
|
|
direct_ip_requests.push_back(r);
|
|
|
|
return r.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Request the list of rules that the server is running (See ISteamGameServer::SetKeyValue() to set the rules server side)
|
|
|
|
HServerQuery Steam_Matchmaking_Servers::ServerRules( uint32 unIP, uint16 usPort, ISteamMatchmakingRulesResponse *pRequestServersResponse )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%hhu.%hhu.%hhu.%hhu:%hu", ((unsigned char *)&unIP)[3], ((unsigned char *)&unIP)[2], ((unsigned char *)&unIP)[1], ((unsigned char *)&unIP)[0], usPort);
|
2019-04-13 12:21:56 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
Steam_Matchmaking_Servers_Direct_IP_Request r;
|
|
|
|
r.id = new_server_query();
|
|
|
|
r.ip = unIP;
|
|
|
|
r.port = usPort;
|
|
|
|
r.rules_response = pRequestServersResponse;
|
2020-02-24 15:05:51 -05:00
|
|
|
r.created = std::chrono::high_resolution_clock::now();
|
2019-04-13 12:21:56 -04:00
|
|
|
direct_ip_requests.push_back(r);
|
|
|
|
return r.id;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Cancel an outstanding Ping/Players/Rules query from above. You should call this to cancel
|
|
|
|
// any in-progress requests before destructing a callback object that may have been passed
|
|
|
|
// to one of the above calls to avoid crashing when callbacks occur.
|
|
|
|
void Steam_Matchmaking_Servers::CancelServerQuery( HServerQuery hServerQuery )
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("Steam_Matchmaking_Servers::CancelServerQuery");
|
2019-04-13 12:21:56 -04:00
|
|
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
|
|
|
auto r = std::find_if(direct_ip_requests.begin(), direct_ip_requests.end(), [&hServerQuery](Steam_Matchmaking_Servers_Direct_IP_Request const& item) { return item.id == hServerQuery; });
|
|
|
|
if (direct_ip_requests.end() == r) return;
|
|
|
|
direct_ip_requests.erase(r);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::RunCallbacks()
|
|
|
|
{
|
2024-04-06 07:49:07 +02:00
|
|
|
// PRINT_DEBUG_ENTRY();
|
2019-04-13 12:21:56 -04:00
|
|
|
|
|
|
|
{
|
|
|
|
auto g = std::begin(gameservers);
|
|
|
|
while (g != std::end(gameservers)) {
|
|
|
|
if (check_timedout(g->last_recv, SERVER_TIMEOUT)) {
|
|
|
|
g = gameservers.erase(g);
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("TIMEOUT");
|
2019-04-13 12:21:56 -04:00
|
|
|
} else {
|
|
|
|
++g;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("requests count = %zu, servers count = %zu", requests.size(), gameservers.size());
|
2019-04-13 12:21:56 -04:00
|
|
|
|
|
|
|
for (auto &r : requests) {
|
|
|
|
if (r.cancelled || r.completed) continue;
|
|
|
|
|
|
|
|
r.gameservers_filtered.clear();
|
|
|
|
for (auto &g : gameservers) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%u==%u | %i==%i", g.server.appid(), r.appid, (int)g.type, (int)r.type);
|
2024-04-09 11:13:36 +02:00
|
|
|
if ((g.server.appid() == r.appid) && (g.type == r.type || settings->matchmaking_server_list_always_lan_type)) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("server found");
|
2019-04-13 12:21:56 -04:00
|
|
|
r.gameservers_filtered.push_back(g);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector <struct Steam_Matchmaking_Request> requests_temp(requests);
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%zu", requests_temp.size());
|
2019-04-13 12:21:56 -04:00
|
|
|
for (auto &r : requests) {
|
|
|
|
r.completed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &r : requests_temp) {
|
|
|
|
if (r.cancelled || r.completed) continue;
|
|
|
|
int i = 0;
|
|
|
|
|
2019-05-26 13:46:43 -04:00
|
|
|
if (r.callbacks) {
|
|
|
|
for (auto &g : r.gameservers_filtered) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("server responded cb %p", r.id);
|
2019-05-26 13:46:43 -04:00
|
|
|
r.callbacks->ServerResponded(r.id, i);
|
|
|
|
++i;
|
|
|
|
}
|
2019-04-13 12:21:56 -04:00
|
|
|
|
2019-05-26 13:46:43 -04:00
|
|
|
if (i) {
|
|
|
|
r.callbacks->RefreshComplete(r.id, eServerResponded);
|
|
|
|
} else {
|
|
|
|
r.callbacks->RefreshComplete(r.id, eNoServersListedOnMasterServer);
|
|
|
|
}
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
2022-07-31 15:49:45 -04:00
|
|
|
|
|
|
|
if (r.old_callbacks) {
|
|
|
|
for (auto &g : r.gameservers_filtered) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("REQUESTS server responded cb %p", r.id);
|
2022-07-31 15:49:45 -04:00
|
|
|
r.old_callbacks->ServerResponded(i);
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i) {
|
|
|
|
r.old_callbacks->RefreshComplete(eServerResponded);
|
|
|
|
} else {
|
|
|
|
r.old_callbacks->RefreshComplete(eNoServersListedOnMasterServer);
|
|
|
|
}
|
|
|
|
}
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
|
2020-02-24 15:05:51 -05:00
|
|
|
std::vector <struct Steam_Matchmaking_Servers_Direct_IP_Request> 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;
|
|
|
|
}
|
|
|
|
}
|
2019-04-13 12:21:56 -04:00
|
|
|
|
|
|
|
for (auto &r : direct_ip_requests_temp) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("request: %u:%hu", r.ip, r.port);
|
2019-04-13 12:21:56 -04:00
|
|
|
for (auto &g : gameservers) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("%u:%u", g.server.ip(), g.server.query_port());
|
2019-04-13 12:21:56 -04:00
|
|
|
uint16 query_port = g.server.query_port();
|
|
|
|
if (query_port == 0xFFFF) {
|
|
|
|
query_port = g.server.port();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (query_port == r.port && g.server.ip() == r.ip) {
|
|
|
|
if (r.rules_response) {
|
2024-02-29 01:16:01 +02:00
|
|
|
server_details_rules(&(g.server), &r);
|
2019-04-13 12:21:56 -04:00
|
|
|
r.rules_response->RulesRefreshComplete();
|
|
|
|
r.rules_response = NULL;
|
|
|
|
}
|
|
|
|
|
2024-02-27 21:17:53 +02:00
|
|
|
if (r.players_response) {
|
2024-02-29 01:16:01 +02:00
|
|
|
server_details_players(&(g.server), &r);
|
2024-02-27 21:17:53 +02:00
|
|
|
r.players_response->PlayersRefreshComplete();
|
|
|
|
r.players_response = NULL;
|
|
|
|
}
|
|
|
|
|
2019-04-13 12:21:56 -04:00
|
|
|
if (r.ping_response) {
|
2024-02-29 01:16:01 +02:00
|
|
|
gameserveritem_t server{};
|
2019-04-13 12:21:56 -04:00
|
|
|
server_details(&(g.server), &server);
|
|
|
|
r.ping_response->ServerResponded(server);
|
|
|
|
r.ping_response = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r.rules_response) r.rules_response->RulesRefreshComplete();
|
|
|
|
if (r.players_response) r.players_response->PlayersRefreshComplete();
|
|
|
|
if (r.ping_response) r.ping_response->ServerFailedToRespond();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Steam_Matchmaking_Servers::Callback(Common_Message *msg)
|
|
|
|
{
|
2024-02-27 21:17:53 +02:00
|
|
|
if (msg->has_gameserver() && msg->gameserver().type() != eFriendsServer) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("got SERVER " "%" PRIu64 ", offline:%u", msg->gameserver().id(), msg->gameserver().offline());
|
2019-04-13 12:21:56 -04:00
|
|
|
if (msg->gameserver().offline()) {
|
|
|
|
for (auto &g : gameservers) {
|
|
|
|
if (g.server.id() == msg->gameserver().id()) {
|
|
|
|
g.last_recv = std::chrono::high_resolution_clock::time_point();
|
2024-02-27 21:17:53 +02:00
|
|
|
g.type = eLANServer;
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bool already = false;
|
|
|
|
for (auto &g : gameservers) {
|
|
|
|
if (g.server.id() == msg->gameserver().id()) {
|
|
|
|
g.last_recv = std::chrono::high_resolution_clock::now();
|
|
|
|
g.server = msg->gameserver();
|
|
|
|
g.server.set_ip(msg->source_ip());
|
2024-02-27 21:17:53 +02:00
|
|
|
g.type = eLANServer;
|
2019-04-13 12:21:56 -04:00
|
|
|
already = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!already) {
|
|
|
|
struct Steam_Matchmaking_Servers_Gameserver g;
|
|
|
|
g.last_recv = std::chrono::high_resolution_clock::now();
|
|
|
|
g.server = msg->gameserver();
|
|
|
|
g.server.set_ip(msg->source_ip());
|
2024-02-27 21:17:53 +02:00
|
|
|
g.type = eLANServer;
|
2019-04-13 12:21:56 -04:00
|
|
|
gameservers.push_back(g);
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("ADDED");
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-02-27 21:17:53 +02:00
|
|
|
|
|
|
|
if (msg->has_gameserver() && msg->gameserver().type() == eFriendsServer) {
|
2024-04-06 07:49:07 +02:00
|
|
|
PRINT_DEBUG("got eFriendsServer SERVER " "%" PRIu64 "", msg->gameserver().id());
|
2024-02-27 21:17:53 +02:00
|
|
|
bool addserver = true;
|
|
|
|
for (auto &g : gameservers_friends) {
|
|
|
|
if (g.source_id == msg->source_id()) {
|
|
|
|
g.ip = msg->gameserver().ip();
|
|
|
|
g.port = msg->gameserver().port();
|
|
|
|
g.last_recv = std::chrono::high_resolution_clock::now();
|
|
|
|
addserver = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (addserver) {
|
|
|
|
struct Steam_Matchmaking_Servers_Gameserver_Friends gameserver_friend;
|
|
|
|
gameserver_friend.source_id = msg->source_id();
|
|
|
|
gameserver_friend.ip = msg->gameserver().ip();
|
|
|
|
gameserver_friend.port = msg->gameserver().port();
|
|
|
|
gameserver_friend.last_recv = std::chrono::high_resolution_clock::now();
|
|
|
|
gameservers_friends.push_back(gameserver_friend);
|
|
|
|
}
|
|
|
|
}
|
2019-04-13 12:21:56 -04:00
|
|
|
}
|