Page 1 of 1

Check if buddy isPlayer (ingame)

Posted: 04 May 2014, 23:54
by blulic
Hi there!
I am building a buddy list with display of buddies with the following states: Offline, Online and Ingame.
In case a buddy is Ingame, I can join his room and play with him.
Is there a way to retrieve if a Buddy is a player (in game), if I am in a Lobby and the Buddy is in a game room?

Buddy interface allows me only to see offline and online states.
I have a workaround to get an ingame state via IUserManager:

var user:User = smartfox.userManager.getUserByName(buddy.name);
user.isPlayer provides information that this user is a player (ingame).
BUT there is another problem - you cannot retrieve a user with IUserManager which is not in your room (lobby), therefore resulting that user is null.
There must be some solution other than fetching the data from the server.

Currently I am using temporary solution: if a buddy is online and not in lobby (user==null), therefore user must be ingame.
I have also found an error in my implementation because of a strange fact:
If an User object is retrieved via userManager.getUserName() with a client who is in a lobby (non player room), it will have a property isPlayer False (but actually that user is a player in a game room)!?
Effectively resulting that the inGame variable will be false (but online).
Here is the part of my code (used later as a list dataprovider):

Code: Select all

			
                        _userId = buddy.id;
			_online = buddy.isOnline;
			
			var user:User = smartfoxserver.userManager.getUserByName(buddy.name);
			if (user!= null) {
				_inGame = user.isPlayer;
			} else {
				if (_online) {
					//user manager didnt found user in lobby room -> must be ingame
					_inGame = true;
				} else {
					_inGame = false;
				}
			}

Many thanks!
Best regards,
Boris

Re: Check if buddy isPlayer (ingame)

Posted: 05 May 2014, 08:28
by Bax
As you noticed, you can't read a user's properties if you are not in the same Room.
My suggestion is that each player, when joining a Room, sets his own Buddy Variables with the data you need, for example the name or id of the Room he is in, and if he is a player in that Room.
All the other users having him as a Buddy will be able to read those variables.