ChangePassword.java 3.1 KB

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