Page 1 of 1

Multi room, sender object comes back null in onPublicMessage

Posted: 21 Jun 2010, 18:54
by jimmie
Hello,

My game allows users to join two rooms at once. The first is a Lobby, which everyone can join. The second is an optional group chat, with a subset of users.

When a user joins a group chat, they suddenly do not receive a sender object from lobby chat messages.

The code is executed in this order...

This occurs in onRoomListUpdate:

Code: Select all

      for each (var room:Room in roomList) {
        if (room.getName() == myLobby) {
          _smartFoxClient.joinRoom(room.getId());
          return;
        }
      }
And that works just fine.

When we successfully join the room (onJoinRoom), we get the Lobby's Id and set some user variables

Code: Select all

      var room : Room = event.params.room;
      _lobbyRoomId = room.getId();
      _smartFoxClient.setUserVariables(uVars);
And then update the room list

Code: Select all

_smartFoxClient.getRoomList();
This time, when the room list is updated, we do the following:

Code: Select all

      var roomArr : Array =_smartFoxClient.getAllRooms();
      
      for each (var room : Room in roomArr) {
        if (room.getName() == _groupRoomName) {
          _groupRoomId = room.getId();
          joinGroupRoom();
          break;
        }
      }
Note that _groupRoomName is defined elsewhere in the game. It is correct in all of my test cases.

joinGroupRoom looks something like this:

Code: Select all

    public function joinGroupRoom() : void {
      if (connectionNotOk()) {
        return;
      }
      
      _smartFoxClient.addEventListener(SFSEvent.onJoinRoom, onGroupRoomJoin);
      _smartFoxClient.joinRoom(_groupRoomId, "", false, true);
    }
After this last joinRoom, we start losing the sender objects in the lobby. The group chat however, is receiving them just fine. A public chat message event looks like this:

Code: Select all

params	Object (@1433d061)	
	message	"Some lobby chat message here"	
	roomId	8	// The Lobby Room Id is correct
	sender	null	
Any thoughts? I have inherited this code, so I'm not sure if this approach is even possible, let alone proper. Any feedback would be very much appreciated.

Thanks!

Posted: 24 Jun 2010, 01:32
by jimmie
The configuration for these lobby's had isGame="true"

Are you only allowed to be in one 'game' at a time?

I changed this to false and all seems to be well in the world.

Posted: 24 Jun 2010, 05:02
by Lapo
isGame should be used for games only.
By default, when in a game room, your don't receive updates for the other Rooms "outside". This is done because usually when you are playing you don't care if new chat/game rooms are created or removed.

Of course when you get out of the game and back to the Lobby you will need to refresh the roomList to be up to date again.

There are two common ways to solve this:

1) Allow the player to be in both the Lobby and the Game Room. His presence in the Lobby will ensure that he receives the RoomList updates so no need for manual updates

OR

2) Join the player in the Game Room and leave the Lobby. When the game is finished and before returning to the Lobby call getRoomList() to grab a fully updated Room List and finally re-join the Lobby.

More on this here:
http://www.smartfoxserver.com/docs/docP ... ecture.htm