room.getCreator() from the client side?
Posted: 23 Nov 2010, 08:59
Guys,
one day struggle and I couldn't figure out this problem, please help!
SFS PRO 1.6.9
Client api - AS2 v.1.6.3
Long story short, I have a task which could be easily done if there were such things as:
1. room.getCreator() from the client side.
2. roomVariablesUpdate - outside of the specific room which is updated. Which could be hard and unnecessary i guess.
Now the long story.
The goal is to make a table list of game rooms within a Lobby room, which contains field with the name of the room creator and various other variables got from the room creator user object.
If in a room there are 2 users and the creator leaves the room, then the one which is left present in the room becomes the creator.
Up to here everything is fine.
The problem is how to update the clients which are sitting in the Lobby room with this creator-change?
My solution tryouts.
1. Using room variables.
Let's put a "roomCreator" variable in every new game room. In zone's config there is roomListVars="true", so when a client in the Lobby gets the roomlist, this roomCreator variable is populated.
However, when the creator leaves the room and his successor becomes creator and this roomCreator variable is changed, the onRoomVariablesUpdate happens only in that specific room (which is reasonable of course) and the clients in the lobby room are not updated.
When a totally new client joins the Lobby it gets roomlist with updated variables and it can see the new roomCreator. But, the old clients which saw the initial room creation, with the initial roomCreator are never updated with the new one! No matter how the game list changes, or how many rooms they join and leave, the client API(or the serverside I dunno...) detects that they already got the info for this room, and do not update the variables!
The only way I found for an "old" client to update the room variable is to join this room, which is no option for a list update.
I tried to put this room variables from both serverside and client side without any difference.
So this didn't worked out for me.
2. Using user variables.
Let's put a "host" variable in every user to be used as a flag. By default it's set to false, but when a user creates a game room, it is set to true. If the host leaves the game room, the guest becomes host. When you cycle the game rooms to populate the room-list you can extract the users, get their variables, check who is host and put his name on the list, right?
Well, actually no! I couldn't get populated userList from room.getUserList() for a game room, from a client joined in a normal Lobby room!
If you do this traceRoom on onUserCountChange or onRoomListUpdate cycle you will see empty users object.
So this too didn't worked out.
Is there a way to get populated user list in a specific room, without being in this room?
I guess it can be done with custom serverside response, but for the purpose of such task as a game list, wouldn't that generate too much traffic?
Is there any easier solution than creating custom roomlists from the server side, or custom server responces for this room changes only?
one day struggle and I couldn't figure out this problem, please help!
SFS PRO 1.6.9
Client api - AS2 v.1.6.3
Long story short, I have a task which could be easily done if there were such things as:
1. room.getCreator() from the client side.
2. roomVariablesUpdate - outside of the specific room which is updated. Which could be hard and unnecessary i guess.
Now the long story.
The goal is to make a table list of game rooms within a Lobby room, which contains field with the name of the room creator and various other variables got from the room creator user object.
If in a room there are 2 users and the creator leaves the room, then the one which is left present in the room becomes the creator.
Up to here everything is fine.
The problem is how to update the clients which are sitting in the Lobby room with this creator-change?
My solution tryouts.
1. Using room variables.
Let's put a "roomCreator" variable in every new game room. In zone's config there is roomListVars="true", so when a client in the Lobby gets the roomlist, this roomCreator variable is populated.
However, when the creator leaves the room and his successor becomes creator and this roomCreator variable is changed, the onRoomVariablesUpdate happens only in that specific room (which is reasonable of course) and the clients in the lobby room are not updated.
When a totally new client joins the Lobby it gets roomlist with updated variables and it can see the new roomCreator. But, the old clients which saw the initial room creation, with the initial roomCreator are never updated with the new one! No matter how the game list changes, or how many rooms they join and leave, the client API(or the serverside I dunno...) detects that they already got the info for this room, and do not update the variables!
The only way I found for an "old" client to update the room variable is to join this room, which is no option for a list update.
I tried to put this room variables from both serverside and client side without any difference.
So this didn't worked out for me.
2. Using user variables.
Let's put a "host" variable in every user to be used as a flag. By default it's set to false, but when a user creates a game room, it is set to true. If the host leaves the game room, the guest becomes host. When you cycle the game rooms to populate the room-list you can extract the users, get their variables, check who is host and put his name on the list, right?
Well, actually no! I couldn't get populated userList from room.getUserList() for a game room, from a client joined in a normal Lobby room!
Code: Select all
function traceRoom(roomObj:Room):Void
{
var users = roomObj.getUserList();
trace("room = "+roomObj.getName()+"; room.getUserCount() = "+ roomObj.getUserCount()+"; users = " + users);
for (var vname in users) {
trace("users[" + vname + "] =" + users[vname]);
trace("users["+vname+"] = " + users[vname].getVariable("host"));
}
}So this too didn't worked out.
Is there a way to get populated user list in a specific room, without being in this room?
I guess it can be done with custom serverside response, but for the purpose of such task as a game list, wouldn't that generate too much traffic?
Is there any easier solution than creating custom roomlists from the server side, or custom server responces for this room changes only?