public void sendChoosePlace(int lobbyId, int placeId, int subPlaceId, int lobbyPage)
        {
            //JesterLogger.log("_____LobbySpace.sendChoosePlace, lobbyId: " + lobbyId + ", placeId: " + placeId + ", subPlaceId: " + subPlaceId + ", lobbyPage: " + lobbyPage);
            this.gameSpace = SpaceBuilder.get().createGame(this, placeId, subPlaceId, lobbyPage);
            //gameSpace.setChatInterface(chatInterface);
            //gameSpace.wait();

            MemoryStream m = new MemoryStream();

            m.SetLength(4 + 1 + 1 + 1);
            BinaryWriter bw  = new BinaryWriter(m);
            int          id_ = getId();

            bw.Write(Converter.GetBigEndian(id_));
            byte choosePlace_ = LobbyProtocol.CHOOSE_PLACE;

            bw.Write(choosePlace_);
            byte placeId_ = (byte)placeId;

            bw.Write(placeId_);
            byte subPlaceId_ = (byte)subPlaceId;

            bw.Write(subPlaceId_);
            clientSession.sessionSend(m);
        }
        /**
         * Singleton of space builder to be implemented
         */
        public static SpaceBuilder getInstance()
        {
            if (instance == null)
            {
                instance = new SpaceBuilder();
            }

            return(instance);
        }
        public override bool callFunction(int fnc, BinaryReader message, CompletionCallback callback = null)
        {
            bool ret = base.callFunction(fnc, message, callback);

            if (ret)
            {
                return(true);
            }

            switch (fnc)
            {
            case LobbyProtocol.CANNOT_ENTER:
                List <Object> objects = new List <Object>();
                eventQueue.addFunction(new Event(LobbyProtocol.CANNOT_ENTER, objects));
                return(true);

            case LobbyProtocol.ENTER_GAME:
                this.placeId    = message.ReadByte();
                this.subPlaceId = message.ReadByte();
                this.lobbyPage  = message.ReadInt16();
                //onShowGameFromLobby(false);
                this.playingGame = true;

                objects = new List <Object>();
                eventQueue.addFunction(new Event(LobbyProtocol.ENTER_GAME, objects));
                return(true);

            case LobbyProtocol.SIGN_PLACE_TO_ENTER:
                placeId    = message.ReadByte();
                subPlaceId = message.ReadByte();
                lobbyPage  = message.ReadByte();
                objects    = new List <Object>();
                eventQueue.addFunction(new Event(LobbyProtocol.SIGN_PLACE_TO_ENTER, objects));

                sendChoosePlace(getId(), placeId, subPlaceId, lobbyPage);
                return(true);

            case LobbyProtocol.LOBBY_INFO:
                //JesterLogger.log("lobbyinfo added event...1");
                while (message.PeekChar() != -1)
                {
                    int mask = 7;
                    int buf  = message.ReadByte();
                    subPlaceId = buf & mask;               // 3 bits for chair sub place
                    mask       = 15;                       // 4 bits for table place
                    placeId    = (buf >> 4) & mask;
                    int    clientId = message.ReadInt16(); // 1 short
                    Client client   = clientsMap[clientId];

                    objects = new List <Object>();
                    objects.Add(placeId);
                    objects.Add(subPlaceId);
                    objects.Add(LobbyPlaceState.BUSY);
                    objects.Add(client);
                    eventQueue.addFunction(new Event(LobbyProtocol.LOBBY_INFO, objects));
                    //JesterLogger.log("lobbyinfo added event...2");
                }
                return(true);

            case LobbyProtocol.ON_GAME_START:
                objects = new List <Object>();
                eventQueue.addFunction(new Event(LobbyProtocol.ON_GAME_START, objects));
                return(true);

            case LobbyProtocol.ON_GAME_FINISH:
                objects = new List <Object>();
                eventQueue.addFunction(new Event(LobbyProtocol.ON_GAME_FINISH, objects));
                return(true);

            case LobbyProtocol.ON_SWITCH_LOBBY:
                int lobbyId = message.ReadInt32();
                lobbyPage = message.ReadByte();
                Space      parent     = getParentSpace();
                LobbySpace lobbySpace = SpaceBuilder.get().createLobby(parent, lobbyId, lobbyPage, clientSession);

                objects = new List <Object>();
                eventQueue.addFunction(new Event(LobbyProtocol.ON_SWITCH_LOBBY, objects));
                return(true);

            case LobbyProtocol.ON_SWITCH_PAGE:
                lobbyId   = message.ReadInt32();
                lobbyPage = message.ReadByte();
                objects   = new List <Object>();
                eventQueue.addFunction(new Event(LobbyProtocol.ON_SWITCH_PAGE, objects));
                return(true);

                //case LobbyProtocol.UPDATE_INDIVIDUAL_RANKING:
                //	var clientID:int = message.readShort();
                //	var client:Client = clientsMap.getValue(clientID);
                //	var points:Number = message.readFloat();
                //	var tiePoints:Number = 0;// message.readFloat();
                //	lobbyUsersInfo.updatePoints(client, points, tiePoints);
                //return new FncRet();
                //
                //case LobbyProtocol.UPDATE_RANKING_POINTS:
                //	var numClients:int = message.readShort();
                //	for (var i:int = 0; i < numClients; i++) {
                //		clientID = message.readShort();
                //		client = clientsMap.getValue(clientID);
                //		points = message.readFloat();
                //		tiePoints = 0;// message.readFloat();
                //		lobbyUsersInfo.updatePoints(client, points, tiePoints);
                //	}
                //return new FncRet();
            }

            return(false);
        }