0

I am in the process of adding a new feature in our game. I would like to give the option for the players to invite their friends to join a room.

The exact description of the feature goes like this: Player A creates a room and invites player B to join, player B has to satisfy these conditions in order to see the invitation: 1. Is a facebook friend of player A. 2. Is online and inside the lobby.

The approach i'm following to do this is as follows: I am using PlayFab to save players data and online status. The first time a user logs in using Facebook, a PlayFab record for this player is created, this entry includes the list of Facebook friends and online status among other data (online status for each player is updated using OnDisconnectedFromPhoton and OnJoinedLobby callbacks)

When player A clicks the invite button inside the room, the list of his online friends is shown (get list of Facebook friends -->check PlayFab records to retrieve their online status --> show Facebook friends who are online). Then the player selects the friends who they want to invite.

This is the part I am having a difficulty with. Is there a way to send the invitation message to this player in the lobby which includes the room number and the invited userId? For example I am thinking about sending the message to all players in the lobby and then only show it to player B (show the message if the userId included in the message == player B userId). But I am hoping there is a more efficient solution because it looks like an overkill to send a message to all players in the lobby every time an invitation is sent!

Can you think of a better approach to do this?

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
naz89
  • 71
  • 5
  • 12

2 Answers2

1

You can't send message to the player in Photon lobby. You should invite player via other channel such as fb api message. Invited user gets room name from the message and can join the room.

photonians
  • 699
  • 1
  • 4
  • 12
1

On mobile platforms, a common approach is to use Push Notifications to enable this. Another way would be using Shared Group Data (https://api.playfab.com/Documentation/Client#Shared%20Group%20Data) to post invitations to others, and have the client do a periodic "heartbeat" to check for those messages. Using this, you could create Shared Group Data using the PlayFab ID of the user who is receiving the invitation (and potentially other messages), and add the message using the PlayFab ID of the user inviting them as the Key for the Key/Value pair you're writing to the Shared Group Data.

And rather than deal with the hassle of adding players to the Shared Group Data (which allows clients to then write to it directly), one other simplification would be to use Cloud Script (https://playfab.com/docs/using-cloud-script/) to control what gets written.