How to handle Friends List?

Options
Hey guys

I've just gotten done implementing a chat system that uses the new Unity GUI... Well, I kind-of did.. I realized after I had implemented the chat system with RPC's that it doesn't have a working Friends list where I can get info from other players, and I also realized that if I use RPC it will only send messages to people in that current room. While that is what I want for public messages, that is NOT what I want for private messages. I want anyone to be able to message anyone privately no matter what room they are in. Would PhotonChat be applicable here?

Also, on the to main question, how does one go about implementing a friends list? Does Photon keep a copy of the list on their server, or should I save a users friends to a string when they add a friend to their list, parse it, and load it back into a List<string> whenever they start the game again?

If that is the case, how do I return information about a certain friend?

Essentially what I'm trying to do is have a list of friends that is divided up into 3 columns. One is the friends name, the second is the name of the room they are in, and the third is a button for joining the game they are in.

Is there a way of returning all of this information via Photon Chat? It seems as if Photon Chat is ran on a separate server, so I don't know how I'd save information about which room they're in...

Comments

  • vadim
    Options
    Hi,

    With PUN. you can get info about friends calling PhotonNetwork.FindFriends with list of friend names while client joined to lobby. Check PhotonNetwork.Friends result (IsOnline, IsInRoom, Room per friend) in OnUpdatedFriendList handler. You need to know friend names, there is no way to get list of all players in the lobby.
    Chat runs on separate server and does not know anything about game lobby or room. It's just for message exchange. Public for everyone subscribed to channel or private for named friend.
    You probably should run both PUN and Chat in parallel. Knowing friend names, client can send them private messages and check their status in lobby.
  • darn... Is there no way to set like a custom property for a user in Photon Chat? If I can do that, then I can just set a string for which room he is currently in.

    I'm no so much worried about being able to whisper and communicate between rooms, but my main worry is how to get a users online status, and the name of the room they are in, even if they are connected to another room. Is there no way to do that?
  • vadim
    Options
    Chat has no custom property feature.
    how to get a users online status, and the name of the room they are in, even if they are connected to another room. Is there no way to do that?
    PhotonNetwork.FindFriends is the way to do that. Check please my previous post or documentation for details.
  • dontonka
    Options
    Hello, I had a question related to Friends to.

    It looks straight forward how to implement it (call FindFriends once connected to master server with our internal friend list name).

    My question is what if my friends has been added while I was playing let say on Europe server, and later on the player play into Asia server, I assume his friends even if online on Europe server, would be seen as offline since the player is currently playing on Asia server? So basically, does the FindFriend look for friend only the the server the player is connected too, or all of them?

    Finally, how should we avoid this scenario? For example, that is a real use case where the player connects to the server by having the best ping (this is a configuration, I think called Best Cloud or something similar). So for player which are really in a window where the ping time is almost the same for 2 servers, and some days it choose one, while the next day it choose another one, and adds friend from different servers, how to address that?

    Cheers,
    Don T.
  • dontonka
    Options
    any answer here, Tobias / Vadim ?
  • Okay, so I finally just got the chance to start trying to toy around with the friends list again. I'm trying to use FindFriends while connected to a Room.. Here's what I have so far:

    I build my friends list from a string in PlayerPrefs. I know this is working.

    After that, once the player joins the room, there i have these lines in the Update() function of NetworkCharacter:


    [I'M TRYING TO PUT CODE HERE BUT IT KEEPS TELLING ME I'M BLACKLISTED EVERY TIME I DO....... Go to the link below to see my code!]
    http://forum.unity3d.com/threads/photon ... st.283904/

    This SHOULD populate mFriendsList, right?

    Well, it is throwing 2 errors when I try and do this...

    Error 1:
    Operation 222 could not be executed (yet). Wait for state JoinedLobby or ConnectedToMaster and their callbacks before calling operations. WebRPCs need a server-side configuration. Enum OperationCode helps identify the operation.

    Error 2:
    FindFriends failed to apply the result, as a required value wasn't provided or the friend list length differed from result.

    What the heck is going on here?
  • dontonka
    Options
    Hello epictickle.

    I didn't implement nothing yet regarding Friends, but this is for sure not the right way to do it ;).

    As the error message state, you can call FindFriend only once connected to a master server, which is not the case if you put the code in the Update. You need to execute that code after those callback has been called: OnJoinedLobby or OnConnectedToMaster. And also, I assume FindFriends is an asynchron call, which means it will return right away, but you will receive the result in PhotonNetwork.Friends later on (might take couples of seconds, the server needs to look about your friends, there is no magic :)).

    So what I would do, is to fire the FindFriends in the OnJoinedLobby or OnConnectedToMaster callback, and also start a Coroutine which will wait until a maximum time or until PhotonNetwork.Friends is not null, which then you can start to do whatever you wants with your friends, even unfriend them ;)

    hope this helps. and please Tobias / Vadim, don't forget post, I would appreciate an answer :).


    Don T.
  • Right, I've since moved my logic for FindFriends to OnJoinedLobby and I am using the OnFriendsListUpdated() callback to handle it... Still, my friends list window is not populating lol. It's hard to test because I am simultaniously getting a memory leak in Unity with which I can only enter play mode once before Unity leaks massively and I have to exit the process in Task Manager. I'm thinking that it's the new GUI that's causing it.. Idk.
  • GOT IT!!!

    I was able to get my friends list to populate...

    Now, my last question is, how does one go about getting updates to their friends list?

    Like, if I am in room A and my friend is offline... Then he comes online and joins room B will I be able to see his online status?

    How does one update this?
  • vadim
    Options
    To get update you need to call FindFriends again being connected to master server.
    You can connect to master in parallel while you are in the room using Photon Realtime .NET SDK
  • I'm using PUN. How hard would it be to integrate Photon Real Time in with PUN?
  • Do I have to refactor everything to use Photon Realtime now? This is turning out to be a little too confusing for me... All I want is to know what room a person is in, and if they are online... That's all...

    Why on earth isn't this functionality available while in a room? I don't understand lol... If I use Photon Realtime couldn't I just keep them connected to the Realtime master server? But if I do that, how do I keep track of what room they are in?
  • Okay, I'm trying to connect to the Realtime Master now using LoadBalancingPeer.Connect(string, string)... It says that I'm connected but then every time I try to use peer.OpFindFriends(string[]), it returns false as if I'm not connected to the master or something... Also, when OpFindFriends is working, does it return the friends list to PhotonNetwork.Friends or what? What's the difference between PUN and Realtime anyways?
  • vadim
    Options
    PUN is plugin tightly integrated with Unity (for price of some Photon functionality), Realtime is standalone SDK. You can run them in parallel.
    Check Realtime SDK demos and tutorials on how to use it.
    Short, you should create LoadBalancingClient, connect it to the cloud, call LoadBalancingClient.OpFindFriends and check result in LoadBalancingClient.FriendList (override OnOperationResponse wirh OperationCode.FindFriends to check that data arrived).
  • Tobias
    Options
    We talk about this in lots of places. Too many in fact. I replied here:
    http://forum.unity3d.com/threads/photon ... st-1881018