@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());
  }
  @Override
  public void handleServerEvent(ISFSEvent event) throws SFSException {
    trace("--------------------------------------------------------");
    // Grab parameters from client request
    userName = (String) event.getParameter(SFSEventParam.LOGIN_NAME);
    cryptedPass = (String) event.getParameter(SFSEventParam.LOGIN_PASSWORD);
    session = (ISession) event.getParameter(SFSEventParam.SESSION);

    customData = (SFSObject) event.getParameter(SFSEventParam.LOGIN_IN_DATA);

    String joinRoom = AuthorizeExtension.LOBBY;

    if (customData == null || customData.getUtfString("session") == null) {
      lobbyLoginAsGuestOrRegistered(event);
    } else {
      joinRoom = customData.getUtfString("room");
      generateSession = customData.getUtfString("session");
      customRoomLogin(event);
    }

    trace("Session loggin in: ", generateSession);

    session.setProperty("room", joinRoom);
    session.setProperty("isRegistered", isRegistered);
    session.setProperty("session", generateSession);
  }
예제 #3
0
  public Room CreateTournamentRoom(String roomName, String tournamentId, int maxPlayers)
      throws SFSCreateRoomException {
    CreateRoomSettings settings = new CreateRoomSettings();
    settings.setName(roomName);
    settings.setGroupId("games");
    settings.setGame(true);
    settings.setMaxSpectators(0);
    settings.setMaxUsers(maxPlayers);
    settings.setExtension(new RoomExtensionSettings("SFJugger", MainExtension.class.getName()));
    settings.setAutoRemoveMode(SFSRoomRemoveMode.NEVER_REMOVE);
    settings.setHidden(false);
    settings.setMaxVariablesAllowed(15);

    List<RoomVariable> roomVars = new ArrayList<RoomVariable>();

    roomVars.add(new SFSRoomVariable("map", "urban_map_RR3_fix", false, false, true));
    roomVars.add(new SFSRoomVariable("ruleClass", PVPGameRule.class.getName(), false, false, true));
    roomVars.add(new SFSRoomVariable("visible", true, false, false, true));
    roomVars.add(new SFSRoomVariable("isTournament", true, false, false, true));
    roomVars.add(new SFSRoomVariable("tournamentId", tournamentId, false, false, true));

    GameSettingModel gSettings = new GameSettingModel();
    gSettings.isWithPractice = false;
    gSettings.teamCount = 2;
    gSettings.maxTime = 0;
    gSettings.maxScore = 35;

    SFSObject data = new SFSObject();
    data.putClass("gameSetting", gSettings);
    roomVars.add(new SFSRoomVariable("gameVar", data, false, false, true));
    settings.setRoomVariables(roomVars);

    return getApi().createRoom(getParentZone(), settings, null, false, null, false, false);
    // return getApi().createRoom(getParentZone(), settings, null);
  }
  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);
  }
  @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));
  }
예제 #6
0
  @Override
  public void handleClientRequest(User paramUser, ISFSObject paramISFSObject) {
    String data = paramISFSObject.getUtfString("data");

    ISFSObject parserObj = SFSObject.newFromJsonData(data);
    System.out.println("username : "******"username"));
    System.out.println("address :" + parserObj.getUtfString("address"));
    //		String from = "*****@*****.**";
    //		String to = "*****@*****.**";
    //		Email myEmail = new SFSEmail(from, to, "Test mail", "Hello from SFS2X");
    //		try {
    //			SmartFoxServer.getInstance().getMailService().sendMail(myEmail);
    //		} catch (MessagingException e) {
    //			e.printStackTrace();
    //			trace(e.getMessage());
    //		}
    send("zcq", parserObj, paramUser);
  }