Пример #1
0
  @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 testDeserializeCustom() {
    SFSSerializer sfsSerializer = new SFSSerializer();
    ISFSObject entityObj = new SFSObject();
    entityObj.putInt("intField", 10);
    ISFSArray subArray = new SFSArray();
    ISFSArray subCustomArray = new SFSArray();
    SFSObject subObj1 = new SFSObject();
    SFSObject subCustomObj = new SFSObject();
    subObj1.putLong("longField", 30L);
    subCustomObj.putLong("longField", 99L);
    subArray.addSFSObject(subObj1);
    subCustomArray.addSFSObject(subCustomObj);

    entityObj.putSFSArray("wildcardList", subArray);
    entityObj.putSFSArray("wildcardedListCustom", subCustomArray);

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

    assertNotNull("Wildcarded deserialized list must not be null!", entity.getWildcardList());
    assertFalse(
        "Wildcarded deserialized list must not be empty!", entity.getWildcardList().isEmpty());
    assertEquals(30L, ((SubEntity) entity.getWildcardList().get(0)).getLongField().longValue());
    assertEquals(
        99L, ((SubEntity) entity.getWildcardedListCustom().get(0)).getLongField().longValue());
  }
  @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));
  }