예제 #1
0
 /*
  * (non-Javadoc)
  * @see com.syncnapsis.data.service.PlayerManager#removeSitter(java.lang.Long, java.lang.Long)
  */
 @Override
 public Player removeSitter(Long playerSittedId, Long playerSitterId) {
   Player sitted = get(playerSittedId);
   Player sitter = get(playerSitterId);
   sitted.getSitters().remove(sitter);
   return save(sitted);
 }
예제 #2
0
 /*
  * (non-Javadoc)
  * @see com.syncnapsis.data.service.PlayerManager#login(java.lang.String, java.lang.String)
  */
 @Override
 public Player login(String username, String password) {
   User user = userManager.login(username, password);
   if (user == null) return null;
   Player player = getByUsername(username);
   if (player != null) {
     securityManager.getPlayerProvider().set(player);
     securityManager.getEmpireProvider().set(player.getCurrentEmpire());
     return player;
   } else {
     userManager.logout();
     return null;
   }
 }
예제 #3
0
  /*
   * (non-Javadoc)
   * @see com.syncnapsis.data.service.PlayerManager#addSitter(java.lang.Long, java.lang.Long)
   */
  @Override
  public Player addSitter(Long playerSittedId, Long playerSitterId) {
    if (playerSittedId.equals(playerSitterId))
      throw new PlayerSelectionInvalidException("sitted equals sitter");

    Player sitted = get(playerSittedId);
    Player sitter = get(playerSitterId);

    for (Player sitter2 : sitted.getSitters()) {
      if (sitter2.getId().equals(sitter.getId()))
        throw new PlayerSittingExistsException("Sitting relation already exists!", sitter);
    }

    if (!checkSitter(sitter))
      throw new PlayerSittingNotPossibleException("sitter has too much sitted", sitter);
    if (!checkSitted(sitted))
      throw new PlayerSittingNotPossibleException("sitted has too much sitters", sitted);

    sitted.getSitters().add(sitter);
    return save(sitted);
  }
예제 #4
0
  /*
   * (non-Javadoc)
   * @see com.syncnapsis.data.service.PlayerManager#register(java.lang.String, java.lang.String,
   * java.lang.String, java.lang.String)
   */
  @Override
  public Player register(String username, String email, String password, String passwordConfirm)
      throws PlayerRegistrationFailedException {
    User user;
    try {
      user = userManager.register(username, email, password, passwordConfirm);
    } catch (UserRegistrationFailedException e) {
      throw new PlayerRegistrationFailedException(e.getMessage());
    }

    Player player = new Player();
    player.setAccountStatus(user.getAccountStatus());
    player.setAccountStatusExpireDate(user.getAccountStatusExpireDate());
    player.setActivated(true);
    // player.setCurrentEmpire(null);
    player.setRole(playerRoleManager.getByMask(GameBaseConstants.ROLE_NORMAL_PLAYER));
    player.setRoleExpireDate(user.getRoleExpireDate());
    player.setUser(user);

    player = save(player);

    return player;
  }
예제 #5
0
 /*
  * (non-Javadoc)
  * @see com.syncnapsis.data.service.PlayerManager#checkSitted(com.syncnapsis.data.model.Player)
  */
 @Override
 public boolean checkSitted(Player sitted) {
   return sitted.getRole().getMaxSitters() < 0
       || sitted.getSitters().size() < sitted.getRole().getMaxSitters();
 }