mirror of
https://github.com/Detanup01/gbe_fork.git
synced 2025-01-13 10:53:57 +08:00
in gameserver_stats: remove & timeout pending requests if the user disconnected
This commit is contained in:
parent
f423b07eef
commit
c17cb8a4f7
@ -65,6 +65,10 @@ class Steam_GameServerStats : public ISteamGameServerStats
|
|||||||
void network_callback_updated_stats(Common_Message *msg);
|
void network_callback_updated_stats(Common_Message *msg);
|
||||||
void network_callback(Common_Message *msg);
|
void network_callback(Common_Message *msg);
|
||||||
|
|
||||||
|
// user connect/disconnect
|
||||||
|
void network_callback_low_level(Common_Message *msg);
|
||||||
|
|
||||||
|
static void steam_gameserverstats_network_low_level(void *object, Common_Message *msg);
|
||||||
static void steam_gameserverstats_network_callback(void *object, Common_Message *msg);
|
static void steam_gameserverstats_network_callback(void *object, Common_Message *msg);
|
||||||
static void steam_gameserverstats_run_every_runcb(void *object);
|
static void steam_gameserverstats_run_every_runcb(void *object);
|
||||||
|
|
||||||
|
@ -21,6 +21,14 @@
|
|||||||
#define PENDING_RequestUserStats_TIMEOUT 7.0
|
#define PENDING_RequestUserStats_TIMEOUT 7.0
|
||||||
|
|
||||||
|
|
||||||
|
void Steam_GameServerStats::steam_gameserverstats_network_low_level(void *object, Common_Message *msg)
|
||||||
|
{
|
||||||
|
// PRINT_DEBUG("Steam_GameServerStats::steam_gameserverstats_network_low_level\n");
|
||||||
|
|
||||||
|
auto inst = (Steam_GameServerStats *)object;
|
||||||
|
inst->network_callback_low_level(msg);
|
||||||
|
}
|
||||||
|
|
||||||
void Steam_GameServerStats::steam_gameserverstats_network_callback(void *object, Common_Message *msg)
|
void Steam_GameServerStats::steam_gameserverstats_network_callback(void *object, Common_Message *msg)
|
||||||
{
|
{
|
||||||
// PRINT_DEBUG("Steam_GameServerStats::steam_gameserverstats_network_callback\n");
|
// PRINT_DEBUG("Steam_GameServerStats::steam_gameserverstats_network_callback\n");
|
||||||
@ -82,6 +90,7 @@ Steam_GameServerStats::Steam_GameServerStats(class Settings *settings, class Net
|
|||||||
this->run_every_runcb = run_every_runcb;
|
this->run_every_runcb = run_every_runcb;
|
||||||
|
|
||||||
this->network->setCallback(CALLBACK_ID_GAMESERVER_STATS, settings->get_local_steam_id(), &Steam_GameServerStats::steam_gameserverstats_network_callback, this);
|
this->network->setCallback(CALLBACK_ID_GAMESERVER_STATS, settings->get_local_steam_id(), &Steam_GameServerStats::steam_gameserverstats_network_callback, this);
|
||||||
|
this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_GameServerStats::steam_gameserverstats_network_low_level, this);
|
||||||
this->run_every_runcb->add(&Steam_GameServerStats::steam_gameserverstats_run_every_runcb, this);
|
this->run_every_runcb->add(&Steam_GameServerStats::steam_gameserverstats_run_every_runcb, this);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -89,6 +98,7 @@ Steam_GameServerStats::Steam_GameServerStats(class Settings *settings, class Net
|
|||||||
Steam_GameServerStats::~Steam_GameServerStats()
|
Steam_GameServerStats::~Steam_GameServerStats()
|
||||||
{
|
{
|
||||||
this->network->rmCallback(CALLBACK_ID_GAMESERVER_STATS, settings->get_local_steam_id(), &Steam_GameServerStats::steam_gameserverstats_network_callback, this);
|
this->network->rmCallback(CALLBACK_ID_GAMESERVER_STATS, settings->get_local_steam_id(), &Steam_GameServerStats::steam_gameserverstats_network_callback, this);
|
||||||
|
this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_GameServerStats::steam_gameserverstats_network_low_level, this);
|
||||||
this->run_every_runcb->remove(&Steam_GameServerStats::steam_gameserverstats_run_every_runcb, this);
|
this->run_every_runcb->remove(&Steam_GameServerStats::steam_gameserverstats_run_every_runcb, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -520,3 +530,46 @@ void Steam_GameServerStats::network_callback(Common_Message *msg)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// user connect/disconnect
|
||||||
|
void Steam_GameServerStats::network_callback_low_level(Common_Message *msg)
|
||||||
|
{
|
||||||
|
uint64 steamid = msg->source_id();
|
||||||
|
// this should never happen, but just in case
|
||||||
|
if (steamid == settings->get_local_steam_id().ConvertToUint64()) return;
|
||||||
|
|
||||||
|
switch (msg->low_level().type())
|
||||||
|
{
|
||||||
|
case Low_Level::CONNECT:
|
||||||
|
// nothing
|
||||||
|
break;
|
||||||
|
|
||||||
|
case Low_Level::DISCONNECT: {
|
||||||
|
all_users_data.erase(steamid);
|
||||||
|
auto it_rm = std::remove_if(
|
||||||
|
pending_RequestUserStats.begin(), pending_RequestUserStats.end(),
|
||||||
|
[=](const RequestAllStats &item) { return item.steamIDUser.ConvertToUint64() == steamid; }
|
||||||
|
);
|
||||||
|
while (pending_RequestUserStats.end() != it_rm) {
|
||||||
|
GSStatsReceived_t data{};
|
||||||
|
data.m_eResult = k_EResultTimeout;
|
||||||
|
data.m_steamIDUser = it_rm->steamIDUser;
|
||||||
|
callback_results->addCallResult(it_rm->steamAPICall, data.k_iCallback, &data, sizeof(data));
|
||||||
|
|
||||||
|
PRINT_DEBUG(
|
||||||
|
"Steam_GameServerStats::network_callback_low_level RequestUserStats timeout, %llu\n",
|
||||||
|
it_rm->steamIDUser.ConvertToUint64()
|
||||||
|
);
|
||||||
|
it_rm = pending_RequestUserStats.erase(it_rm);
|
||||||
|
}
|
||||||
|
|
||||||
|
// PRINT_DEBUG("Steam_GameServerStats::network_callback_low_level removed user %llu\n", steamid);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
PRINT_DEBUG("Steam_GameServerStats::network_callback_low_level unknown type %i\n", (int)msg->low_level().type());
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user