Page 1 of 1

problem with SmartfoxClient, please help.

Posted: 13 Apr 2007, 17:03
by Dr_Malito
Hi,

Please Lapo, Patso or any smartfox guru.. I'm stuck with this.

I'm creating a game using an extension with custom login.

In my config I have this:
<Zone name="mw" uCountUpdate="true" buddyList="20" maxUsers="4000" customLogin="true">
<Rooms>
<Room name="Lumina" maxUsers="50" isPrivate="false" isTemp="false" autoJoin="true" uCountUpdate="true" />
</Rooms>
<Extensions>
<extension name="json" className="jsonSample.as" type="script" />
<extension name="mwlogin" className="mwLogin.as" type="script" />
</Extensions>
</Zone>
The extension code is:

Code: Select all

var obj = _server.loginUser(nick, pass, chan)
...

if (error == "")
{
	u = _server.instance.getUserByChannel(chan)
	trace("User " + u.getName() + " logged in")
			
	response.nick = u.getName()
	response._cmd = "logOK"
}

...

_server.sendResponse(response, -1, null, chan)	
_server.sendRoomList(u)
_server.joinRoom(u,-1,false,defaultRoom.getId(),"",false,false)
The response of that is
[Sending]: <msg t='sys'><body action='verChk' r='0'><ver v='137' /></body></msg>

[Received]: <cross-domain-policy><allow-access-from domain="*" to-ports="9339" /></cross-domain-policy>
[Received]: <msg t="sys"><body action="apiOK" r="0" /></msg>
[Sending]: <msg t='sys'><body action='login' r='0'><login z='mw'><nick><![CDATA[malito]]></nick><pword><![CDATA[monster]]></pword></login></body></msg>

[Received]: <msg t="xt"><body action="xtRes" r="-1"><dataObj><var n=&apos;nick&apos; t=&apos;s&apos;>malito</var><var n=&apos;_cmd&apos; t=&apos;s&apos;>logOK</var></dataObj></body></msg>
RESPONSE: {"_cmd":"logOK","nick":"malito"}

[Sending]: <msg t='sys'><body action='getRmList' r='-1'></body></msg>

[Received]: <msg t="sys"><body action="rmList" r="0"><rmList><rm id="7" priv="0" temp="0" game="0" ucnt="0" maxu="50" maxs="0"><n>Lumina</n></rm></rmList></body></msg>

[Sending]: <msg t='sys'><body action='autoJoin' r='-1'></body></msg>

[Received]: <msg t="sys"><body action="uCount" r="7" u="1" /></msg>
[Received]: <msg t="sys"><body action="rmList" r="0"><rmList><rm id="7" priv="0" temp="0" game="0" ucnt="1" maxu="50" maxs="0"><n>Lumina</n></rm></rmList></body></msg>

[Received]: <msg t="sys"><body action="joinKO" r="0"><error msg="User is already in this room!" /></body></msg>
[Received]: <msg t="sys"><body action="uCount" r="7" u="1" /></msg>
The console have the following output:

Code: Select all

12:14:44.499 - [ INFO ] > Server is up and running!
[mwLogin.as]: User malito logged in
[mwLogin.as]: User: malito joined room: Lumina
12:18:22.162 - [ INFO ] > Room Join Error: User is already in this room!, User:
malito, IP: 127.0.0.1
12:18:23.107 - [ WARNING ] > Extension Call has invalid RoomID. User = malito -
/127.0.0.1
:?: :?: :?:

I'm using an external class for the SmartfoxClient

Code: Select all

this.evtQueue = [];
		//this.ip	 = "www.xatme.com";
		this.ip	 = "127.0.0.1";
		this.port = 9339;
		this.zone = "mw";
		this.extensionName = "mwlogin";
		this.protocolo = "xml";
		
		this.smartfox = new SmartFoxClient();
		this.smartfox.debug = true;

		this.smartfox.onConnection = Delegate.create(this,handleConnection);
		this.smartfox.onUserVariablesUpdate = Delegate.create(this,onUserVariablesUpdate);
		this.smartfox.onRoomListUpdate = Delegate.create(this,onRoomListUpdate);
....
When I call any extension command, I get the message [ WARNING ] > Extension Call has invalid RoomID. User = malito -

And I have this in my flash

Code: Select all

var room:Room = this.smartfox.getRoom(this.smartfox.activeRoomId)
trace("CurrentRoom is : " + room.getName())
trace("My user ID is: " + this.smartfox.myUserId)
trace("I am player " + this.smartfox.playerId)
trace("Current API version: " + this.smartfox.getVersion())
that code returns this:

Code: Select all

CurrentRoom is : undefined
My user ID is: null
I am player null
Current API version: 1.3.7
I have converted the SmartFoxCLient object to JSON, and this is the result:

Code: Select all

{"ipAddress":"127.0.0.1","messageHandlers":{"xt":{},"sys":{}},"arrayTags":
{"uLs":true,"rmList":true,"vars":true,"bList":true,"vs":true},
"amIModerator":false,"changingRoom":false,"isConnected":true,
"debug":true,"playerId":null,"myUserName":"",
"myUserId":null,"activeRoomId":null,
"buddyVars":[],"buddyList":[],
"roomList":[null,null,null,null,null,null,null,{"variables":[],"userList":{},
"specCount":null,"userCount":1,"description":"","updatable":false,
"limbo":false,"priv":false,"game":false,"temp":false,"maxSpectators":0,
"maxUsers":50,"name":"Lumina","id":7}],
"os":{"hexTable":[0,1,2,3,4,5,6,7,8,9],
"ascTabRev":[],"ascTab":[],"eof":"","debug":false,"xmlStr":"",
"tabs":"\t\t\t\t\t\t\t\t\t\t"}}
Please.. I really need this.

Posted: 14 Apr 2007, 09:19
by patso
Ok. Now I found where the problem is. I'll try to explain it the best I can.
First about the Id variables.
myUserId - default value - null. When you write your own login extension(as in your case) the user id it's not sent by SFS autocratically - you must update it manually.
activeRoomId - default value - null. activeRoomId is the Id of the last room you join. It's updated after the client receive a "joinOk" message from the server - in simple words when the client receive a message about that it's joined successfully to the room. This is important it's updated when you receive message that you are joined not when you try to join - and this natural since your attempt to join may fall.

What happens in your case. You have custom login extension. I don't see to update the myUserId on the client side. Your problem is not in this, but if you don't update the myUserId this may cause problems - thats why i mention it(and because you trace it - may be you need it).
After this you have this code

Code: Select all

_server.joinRoom(u,-1,false,defaultRoom.getId(),"",false,false)
This join the user to the room but not send update about this to the client - the last parameter is set to false. And when you try to invoke autojoin on the client side it says that you are already in this room because it's true. The extension join the user to this room. And since the extension not send update about the room join and the autojoin fails the activeRoomId is not updated and it remains null. One option is the last argument to true

Code: Select all

_server.joinRoom(u,-1,false,defaultRoom.getId(),"",false,true)
and this will send update to the client about the user join. Other way is to remove this line from the extension and to leave the client to join the default room using auto join, or to update the activeRoomId on the client side using some other way.
activeRoomId is very important since in SFS to do something you must be in room and the most of the functions have optional fromRoom argument. If you not passed this optional argument the SFS cleint replace it with ActiveRoomId. In your case it's not updated properly and that's why you receive this errors.
Another situations is when your users can join to more than one room - in this case is good idea to track the current room id in your custom variable and to call the functions that use fromRoomId with it - otherwise you may have (and in most cases you'll have) problems.

I hope this help you. May be I haven't explain it good - but I hope you can understand me. In the opposite case feel free to ask
:) .

Posted: 16 Apr 2007, 13:42
by Dr_Malito
Thanks patso!

that was exactly my problem. :D