Page 1 of 1
server created rooms rejecting vars
Posted: 12 Nov 2010, 22:53
by yuvallahav
Hello! Again!
The fun never ends, does it?? :)
Here's a piece of code I've used in my extension:
Code: Select all
var user_name = user.getName();
var op_name = op_obj.getName();
var roomVars = new Array();
roomVars.push({name:"Player1", val:user_name, priv:false, persistent:true});
roomVars.push({name:"Player2", val:op_name, priv:false, persistent:true});
var roomObj = {};
roomObj.name = "Game@"+user_name+"@"+op_name;
roomObj.isGame = true;
roomObj.maxU = 2;
roomObj.uCount = false;
roomObj.isLimbo = false;
roomObj.maxS = 0;
var new_room = _server.createRoom(roomObj, user, true, true, roomVars, null, true);
if(new_room != null){
_server.joinRoom(user, lobby_id, true, new_room.getId(), null, false, false);
_server.joinRoom(op_obj, lobby_id, true, new_room.getId(), null, false, false);
}else{
trace("crap...");
}
[/size]
Now... the room is created just fine, the user and opponent objects are just fine, every thing seems to be just fine, only the room does not show, or hold the room variables I'm trying to push it.
Not in the admin console, and not on the connected clients who do get the onRoomAdded event, only, again, without the room variables.
What am I doing wrong here??
(just to be clear, all my variables I use all check out, nothing is undefined or not in it's place).
Thanks!
Yuval Lahav.
Posted: 13 Nov 2010, 07:05
by yuvallahav
A little update, I've tried, instead of trying to add the room variables while creating the room (which didn't work, and also didn't fire up any error on the server), to set the variables after the room was created and verified:
Code: Select all
var new_room = _server.createRoom(roomObj, user, true, true, [], null, true);
if(new_room != null){
var roomVars = new Array();
roomVars.push({name:"Player1", val:user_name, priv:false, persistent:true});
roomVars.push({name:"Player2", val:op_name, priv:false, persistent:true});
and it didn't work, and also, thinking the the new room can't get variables without users in it (why would it be this way, I don't know, but had nothing more to try...) I tried the same after I joined some users into it, again, it didn't work completely...
I'm missing something here, but I can't seem to find what it is, any help guys??
Thanks again.
Yuval Lahav.
Posted: 13 Nov 2010, 10:33
by yuvallahav
As always, I'm here with an update...
It would seem the variables object does not work when I try to use the user name of my user object as the value of my variable... and yes, this means I've tried it with a sting (works), number (works), a different information from the user object (user id, and yes, it works), it would seem that just the user name, even though present, and shows up on trace, simply does not fit into the code somehow, and is being rejected, beats me why... so here are examples that don't work, and after the jump, examples that do work:
Code: Select all
DOESN'T WORK:
var user_name = user.getName();
var roomVars = new Array();
roomVars.push({name:"Player1", val:user_name, priv:true, persistent:true});
Code: Select all
DOESN'T WORK:
var roomVars = new Array();
roomVars.push({name:"Player1", val:user.getName(), priv:true, persistent:true});
Code: Select all
DOES WORK:
var user_id= user.getUserId();
var roomVars = new Array();
roomVars.push({name:"Player1", val:user_id, priv:true, persistent:true});
Code: Select all
DOES WORK:
var roomVars = new Array();
roomVars.push({name:"Player1", val:user.getUserId(), priv:true, persistent:true});
Code: Select all
DOES WORK:
var roomVars = new Array();
roomVars.push({name:"Player1", val:"Yuval", priv:true, persistent:true});
So what is that guys, how come the only thing I can't use as the value of the variable is the user name?
Hope there is some kind of explanation to this...
Yuval Lahav.
Posted: 13 Nov 2010, 10:50
by yuvallahav
I must be going crazy here guys...
Trying this:
Code: Select all
var varList = {};
varList.user_name = user.getName();
varList.user_id = user.getUserId();
_server.setUserVariables(user, varList, false);
Does not work FOR THE USER NAME, but does work FOR THE USER ID!!
And tracing "user.getName()" will output the user name!!
Whats going on here? is the user name returned by getName() is some kind of object that can be traced but not used inside object that expect a string, numeric or Boolean value??
(just to be on the safe side, I also tried user.getName().toString(), just to be sure, and no, it didn't make any difference...).
Please set my mind strait...
Yuval.
Posted: 13 Nov 2010, 13:29
by Lapo
Which server version please?
Posted: 13 Nov 2010, 14:18
by yuvallahav
Hey Lapo, good to hear from you, especialy on a weekend :)
Server version:
SmartFoxServer PRO - Ver. 1.6.8
Thanks, I hope there is a way around this since it's driving me mad!!
Yuval Lahav.
Posted: 13 Nov 2010, 14:31
by yuvallahav
Also, just installed the update patch for the 1.6.9 server pro, and nothing changed, same issue.
Thanks!
Posted: 13 Nov 2010, 20:06
by BigFIsh
I know this may be crazy, but try.. String(user.getName()) instead of user.getName().toString(). I remembered encountering something like this (last year), and re-casting it into a string seems to resolve the problem.
Posted: 13 Nov 2010, 21:03
by yuvallahav
Hey! Crazy as this was, it worked!!
But alas, I do not get to rest easy now, since yes, the room was created, yes, the variables were set correctly this time, yes, my 2 users got connected to the new room, but alas!! they were also left logged on to the room they were in before they were logged into the new room by the server... do I always need to invoke "leaveRoom()" on the server side before logging new users to a different room? I was under the impression this is only needed when I'm using a multi-room log-in allowed policy, which I don't....
Thanks again for the help and for future advice!
Yuval Lahav.
Posted: 13 Nov 2010, 22:35
by BigFIsh
Can you show us the snippet code that was used to join clients to the new room?
Posted: 13 Nov 2010, 22:39
by yuvallahav
Sure, sure, here it is:
Code: Select all
var user_name = String(user.getName());
var op_name = String(op_obj.getName());
var roomVars = new Array({name:"Player1", val:user_name, priv:true, persistent:true},{name:"Player2", val:op_name, priv:true, persistent:true});
var roomObj = {name:"G@"+user_name+"@"+op_name,isGame:true,maxU:2,uCount:false,isLimbo:false,maxS:0};
var new_room = _server.createRoom(roomObj, user, true, true, roomVars, null, true);
if(new_room != null){
_server.joinRoom(user, lobby_id, true, new_room.getId(), null, false, true);
_server.joinRoom(op_obj, lobby_id, true, new_room.getId(), null, false, true);
}
Here is the creation of the room with the now working variables, and the joining to the room.
Again, on the admin console, they do show up in the new rooms, but they also show up still in their old room.
The onJoinRoom event was fired for both with the new room.
Posted: 14 Nov 2010, 07:17
by BigFIsh
Your code looks valid to me, unless the lobby_id is incorrect. So please re-check that. It should be the same id of the lobby room in which the users were in prior to joining the new room.
Posted: 14 Nov 2010, 07:26
by yuvallahav
Yeah, it's good, tried that already :(
Yuval.
(... thinking that if I won't solve this soon I'll just have to bundle up my config and extention and a part of my flash source file and let you have a better look... :)
Posted: 14 Nov 2010, 07:30
by yuvallahav
Found the problem.... sometimes I get stupid in the mornings, or at night, when it's late... They didn't log-out from the old room since it wasn't the lobby room they where in... sorry... :)
Yuval.