Page 1 of 1

GetUserList() not returning users?

Posted: 06 Jan 2009, 19:13
by jeff_o
Heya, so I have a room object called r, and r.GetUserList() seems to return an empty hashtable which I called users (as verified by doing users.Count which gave me 0) BUT if i do r.GetUserCount() this returns 2 as was expected...

Posted: 06 Jan 2009, 21:05
by ThomasLund
Hmmm

In the code I got for the lobby demo I am grabbing the user list from the current room - and that seems to work fine.

Code: Select all

Room currentActiveRoom = smartFox.GetActiveRoom();

....

foreach (User user in currentActiveRoom.GetUserList().Values)
{
   GUILayout.Label(user.GetName());
}


Can you give me a code snippet that shows the problem in your end?

Best
Thomas

Posted: 06 Jan 2009, 21:23
by jeff_o
Here is my relevant code:

public void OnRoomListUpdate(Hashtable roomList)
{
rooms = roomList; // rooms is just a hashtable to hold the list of rooms which i can access later on
// Populate the room list on the rooms tab
foreach (Room room in roomList.Values)
roomListBox.Items.Add(room.GetName());
}


private void roomListBox_SelectedIndexChanged(object sender, EventArgs e)
{
foreach(Room r in rooms.Values)
{
if (r.GetName() == roomListBox.SelectedItem.ToString())
{
Hashtable users = r.GetUserList();

Console.WriteLine("found matching room, users length=" + users.Count); // this is oddly 0, but it should be 2
foreach(User u in users)
usersInRoomListBox.Items.Add(u.GetName());


numUsersTextBox.Text = r.GetUserCount().ToString(); // this correctly returns 2
maxUsersTextBox.Text = r.GetMaxUsers().ToString();
break;
}
}
}

And this is with v1.0

Posted: 11 Jan 2009, 20:58
by ThomasLund
Just a quick post - this is not forgotten, but I am caught up in some iPhone releases right now. Will take a look asap during the next days.

/Thomas

Posted: 08 Apr 2009, 11:53
by shaitaaan
Any update on this?

I am facing the same problem...
Even a workaround would help.

Thanks in advance.

Posted: 08 Apr 2009, 20:44
by ThomasLund
From what I can see - and I'm looking now for Marco to back me up on this or tell me different - then the user list is not send to the client on room list updates. Only the user count is sent.

This means that the client API doesnt have the information that you try to access.

I just checked with the AS3 API code, and here it is the same. RoomListUpdate doesnt contain and process any userlist.

The userlist for a room us updated only when joining a room, or when another user is entering the room that the client is currently in.

That means you would need to join a room to get the requested info - no other way around it.

Marco - this seems to be by design. Is there any way to force a userlist update on a room that you are not logged into?

/Thomas

Posted: 09 Apr 2009, 06:00
by Lapo
The userlist for a room us updated only when joining a room, or when another user is entering the room that the client is currently in.

This is exactly correct. From client side you are not able to "see" the users in a room that you haven't joined.

The reason is (of course) bandwidth optimization, otherwise the client would need to receive huge amount of packets.

That means you would need to join a room to get the requested info - no other way around it.

There are way around it: server side extensions.
If you need to enhance the data that you can "see" from client side you can perform any custom call to your server side code and receive back any information that is relevant to your application logic.

One case scenario, which I believe matches this post, is when you need to see the names of the users playing in a certain room, or maybe the room variables of a game room etc...
Instead of joining that room you can simply send a request to your server side code... like: "hey, tell me the names of the players in game room #10"

This way you just take a peek at the room's user list on-demand, instead of having the server continuosly firing updates at you about any user list in any room which would be an overkill.

A more in-depth analysis of this use case can be found in this discussion: viewtopic.php?p=12388#12388
It's related with Room Variables and their visibility from outside of the room, the same concept applies for user lists.

Hope it helps

Posted: 09 Apr 2009, 06:23
by ThomasLund
Thanks Marco

Clears up the issue and solves the original problem with a solution.

(And no bug in the API - phew) :-D

Best
Thomas