From 3c9b327fb5664cc0b0d58599c6a4793d71bde60b Mon Sep 17 00:00:00 2001 From: otavepto Date: Sat, 23 Mar 2024 17:01:27 +0200 Subject: [PATCH] * cleanup/remove all networking callbacks on object destruction * reset pointers on client destruction --- dll/auth.cpp | 12 ++- dll/dll/auth.h | 1 + dll/dll/steam_friends.h | 4 +- dll/dll/steam_game_coordinator.h | 2 +- dll/dll/steam_gamesearch.h | 2 +- dll/dll/steam_masterserver_updater.h | 2 +- dll/dll/steam_matchmaking.h | 3 +- dll/dll/steam_matchmaking_servers.h | 2 + dll/dll/steam_networking.h | 3 +- dll/dll/steam_networking_messages.h | 3 +- dll/dll/steam_networking_sockets.h | 3 +- dll/dll/steam_networking_socketsserialized.h | 2 +- dll/dll/steam_networking_utils.h | 2 +- dll/dll/steam_parties.h | 2 +- dll/dll/steam_remoteplay.h | 2 +- dll/dll/steam_tv.h | 2 +- dll/dll/steam_unified_messages.h | 8 +- dll/steam_client.cpp | 102 +++++++++---------- dll/steam_matchmaking_servers.cpp | 5 + overlay_experimental/steam_overlay.cpp | 3 +- 20 files changed, 93 insertions(+), 72 deletions(-) diff --git a/dll/auth.cpp b/dll/auth.cpp index 49628667..75af6c0b 100644 --- a/dll/auth.cpp +++ b/dll/auth.cpp @@ -41,11 +41,17 @@ Auth_Manager::Auth_Manager(class Settings *settings, class Networking *network, this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &steam_auth_manager_ticket_callback, this); } +Auth_Manager::~Auth_Manager() +{ + this->network->rmCallback(CALLBACK_ID_AUTH_TICKET, settings->get_local_steam_id(), &steam_auth_manager_ticket_callback, this); + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &steam_auth_manager_ticket_callback, this); +} + #define STEAM_TICKET_PROCESS_TIME 0.03 void Auth_Manager::launch_callback(CSteamID id, EAuthSessionResponse resp, double delay) { - ValidateAuthTicketResponse_t data; + ValidateAuthTicketResponse_t data{}; data.m_SteamID = id; data.m_eAuthSessionResponse = resp; data.m_OwnerSteamID = id; @@ -55,11 +61,11 @@ void Auth_Manager::launch_callback(CSteamID id, EAuthSessionResponse resp, doubl void Auth_Manager::launch_callback_gs(CSteamID id, bool approved) { if (approved) { - GSClientApprove_t data; + GSClientApprove_t data{}; data.m_SteamID = data.m_OwnerSteamID = id; callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); } else { - GSClientDeny_t data; + GSClientDeny_t data{}; data.m_SteamID = id; data.m_eDenyReason = k_EDenyNotLoggedOn; //TODO: other reasons? callbacks->addCBResult(data.k_iCallback, &data, sizeof(data)); diff --git a/dll/dll/auth.h b/dll/dll/auth.h index b5bffd8f..f8f35b36 100644 --- a/dll/dll/auth.h +++ b/dll/dll/auth.h @@ -643,6 +643,7 @@ class Auth_Manager { std::vector outbound; public: Auth_Manager(class Settings *settings, class Networking *network, class SteamCallBacks *callbacks); + ~Auth_Manager(); void Callback(Common_Message *msg); uint32 getTicket( void *pTicket, int cbMaxTicket, uint32 *pcbTicket ); diff --git a/dll/dll/steam_friends.h b/dll/dll/steam_friends.h index 861a06ff..78ae04a5 100644 --- a/dll/dll/steam_friends.h +++ b/dll/dll/steam_friends.h @@ -238,7 +238,9 @@ Steam_Friends(Settings* settings, Networking* network, SteamCallResults* callbac ~Steam_Friends() { - //TODO rm network callbacks + this->network->rmCallback(CALLBACK_ID_FRIEND, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this); + this->network->rmCallback(CALLBACK_ID_FRIEND_MESSAGES, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this); + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Friends::steam_friends_callback, this); this->run_every_runcb->remove(&Steam_Friends::steam_friends_run_every_runcb, this); } diff --git a/dll/dll/steam_game_coordinator.h b/dll/dll/steam_game_coordinator.h index e0a2f700..2d20cff4 100644 --- a/dll/dll/steam_game_coordinator.h +++ b/dll/dll/steam_game_coordinator.h @@ -69,7 +69,7 @@ Steam_Game_Coordinator(class Settings *settings, class Networking *network, clas ~Steam_Game_Coordinator() { - //TODO rm network callbacks + //this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Game_Coordinator::steam_callback, this); this->run_every_runcb->remove(&Steam_Game_Coordinator::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_gamesearch.h b/dll/dll/steam_gamesearch.h index 0fffa5ef..ada10e0b 100644 --- a/dll/dll/steam_gamesearch.h +++ b/dll/dll/steam_gamesearch.h @@ -59,7 +59,7 @@ Steam_Game_Search(class Settings *settings, class Networking *network, class Ste ~Steam_Game_Search() { - //TODO rm network callbacks + //this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Game_Search::steam_callback, this); this->run_every_runcb->remove(&Steam_Game_Search::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_masterserver_updater.h b/dll/dll/steam_masterserver_updater.h index bb5b4604..2d2bc649 100644 --- a/dll/dll/steam_masterserver_updater.h +++ b/dll/dll/steam_masterserver_updater.h @@ -57,7 +57,7 @@ Steam_Masterserver_Updater(class Settings *settings, class Networking *network, ~Steam_Masterserver_Updater() { - //TODO rm network callbacks + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Masterserver_Updater::steam_callback, this); this->run_every_runcb->remove(&Steam_Masterserver_Updater::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_matchmaking.h b/dll/dll/steam_matchmaking.h index 00fea182..e6ae84ed 100644 --- a/dll/dll/steam_matchmaking.h +++ b/dll/dll/steam_matchmaking.h @@ -325,7 +325,8 @@ Steam_Matchmaking(class Settings *settings, class Networking *network, class Ste ~Steam_Matchmaking() { - //TODO rm network callbacks + this->network->rmCallback(CALLBACK_ID_LOBBY, settings->get_local_steam_id(), &Steam_Matchmaking::steam_matchmaking_callback, this); + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Matchmaking::steam_matchmaking_callback, this); this->run_every_runcb->remove(&Steam_Matchmaking::steam_matchmaking_run_every_runcb, this); } diff --git a/dll/dll/steam_matchmaking_servers.h b/dll/dll/steam_matchmaking_servers.h index 91248893..ea56c40f 100644 --- a/dll/dll/steam_matchmaking_servers.h +++ b/dll/dll/steam_matchmaking_servers.h @@ -69,6 +69,8 @@ public ISteamMatchmakingServers001 void RequestOldServerList(AppId_t iApp, ISteamMatchmakingServerListResponse001 *pRequestServersResponse, EMatchMakingType type); public: Steam_Matchmaking_Servers(class Settings *settings, class Networking *network); + ~Steam_Matchmaking_Servers(); + // 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 ) diff --git a/dll/dll/steam_networking.h b/dll/dll/steam_networking.h index b867a0dd..721694e1 100644 --- a/dll/dll/steam_networking.h +++ b/dll/dll/steam_networking.h @@ -251,7 +251,8 @@ Steam_Networking(class Settings *settings, class Networking *network, class Stea ~Steam_Networking() { - //TODO rm network callbacks + this->network->rmCallback(CALLBACK_ID_NETWORKING, settings->get_local_steam_id(), &Steam_Networking::steam_networking_callback, this); + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Networking::steam_networking_callback, this); this->run_every_runcb->remove(&Steam_Networking::steam_networking_run_every_runcp, this); } diff --git a/dll/dll/steam_networking_messages.h b/dll/dll/steam_networking_messages.h index 99321614..4ef776c0 100644 --- a/dll/dll/steam_networking_messages.h +++ b/dll/dll/steam_networking_messages.h @@ -82,7 +82,8 @@ Steam_Networking_Messages(class Settings *settings, class Networking *network, c ~Steam_Networking_Messages() { - //TODO rm network callbacks + this->network->rmCallback(CALLBACK_ID_NETWORKING_MESSAGES, settings->get_local_steam_id(), &Steam_Networking_Messages::steam_callback, this); + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Networking_Messages::steam_callback, this); this->run_every_runcb->remove(&Steam_Networking_Messages::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_networking_sockets.h b/dll/dll/steam_networking_sockets.h index 74762e79..295a80eb 100644 --- a/dll/dll/steam_networking_sockets.h +++ b/dll/dll/steam_networking_sockets.h @@ -133,7 +133,8 @@ Steam_Networking_Sockets(class Settings *settings, class Networking *network, cl ~Steam_Networking_Sockets() { - //TODO rm network callbacks + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Networking_Sockets::steam_callback, this); + this->network->rmCallback(CALLBACK_ID_NETWORKING_SOCKETS, settings->get_local_steam_id(), &Steam_Networking_Sockets::steam_callback, this); this->run_every_runcb->remove(&Steam_Networking_Sockets::steam_run_every_runcb, this); if (this->s->used) { this->s->used -= 1; diff --git a/dll/dll/steam_networking_socketsserialized.h b/dll/dll/steam_networking_socketsserialized.h index 747a6bb0..f961f436 100644 --- a/dll/dll/steam_networking_socketsserialized.h +++ b/dll/dll/steam_networking_socketsserialized.h @@ -60,7 +60,7 @@ Steam_Networking_Sockets_Serialized(class Settings *settings, class Networking * ~Steam_Networking_Sockets_Serialized() { - //TODO rm network callbacks + this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Networking_Sockets_Serialized::steam_callback, this); this->run_every_runcb->remove(&Steam_Networking_Sockets_Serialized::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_networking_utils.h b/dll/dll/steam_networking_utils.h index 342f3fbd..0e49fcf1 100644 --- a/dll/dll/steam_networking_utils.h +++ b/dll/dll/steam_networking_utils.h @@ -64,7 +64,7 @@ Steam_Networking_Utils(class Settings *settings, class Networking *network, clas ~Steam_Networking_Utils() { - //TODO rm network callbacks + //this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Networking_Utils::steam_callback, this); this->run_every_runcb->remove(&Steam_Networking_Utils::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_parties.h b/dll/dll/steam_parties.h index 02019b04..4a3437bb 100644 --- a/dll/dll/steam_parties.h +++ b/dll/dll/steam_parties.h @@ -59,7 +59,7 @@ Steam_Parties(class Settings *settings, class Networking *network, class SteamCa ~Steam_Parties() { - //TODO rm network callbacks + //this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Parties::steam_callback, this); this->run_every_runcb->remove(&Steam_Parties::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_remoteplay.h b/dll/dll/steam_remoteplay.h index fcfac392..66f09c41 100644 --- a/dll/dll/steam_remoteplay.h +++ b/dll/dll/steam_remoteplay.h @@ -58,7 +58,7 @@ Steam_RemotePlay(class Settings *settings, class Networking *network, class Stea ~Steam_RemotePlay() { - //TODO rm network callbacks + //this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_RemotePlay::steam_callback, this); this->run_every_runcb->remove(&Steam_RemotePlay::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_tv.h b/dll/dll/steam_tv.h index 2e40e39a..2005518d 100644 --- a/dll/dll/steam_tv.h +++ b/dll/dll/steam_tv.h @@ -59,7 +59,7 @@ Steam_TV(class Settings *settings, class Networking *network, class SteamCallRes ~Steam_TV() { - //TODO rm network callbacks + //this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_TV::steam_callback, this); //this->run_every_runcb->remove(&Steam_TV::steam_run_every_runcb, this); } diff --git a/dll/dll/steam_unified_messages.h b/dll/dll/steam_unified_messages.h index bc08099a..35debbeb 100644 --- a/dll/dll/steam_unified_messages.h +++ b/dll/dll/steam_unified_messages.h @@ -48,8 +48,8 @@ Steam_Unified_Messages(class Settings *settings, class Networking *network, clas this->settings = settings; this->network = network; this->run_every_runcb = run_every_runcb; -// this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Unified_Messages::steam_callback, this); -// this->run_every_runcb->add(&Steam_Unified_Messages::steam_run_every_runcb, this); + // this->network->setCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Unified_Messages::steam_callback, this); + // this->run_every_runcb->add(&Steam_Unified_Messages::steam_run_every_runcb, this); this->callback_results = callback_results; this->callbacks = callbacks; @@ -57,8 +57,8 @@ Steam_Unified_Messages(class Settings *settings, class Networking *network, clas ~Steam_Unified_Messages() { - //TODO rm network callbacks -// this->run_every_runcb->remove(&Steam_Unified_Messages::steam_run_every_runcb, this); + // this->network->rmCallback(CALLBACK_ID_USER_STATUS, settings->get_local_steam_id(), &Steam_Unified_Messages::steam_callback, this); + // this->run_every_runcb->remove(&Steam_Unified_Messages::steam_run_every_runcb, this); } // Sends a service method (in binary serialized form) using the Steam Client. diff --git a/dll/steam_client.cpp b/dll/steam_client.cpp index 9eb036dd..f3f7dcaf 100644 --- a/dll/steam_client.cpp +++ b/dll/steam_client.cpp @@ -133,61 +133,61 @@ Steam_Client::Steam_Client() Steam_Client::~Steam_Client() { - delete steam_gameserver; - delete steam_gameserver_utils; - delete steam_gameserverstats; - delete steam_gameserver_networking; - delete steam_gameserver_http; - delete steam_gameserver_inventory; - delete steam_gameserver_ugc; - delete steam_gameserver_apps; - delete steam_gameserver_networking_sockets; - delete steam_gameserver_networking_sockets_serialized; - delete steam_gameserver_networking_messages; - delete steam_gameserver_game_coordinator; - delete steam_masterserver_updater; + delete steam_gameserver; steam_gameserver = nullptr; + delete steam_gameserver_utils; steam_gameserver_utils = nullptr; + delete steam_gameserverstats; steam_gameserverstats = nullptr; + delete steam_gameserver_networking; steam_gameserver_networking = nullptr; + delete steam_gameserver_http; steam_gameserver_http = nullptr; + delete steam_gameserver_inventory; steam_gameserver_inventory = nullptr; + delete steam_gameserver_ugc; steam_gameserver_ugc = nullptr; + delete steam_gameserver_apps; steam_gameserver_apps = nullptr; + delete steam_gameserver_networking_sockets; steam_gameserver_networking_sockets = nullptr; + delete steam_gameserver_networking_sockets_serialized; steam_gameserver_networking_sockets_serialized = nullptr; + delete steam_gameserver_networking_messages; steam_gameserver_networking_messages = nullptr; + delete steam_gameserver_game_coordinator; steam_gameserver_game_coordinator = nullptr; + delete steam_masterserver_updater; steam_masterserver_updater = nullptr; - delete steam_matchmaking; - delete steam_matchmaking_servers; - delete steam_user_stats; - delete steam_apps; - delete steam_networking; - delete steam_remote_storage; - delete steam_screenshots; - delete steam_http; - delete steam_controller; - delete steam_ugc; - delete steam_applist; - delete steam_music; - delete steam_musicremote; - delete steam_HTMLsurface; - delete steam_inventory; - delete steam_video; - delete steam_parental; - delete steam_networking_sockets; - delete steam_networking_sockets_serialized; - delete steam_networking_messages; - delete steam_game_coordinator; - delete steam_networking_utils; - delete steam_unified_messages; - delete steam_game_search; - delete steam_parties; - delete steam_remoteplay; - delete steam_tv; + delete steam_matchmaking; steam_matchmaking = nullptr; + delete steam_matchmaking_servers; steam_matchmaking_servers = nullptr; + delete steam_user_stats; steam_user_stats = nullptr; + delete steam_apps; steam_apps = nullptr; + delete steam_networking; steam_networking = nullptr; + delete steam_remote_storage; steam_remote_storage = nullptr; + delete steam_screenshots; steam_screenshots = nullptr; + delete steam_http; steam_http = nullptr; + delete steam_controller; steam_controller = nullptr; + delete steam_ugc; steam_ugc = nullptr; + delete steam_applist; steam_applist = nullptr; + delete steam_music; steam_music = nullptr; + delete steam_musicremote; steam_musicremote = nullptr; + delete steam_HTMLsurface; steam_HTMLsurface = nullptr; + delete steam_inventory; steam_inventory = nullptr; + delete steam_video; steam_video = nullptr; + delete steam_parental; steam_parental = nullptr; + delete steam_networking_sockets; steam_networking_sockets = nullptr; + delete steam_networking_sockets_serialized; steam_networking_sockets_serialized = nullptr; + delete steam_networking_messages; steam_networking_messages = nullptr; + delete steam_game_coordinator; steam_game_coordinator = nullptr; + delete steam_networking_utils; steam_networking_utils = nullptr; + delete steam_unified_messages; steam_unified_messages = nullptr; + delete steam_game_search; steam_game_search = nullptr; + delete steam_parties; steam_parties = nullptr; + delete steam_remoteplay; steam_remoteplay = nullptr; + delete steam_tv; steam_tv = nullptr; - delete steam_utils; - delete steam_friends; - delete steam_user; - delete steam_overlay; + delete steam_utils; steam_utils = nullptr; + delete steam_friends; steam_friends = nullptr; + delete steam_user; steam_user = nullptr; + delete steam_overlay; steam_overlay = nullptr; - delete ugc_bridge; + delete ugc_bridge; ugc_bridge = nullptr; - delete run_every_runcb; - delete callbacks_server; - delete callbacks_client; - delete callback_results_server; - delete callback_results_client; - delete network; + delete run_every_runcb; run_every_runcb = nullptr; + delete callbacks_server; callbacks_server = nullptr; + delete callbacks_client; callbacks_client = nullptr; + delete callback_results_server; callback_results_server = nullptr; + delete callback_results_client; callback_results_client = nullptr; + delete network; network = nullptr; } void Steam_Client::userLogIn() diff --git a/dll/steam_matchmaking_servers.cpp b/dll/steam_matchmaking_servers.cpp index 90128190..ef50e36a 100644 --- a/dll/steam_matchmaking_servers.cpp +++ b/dll/steam_matchmaking_servers.cpp @@ -33,6 +33,11 @@ Steam_Matchmaking_Servers::Steam_Matchmaking_Servers(class Settings *settings, c this->network->setCallback(CALLBACK_ID_GAMESERVER, (uint64) 0, &network_callback, this); } +Steam_Matchmaking_Servers::~Steam_Matchmaking_Servers() +{ + this->network->rmCallback(CALLBACK_ID_GAMESERVER, (uint64) 0, &network_callback, this); +} + static int server_list_request = 0; HServerListRequest Steam_Matchmaking_Servers::RequestServerList(AppId_t iApp, ISteamMatchmakingServerListResponse *pRequestServersResponse, EMatchMakingType type) diff --git a/overlay_experimental/steam_overlay.cpp b/overlay_experimental/steam_overlay.cpp index 06aec006..7c37fcb5 100644 --- a/overlay_experimental/steam_overlay.cpp +++ b/overlay_experimental/steam_overlay.cpp @@ -141,14 +141,15 @@ Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_resu ++i; } - run_every_runcb->add(&Steam_Overlay::overlay_run_callback, this); this->network->setCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::overlay_networking_callback, this); + run_every_runcb->add(&Steam_Overlay::overlay_run_callback, this); } Steam_Overlay::~Steam_Overlay() { if (settings->disable_overlay) return; + this->network->rmCallback(CALLBACK_ID_STEAM_MESSAGES, settings->get_local_steam_id(), &Steam_Overlay::overlay_networking_callback, this); run_every_runcb->remove(&Steam_Overlay::overlay_run_callback, this); }