@Override
  public void handleClientRequest(User user, ISFSObject isfso) {
    trace("isplay: " + user.getVariable("isplay"));
    Boolean isplay = user.getVariable("isplay").getBoolValue();
    if (isplay == true) {
      if (user.getVariable("ischuong").getBoolValue()) {
        ISFSObject obj = new SFSObject();
        obj.putBool("status", false);
        obj.putUtfString("message", "Chương không có quyền đặt tiền");
        send("betgame", obj, user);
      } else {
        Double bet = 0.0;
        bet = isfso.getDouble("betmoney");
        trace(bet);
        SFSUserVariable money = SFSUserVariable.newInstance("bet", bet);
        try {
          user.setVariable(money);
        } catch (SFSVariableException ex) {
        }
        trace("Thong tin user sau bet game: " + user.getVariable("bet"));
        ISFSObject obj = new SFSObject();
        obj.putBool("status", true);
        obj.putInt("betid", user.getId());
        obj.putDouble("betmoney", bet);
        send("betgame", obj, this.getParentExtension().getParentRoom().getUserList());
      }

    } else {
      ISFSObject obj = new SFSObject();
      obj.putBool("status", false);
      obj.putUtfString("message", "Không có quyền chơi, chờ ván sau");
      send("betgame", obj, user);
    }
  }
  @Test
  public void testBasicTransportObject() {
    SFSSerializer serializer = new SFSSerializer();

    ISFSObject input = new SFSObject();
    input.putUtfString("name", "John");
    input.putUtfString("surname", "Smith");
    input.putLong("age", 50L);

    BasicTransportObject to = serializer.deserialize(BasicTransportObject.class, input);
    assertEquals("John", to.get("name"));
    assertEquals("Smith", to.get("surname"));
    assertEquals(50L, to.get("age"));
  }
  public void handleServerEvent(ISFSEvent event) throws SFSException {

    User user = (User) event.getParameter(SFSEventParam.USER);

    trace("ClueGameExtension UserDisconnectEventHandler got user: "******"room");

    if (uv == null) return;

    Room room = (Room) getParentExtension().getParentZone().getRoomByName(uv.getStringValue());

    trace("ClueGameExtension UserDisconnectEventHandler got room: " + room);

    // handles both the user disconnected event and the user exit room events

    if (room != null) {
      // set the game to over
      if (room.getUserList().size() < 3) {
        room.removeVariable("isGameStarted");
      }
    }

    // send the note to all other players
    List<User> users = room.getUserList();
    ISFSObject resObj = SFSObject.newInstance();
    resObj.putUtfString(
        "message",
        "Game is over because there are less than 3 players.  A player has disconnected from the server.");
    send("gameOver", resObj, users);
  }
  private void customRoomLogin(ISFSEvent event) throws SFSLoginException {
    trace("Game Login by session");

    DBCollection users = AuthorizeExtension.users;

    BasicDBObject query = new BasicDBObject();
    query.put("session", generateSession);

    DBCursor cursor = users.find(query);

    if (!cursor.hasNext()) {
      trace("Game Login User not found!", generateSession);
      SFSErrorData data = new SFSErrorData(SFSErrorCode.LOGIN_BAD_PASSWORD);
      data.addParameter(userName);

      throw new SFSLoginException("Login failed for user: "******"Game Login User logged in!", generateSession);
      document = cursor.next();

      ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
      outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, document.get("nickname").toString());

      Boolean isGuest = (Boolean) document.get("is_guest");
      if (isGuest == null) {
        isRegistered = true;
      } else {
        isRegistered = false;
      }
    }
  }
  @Test
  public void testDeserialize() {
    SFSSerializer sfsSerializer = new SFSSerializer();

    ISFSObject subEntityObj = new SFSObject();
    subEntityObj.putLong("longField", 20L);
    ISFSObject entityObj = new SFSObject();
    entityObj.putInt("intField", 10);
    entityObj.putSFSObject("subEntity", subEntityObj);
    entityObj.putUtfString("notDeserializable", "value1");
    entityObj.putUtfString("notSerializable", "value2");
    entityObj.putUtfString("enumField", "white");
    entityObj.putUtfString("changedName", "changedValue");
    entityObj.putUtfString("fieldWithoutGetter", "value");
    entityObj.putInt("fieldCustomSerializable", 10);
    entityObj.putUtfString("totallyIgnoredField", "value");

    entityObj.putUtfStringArray("colors", Arrays.asList("black", "black", "white"));

    ISFSArray subArray = new SFSArray();
    SFSObject subObj1 = new SFSObject();
    subObj1.putLong("longField", 30L);
    subObj1.putUtfStringArray("stringsList", Arrays.asList("testString"));
    SFSObject subObj2 = new SFSObject();
    subArray.addSFSObject(subObj1);
    subArray.addSFSObject(subObj2);

    entityObj.putSFSArray("subEntities", subArray);

    Entity entity = sfsSerializer.deserialize(Entity.class, entityObj);

    assertEquals(Entity.Color.white, entity.getEnumField());
    assertEquals(Entity.Color.white, entity.getColors().get(2));
    assertEquals(entityObj.getInt("intField"), entity.getIntField());
    assertEquals((Long) 10L, entity.fieldCustomSerializable);
    assertEquals(entityObj.getUtfString("fieldWithoutGetter"), entity.fieldWithoutGetter);
    assertEquals(entityObj.getUtfString("notSerializable"), entity.getNotSerializable());
    assertEquals(entityObj.getUtfString("changedName"), entity.getNameToBeChanged());
    assertNull(entity.getNotDeserializable());
    assertNull(entity.totallyIgnoredField);
    assertEquals(subEntityObj.getLong("longField"), entity.getSubEntity().getLongField());

    assertNotNull(entity.getSubEntities());
    assertFalse(entity.getSubEntities().isEmpty());
    assertEquals(30L, entity.getSubEntities().get(0).getLongField().longValue());
    assertEquals("testString", entity.getSubEntities().get(0).getStringsList().get(0));
  }
  private void handleGuest(ISFSEvent event) throws NoSuchElementException {
    trace("Guest is loggin in", userName);

    DBCollection users = AuthorizeExtension.users;

    // Create random num 0..99
    Random randomGenerator = new Random();
    userName = userName + randomGenerator.nextInt(100);

    // Set new Name
    ISFSObject outData = (ISFSObject) event.getParameter(SFSEventParam.LOGIN_OUT_DATA);
    outData.putUtfString(SFSConstants.NEW_LOGIN_NAME, userName);

    // Insert DB
    BasicDBObject newUser = new BasicDBObject();
    newUser.put("nickname", userName);
    newUser.put("session", generateSession);
    newUser.put("is_guest", true);

    users.insert(newUser);

    isRegistered = false;
  }