Ejemplo n.º 1
0
  /**
   * Check if reconnecting account may auth.
   *
   * @param accountId id of account
   * @param loginOk loginOk
   * @param reconnectKey reconnect key
   * @param client aion client
   */
  public static synchronized void authReconnectingAccount(
      int accountId, int loginOk, int reconnectKey, AionConnection client) {
    ReconnectingAccount reconnectingAccount = reconnectingAccounts.remove(accountId);

    if (reconnectingAccount != null && reconnectingAccount.getReconnectionKey() == reconnectKey) {
      Account acc = reconnectingAccount.getAccount();

      client.setAccount(acc);
      accountsOnLS.put(acc.getId(), client);
      client.setState(State.AUTHED_LOGIN);
      client.setSessionKey(new SessionKey(client.getAccount()));
      client.sendPacket(new SM_UPDATE_SESSION(client.getSessionKey()));
    } else {
      client.close(/* new SM_UPDATE_SESSION, */ true);
    }
  }
Ejemplo n.º 2
0
  /**
   * Tries to authentificate account.<br>
   * If success returns {@link AionAuthResponse#AUTHED} and sets account object to connection.<br>
   * If {@link com.aionemu.loginserver.configs.Config#ACCOUNT_AUTO_CREATION} is enabled - creates
   * new account.<br>
   *
   * @param name name of account
   * @param password password of account
   * @param connection connection for account
   * @return Response with error code
   */
  public static AionAuthResponse login(String name, String password, AionConnection connection) {
    Account account = loadAccount(name);

    // Try to create new account
    if (account == null && Config.ACCOUNT_AUTO_CREATION) {
      account = createAccount(name, password);
    }

    // If account not found and not created
    if (account == null) {
      return AionAuthResponse.INVALID_PASSWORD;
    }

    // check for paswords beeing equals
    if (!account.getPasswordHash().equals(AccountUtils.encodePassword(password))) {
      return AionAuthResponse.INVALID_PASSWORD;
    }

    // check for paswords beeing equals
    if (account.getActivated() != 1) {
      return AionAuthResponse.INVALID_PASSWORD;
    }

    // If account expired
    if (AccountTimeController.isAccountExpired(account)) {
      return AionAuthResponse.TIME_EXPIRED;
    }

    // if account is banned
    if (AccountTimeController.isAccountPenaltyActive(account)) {
      return AionAuthResponse.BAN_IP;
    }

    // if account is restricted to some ip or mask
    if (account.getIpForce() != null) {
      if (!NetworkUtils.checkIPMatching(account.getIpForce(), connection.getIP())) {
        return AionAuthResponse.BAN_IP;
      }
    }

    // if ip is banned
    if (BannedIpController.isBanned(connection.getIP())) {
      return AionAuthResponse.BAN_IP;
    }

    // Do not allow to login two times with same account
    synchronized (AccountController.class) {
      if (GameServerTable.isAccountOnAnyGameServer(account)) {
        GameServerTable.kickAccountFromGameServer(account);
        return AionAuthResponse.ALREADY_LOGGED_IN;
      }

      // If someone is at loginserver, he should be disconnected
      if (accountsOnLS.containsKey(account.getId())) {
        AionConnection aionConnection = accountsOnLS.remove(account.getId());

        aionConnection.close(true);

        return AionAuthResponse.ALREADY_LOGGED_IN;
      } else {
        connection.setAccount(account);
        accountsOnLS.put(account.getId(), connection);
      }
    }

    AccountTimeController.updateOnLogin(account);

    // if everything was OK
    getAccountDAO().updateLastIp(account.getId(), connection.getIP());

    return AionAuthResponse.AUTHED;
  }