Skip to content

Commit

Permalink
Fixes on top of #33
Browse files Browse the repository at this point in the history
  • Loading branch information
yancouto committed Jan 15, 2024
1 parent 6f20a76 commit d960195
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 22 deletions.
6 changes: 5 additions & 1 deletion docs/apps.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Function Reference

local params = Steam.apps.getLaunchCommandLineParam()
local connect_string = tryParseConnectString(params)
if (connect_string) then
if connect_string then
initiateJoinGame(connect_string)
end

.. warning::

This is currently hardcoded in luasteam to a 1024 characters maximum.
31 changes: 18 additions & 13 deletions docs/friends.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,31 @@ Function Reference
}
}

.. function:: friends.inviteUserToGame(steam_id, connect_string)
.. function:: friends.inviteUserToGame(steamIDFriend, connect_string)

:param uint64 steam_id: The Steam ID of the other user.
:param string connect_string: Custom string that tells the joining player how to join the game
:returns: True if invite was sent successfully, false if not
:param uint64 steamIDFriend: The Steam ID of the friend to invite.
:param string connect_string: A string that lets the friend know how to join the game (I.E. the game server IP). This can not be longer than 256 characters.
:returns: (`boolean`) **true** if invite was sent successfully, **false** under the following conditions:

* The Steam ID provided to `steamIDFriend`` was invalid.
* The Steam ID provided to `steamIDFriend`` is not a friend or does not share the same Steam Group as the current user.
* The value provided to `connect_string` was too long.
:SteamWorks: `InviteUserToGame <https://partner.steamgames.com/doc/api/ISteamFriends#InviteUserToGame>`_

Invites the given user steam_id to the game identified by `connect_string`
Invites the given user `steamIDFriend` to the game identified by `connect_string`

The connect_string can be received by the application on the joining player in two ways depending on whether the game is already running or it is being launched.
The `connect_string`` can be received by the application on the joining player in two ways depending on whether the game is already running or it is being launched.

You should implement the callback :func:`friends.onGameRichPresenceJoinRequested` to receive the `connect_string` on the invitee and ultimately establish the connection on an already running application.

You should also call :func:`apps.getLaunchCommandLineParams` on game launch and check if the game was launched with the `connect_string`, and immediately take steps to establish the connection.

To add UI elements to invite or join the game over the Steam overlay or friends menu, also set the rich presence key `connect` with the `connect_string` value and clear it when the game is no longer available to join.
To add UI elements to invite or join the game over the Steam overlay or friends menu, also set the rich presence key `connect` with the `connect_string` value and clear it when the game is no longer available to join.

**Example**::

local friend_id = getSteamIdSomehow()
local success = Steam.friends.inviteUserToGame(friend_id, 'serverID=birthday_party')

Callbacks Reference
-------------------
Expand Down Expand Up @@ -160,17 +162,20 @@ Callbacks Reference

:param table data: A table similar to `GameRichPresenceJoinRequested_t <https://partner.steamgames.com/doc/api/ISteamFriends#GameRichPresenceJoinRequested_t>`_

* **data.steamIDFriend** (`uint64`) -- Steam ID of friend from through the invite was received
* **data.connectString** (`string`) -- custom connect string to parse for connection details
* **data.steamIDFriend** (`uint64`) -- The friend they joined through. This will be invalid if not directly via a friend.
* **data.connect** (`string`) -- The value associated with the "connect" Rich Presence key.

:returns: nothing
:SteamWorks: `GameRichPresenceJoinRequested_t <https://partner.steamgames.com/doc/api/ISteamFriends#GameRichPresenceJoinRequested_t>`_

Called when the user tries to join a game from their friends list or after a user accepts an invite by a friend with :func:`friends.inviteUserToGame`.


**Example**::

function Steam.friends.onGameRichPresenceJoinRequested(data)
if (game_state=='main_menu') then
initiateJoinGame(data.connectString)
if game_state == 'main_menu' then
initiateJoinGame(data.connect)
else
showDialog("you can only join a game from the main menu")
end
Expand Down
5 changes: 1 addition & 4 deletions src/apps.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#include "apps.hpp"
#include <iomanip>


// ============================
// ======== SteamApps =========
Expand All @@ -21,10 +19,9 @@ EXTERN int luasteam_isDlcInstalled(lua_State *L) {

// int GetLaunchCommandLine( char *pszCommandLine, int cubCommandLine );
EXTERN int luasteam_getLaunchCommandLine(lua_State *L) {
char *pCommandLine = (char*) malloc(1024);
char pCommandLine[1024];
SteamApps()->GetLaunchCommandLine(pCommandLine, 1024);
lua_pushstring(L, pCommandLine);
free(pCommandLine);
return 1;
}

Expand Down
6 changes: 2 additions & 4 deletions src/friends.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void CallbackListener::OnGameRichPresenceJoinRequested(GameRichPresenceJoinReque
luasteam::pushuint64(L, data->m_steamIDFriend.ConvertToUint64());
lua_setfield(L, -2, "steamIDFriend");
lua_pushstring(L, data->m_rgchConnect);
lua_setfield(L, -2, "connectString");
lua_setfield(L, -2, "connect");
lua_call(L, 1, 0);
lua_pop(L, 1);
}
Expand Down Expand Up @@ -120,9 +120,7 @@ void add_friends(lua_State *L) {
lua_setfield(L, -2, "friends");
}

void init_friends(lua_State *L) {
friends_listener = new CallbackListener();
}
void init_friends(lua_State *L) { friends_listener = new CallbackListener(); }

void shutdown_friends(lua_State *L) {
luaL_unref(L, LUA_REGISTRYINDEX, friends_ref);
Expand Down

0 comments on commit d960195

Please sign in to comment.