Page 1 of 1

using sendPublicMessage after _server.joinRoom issue

Posted: 08 Oct 2009, 20:58
by mistermind
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


Code: Select all



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());

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(); = 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());


Code: Select all

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/
   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

Code: Select all

// Clear the old data, we need to start from a clean list

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

Code: Select all

var currRoom:Room = sfs.getRoom(roomId)

Problem is, I don't know why :)

Posted: 08 Oct 2009, 21:49
by mistermind
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.
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"