GetUserList() not returning users?
GetUserList() not returning users?
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...
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
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.
Can you give me a code snippet that shows the problem in your end?
Best
Thomas
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
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
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
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
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
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
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
-
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Return to “.Net / Unity3D API”
Who is online
Users browsing this forum: No registered users and 2 guests