How to challenge another user to a realtime match?

We are trying to implement a use-case in Basketball PVP in which a player clicks their friends name from their PlayFab friends list and then the app sends an invite to their friend. On their friends screen they will get an option to accept the invite, in which case both players will join the Photon room to play their TrueSync match.

In our original implementation we created an open room with the challenger & challengie's ID's, then the challengie's app periodically checks if this room exists. The problem with this solution is that any user joining a random room will accidentally join this room (taking up the friends spot). Another problem is that if the user is on a different Photon region they will not see the room.

To work around this we looked into using PlayFab for the communication. This is what we posted on their forum:

=====================================================

"How do we send a message from one user to another using PlayFab?

In Basketball PVP we would like a user to click on a PlayFab friend in the leaderboard, then our app would send a message to their friend's PlayFab account with the Photon region and the room name info. Then if their friend has the app open they would get the info and join the server/room."

========PlayFab answered with this===========

"Since you're using Photon, the way to do this would be by using their FindFriends method. And you can send other messages between players using SendPrivateMessage.

We are planning on adding a generic messaging system, and when we do, we'll provide a system for notification. Right now, your options would be Push Notifications, or a persistent connection to the client using Photon Cloud or custom game servers (Client/GetFriendsList contains the current Lobby IDs for friends)."
=====================================================

Would PlayFab's advice work? Won't it still have problems if the friend is not on the same Photon server?

What do you suggest we do?

Thanks,
Joe

Comments

  • JohnTubeJohnTube mod
    edited February 16
    Hi @joe,

    Thank you for choosing Photon!

    Nice app you got there! Looks interesting.

    The problem with this solution is that any user joining a random room will accidentally join this room (taking up the friends spot).

    Well you missed two features that can help you avoid this:

    1. Rooms can be invisible inside the lobby and can be joined only by name and not randomly. Use room.IsVisible = false or create it with roomOption.IsVisible = false.
    2. Rooms can have reserved spots for expected users. Check the docs here.

    then the challengie's app periodically checks if this room exists

    You can make use of FindFriends to know when the friend is inside the room.
    Or you can use CreateOrJoin operation if you do not mind who gets into the room first.

    Another problem is that if the user is on a different Photon region they will not see the room.

    This one is very tricky. I can see two options:
    1. Switch region from one client. So both players should be on the region where the room is created.
    2. Create one room per region and sync data between them. This is a tough one.

    I'm interested to know more details about your challenge/invitation system implementation as I'm using one myself in WordCore:

    1. Do you exchange invitations via Push Notifications, Photon Chat, Facebook, PlayFab's CloudScript or something else?
    2. Do you create the room when the challenge/invitation is sent or when the challenged/invited has accepted?


  • joejoe
    edited February 20
    Hey John,

    Thank you for your prompt and thoughtful response.

    To answer your 2 questions... I already explained how we exchange invitations. "In our original implementation we created an open room with the challenger & challengie's ID's, then the challengie's app periodically checks if this room exists."

    Thank you for mentioning reserved spots for users and the link to the docs. What I found in the docs that I think will work even better is using a filter when calling JoinRandomRoom.

    This is what our implementation looks like:
    	//CALLED BY THE CHALLENGER
    	public void ChallengeUser(string[] playFabIdAndDisplayName){
    
    
    		string roomSuffix = RemoveSpecialCharacters (PhotonNetwork.player.customProperties ["teamName"].ToString ());
    
    		//TODO: Use a custom room property customgame = 1. 
    		//TODO: Then update our PhotonNetwork.JoinRandomRoom() code so that users searching for random games do not join rooms created for invites
    
    
    		this.JoinCustomGame (playFabIdAndDisplayName[0] + "_" + roomSuffix);
    
    	}
    
    	//CALLED BY THE CHALLENGIE (Person receiving the challenge)
    	private void CheckForChallenge(){
    		//This is called every 5 seconds
    
    		RoomInfo[] roomList = PhotonNetwork.GetRoomList ();
    
    		foreach (RoomInfo game in roomList) {
    
    			string n = game.name;
    
    			if (n.IndexOf('_') > 0 && n.Substring(0, n.IndexOf('_')) == PlayFabManager.PlayFabId && game.open){
    
    				string challengerName = n.Substring(n.IndexOf('_') + 1);
    				this.ShowAcceptChallengeBox(challengerName);
    			}
    
    		}
    	}
    
    I believe this is an OK solution, although this will still not work if they are on a different server region. How are you planning to do it in WordCore?
  • Hi @joe,

    I only use EU region for now as the game is still in alpha and I also do not think I will change this later as since it's round based, latency is not much of an issue unless disconnects rate is too high.

    The room name trick is very useful especially with PlayFab. I use the room name to store the UserID/PlayFabId of the player creating the room as I save the room state in a SharedGroup key/value with SharedGroupId with this format "{CreatorPlayFabId}_GamesList". You may not need this.

    You need to send room names of challenges asap instead of polling only.
    I use a the same GamesList SharedGroup for polling as I allow first player to leave the room and second player to rejoin it (load it/re create it).
  • "You need to send room names of challenges asap instead of polling only." Yes, but there is no way in Photon to do this correct? Photon should have a way for a user to send a message to another user when they are not in a room yet.
  • You can send room name in the invitation/challenge using (you can combine more than one):
    - Push Notifications: send data + message or data only.
    - Photon Chat: send private or public message.
    - Facebook: see Facebook GameRequests.
    - Polling: using PlayFab's CloudScript or something else
  • Thanks for the tips! For Push Notifications: Would the user receiving the challenge need to have Push Notifications enabled?

    Sounds like using Photon Chat is the way to go, I had not thought of this. Because this would work even if user is not logged into Facebook, and would also work if user did not have push notifications enabled.
  • Yes Push Notifications is not reliable. Also PlayFab does not support advanced push notifications for iOS, only for Android, so you can't send custom data with the message to iOS.
    For WordCore here is how we exchange data between clients outside rooms:
    - Push Notifications
    - Fallback: Polling using CloudScript (ExecuteCloudScript or Photon WebRPC). We send client state data and make diff on CloudScript and return only what client is missing.
  • Thanks for sharing that information. What are the advantages of doing CloudScript as apposed to Photon Chat?
  • Photon Chat requires handling a separate new client connection and also separate bill :smile: but offers you more options also.
    CloudScript is good but it has its drawbacks also due to PlayFab's limited data storage options. The CloudScript way also has the disadvantages of polling.
  • Oh, I did not know chat needed a separate connection. And if CloudScript requires polling, then I guess it makes sense to go with my original solution.
  • So just to Clarify, PlayFab Support was incorrect when they said this:

    "Since you're using Photon, the way to do this would be by using their FindFriends method. And you can send other messages between players using SendPrivateMessage."

    The above would not actually work for our use case?
  • JohnTubeJohnTube mod
    edited February 21
    They (Brendan) are referring to Photon Chat! As the Photon PlayFab AddOn gives you two Photon AppIDs: Realtime and Chat.
  • And Photon chat will work even if players are on different server regions correct?
  • No Photon Chat is also region locked.
  • Oh okay. I will let him know that won't work. Is FindFriends also region locked?
  • Yes. Photon Cloud is designed to allow low latency between players connected to same region (same master server).
  • Yes I understand that, but we have discovered that two people in the same room, one persons phone could connect to Japan server, and the other connect to West Coast USA.
  • @joe will you please explain that ?
Sign In or Register to comment.