From 3bf7e4d032d2f2948392ef5de56aedbfd30bf23c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Bernon?= Date: Fri, 19 Jan 2024 11:40:09 +0100 Subject: [PATCH] lsteamclient: Copy the ServerResponded parameter for delayed callbacks. CW-Bug-Id: #23272 --- lsteamclient/steamclient_main.c | 6 +++++ lsteamclient/unix_private.h | 1 + lsteamclient/unix_steam_networking_manual.cpp | 2 +- lsteamclient/unixlib.cpp | 26 ++++++++++++++++--- lsteamclient/unixlib.h | 7 +++++ 5 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lsteamclient/steamclient_main.c b/lsteamclient/steamclient_main.c index 86cb823d..c05e78cd 100644 --- a/lsteamclient/steamclient_main.c +++ b/lsteamclient/steamclient_main.c @@ -389,6 +389,12 @@ void execute_pending_callbacks(void) params.callback->call_iface_vtable.arg0, params.callback->call_iface_vtable.arg1, params.callback->call_iface_vtable.arg2) ); break; + case CALL_IFACE_VTABLE_0_SERVER_RESPONDED: + TRACE( "CALL_IFACE_VTABLE_0_SERVER_RESPONDED iface %p, server %p.\n", params.callback->server_responded.iface, + params.callback->server_responded.server ); + CALL_VTBL_FUNC( params.callback->server_responded.iface, 0, void, (void *, gameserveritem_t_105 *), (params.callback->server_responded.iface, + params.callback->server_responded.server) ); + break; case CALL_IFACE_VTABLE_0_ADD_PLAYER_TO_LIST: TRACE( "CALL_IFACE_VTABLE_0_ADD_PLAYER_TO_LIST iface %p, name %s, score %u, time_played %f.\n", params.callback->add_player_to_list.iface, params.callback->add_player_to_list.name, params.callback->add_player_to_list.score, params.callback->add_player_to_list.time_played ); diff --git a/lsteamclient/unix_private.h b/lsteamclient/unix_private.h index b9208aee..32452ecd 100644 --- a/lsteamclient/unix_private.h +++ b/lsteamclient/unix_private.h @@ -20,6 +20,7 @@ extern "C" struct w_steam_iface; extern void queue_vtable_callback( struct w_steam_iface *w_iface, enum callback_type type, uint64_t arg0, uint64_t arg1, uint64_t arg2 ); +extern void queue_vtable_callback_0_server_responded( struct w_steam_iface *w_iface, gameserveritem_t_105 *server ); extern void queue_vtable_callback_0_add_player_to_list( struct w_steam_iface *w_iface, const char *pchName, int nScore, float flTimePlayed ); extern void queue_vtable_callback_0_rules_responded( struct w_steam_iface *w_iface, const char *pchRule, const char *pchValue ); diff --git a/lsteamclient/unix_steam_networking_manual.cpp b/lsteamclient/unix_steam_networking_manual.cpp index b8d4fd84..2cfaf108 100644 --- a/lsteamclient/unix_steam_networking_manual.cpp +++ b/lsteamclient/unix_steam_networking_manual.cpp @@ -670,7 +670,7 @@ struct SteamMatchmakingPingResponse : u_ISteamMatchmakingPingResponse void SteamMatchmakingPingResponse::ServerResponded( gameserveritem_t_105 *server ) { - queue_vtable_callback( this->w_iface, CALL_IFACE_VTABLE_0, (intptr_t)server, 0, 0 ); + queue_vtable_callback_0_server_responded( this->w_iface, server ); } void SteamMatchmakingPingResponse::ServerFailedToRespond(void) diff --git a/lsteamclient/unixlib.cpp b/lsteamclient/unixlib.cpp index 29314cc6..6d97d7c0 100644 --- a/lsteamclient/unixlib.cpp +++ b/lsteamclient/unixlib.cpp @@ -16,7 +16,7 @@ struct callback_entry static struct list callbacks = LIST_INIT( callbacks ); static pthread_mutex_t callbacks_lock = PTHREAD_MUTEX_INITIALIZER; -extern void queue_vtable_callback( struct w_steam_iface *w_iface, enum callback_type type, uint64_t arg0, uint64_t arg1, uint64_t arg2 ) +void queue_vtable_callback( struct w_steam_iface *w_iface, enum callback_type type, uint64_t arg0, uint64_t arg1, uint64_t arg2 ) { struct callback_entry *entry; uint32_t size = 0; @@ -38,7 +38,27 @@ extern void queue_vtable_callback( struct w_steam_iface *w_iface, enum callback_ pthread_mutex_unlock( &callbacks_lock ); } -extern void queue_vtable_callback_0_add_player_to_list( struct w_steam_iface *w_iface, const char *pchName, int nScore, float flTimePlayed ) +void queue_vtable_callback_0_server_responded( struct w_steam_iface *w_iface, gameserveritem_t_105 *server ) +{ + uint32_t size = sizeof(*server); + struct callback_entry *entry; + + size += sizeof(struct callback_entry); + if (!(entry = (struct callback_entry *)malloc( size ))) return; + + entry->callback.type = CALL_IFACE_VTABLE_0_SERVER_RESPONDED; + size -= offsetof( struct callback_entry, callback ); + entry->callback.size = size; + + entry->callback.server_responded.iface = w_iface; + entry->callback.server_responded.server[0] = *server; + + pthread_mutex_lock( &callbacks_lock ); + list_add_tail( &callbacks, &entry->entry ); + pthread_mutex_unlock( &callbacks_lock ); +} + +void queue_vtable_callback_0_add_player_to_list( struct w_steam_iface *w_iface, const char *pchName, int nScore, float flTimePlayed ) { uint32_t name_size = strlen( pchName ) + 1, size = name_size; struct callback_entry *entry; @@ -60,7 +80,7 @@ extern void queue_vtable_callback_0_add_player_to_list( struct w_steam_iface *w_ pthread_mutex_unlock( &callbacks_lock ); } -extern void queue_vtable_callback_0_rules_responded( struct w_steam_iface *w_iface, const char *pchRule, const char *pchValue ) +void queue_vtable_callback_0_rules_responded( struct w_steam_iface *w_iface, const char *pchRule, const char *pchValue ) { uint32_t rule_size = strlen( pchRule ) + 1, value_size = strlen( pchValue ) + 1, size = rule_size + value_size; struct callback_entry *entry; diff --git a/lsteamclient/unixlib.h b/lsteamclient/unixlib.h index aa175a3d..86e3187f 100644 --- a/lsteamclient/unixlib.h +++ b/lsteamclient/unixlib.h @@ -39,6 +39,7 @@ enum callback_type CALL_IFACE_VTABLE_0, CALL_IFACE_VTABLE_1, CALL_IFACE_VTABLE_2, + CALL_IFACE_VTABLE_0_SERVER_RESPONDED, CALL_IFACE_VTABLE_0_ADD_PLAYER_TO_LIST, CALL_IFACE_VTABLE_0_RULES_RESPONDED, }; @@ -78,6 +79,12 @@ struct callback uint64_t arg2; } call_iface_vtable; + struct + { + struct w_steam_iface *iface; + gameserveritem_t_105 server[]; + } server_responded; + struct { struct w_steam_iface *iface;