Ejemplo n.º 1
0
 /**
  * Removes from db characters that should be deleted (their deletion time has passed).
  *
  * @param account
  */
 private static void removeDeletedCharacters(Account account) {
   /* Removes chars that should be removed */
   Iterator<PlayerAccountData> it = account.iterator();
   while (it.hasNext()) {
     PlayerAccountData pad = it.next();
     Race race = pad.getPlayerCommonData().getRace();
     long deletionTime = ((long) pad.getDeletionTimeInSeconds()) * 1000;
     if (deletionTime != 0 && deletionTime <= System.currentTimeMillis()) {
       it.remove();
       account.decrementCountOf(race);
       PlayerService.deletePlayerFromDB(pad.getPlayerCommonData().getPlayerObjId());
       if (GSConfig.FACTIONS_RATIO_LIMITED
           && pad.getPlayerCommonData().getLevel() >= GSConfig.FACTIONS_RATIO_LEVEL) {
         if (account.getNumberOf(race) == 0) {
           GameServer.updateRatio(pad.getPlayerCommonData().getRace(), -1);
         }
       }
     }
   }
 }
Ejemplo n.º 2
0
  /**
   * Returns {@link Account} object that has given id.
   *
   * @param accountId
   * @param accountTime
   * @param accountName
   * @param accessLevel
   * @param membership
   * @return Account
   */
  public static Account getAccount(
      int accountId,
      String accountName,
      AccountTime accountTime,
      byte accessLevel,
      byte membership) {
    log.debug("[AS] request for account: " + accountId);

    Account account = accountsMap.get(accountId);
    if (account == null) {
      account = loadAccount(accountId);

      if (CacheConfig.CACHE_ACCOUNTS) accountsMap.put(accountId, account);
    }

    account.setName(accountName);
    account.setAccountTime(accountTime);
    account.setAccessLevel(accessLevel);
    account.setMembership(membership);

    removeDeletedCharacters(account);

    return account;
  }
Ejemplo n.º 3
0
  /**
   * Loads account data and returns.
   *
   * @param accountId
   * @param accountName
   * @return
   */
  private static Account loadAccount(int accountId) {
    Account account = new Account(accountId);

    PlayerDAO playerDAO = DAOManager.getDAO(PlayerDAO.class);
    PlayerAppearanceDAO appereanceDAO = DAOManager.getDAO(PlayerAppearanceDAO.class);

    List<Integer> playerOids = playerDAO.getPlayerOidsOnAccount(accountId);

    for (int playerOid : playerOids) {
      PlayerCommonData playerCommonData = playerDAO.loadPlayerCommonData(playerOid);
      PlayerAppearance appereance = appereanceDAO.load(playerOid);

      LegionMember legionMember =
          DAOManager.getDAO(LegionMemberDAO.class).loadLegionMember(playerOid);

      /** Load only equipment and its stones to display on character selection screen */
      List<Item> equipment = DAOManager.getDAO(InventoryDAO.class).loadEquipment(playerOid);

      PlayerAccountData acData =
          new PlayerAccountData(playerCommonData, appereance, equipment, legionMember);
      playerDAO.setCreationDeletionTime(acData);

      account.addPlayerAccountData(acData);

      /** load account warehouse only once */
      if (account.getAccountWarehouse() == null) {
        // TODO memory lake.....
        Player player = new Player(new PlayerController(), playerCommonData, appereance, account);
        Storage accWarehouse =
            DAOManager.getDAO(InventoryDAO.class)
                .loadStorage(player, StorageType.ACCOUNT_WAREHOUSE);
        ItemService.loadItemStones(accWarehouse.getStorageItems());
        account.setAccountWarehouse(accWarehouse);
      }
    }

    /** For new accounts - create empty account warehouse */
    if (account.getAccountWarehouse() == null)
      account.setAccountWarehouse(new Storage(StorageType.ACCOUNT_WAREHOUSE));

    return account;
  }