using sendPublicMessage after _server.joinRoom issue

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

using sendPublicMessage after _server.joinRoom issue

Postby mistermind » 08 Oct 2009, 20:58

Hello again.
I'm having some issues with using the sendPublicMessage method from the client after joining a room from an extension on the server.

SmartfoxServer 1.6.6

config.xml

Code: Select all

...
<DisabledSysEvents>
   <event>onJoinRoom</event>
   <event>onJoinRoomError</event>
   <event>onRoomAdded</event>
   <event>onCreateRoomError</event>
</DisabledSysEvents>

<DisabledSysActions>
   <action>joinRoom</action>
   <action>leaveRoom</action>
   <action>createRoom</action>
   <action>setUserVariables</action>
</DisabledSysActions>
...


client side

Code: Select all

...
private function onRoomListUpdate(event:SFSEvent):void {
   var sendXtObj:Object = new Object();
   sendXtObj.u = myVars.getName();
   sendXtObj.p = myVars.getPass();
   sfs.sendXtMessage("serverRequest", "j", sendXtObj, "json");
}
...
private function sendMsg(event:Event):void {
   sfs.sendPublicMessage(msgTextField.text, Global.getLobbyId());
}
...


serverRequest.as

Code: Select all

...
function handleRequest(cmd, params, user, fromRoom, protocol) {
...
   var lobbyRoom = zone.getRoomByName("Lobby Room");
   var lobbyJoin = _server.joinRoom(user, -1, false, lobbyRoom.getId());
   var tradeRoom = zone.getRoomByName("Trade Room");
   var tradeJoin = _server.joinRoom(user, lobbyRoom.getId(), false, tradeRoom.getId());
...
zone = _server.getCurrentZone();
var clanRoom =  zone.getRoomByName(user.getVariable("clan").getValue());
if (!clanRoom) {
   var roomObj = new Object();
   roomObj.name = user.getVariable("clan").getValue();
   roomObj.isGame = false;
   roomObj.maxU = 1000;
   var newClanRoom = _server.createRoom(roomObj, user, false, false);
   if (newClanRoom != null){
      var clanJoin = _server.joinRoom(user, lobbyRoom.getId(), false, newClanRoom.getId());
   }
}


Error

Code: Select all

*************************************************************
Warning:
You haven't joined any rooms!
In order to interact with the server you should join at least one room.
Please consult the documentation for more infos.
*************************************************************


Basically, the extension is joining the user in the lobby, but the client doesn't know that. I was almost 100% that the problem was the fact I was disabling the sysEvent onJoinRoom (since it wasn't triggering the joinOK xml), but upon activating it back in, I get the following error on SFS API upon triggering onJoinRoom event:

Code: Select all

TypeError: Error #1009: Cannot access a property or method of a null object reference.
   at it.gotoandplay.smartfoxserver.handlers::SysHandler/handleJoinOk()
   at Function/http://adobe.com/AS3/2006/builtin::apply()
   at it.gotoandplay.smartfoxserver.handlers::SysHandler/handleMessage()
   at it.gotoandplay.smartfoxserver::SmartFoxClient/xmlReceived()
   at it.gotoandplay.smartfoxserver::SmartFoxClient/handleMessage()
   at it.gotoandplay.smartfoxserver::SmartFoxClient/handleSocketData()


which acording to Flash CS4 debugger is in this line on SysHandler.as:

Code: Select all

// Clear the old data, we need to start from a clean list
currRoom.clearUserList()


that I'm guessing its because the currRoom is null (again on SysHandler.as, right above that line)

Code: Select all

var currRoom:Room = sfs.getRoom(roomId)

Problem is, I don't know why :)
SELECT * FROM users WHERE clue > 0
0 rows returned.
User avatar
mistermind
Posts: 131
Joined: 15 Sep 2007, 01:33
Contact:

Postby mistermind » 08 Oct 2009, 21:49

Problem Solved!
For anyone interested to know, here it is:

Code: Select all

var newClanRoom = _server.createRoom(roomObj, user, false, false);


The third parameter on createRoom sends an update to the client reporting that a new room is created. The client needs that information so it stores on the cache the specified created room. Even if you don't actually need to use that information, the client needs it for one reason:
Once it receives onJoinRoom, it must know which room object it is referring to otherwise it will generate that nasty error, since that room doesn't technically exist on the client.
Basically:
server - "He joined room clan"
client - "clan? what clan? I see you are sending an id to me, but I don't have that room object with me here"
SELECT * FROM users WHERE clue > 0

0 rows returned.

Return to “Server Side Extension Development”

Who is online

Users browsing this forum: No registered users and 28 guests