Lobby in Flash

Options
InvaderDIM
edited January 2012 in Flash (deprecated)
Hi, everybody!

How to connect to Lobby in Flash client? And how to get list of all rooms. I tried to change room name in flash chat tutorial to 'chat_lobby', but it still works as game room (client receive join events, ets.). Also i cant find in flash API how to get list of all rooms.

Comments

  • Boris
    Options
    Did you change the AppId to connect to LiteLobby?

    PhotonChat.setupPhoton()
    Photon.getInstance().initializeConnection(server, port, policyPort, "LiteLobby");
  • Yes, probably that was my problem about connection (thanks for that!). Ok, now i can connect to lobby, and how to get room list? I see that "On join, the complete games list is sent once to get a client up to date." So will i receive room list with JoinEvent (how to?) or somehow else?
  • Boris
    Options
    lite lobby does not send join events, instead you get custom event 1 after lobby join with all games and custom event 2 with lobby changes.
    If you enter a game with the same connection you stop receiving lobby updates and you have to reenter when you finish the game. If you want to receive updates at the same time you do currently need a second connection.
  • InvaderDIM
    edited June 2011
    Options
    .
  • When i connect to lobby i receive join event. When anybody else connects i don't have join event. It's ok, no flood events in lobby. The idea that 1 connection - 1 room is also clear (when i join new room i'll leave current). The problem is that i don't have any CustomEvent in lobby.

    I have client №1 that connects to "LiteLobby" and join to "gameRoom". And i have client №2 that connects to "LiteLobby" and join to "test_lobby".
    In client №2 i have:
    photonServer.addEventListener(CustomEvent.TYPE, handlePhotonEvent);
    
    private function handlePhotonEvent(event : Event) : void {
         switch(event.type){
    	     case CustomEvent.TYPE:
    		     trace ("Have CustomEvent    " + (event as CustomEvent).getData());
    		     break;
         }
    }
    
    I start client №1 and then client №2. But i don't have any CustomEvent in client №2. What is wrong?
  • Boris
    Options
    InvaderDIM wrote:
    When i connect to lobby i receive join event. When anybody else connects i don't have join event.
    The lite lobby code does not send join events (PublishJoinEvent is overriden and empty), just a join operation response in the LiteGame base class.
    If you really get a join event it seems that you still join a normal lite game?
  • I have started from beginning. I have only changed Application ID (to LiteLobby) and room name (to DemoChat_lobby) in your flash chat example (from Photon-Flash-v5-5-3_SDK). Yes you right, only JoinResponse in lobby. No any join events.

    But no any custom events on join anyway. I have added 'case CustomEvent.TYPE:' to handlePhotonEvent.
  • Boris
    Options
    ok, just found the solution:
    File demos\demo_01_chat\classes\de\exitgames\photon_as\Photon.as contains class Photon.
    It overrides function parseEventData:
    override protected function parseEventData(pData : Object) : void {
    			// parse core events
    			super.parseEventData(pData);
    			
    			// add custom events parsing here
    			switch (pData[CoreKeys.CODE]) {
    				case Constants.EV_CUSTOM_CHAT: 
    					var ev_chat : ChatEvent = ChatEvent.create(pData);
    					dispatchEvent(ev_chat);
    					break;
    				default:break;
    			}
    		}
    
    You have to dispatch event codes 1 and 2 here:
    case 1:
    case 2:
       var ev_custom : CustomEvent = CustomEvent.create(pData);
       dispatchEvent(ev_custom);
       break;
    
  • Tobias
    Options
    The lobby is a special sort of room and by default, does not send events. This was done to make sure hundreds of users can get into a lobby without spamming everyone in the process. It's streamlined to send just the game info.
    In some cases, lobbies won't have hundreds of users, so events might be ok. In this case, as Boris points out, you have the code to change this and allow custom events.

    Just my 2 cents about "why it works this way".
  • Hi everyone, I have a problem to connecto to lobby too... (Using Photon-Flash-v3-0-0-2-RC3_SDK).

    I changed the connection, to connect to "LiteLobby" : Photon.getInstance().initializeConnection(server, port, policyPort, "LiteLobby");...
    Then... I receive a customEvent from photonServer, that is supposed that gives me the list of rooms in the lobby...

    I have coded a custom event en AS3, copying/pasting from "chat_demo" to handle this:
    public class RoomsListEvent extends BasicEvent 
    {		
    	public static const TYPE:String = "onRoomsListEvent";
    	private var _message:String;
    	
            public function RoomsListEvent(type:String, bubbles:Boolean = false, cancelable:Boolean = false)
            {
    	        super(type, bubbles, cancelable);
    	}
    		
    	public static function create(eventCode:int, pObject:Object) : RoomsListEvent 
            {
    		var ev:RoomsListEvent = new RoomsListEvent(TYPE);
    		ev.setBasicValues(eventCode, pObject);
    		var roomsListObj:Object = pObject[CoreKeys.DATA];			
    		ev.setMessage(roomsListObj[0]);
    		return ev;
    	}
    		
    	public function getMessage() : String {
    	        return _message;
    	}
    		
    	public function setMessage(message:String) : void {
    		_message = message;
    	}
    }
    

    And the message i get is "null"... well, i suppose when i connect to lobby, there ins't any created room yet (overwhelming logic)...

    What is the next Step to connect/create a room in lobby?
    i have readed entire documentation, even look at unity examples on its client SDK... i saw there, that the way to create a lobby, is with a join function.... but i didn't see anything equals at Flash SDK....
    I tried this, because i'm student and i want to create an online flash game... and at first Photon suits me very well... but... i don't know how to go on.

    Thank you very much in advance.

    PS: I hope you forgive me if I have given many kicks to the English grammar
  • Tobias
    Options
    I assume you run a Photon server yourself?
    As you already noticed, the operations for LiteLobby are not implemented in Flash yet. To learn more about it's use, you could fallback to DotNet, where a "Demo Lobby" exists and you can see the source for the needed operations.

    In LiteLobby (speaking of the server logic), the clients can create many lobbies and each "actual game" might be linked to one lobby (or none). This is code from C# LiteLobbyPeer.cs (from said demo):
    public virtual bool OpJoinFromLobby(string gameName, string lobbyName, Hashtable actorProperties, bool broadcastActorProperties)
    {
        if (this.DebugOut >= DebugLevel.ALL)
        {
            this.Listener.DebugReturn(DebugLevel.ALL, String.Format("OpJoin({0}/{1})", gameName, lobbyName));
        }
    
        // All operations get their parameters as key-value set (a Hashtable)
        Dictionary<byte, object> opParameters = new Dictionary<byte, object>();
        opParameters[(byte)LiteLobbyOpKey.RoomName] = gameName;
        opParameters[(byte)LiteLobbyOpKey.LobbyName] = lobbyName;
    
        if (actorProperties != null)
        {
            opParameters[(byte)LiteOpKey.ActorProperties] = actorProperties;
            if (broadcastActorProperties)
            {
                opParameters[(byte)LiteOpKey.Broadcast] = broadcastActorProperties;
            }
        }
    
        return OpCustom((byte)LiteLobbyOpCode.Join, opParameters, true);
    }
    


    LiteLobbyOpKey.LobbyName is (byte)242 as code and needs the name of the lobby that the new room should be linked to.
    A peer who creates a room will leave the lobby. You need another to join the lobby and to see the result when you create such a room.

    "Inside" the room, everything is used like there is no lobby.
  • Thank you very much Tobias for your answer... it gives me a Clue, and now i can say that i can Join to a room inside a lobby... i'm not sure if its was the cleanest way to do this... but works! :ugeek:
    If someone, like myself, has had trouble with this ... I'll be happy to help ...I will keep watching the forum ...

    And I hope we can soon enjoy the promised support for Flash LiteLobby library.

    A Greeting.
  • Tobias
    Options
    Good to know you were able to do this and support others there. Thanks, santipikanti!