GetUserList() not returning users?

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

jeff_o
Posts: 13
Joined: 03 Oct 2008, 20:59

GetUserList() not returning users?

Postby jeff_o » 06 Jan 2009, 19:13

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...
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 06 Jan 2009, 21:05

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
jeff_o
Posts: 13
Joined: 03 Oct 2008, 20:59

Postby jeff_o » 06 Jan 2009, 21:23

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
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 11 Jan 2009, 20:58

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
shaitaaan
Posts: 11
Joined: 02 Apr 2009, 04:29
Contact:

Postby shaitaaan » 08 Apr 2009, 11:53

Any update on this?

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

Thanks in advance.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 08 Apr 2009, 20:44

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
User avatar
Lapo
Site Admin
Posts: 23007
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 09 Apr 2009, 06:00

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
Lapo
--
gotoAndPlay()
...addicted to flash games
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 09 Apr 2009, 06:23

Thanks Marco

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

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

Best
Thomas

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 20 guests