5
\$\begingroup\$

I'm trying to send an invitation to a steam friend and have it that when he accepts I create a PUN 2 room for both players and they can start their match. So far I've done this :

 protected Steamworks.Callback<GameRichPresenceJoinRequested_t> m_GameRichPresenceJoinRequested;


private void OnEnable()
{
    m_GameRichPresenceJoinRequested = Callback<GameRichPresenceJoinRequested_t>.Create(OnGameRichPresenceJoinRequested);
}


public void InviteFriend()
{

    SteamFriends.InviteUserToGame(steamFriendData.friendSteamId, "");
}

private void OnGameRichPresenceJoinRequested(GameRichPresenceJoinRequested_t pCallback)
{
     Debug.Log(pCallback.m_rgchConnect);
    Debug.Log("<color=green>Friend accepted the invite</color> ");
}

The invite is being sent to the correct friend and when he accepts it launches the game but I get no callback from that and thus have no way to place them in a room. What am I doing wrong ?

\$\endgroup\$
3
  • \$\begingroup\$ You are missing the callback on your side or on your friends side? And do you need a callback in the first place? If you send him the pun room id as extra parameter, he could join the room on start. And are you sure your OnEnabled is called? Have you tried moving it to OnStart? \$\endgroup\$
    – Zibelas
    Apr 28, 2020 at 13:08
  • \$\begingroup\$ @Zibelas Yes sending him the room Id will allow the other user to join when the games starts. That is what I am doing as of now. The problem is that steam displays a warning that the game is launching with custom command line options. I want to get rid of that warning somehow. \$\endgroup\$
    – Uri Popov
    Apr 29, 2020 at 11:13
  • \$\begingroup\$ I've tried SteamApps.GetLaunchCommandLine. Similar to you i put it on my title screen but launchCmd is always empty. I created a standalone exe, send an invite from one steam account, received by another steam account, click play, app launch....but nothing in the command line....Did you do anything extra to make yours work. FYI, my app is still in development so it's using the 'spacewar' thingy. \$\endgroup\$
    – hafiz
    Nov 17, 2021 at 4:49

2 Answers 2

2
\$\begingroup\$

There are 2 ways receiver can receive invite

One is from OnGameRichPresenceJoinRequested as you have posted.

Take a note that OnGameRichPresenceJoinRequested will only called on receiver side if he is already playing the game. That is, app is already running, and someone happen to send him an invite and he accept it while exe is running

Two is from SteamApps.GetLaunchCommandLine

On the other hand if he is not playing that game at the moment and request came through friend chat. If he accepts invite from there, parameter will instead sent via Steam's launch command. (Similar to exe launch arguments, but this one is from Steam, for security reason)

For Steamworks.NET, uses SteamApps.GetLaunchCommandLine. Usually it comes by this format +connect_lobby LOBBY_ID. So parse it accordingly and handle it the same way as you get with OnGameRichPresenceJoinRequested.

See https://partner.steamgames.com/doc/api/ISteamMatchmaking and search for keyword connect_lobby

For example, I call this at my title screen.

    private void _AcquireLaunchCommandLine( )
    {
        string launchCmd;
        if( SteamApps.GetLaunchCommandLine( out launchCmd, 260 ) > 0 )
            _ParseCommandLine( launchCmd );
        Debug.Log( $"Got Steam _AcquireLaunchCommandLine '{launchCmd}'" );
    }
\$\endgroup\$
0
\$\begingroup\$

Under the official steam docs for the GameRichPresenceJoinRequested_t function

NOTE: This callback is made when joining a game. If the user is attempting to join a lobby, then the callback GameLobbyJoinRequested_t will be made.

So perhaps the user is attempting to join a lobby instead, and the wrong callback was provided?

Alternatively:

Also, in your code you do:

public void InviteFriend()
{

    SteamFriends.InviteUserToGame(steamFriendData.friendSteamId, "");
}

without assigning it to a variable to see what's happening, but according to the docs for InviteUserToGame (scroll about halfway down the page):

Returns: bool Triggers a GameRichPresenceJoinRequested_t callback. true if the invite was successfully sent. 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 pchConnectString was too long.

So first of all, if you store it to a bool variable, like so:

public void InviteFriend()
{

    bool wasItSent = SteamFriends.InviteUserToGame(steamFriendData.friendSteamId, "");

    Debug.Log("Was it sent? " + wasItSent);
}

you will probably find that that bool returns false, and if so then probably you have to look into those 3 conditions that happen when it is false. It seems now you are assuming that it is sent, from your last function which debugs "sent successfully", but never actually checking if the send failed

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .