Ejemplo n.º 1
0
 /**
  * Returns a string indicating the status of the account. It can be:
  *
  * <ul>
  *   <li>active
  *   <li>inactive
  *   <li>banned
  * </ul>
  *
  * @param transaction DBTransactions
  * @return a string indicating the status of the account.
  * @throws SQLException
  */
 public String getStatus(DBTransaction transaction) throws SQLException {
   String res = null;
   if (DAORegister.get().get(AccountDAO.class).hasPlayer(transaction, username)) {
     res = DAORegister.get().get(AccountDAO.class).getAccountBanMessage(transaction, username);
   }
   return res;
 }
Ejemplo n.º 2
0
  /**
   * Creates a character for a account of a player
   *
   * @param username player's username
   * @param character
   * @param template the template we are going to use to create the object.
   * @param address ip address of client
   * @return a Result indicating if account creation was done successfully or if it is not the
   *     cause.
   */
  public CharacterResult createCharacter(
      String username, String character, RPObject template, String address) {
    try {
      if (!Boolean.parseBoolean(
          Configuration.getConfiguration().get("allow_account_creation", "true"))) {
        return new CharacterResult(Result.FAILED_CREATE_ON_MAIN_INSTEAD, character, template);
      }
    } catch (IOException e) {
      logger.error(e, e);
    }

    // check account creation limits
    try {
      if (DAORegister.get()
          .get(CharacterDAO.class)
          .isCharacterCreationLimitReached(username, address)) {
        return new CharacterResult(Result.FAILED_TOO_MANY, character, template);
      }
    } catch (SQLException e) {
      logger.error(e, e);
      return new CharacterResult(Result.FAILED_EXCEPTION, character, template);
    } catch (IOException e) {
      logger.error(e, e);
      return new CharacterResult(Result.FAILED_EXCEPTION, character, template);
    }
    return ruleProcessor.createCharacter(username, character, template);
  }
Ejemplo n.º 3
0
  /**
   * Creates an account for a player in the game.
   *
   * @param username player's username
   * @param password player's password
   * @param email player's email
   * @param address ip address of client
   * @return a Result indicating if account creation was done successfully or not.
   */
  public AccountResult createAccount(
      String username, String password, String email, String address) {
    try {
      if (!Boolean.parseBoolean(
          Configuration.getConfiguration().get("allow_account_creation", "true"))) {
        return new AccountResult(Result.FAILED_CREATE_ON_MAIN_INSTEAD, username);
      }
    } catch (IOException e) {
      logger.error(e, e);
    }

    // check account creation limits
    try {
      if (DAORegister.get().get(AccountDAO.class).isAccountCreationLimitReached(address)) {
        return new AccountResult(Result.FAILED_TOO_MANY, username);
      }
    } catch (SQLException e) {
      logger.error(e, e);
      return new AccountResult(Result.FAILED_EXCEPTION, username);
    } catch (IOException e) {
      logger.error(e, e);
      return new AccountResult(Result.FAILED_EXCEPTION, username);
    }

    // forward the creation request to the game
    return ruleProcessor.createAccount(username, password, email);
  }
 @Override
 public void execute(DBTransaction transaction) throws SQLException, IOException {
   details =
       DAORegister.get()
           .get(PendingAchievementDAO.class)
           .getPendingAchievementDetails(transaction, getPlayer().getName());
 }
Ejemplo n.º 5
0
 /**
  * Returns true if an account is temporarily blocked due to too many tries in the defined time
  * frame.
  *
  * @param transaction DBTransactions
  * @return true if an account is temporarily blocked due to too many tries in the defined time
  *     frame.
  * @throws SQLException if there is any database problem.
  */
 public boolean isBlocked(DBTransaction transaction) throws SQLException {
   boolean res = true;
   LoginEventDAO loginEventDAO = DAORegister.get().get(LoginEventDAO.class);
   res =
       loginEventDAO.isAccountBlocked(transaction, username)
           || loginEventDAO.isAddressBlocked(transaction, address.getHostAddress());
   return res;
 }
 @Override
 public Result validate() {
   if (charname.equals(username)) {
     return null;
   }
   try {
     if (DAORegister.get().get(AccountDAO.class).hasPlayer(charname)) {
       return Result.FAILED_PLAYER_EXISTS;
     }
   } catch (SQLException e) {
     logger.error("Error while trying to validate character name", e);
     return Result.FAILED_EXCEPTION;
   }
   return null;
 }
Ejemplo n.º 7
0
 /**
  * Add a login event to database each time player login, even if it fails.
  *
  * @param transaction DBTransactions
  * @param address the IP address that originated the request.
  * @param result 0 failed password, 1 successful login, 2 banned, 3 inactive, 4 blocked, 5 merged
  * @throws SQLException if there is any database problem.
  */
 public void addLoginEvent(DBTransaction transaction, InetAddress address, int result)
     throws SQLException {
   String service = null;
   try {
     Configuration conf = Configuration.getConfiguration();
     if (conf.has("server_service")) {
       service = conf.get("server_service");
     } else {
       service = conf.get("server_typeGame");
     }
   } catch (IOException e) {
     logger.error(e, e);
   }
   DAORegister.get()
       .get(LoginEventDAO.class)
       .addLoginEvent(transaction, username, address, service, seed, result);
 }
Ejemplo n.º 8
0
 /**
  * Verify that a player is whom he/she says it is.
  *
  * @param transaction DBTransactions
  * @return true if it is correct: username and password matches.
  * @throws SQLException if there is any database problem.
  */
 public boolean verify(DBTransaction transaction) throws SQLException {
   return DAORegister.get().get(AccountDAO.class).verify(transaction, this);
 }