Problem Creating Rooms

Added by Jason Muscat 780 days ago

Hey folks,

I'm attempting to move beyond the example code and seem to be having an issue with creating rooms. Up until this point I'd been using the example gameroom.roomA, gameroom.roomB, gameroom.roomC rooms without a problem. Now I'm attempting to create rooms with my own roomIDs and getting the following behavior: the first time I attempt to create the room, the follwing appears in the output:

@12/15/09 14:13:14.360 UTC-8 INFO: Dereferencing resources for room [gameroom.test123].
12/15/09 14:13:14.376 UTC-8 INFO: Room [gameroom.test123] shutdown complete.
12/15/09 14:13:14.376 UTC-8 INFO: [ROOM_MANAGER] Client-side room object removed: [gameroom.test123].@

Which is essentially what I see returned if I do a RoomManager.removeRoom call. However, a couple seconds later I receive:
@
12/15/09 14:13:14.548 UTC-8 INFO: [SERVER] Room creation results for room [gameroom.test123]: SUCCESS@

And then if I close my movie and restart, the same createRoom action fires, only this time it works as expected, firing the RoomManagerEvent.ROOM_ADDED event, etc.

Any help would be greatly appreciated.

Thanks,

Musky


Replies

RE: Problem Creating Rooms - Added by colin moock 780 days ago

hi jason,
can you please try creating a room in a brand new, clean test file and see if that works? if not, please post the test code. if it works, and you still can't figure out why your app's version doesn't work, please post your app's code.

thanks,
colin

RE: Problem Creating Rooms - Added by Jason Muscat 780 days ago

OK, I have this bare minimum code here that connects, joins the lobby, tries to get a synchronized roomlist with a specific qualifier and then tries to create a room. The 2 issues I'm having are:

1) the one mentioned above, if you change the roomID to something new (i.e. from "gameroom.aaaa" to "gameroom.bbbb" the output from reactor will indicate that the room has actually been removed and no room added event will fire. However the room will actually be created on the server and be present the next time you try to create it.

2) even though I know there are several rooms on the server with the qualifier "gameroom" the synchronizeRoomList returns nothing. Unless I don't pass a qualifier then I get everything, as expected.

I'm sure I'm missing something obvious here :/ Thanks for the help.

--j

package  
{
    import flash.display.MovieClip;
    import net.user1.reactor.*;
    /**
     * ...
     * @author ...
     */
    public class RoomTestMain extends MovieClip
    {
        private var _roomList:Array;
        private var _reactor:Reactor;
        private var ROOMID_LOBBY:String = "lobby";
        private var _currentRoomID:String;
        private var _currentRoom:Room;

        public function RoomTestMain() 
        {
            _reactor = new Reactor();
            _reactor.connect("tryunion.com", 9100);
            _reactor.addEventListener(ReactorEvent.READY, readyListener);
        }

        private function readyListener(e:ReactorEvent):void 
        {
            trace("----------------------------- " + readyListener);
            // Ask the RoomManager to create the room on the server
            _currentRoomID = ROOMID_LOBBY;
            _currentRoom = _reactor.getRoomManager().createRoom(_currentRoomID);

            // Join the room LOBBY
            _currentRoom.addEventListener(RoomEvent.JOIN, joinListener);
            _currentRoom.join();

            _reactor.getRoomManager().synchronizeRoomList("gameroom");
        }

        private function joinListener(e:RoomEvent):void 
        {
            _reactor.getRoomManager().createRoom("gameroom.aaaa");
        }
    }
}

RE: Problem Creating Rooms - Added by Jason Muscat 778 days ago

So it looks like the missing line here was:

reactor.getRoomManager().watchForRooms("gameroom");

I never would have guessed form the docs that this would be required for both the synchronizeRoomList and createroom to trigger the ROOM_ADDED event. In fact, it looks like they make it very clear that that event will fire in both circumstances but it was not doing so for me.

ROOM_ADDED    Constant     
public static const ROOM_ADDED:String = ROOM_ADDED

Since :     Reactor 1.0.0

Dispatched when the RoomManager adds a new Room object to its room list. The RoomManager adds new Room objects to its room list under the following circumstances:

    * the current client creates a room via RoomManager's createRoom() method
    * the current client joins a room via RoomManager's joinRoom() method
    * the current client observes a room via RoomManager's observeRoom() method
    * the current client synchronizes the client-side room list with the server's room list (via synchronizeRoomList())
    * a room added to the server has a qualifier that is being watched by the current client

I guess the reactor output I mentioned is normal when creating a room:

12/15/09 14:13:14.360 UTC-8 INFO: Dereferencing resources for room [gameroom.test123].
12/15/09 14:13:14.376 UTC-8 INFO: Room [gameroom.test123] shutdown complete.
12/15/09 14:13:14.376 UTC-8 INFO: [ROOM_MANAGER] Client-side room object removed: [gameroom.test123]

Can you explain what this means?

Thanks,

--j

RE: Problem Creating Rooms - Added by colin moock 778 days ago

hi jason,
first, here's the explanation for the behaviour you observed: your app asks the server for a room list and then subsequently asks to create room "aaaa". locally, reactor creates the Room object for "aaaa", but the room list has already been generated by the server (before "aaaa" was ever created). when reactor receives said room list, the Room object for "aaaa" exists in reactor, but room "aaaa" is not in the list of rooms returned by the server, so reactor removes the Room object for room "aaaa".

that behaviour is not ideal, so we'll be tweaking reactor in the future to ignore room-list updates for rooms that have creation- or removal-requests pending. thanks very much for reporting this issue.

stepping back a bit from the synchronizeRoomList() issue you discovered, at the risk of sounding like microsoft's paperclip...it looks like you're trying to build a list of rooms for a lobby interface. generally speaking, the best tool for that job is RoomManager's watchForRooms() method and the two events RoomManagerEvent.ROOM_ADDED and RoomManagerEvent.ROOM_REMOVED. you don't need to use synchronizeRoomList() if you are already using watchForRooms(). the watchForRooms() approach is fully automated...you just ask to be updated and then listen for updates. you would only use synchronizeRoomList() when you want to manage your update requests manually (perhaps via user input, or on a schedule). and this is no need to ever use synchronizeRoomList() together with watchForRooms().

i modified your example slightly to show the basic code required for a "watchForRooms()"-based lobby. hopefully the following code will help point you in the right direction.

package {
  import flash.display.Sprite;

  import net.user1.logger.Logger;
  import net.user1.reactor.*;

  public class LobbyExample extends Sprite {
    private var reactor:Reactor;
    private var ROOMID_LOBBY:String = "lobby";
    private var currentRoom:Room;

    public function LobbyExample () {
      reactor = new Reactor();
      reactor.getLog().setLevel(Logger.DEBUG);
      reactor.connect("tryunion.com", 9100);
      reactor.addEventListener(ReactorEvent.READY, readyListener);
      reactor.getRoomManager().addEventListener(RoomManagerEvent.ROOM_ADDED, roomAddedListener);
      reactor.getRoomManager().addEventListener(RoomManagerEvent.ROOM_REMOVED, roomRemovedListener);
      reactor.getRoomManager().watchForRooms("gameroom");
    }

    private function readyListener (e:ReactorEvent):void {
      trace("----------------------------- " + readyListener);
      // Ask the RoomManager to create the room on the server
      currentRoom = reactor.getRoomManager().createRoom(ROOMID_LOBBY);

      // Join the room LOBBY
      currentRoom.addEventListener(RoomEvent.JOIN, joinListener);
      currentRoom.join();
    }

    private function joinListener (e:RoomEvent):void {
      reactor.getRoomManager().createRoom("gameroom.bbbb");
    }

    protected function roomAddedListener (e:RoomManagerEvent):void {
      if (e.getRoomIdQualifier() == "gameroom") {
        trace("*** Game room added: " + e.getRoomID());
      }
    }

    protected function roomRemovedListener (e:RoomManagerEvent):void {
      if (e.getRoomIdQualifier() == "gameroom") {
        trace("*** Game room removed: " + e.getRoomID());
      }
    }
  }
}

for a more involved lobby example, please see:
http://www.unionplatform.com/?page_id=801

thanks again for your question!

colin

RE: Problem Creating Rooms - Added by colin moock 778 days ago

forgot to answer this question:

I guess the reactor output I mentioned is normal when creating a room:

12/15/09 14:13:14.360 UTC-8 INFO: Dereferencing resources for room [gameroom.test123].
12/15/09 14:13:14.376 UTC-8 INFO: Room [gameroom.test123] shutdown complete.
12/15/09 14:13:14.376 UTC-8 INFO: [ROOM_MANAGER] Client-side room object removed: [gameroom.test123]

--
no, that is not normal. you'll see that log messaging when a room is removed. in your example, the room was removed because the server's room list did not include the client-side room that was created after the room list was requested.

colin

RE: Problem Creating Rooms - Added by colin moock 694 days ago

hi jason,
just a follow up to this thread: we've overhauled the Room object management code in Reactor, and this issue is now fixed. please try your test again when we ship Union 1.0.0 Alpha 7.

thanks!
colin