Вот часть этого кода, вот мне именно его нужно отредактировать, сама проблема с L2DatabaseFactory под терлионов, у них это просто DatabaseFactory
+ else if (_command.equalsIgnoreCase("pkrecovery"))
+ {
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ html.replace("%question%", getPassKeyQuestion(activeChar));
+ activeChar.sendPacket(html);
+ html = null;
+ }
+ else if (_command.startsWith("pkset"))
+ {
+ StringTokenizer st = new StringTokenizer(_command, "]");
+
+ if (st.countTokens() != 5)
+ {
+ activeChar.sendMessage("Вы ввели не все данные!");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+
+ String newCommand = st.nextToken();
+ String pass1 = st.nextToken();
+ pass1 = pass1.substring(1, pass1.length() - 1);
+ String pass2 = st.nextToken();
+ pass2 = pass2.substring(1, pass2.length() - 1);
+ String question = st.nextToken();
+ question = question.substring(1, question.length() - 1);
+ String answer = st.nextToken();
+ answer = answer.substring(1, answer.length());
+
+ if (pass1 == null || pass2 == null || question == null || answer == null)
+ {
+ activeChar.sendMessage("Ошибка при вводе");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+
+ if (!pass1.equals(pass2))
+ {
+ activeChar.sendMessage("Вы ввели разные пароли");
+ activeChar.sendMessage("pass1 = " + pass1);
+ activeChar.sendMessage("pass2 = " + pass2);
+ activeChar.sendMessage("Question = " + question);
+ activeChar.sendMessage("answer = " + answer);
+
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/setup.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+ insertPassKeyInformation(activeChar, pass1, question, answer);
+
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ activeChar.sendPacket(html);
+ html = null;
+ }
+ else if (_command.startsWith("pklogin"))
+ {
+ StringTokenizer st = new StringTokenizer(_command, " ");
+ if (st.countTokens() != 2)
+ {
+ activeChar.sendMessage("Вы допустили ошибку при вводе пароля!");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+ String newCommand = st.nextToken();
+ String pass = st.nextToken();
+
+ Connection con = null;
+ String query = "SELECT passkey FROM passkey WHERE obj_Id = ?";
+ String pwdindb = "error";
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement ps = con.prepareStatement(query);
+ ps.setInt(1, activeChar.getObjectId());
+ ResultSet rs = ps.executeQuery();
+
+ while (rs.next())
+ pwdindb = rs.getString(1);
+
+ rs.close();
+ ps.close();
+ ps = null;
+ rs = null;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ con = null;
+ }
+
+ if (pwdindb.equals(encodePass(pass)))
+ {
+ activeChar.setIsParalyzed(false);
+ }
+ else
+ {
+ activeChar.sendMessage("Вы ввели не правильный пароль");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+ }
+ else if (_command.startsWith("pkrec"))
+ {
+ StringTokenizer st = new StringTokenizer(_command, " ");
+ if (st.countTokens() != 4)
+ {
+ activeChar.sendMessage("Вы допустили ошибку при вводе данных!");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ html.replace("%question%", getPassKeyQuestion(activeChar));
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+
+ String newCommand = st.nextToken();
+ String answer = st.nextToken();
+ String pass1 = st.nextToken();
+ String pass2 = st.nextToken();
+
+ if (!pass1.equals(pass2))
+ {
+ activeChar.sendMessage("Вы ввели разные пароли");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ html.replace("%question%", getPassKeyQuestion(activeChar));
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+
+ Connection con = null;
+ String query = "SELECT answer FROM passkey WHERE obj_Id = ?";
+ String anwindb = "error";
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement ps = con.prepareStatement(query);
+ ps.setInt(1, activeChar.getObjectId());
+ ResultSet rs = ps.executeQuery();
+
+ while (rs.next())
+ anwindb = rs.getString(1);
+
+ rs.close();
+ ps.close();
+ ps = null;
+ rs = null;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ con = null;
+ }
+
+ if (anwindb.equals(answer))
+ {
+ updPassKey(activeChar, pass1);
+ activeChar.sendMessage("Вы успешно изменили пароль.");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/login.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ activeChar.sendPacket(html);
+ html = null;
+ }
+ else
+ {
+ activeChar.sendMessage("Вы ввели неправильный ответ на свой вопрос");
+ String htmContent = HtmCache.getInstance().getHtm("data/html/passkey/recovery.htm");
+ NpcHtmlMessage html = new NpcHtmlMessage(1);
+ html.setHtml(htmContent);
+ html.replace("%question%", getPassKeyQuestion(activeChar));
+ activeChar.sendPacket(html);
+ html = null;
+ return;
+ }
+
+ }
}
catch(Exception e)
@@ -409,4 +642,171 @@
// }
}
+
+ private void updPassKey(L2PcInstance player, String pass)
+ {
+ Connection con = null;
+ String query = "UPDATE passkey SET passkey = ? WHERE obj_Id = ?";
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement st = con.prepareStatement(query);
+ st.setString(1, encodePass(pass));
+ st.setInt(2, player.getObjectId());
+ st.executeUpdate();
+ st.close();
+ st = null;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ con = null;
+ }
+ }
+
+ private String encodePass(String password)
+ {
+ String pass = "error";
+ try
+ {
+ MessageDigest md = MessageDigest.getInstance("SHA");
+ byte[] raw = password.getBytes("UTF-8");
+ byte[] hash = md.digest(raw);
+ pass = Base64.encodeBytes(hash);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ return pass;
+ }
+
+ private void insertPassKeyInformation(L2PcInstance player, String pass, String question, String answer)
+ {
+ Connection con = null;
+ String query = "INSERT INTO passkey (obj_Id, passkey, question, answer) VALUES (?,?,?,?)";
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement st = con.prepareStatement(query);
+ st.setInt(1, player.getObjectId());
+ st.setString(2, encodePass(pass));
+ st.setString(3, question);
+ st.setString(4, answer);
+ st.execute();
+ st.close();
+ st = null;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ con = null;
+ }
+ }
+
+ private String getPassKeyQuestion(L2PcInstance player)
+ {
+ Connection con = null;
+ String query = "SELECT question FROM passkey WHERE obj_Id = ?";
+ String question = "error";
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement st = con.prepareStatement(query);
+ st.setInt(1, player.getObjectId());
+ ResultSet rs = st.executeQuery();
+
+ while (rs.next())
+ question = rs.getString(1);
+
+ rs.close();
+ st.close();
+ st = null;
+ rs = null;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ con = null;
+ }
+
+ return question;
+ }
+
+ public static boolean getPassKeyEnable(L2PcInstance player)
+ {
+ Connection con = null;
+ String query = "SELECT COUNT(*) FROM passkey WHERE obj_Id = ?";
+ int count = 0;
+
+ try
+ {
+ con = L2DatabaseFactory.getInstance().getConnection();
+ PreparedStatement st = con.prepareStatement(query);
+ st.setInt(1, player.getObjectId());
+ ResultSet rs = st.executeQuery();
+
+ while (rs.next())
+ count = rs.getInt(1);
+
+ rs.close();
+ st.close();
+ st = null;
+ rs = null;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ finally
+ {
+ try
+ {
+ con.close();
+ }
+ catch (SQLException e)
+ {
+ e.printStackTrace();
+ }
+ con = null;
+ }
+
+ if (count == 1)
+ return true;
+ else
+ return false;
+ }