public boolean savePassword(String password) {
    if (passwordExist()) {
      _log.warning(
          "[SecondaryPasswordAuth]" + _activeClient.getAccountName() + " forced savePassword");
      _activeClient.closeNow();
      return false;
    }

    if (!validatePassword(password)) {
      _activeClient.sendPacket(new Ex2ndPasswordAck(Ex2ndPasswordAck.WRONG_PATTERN));
      return false;
    }

    password = cryptPassword(password);

    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement(INSERT_PASSWORD);
      statement.setString(1, _activeClient.getAccountName());
      statement.setString(2, VAR_PWD);
      statement.setString(3, password);
      statement.execute();
      statement.close();
    } catch (Exception e) {
      _log.log(Level.SEVERE, "Error while writing password.", e);
      return false;
    } finally {
      L2DatabaseFactory.close(con);
    }
    _password = password;
    return true;
  }
Esempio n. 2
0
 /** @see com.l2jserver.gameserver.network.clientpackets.L2GameClientPacket#runImpl() */
 @Override
 protected void runImpl() {
   L2GameClient client = this.getClient();
   if (client != null) {
     client.sendPacket(new ExShowAgitInfo());
   }
 }
  private void loadPassword() {
    String var, value = null;

    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement(SELECT_PASSWORD);
      statement.setString(1, _activeClient.getAccountName());
      ResultSet rs = statement.executeQuery();
      while (rs.next()) {
        var = rs.getString("var");
        value = rs.getString("value");

        if (var.equals(VAR_PWD)) {
          _password = value;
        } else if (var.equals(VAR_WTE)) {
          _wrongAttempts = Integer.parseInt(value);
        }
      }
      statement.close();
    } catch (Exception e) {
      _log.log(Level.SEVERE, "Error while reading password.", e);
    } finally {
      L2DatabaseFactory.close(con);
    }
  }
 @Override
 protected void runImpl() {
   L2GameClient client = getClient();
   if (client != null) {
     L2Object object = L2World.getInstance().findObject(_objectId);
     if (object instanceof L2ItemInstance) {
       L2ItemInstance item = (L2ItemInstance) object;
       if (item.isPublished()) {
         client.sendPacket(new ExRpItemLink(item));
       } else {
         if (Config.DEBUG) {
           _log.info(
               getClient()
                   + " requested item link for item which wasnt published! ID:"
                   + _objectId);
         }
       }
     }
   }
 }
  public boolean checkPassword(String password, boolean skipAuth) {
    password = cryptPassword(password);

    if (!password.equals(_password)) {
      _wrongAttempts++;
      if (_wrongAttempts < Config.SECOND_AUTH_MAX_ATTEMPTS) {
        _activeClient.sendPacket(
            new Ex2ndPasswordVerify(Ex2ndPasswordVerify.PASSWORD_WRONG, _wrongAttempts));
        insertWrongAttempt(_wrongAttempts);
      } else {
        LoginServerThread.getInstance()
            .sendTempBan(
                _activeClient.getAccountName(),
                _activeClient.getConnectionAddress().getHostAddress(),
                Config.SECOND_AUTH_BAN_TIME);
        LoginServerThread.getInstance()
            .sendMail(
                _activeClient.getAccountName(),
                "SATempBan",
                _activeClient.getConnectionAddress().getHostAddress(),
                Integer.toString(Config.SECOND_AUTH_MAX_ATTEMPTS),
                Long.toString(Config.SECOND_AUTH_BAN_TIME),
                Config.SECOND_AUTH_REC_LINK);
        _log.warning(
            _activeClient.getAccountName()
                + " - ("
                + _activeClient.getConnectionAddress().getHostAddress()
                + ") has inputted the wrong password "
                + _wrongAttempts
                + " times in row.");
        insertWrongAttempt(0);
        _activeClient.close(
            new Ex2ndPasswordVerify(
                Ex2ndPasswordVerify.PASSWORD_BAN, Config.SECOND_AUTH_MAX_ATTEMPTS));
      }
      return false;
    }
    if (!skipAuth) {
      _authed = true;
      _activeClient.sendPacket(
          new Ex2ndPasswordVerify(Ex2ndPasswordVerify.PASSWORD_OK, _wrongAttempts));
    }
    insertWrongAttempt(0);
    return true;
  }
  public boolean changePassword(String oldPassword, String newPassword) {
    if (!passwordExist()) {
      _log.warning(
          "[SecondaryPasswordAuth]" + _activeClient.getAccountName() + " forced changePassword");
      _activeClient.closeNow();
      return false;
    }

    if (!checkPassword(oldPassword, true)) return false;

    if (!validatePassword(newPassword)) {
      _activeClient.sendPacket(new Ex2ndPasswordAck(Ex2ndPasswordAck.WRONG_PATTERN));
      return false;
    }

    newPassword = cryptPassword(newPassword);

    Connection con = null;
    try {
      con = L2DatabaseFactory.getInstance().getConnection();
      PreparedStatement statement = con.prepareStatement(UPDATE_PASSWORD);
      statement.setString(1, newPassword);
      statement.setString(2, _activeClient.getAccountName());
      statement.setString(3, VAR_PWD);
      statement.execute();
      statement.close();
    } catch (Exception e) {
      _log.log(Level.SEVERE, "Error while reading password.", e);
      return false;
    } finally {
      L2DatabaseFactory.close(con);
    }
    _password = newPassword;
    _authed = false;
    return true;
  }
 public boolean insertWrongAttempt(int attempts) {
   Connection con = null;
   try {
     con = L2DatabaseFactory.getInstance().getConnection();
     PreparedStatement statement = con.prepareStatement(INSERT_ATTEMPT);
     statement.setString(1, _activeClient.getAccountName());
     statement.setString(2, VAR_WTE);
     statement.setString(3, Integer.toString(attempts));
     statement.setString(4, Integer.toString(attempts));
     statement.execute();
     statement.close();
   } catch (Exception e) {
     _log.log(Level.SEVERE, "Error while writing wrong attempts.", e);
     return false;
   } finally {
     L2DatabaseFactory.close(con);
   }
   return true;
 }
 public void openDialog() {
   if (passwordExist())
     _activeClient.sendPacket(new Ex2ndPasswordCheck(Ex2ndPasswordCheck.PASSWORD_PROMPT));
   else _activeClient.sendPacket(new Ex2ndPasswordCheck(Ex2ndPasswordCheck.PASSWORD_NEW));
 }
  private void initNewChar(L2GameClient client, L2PcInstance newChar) {
    if (Config.DEBUG) _log.fine("Character init start");

    L2World.getInstance().storeObject(newChar);

    L2PcTemplate template = newChar.getTemplate();

    newChar.addAdena("Init", Config.STARTING_ADENA, null, false);

    newChar.setXYZInvisible(template.spawnX, template.spawnY, template.spawnZ);
    newChar.setTitle("");

    if (Config.ENABLE_VITALITY)
      newChar.setVitalityPoints(
          Math.min(Config.STARTING_VITALITY_POINTS, PcStat.MAX_VITALITY_POINTS), true);

    if (Config.STARTING_LEVEL > 1) {
      newChar.getStat().addLevel((byte) (Config.STARTING_LEVEL - 1));
    }
    if (Config.STARTING_SP > 0) {
      newChar.getStat().addSp(Config.STARTING_SP);
    }

    L2ShortCut shortcut;
    // add attack shortcut
    shortcut = new L2ShortCut(0, 0, 3, 2, 0, 1);
    newChar.registerShortCut(shortcut);
    // add take shortcut
    shortcut = new L2ShortCut(3, 0, 3, 5, 0, 1);
    newChar.registerShortCut(shortcut);
    // add sit shortcut
    shortcut = new L2ShortCut(10, 0, 3, 0, 0, 1);
    newChar.registerShortCut(shortcut);

    for (PcTemplateItem ia : template.getItems()) {
      L2ItemInstance item =
          newChar.getInventory().addItem("Init", ia.getItemId(), ia.getAmount(), newChar, null);

      if (item == null) {
        _log.warning(
            "Could not create item during char creation: itemId "
                + ia.getItemId()
                + ", amount "
                + ia.getAmount()
                + ".");
        continue;
      }

      // add tutbook shortcut
      if (item.getItemId() == 5588) {
        shortcut = new L2ShortCut(11, 0, 1, item.getObjectId(), 0, 1);
        newChar.registerShortCut(shortcut);
      }

      if (item.isEquipable() && ia.isEquipped()) {
        newChar.getInventory().equipItem(item);
      }
    }

    for (L2SkillLearn skill :
        SkillTreesData.getInstance()
            .getAvailableSkills(newChar, newChar.getClassId(), false, true)) {
      newChar.addSkill(
          SkillTable.getInstance().getInfo(skill.getSkillId(), skill.getSkillLevel()), true);
      if (skill.getSkillId() == 1001 || skill.getSkillId() == 1177) {
        shortcut = new L2ShortCut(1, 0, 2, skill.getSkillId(), skill.getSkillLevel(), 1);
        newChar.registerShortCut(shortcut);
      }
      if (skill.getSkillId() == 1216) {
        shortcut = new L2ShortCut(10, 0, 2, skill.getSkillId(), skill.getSkillLevel(), 1);
        newChar.registerShortCut(shortcut);
      }
      if (Config.DEBUG)
        _log.fine("Adding starter skill:" + skill.getSkillId() + " / " + skill.getSkillLevel());
    }

    if (!Config.DISABLE_TUTORIAL) startTutorialQuest(newChar);

    newChar.setOnlineStatus(true, false);
    newChar.deleteMe();

    CharSelectionInfo cl =
        new CharSelectionInfo(client.getAccountName(), client.getSessionId().playOkID1);
    client.getConnection().sendPacket(cl);
    client.setCharSelection(cl.getCharInfo());

    if (Config.DEBUG) _log.fine("Character init end");
  }