Skip to content

Instantly share code, notes, and snippets.

@u3games
Last active November 21, 2015 15:11
Show Gist options
  • Save u3games/00d0ebdd8c31ee5b3f6c to your computer and use it in GitHub Desktop.
Save u3games/00d0ebdd8c31ee5b3f6c to your computer and use it in GitHub Desktop.
L2JServer - Add/Change email system - Data
Index: game/data/html/mods/ChangeEmail.htm
===================================================================
--- game/data/html/mods/ChangeEmail.htm (revision 0)
+++ game/data/html/mods/ChangeEmail.htm (working copy)
@@ -0,0 +1,10 @@
+<html><body>
+<center>
+<td>
+<tr>Current Email:</tr><tr><edit type="email" var="oldemail" width=150></tr><br>
+<tr>New Email</tr><tr><edit type="email" var="newemail" width=150></tr><br>
+<tr>Repeat New Email</tr><tr><edit type="email" var="repeatnewemail" width=150></tr><br>
+<td>
+<button value="Change Email" action="bypass -h voice .email $oldemail $newemail $repeatnewemail" width=160 height=25 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df">
+</center>
+</body></html>
Index: game/data/html/mods/NewEmail.htm
===================================================================
--- game/data/html/mods/NewEmail.htm (revision 0)
+++ game/data/html/mods/NewEmail.htm (working copy)
@@ -0,0 +1,9 @@
+<html><body>
+<center>
+<td>
+<tr>New Email</tr><tr><edit type="email" var="newemail" width=150></tr><br>
+<tr>Repeat New Email</tr><tr><edit type="email" var="repeatnewemail" width=150></tr><br>
+<td>
+<button value="Change Email" action="bypass -h voice .email $newemail $repeatnewemail" width=160 height=25 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df">
+</center>
+</body></html>
Index: game/data/scripts/handlers/MasterHandler.java
===================================================================
--- game/data/scripts/handlers/MasterHandler.java (revision 39173)
+++ game/data/scripts/handlers/MasterHandler.java (working copy)
@@ -272,6 +272,7 @@
import handlers.usercommandhandlers.Time;
import handlers.usercommandhandlers.Unstuck;
import handlers.voicedcommandhandlers.Banking;
+import handlers.voicedcommandhandlers.ChangeEmail;
import handlers.voicedcommandhandlers.ChangePassword;
import handlers.voicedcommandhandlers.ChatAdmin;
import handlers.voicedcommandhandlers.Debug;
@@ -532,6 +533,7 @@
(Config.L2JMOD_CHAT_ADMIN ? ChatAdmin.class : null),
(Config.L2JMOD_MULTILANG_ENABLE && Config.L2JMOD_MULTILANG_VOICED_ALLOW ? Lang.class : null),
(Config.L2JMOD_DEBUG_VOICE_COMMAND ? Debug.class : null),
+ (Config.L2JMOD_ALLOW_CHANGE_EMAIL ? ChangeEmail.class : null),
(Config.L2JMOD_ALLOW_CHANGE_PASSWORD ? ChangePassword.class : null),
},
{
Index: game/data/scripts/handlers/voicedcommandhandlers/ChangeEmail.java
===================================================================
--- game/data/scripts/handlers/voicedcommandhandlers/ChangeEmail.java (revision 0)
+++ game/data/scripts/handlers/voicedcommandhandlers/ChangeEmail.java (working copy)
@@ -0,0 +1,210 @@
+/*
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later
+ * version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package handlers.voicedcommandhandlers;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.StringTokenizer;
+import java.util.logging.Level;
+
+import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
+import com.l2jserver.gameserver.LoginServerThread;
+import com.l2jserver.gameserver.cache.HtmCache;
+import com.l2jserver.gameserver.handler.IVoicedCommandHandler;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
+
+/**
+ * @author Nik, U3Games
+ */
+
+public class ChangeEmail implements IVoicedCommandHandler
+{
+ private boolean _firstEmail = false;
+ private static String _email = null;
+ private static String _html = null;
+
+ private static final String[] _voicedCommands =
+ {
+ "email"
+ };
+
+ @Override
+ public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+ {
+ if (target != null)
+ {
+ final StringTokenizer st = new StringTokenizer(target);
+
+ if (_firstEmail)
+ {
+ try
+ {
+ String _newEmail = null, _repeatNewEmail = null;
+ if (st.hasMoreTokens())
+ {
+ _newEmail = st.nextToken();
+ }
+ if (st.hasMoreTokens())
+ {
+ _repeatNewEmail = st.nextToken();
+ }
+
+ if (!((_newEmail == null) || (_repeatNewEmail == null)))
+ {
+ if (!_newEmail.equals(_repeatNewEmail))
+ {
+ activeChar.sendMessage("The new email doesn't match with the repeated one!");
+ return false;
+ }
+ if (_newEmail.length() < 7)
+ {
+ activeChar.sendMessage("The new email is shorter than 7 chars! Please try with a longer one.");
+ return false;
+ }
+ if (_newEmail.length() > 255)
+ {
+ activeChar.sendMessage("The new email is longer than 255 chars! Please try with a shorter one.");
+ return false;
+ }
+
+ LoginServerThread.getInstance().sendChangeEmail(activeChar.getAccountName(), activeChar.getName(), null, _newEmail);
+ }
+ else
+ {
+ activeChar.sendMessage("Invalid email data! You have to fill all boxes.");
+ return false;
+ }
+ }
+ catch (Exception e)
+ {
+ activeChar.sendMessage("A problem occured while changing email!");
+ _log.log(Level.WARNING, "", e);
+ }
+ }
+ else
+ {
+ try
+ {
+ String _curEmail = null, _newEmail = null, _repeatNewEmail = null;
+ if (st.hasMoreTokens())
+ {
+ _curEmail = st.nextToken();
+ }
+ if (st.hasMoreTokens())
+ {
+ _newEmail = st.nextToken();
+ }
+ if (st.hasMoreTokens())
+ {
+ _repeatNewEmail = st.nextToken();
+ }
+
+ if (!((_curEmail == null) || (_newEmail == null) || (_repeatNewEmail == null)))
+ {
+ if (!_newEmail.equals(_repeatNewEmail))
+ {
+ activeChar.sendMessage("The new email doesn't match with the repeated one!");
+ return false;
+ }
+ if (_newEmail.length() < 7)
+ {
+ activeChar.sendMessage("The new email is shorter than 7 chars! Please try with a longer one.");
+ return false;
+ }
+ if (_newEmail.length() > 255)
+ {
+ activeChar.sendMessage("The new email is longer than 255 chars! Please try with a shorter one.");
+ return false;
+ }
+
+ _firstEmail = false;
+ LoginServerThread.getInstance().sendChangeEmail(activeChar.getAccountName(), activeChar.getName(), _curEmail, _newEmail);
+ }
+ else
+ {
+ activeChar.sendMessage("Invalid email data! You have to fill all boxes.");
+ return false;
+ }
+ }
+ catch (Exception e)
+ {
+ activeChar.sendMessage("A problem occured while changing email!");
+ _log.log(Level.WARNING, "", e);
+ }
+ }
+ }
+ else
+ {
+ // Load Email
+ loadEmail(activeChar.getObjectId());
+
+ // Check
+ if (_email == null)
+ {
+ _firstEmail = true;
+ _html = HtmCache.getInstance().getHtm("en", "data/html/mods/NewEmail.htm");
+ }
+ else
+ {
+ _html = HtmCache.getInstance().getHtm("en", "data/html/mods/ChangeEmail.htm");
+ }
+
+ if (_html == null)
+ {
+ _html = "<html><body><br><br><center><font color=LEVEL>404:</font> File Not Found</center></body></html>";
+ }
+
+ activeChar.sendPacket(new NpcHtmlMessage(_html));
+ return true;
+ }
+ return true;
+ }
+
+ /**
+ * @param _objectId
+ * @return
+ */
+ public String loadEmail(int _objectId)
+ {
+ try (Connection con = ConnectionFactory.getInstance().getConnection();
+ PreparedStatement ps = con.prepareStatement("SELECT email FROM accounts WHERE login=?"))
+ {
+ ps.setInt(1, _objectId);
+ try (ResultSet rs = ps.executeQuery())
+ {
+ while (rs.next())
+ {
+ _email = rs.getString(1);
+ }
+ }
+ }
+ catch (SQLException e)
+ {
+ _log.log(Level.WARNING, "A problem occured while load email: ", e);
+ }
+
+ return _email;
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return _voicedCommands;
+ }
+}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment