ChangePassword.java 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.voicedcommandhandlers;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Level;
  22. import com.l2jserver.gameserver.LoginServerThread;
  23. import com.l2jserver.gameserver.cache.HtmCache;
  24. import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  27. /**
  28. * @author Nik
  29. */
  30. public class ChangePassword implements IVoicedCommandHandler
  31. {
  32. private static final String[] _voicedCommands =
  33. {
  34. "changepassword"
  35. };
  36. @Override
  37. public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
  38. {
  39. if (target != null)
  40. {
  41. final StringTokenizer st = new StringTokenizer(target);
  42. try
  43. {
  44. String curpass = null, newpass = null, repeatnewpass = null;
  45. if (st.hasMoreTokens())
  46. {
  47. curpass = st.nextToken();
  48. }
  49. if (st.hasMoreTokens())
  50. {
  51. newpass = st.nextToken();
  52. }
  53. if (st.hasMoreTokens())
  54. {
  55. repeatnewpass = st.nextToken();
  56. }
  57. if (!((curpass == null) || (newpass == null) || (repeatnewpass == null)))
  58. {
  59. if (!newpass.equals(repeatnewpass))
  60. {
  61. activeChar.sendMessage("The new password doesn't match with the repeated one!");
  62. return false;
  63. }
  64. if (newpass.length() < 3)
  65. {
  66. activeChar.sendMessage("The new password is shorter than 3 chars! Please try with a longer one.");
  67. return false;
  68. }
  69. if (newpass.length() > 30)
  70. {
  71. activeChar.sendMessage("The new password is longer than 30 chars! Please try with a shorter one.");
  72. return false;
  73. }
  74. LoginServerThread.getInstance().sendChangePassword(activeChar.getAccountName(), activeChar.getName(), curpass, newpass);
  75. }
  76. else
  77. {
  78. activeChar.sendMessage("Invalid password data! You have to fill all boxes.");
  79. return false;
  80. }
  81. }
  82. catch (Exception e)
  83. {
  84. activeChar.sendMessage("A problem occured while changing password!");
  85. _log.log(Level.WARNING, "", e);
  86. }
  87. }
  88. else
  89. {
  90. // showHTML(activeChar);
  91. String html = HtmCache.getInstance().getHtm("en", "data/html/mods/ChangePassword.htm");
  92. if (html == null)
  93. {
  94. html = "<html><body><br><br><center><font color=LEVEL>404:</font> File Not Found</center></body></html>";
  95. }
  96. activeChar.sendPacket(new NpcHtmlMessage(html));
  97. return true;
  98. }
  99. return true;
  100. }
  101. @Override
  102. public String[] getVoicedCommandList()
  103. {
  104. return _voicedCommands;
  105. }
  106. }