예제 #1
0
  /**
   * This method is for answering GameServer question about account authentication on GameServer
   * side.
   *
   * @param key
   * @param gsConnection
   */
  public static synchronized void checkAuth(SessionKey key, GsConnection gsConnection) {
    AionConnection con = accountsOnLS.get(key.accountId);

    if (con != null) {
      if (con.getSessionKey().checkSessionKey(key)) {
        /** account is successful logged in on gs remove it from here */
        accountsOnLS.remove(key.accountId);

        GameServerInfo gsi = gsConnection.getGameServerInfo();
        Account acc = con.getAccount();

        /** Add account to accounts on GameServer list and update accounts last server */
        gsi.addAccountToGameServer(acc);

        acc.setLastServer(gsi.getId());
        getAccountDAO().updateLastServer(acc.getId(), acc.getLastServer());

        /** Send response to GameServer */
        gsConnection.sendPacket(
            new SM_ACCOUNT_AUTH_RESPONSE(
                key.accountId, true, acc.getName(), acc.getAccessLevel(), acc.getMembership()));
      }
    } else {
      gsConnection.sendPacket(
          new SM_ACCOUNT_AUTH_RESPONSE(key.accountId, false, null, (byte) 0, (byte) 0));
    }
  }
예제 #2
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);
    }
  }
예제 #3
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;
  }