Hi everyone,
I tried to search for this concept everywhere but with no luck hope someone would help here
I have a multiplayer game that uses photon server for rooms and communication
But photon doesnt provide a datebase for me keep friendlist for each user so im doing it on my mysql database
The problem im facing is that I dunno how to keep Status of friends that are online or offline do I have to keep a socket opened with each online player which doesnt seem ideal, or shall I update there last activity and if its less than 2 minutes then i assume he is online, or there is another more efficient approach
Well when a player logs on you could store him in a FriendsLookUp dictionary, which is fast for look ups.
Dictionary<int, List> friends = new Dictionary<int, List>();
int is the PlayerID key.
List are FriendID’s.
Now its easy to match a players friends id with online ID’s.
You can now run this check for all onlone players in a foreach loop every 10 second or so and match them with other online IDs. Every 10 second or so, so it doesnt become too heavy. And remember to remove people from the list when they log off.
I haven’t actually implemented a friends list yet but I could probably add it fairly quickly to my server. I use photon for networking also with a MySQL database. Whenever a player logs in, I add the photon peer to a dictionary indexed by the players id. When the player wants to see if someone is online or if you want to send to the player, lookup the id of the friend in the peer dictionary and if it exists,they are online. Just don’t forget to remove the photon peer after they disconnect
yes, which you can store and retrieve from the database with something like Retrieve * from friendslisttable where ACCTID = someid. Or whatever the syntax for MySQL is
Thank you very much guys,
it seems like checking if the player disconnected is the hardest part specially if the player lost internet connection.
What i was thinking of is that if he closed the application while having an internet connection the application will make a web service call for my database to inform his new status (disconnected),
and if he disconnected suddenly (lost of internet connection) then if his last call is older than (10 seconds) which BFGames suggested then he is considered offline.
Taking this approach at the moment, if anyone got any suggestions that may raise the performance of this friendlist then please guide us
If you are writing your own server code, there is a simpler way then checking every 10 seconds. The class PeerBase has an overrideable function call OnDisconnect which gets called whenever the player losses connection, closes the connection, and etc.
Looking back at your post, your having the client access the database through web calls? Are you using the photon unity networking stuff or are you going to host the server yourself?
yes im having client accessing database using webservices its a normal “Post” call its there only for the friendlist so far, as for photon im using it for making rooms and connecting players to each other thats all, i’ll be using OnDisconnect for general cases where the internet connection still there, and if not i’ll use the 10 seconds logic because if someone lost internet connection i can’t use the Ondisconnect to update my database right?
I use OnDisconnect in my server to remove references to the peer and save data to the database like if they are on or off for the friends list. I dont see the problem on why not to do it there.