Friend Requests

I know this has been asked multiple times, but I am very confused on how to do it. I have Photon Chat and can get the two players communicating privately but have no idea how to implement a friend rerquest system with this. Thanks for ur time:)

Comments

  • JohnTubeJohnTube mod
    edited April 19
    hi @scoutmaster,

    Thank you for choosing Photon!

    In order to implement a friends system, you need a way to save friends lists and pending friends requests.
    Photon in general and Photon Chat, in particular, do not offer persistence.
    So you need another service to save that data.
    You can also optionally cache that data locally on the client device but it needs to be periodically updated.

    How to use Photon Chat with the other service to have a friends system:

    When the player connects, get the friends list and the pending friends requests.
    Optionally add the friends to Photon Chat using AddFriends to be able to receive status updates from them.
    Optionally periodically call FindFriends in Photon Realtime/PUN to find out what your friends are doing in the game.
    Optionally calculate pending friendship requests timeouts and do a cleanup.

    To add a new friend:
    Save the request in your outgoing pending friendship requests.
    Send a request to the user using a private message in Photon Chat.
    Save the request in the incoming pending friendship requests of the user.
    if the user accepts, add yourself to his/her friends' list and add the user to your friends' list. Optionally add the new friend to Photon Chat using AddFriends.
    if the user denies, remove the request from your outgoing pending requests and from his/her incoming pending requests.

    To remove a friend:
    Remove a friend from your friends' list.
    Optionally inform the friend using a private message in Photon Chat.
    Optionally remove yourself from his/her friends' list.
    Optionally remove the friend from Photon Chat using RemoveFriends.
  • Thanks so much for the reply! So to save my friends I am using an SQL database and loading them into photon when the user logins, all that works fine. But my big issue now is that the friend accept screen appears on both the players screen. Is there a way to only have it work on the receivers end and not on the senders. Thanks again.
  • edited April 19
    I got it working. Thanks for your help.. In case anyone needs help in this ill paste my code:
    
            if((string)message == _FRIENDREQUESTTAG)
            {
                if(sender == PhotonNetwork.LocalPlayer.UserId || sender == PhotonNetwork.LocalPlayer.NickName)
                {
                    Debug.Log("Local!");
                    return;
                }
                string FormatedString = string.Format("<b> {0} </b> has added you as a friend", sender);
    
                FriendRequestPrefab.SetActive(true);
                FriendName.text = FormatedString;
    
            }
    
    this chunk is on the onprivatemessage and im sending the message with the username, and a custom message called "FriendRequest" and filtering it out in the onprivatemessage method.
Sign In or Register to comment.