From 309a1cdd6df4b66debe25b8c655d03524c76c78a Mon Sep 17 00:00:00 2001 From: Infiland Date: Thu, 18 Jun 2026 14:54:15 +0200 Subject: [PATCH] Add lobby metadata refresh by ID --- docs/lobbies.js | 51 +++++++++++++++++++ .../extensions/steamworks/Steamworks.yy | 4 +- .../steamworks_cpp/GMLSteam/steam_callbacks.h | 3 +- .../GMLSteam/steam_matchmaking.cpp | 41 +++++++++++++++ 4 files changed, 97 insertions(+), 2 deletions(-) diff --git a/docs/lobbies.js b/docs/lobbies.js index e5c8f42a..a6f8eaf9 100644 --- a/docs/lobbies.js +++ b/docs/lobbies.js @@ -145,6 +145,55 @@ * @func_end */ +/** + * @func steam_lobby_request_data + * @desc This function requests a metadata refresh for the given lobby ID. This is useful when you have a lobby ID from ${function.steam_get_friends_game_info} or a previous lobby list and want to read its latest lobby fields without joining it. + * + * @param {int64} lobby_id Identifier of the lobby to refresh metadata for + * + * @returns {boolean} + * + * @event steam + * @member {string} event_type The string value `"lobby_data_update"` + * @member {int64} lobby_id The lobby unique identifier + * @member {int64} member_id The lobby ID again for lobby metadata updates, or a member Steam ID for member data updates + * @member {boolean} success Whether or not the lobby data refresh was successful + * @member {real} result The code of the result + * @event_end + * + * @example + * ```gml + * var _friend_info = steam_get_friends_game_info(_friend_id); + * if (_friend_info.lobbyId != 0) + * { + * steam_lobby_request_data(_friend_info.lobbyId); + * } + * ``` + * The code above requests the latest metadata for a friend's lobby. Handle the `"lobby_data_update"` Steam async event before reading the fields with ${function.steam_lobby_get_data_by_id}. + * @func_end + */ + +/** + * @func steam_lobby_get_data_by_id + * @desc This function returns a cached lobby field value for the given lobby ID, as set by ${function.steam_lobby_set_data}. Use ${function.steam_lobby_request_data} first if you need to refresh metadata for a lobby you are not currently in. + * + * @param {int64} lobby_id Identifier of the lobby to read cached metadata from + * @param {string} key String representation of the data + * + * @returns {string} + * + * @example + * ```gml + * if (async_load[? "event_type"] == "lobby_data_update" && async_load[? "success"]) + * { + * var _lobby_id = async_load[? "lobby_id"]; + * var _title = steam_lobby_get_data_by_id(_lobby_id, "title"); + * } + * ``` + * The code above reads the cached `title` field after Steam reports that the lobby metadata was refreshed. + * @func_end + */ + /** * @func steam_lobby_get_lobby_id * @desc This function returns the Steam ID of the current lobby. @@ -847,12 +896,14 @@ * @ref steam_lobby_list_request * @ref steam_lobby_list_get_count * @ref steam_lobby_list_get_data + * @ref steam_lobby_get_data_by_id * @ref steam_lobby_list_get_lobby_id * @ref steam_lobby_list_get_lobby_member_count * @ref steam_lobby_list_get_lobby_member_id * @ref steam_lobby_list_get_lobby_owner_id * @ref steam_lobby_list_is_loading * @ref steam_lobby_list_join + * @ref steam_lobby_request_data * @section_end * * @section_const Constants diff --git a/source/Steamworks_gml/extensions/steamworks/Steamworks.yy b/source/Steamworks_gml/extensions/steamworks/Steamworks.yy index 5d4f2420..325cd0dd 100644 --- a/source/Steamworks_gml/extensions/steamworks/Steamworks.yy +++ b/source/Steamworks_gml/extensions/steamworks/Steamworks.yy @@ -473,6 +473,8 @@ {"$GMExtensionFunction":"","%Name":"steam_lobby_create","argCount":0,"args":[2,2,],"documentation":"/// @param {Real} type Constant that indicate the status of the lobby (see constants)\n/// @param {Real} max_members Indicates the maximum allowed number of users in the lobby (including the lobby's creator)\n/// @returns {Bool}","externalName":"steam_lobby_create","help":"steam_lobby_create(type, max_members)","hidden":false,"kind":4,"name":"steam_lobby_create","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, {"$GMExtensionFunction":"","%Name":"steam_lobby_set_data","argCount":0,"args":[1,2,],"documentation":"/// @param {String} key The key to set the data for\n/// @param {String} value The value to set\n/// @returns {Bool}","externalName":"steam_lobby_set_data","help":"steam_lobby_set_data(key, value)","hidden":false,"kind":4,"name":"steam_lobby_set_data","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, {"$GMExtensionFunction":"","%Name":"steam_lobby_get_data","argCount":0,"args":[1,],"documentation":"/// @param {String} key String representation of the data\n/// @returns {String}","externalName":"steam_lobby_get_data","help":"steam_lobby_get_data(key)","hidden":false,"kind":4,"name":"steam_lobby_get_data","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, + {"$GMExtensionFunction":"","%Name":"steam_lobby_request_data","argCount":0,"args":[2,],"documentation":"/// @param {Int64} lobby_id Identifier of the lobby to refresh metadata for\n/// @returns {Bool}","externalName":"steam_lobby_request_data","help":"steam_lobby_request_data(lobby_id)","hidden":false,"kind":4,"name":"steam_lobby_request_data","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, + {"$GMExtensionFunction":"","%Name":"steam_lobby_get_data_by_id","argCount":0,"args":[2,1,],"documentation":"/// @param {Int64} lobby_id Identifier of the lobby to read cached metadata from\n/// @param {String} key String representation of the data\n/// @returns {String}","externalName":"steam_lobby_get_data_by_id","help":"steam_lobby_get_data_by_id(lobby_id, key)","hidden":false,"kind":4,"name":"steam_lobby_get_data_by_id","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, {"$GMExtensionFunction":"","%Name":"steam_lobby_set_type","argCount":0,"args":[2,],"documentation":"/// @param {Real} type The lobby visibility (see constants).\n/// @returns {Undefined}","externalName":"steam_lobby_set_type","help":"steam_lobby_set_type(type)","hidden":false,"kind":4,"name":"steam_lobby_set_type","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, {"$GMExtensionFunction":"","%Name":"steam_lobby_list_is_loading","argCount":0,"args":[],"documentation":"/// @returns {Bool}","externalName":"steam_lobby_list_is_loading","help":"steam_lobby_list_is_loading()","hidden":false,"kind":4,"name":"steam_lobby_list_is_loading","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, {"$GMExtensionFunction":"","%Name":"steam_net_set_auto_accept_p2p_sessions","argCount":0,"args":[2,],"documentation":"/// @param {Bool} enable disable/enable auto accept sessions\n/// @returns {Undefined}","externalName":"steam_net_set_auto_accept_p2p_sessions","help":"steam_net_set_auto_accept_p2p_sessions(auto_accept)","hidden":false,"kind":4,"name":"steam_net_set_auto_accept_p2p_sessions","resourceType":"GMExtensionFunction","resourceVersion":"2.0","returnType":1,}, @@ -786,4 +788,4 @@ "tvosProps":false, "tvosSystemFrameworkEntries":[], "tvosThirdPartyFrameworkEntries":[], -} \ No newline at end of file +} diff --git a/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_callbacks.h b/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_callbacks.h index 4c67d6f5..11540e04 100644 --- a/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_callbacks.h +++ b/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_callbacks.h @@ -12,6 +12,7 @@ class steam_net_callbacks_t }; STEAM_CALLBACK(steam_net_callbacks_t, p2p_session_request, P2PSessionRequest_t); //STEAM_CALLBACK(steam_net_callbacks_t, OnPersonaStateChange, PersonaStateChange_t); + STEAM_CALLBACK(steam_net_callbacks_t, lobby_data_update, LobbyDataUpdate_t); STEAM_CALLBACK(steam_net_callbacks_t, lobby_chat_update, LobbyChatUpdate_t); STEAM_CALLBACK(steam_net_callbacks_t, lobby_chat_message, LobbyChatMsg_t); STEAM_CALLBACK(steam_net_callbacks_t, lobby_join_requested, GameLobbyJoinRequested_t); @@ -43,4 +44,4 @@ class steam_net_callbacks_t void parties_change_num_open_slots(ChangeNumOpenSlotsCallback_t* e, bool failed); void parties_join_party(JoinPartyCallback_t* e, bool failed); }; -extern steam_net_callbacks_t steam_net_callbacks; \ No newline at end of file +extern steam_net_callbacks_t steam_net_callbacks; diff --git a/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_matchmaking.cpp b/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_matchmaking.cpp index 7c6805af..d0436fda 100644 --- a/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_matchmaking.cpp +++ b/source/Steamworks_gml/extensions/steamworks/steamworks_cpp/GMLSteam/steam_matchmaking.cpp @@ -514,6 +514,15 @@ YYEXPORT void /*double*/ steam_lobby_create(RValue& Result, CInstance* selfinst, #pragma region Managing lobbies +void steam_net_callbacks_t::lobby_data_update(LobbyDataUpdate_t* e) +{ + steam_net_event q((char*)"lobby_data_update"); + q.set_uint64_all("lobby_id", e->m_ulSteamIDLobby); + q.set_uint64_all("member_id", e->m_ulSteamIDMember); + q.set_success(e->m_bSuccess); + q.dispatch(); +} + /// [lobby owner only] Sets the data for the current lobby. YYEXPORT void /*double*/ steam_lobby_set_data(RValue& Result, CInstance* selfinst, CInstance* otherinst, int argc, RValue* arg)//(char* key, char* value) { @@ -544,6 +553,38 @@ YYEXPORT void /*char**/ steam_lobby_get_data(RValue& Result, CInstance* selfinst else YYCreateString(&Result, ""); } +/// [anyone] Requests a metadata refresh for the given lobby. +YYEXPORT void /*double*/ steam_lobby_request_data(RValue& Result, CInstance* selfinst, CInstance* otherinst, int argc, RValue* arg)//(int64 lobby_id) +{ + uint64 lobby_id = (uint64)YYGetInt64(arg, 0); + + Result.kind = VALUE_BOOL; + if (SteamMatchmaking()) + { + Result.val = SteamMatchmaking()->RequestLobbyData(CSteamID(lobby_id)); + } + else + { + Result.val = false; + } +} + +/// [anyone] Retrieves cached data for the given lobby. +YYEXPORT void /*char**/ steam_lobby_get_data_by_id(RValue& Result, CInstance* selfinst, CInstance* otherinst, int argc, RValue* arg)//(int64 lobby_id, char* key) +{ + uint64 lobby_id = (uint64)YYGetInt64(arg, 0); + char* key = (char*)YYGetString(arg, 1); + + if (SteamMatchmaking()) + { + YYCreateString(&Result, SteamMatchmaking()->GetLobbyData(CSteamID(lobby_id), key)); + } + else + { + YYCreateString(&Result, ""); + } +} + /// [lobby owner only] Changes the type of the current lobby. YYEXPORT void /*double*/ steam_lobby_set_type(RValue& Result, CInstance* selfinst, CInstance* otherinst, int argc, RValue* arg)//(double type) {