Noticias:

Debes de estar registrado para poder ver el contenido indicado. Registrate o Conectate

Menú Principal

[Comando] .email (Cambiar Email)

Iniciado por Swarlog, Ago 05, 2022, 01:28 AM

Tema anterior - Siguiente tema

Swarlog


Simple comando con el que poder editar o añadir/vincular el correo a vuestra cuenta, para recuperacion de contraseñas.

CitarCORE:

Index: dist/game/config/L2JMods.properties
===================================================================
--- dist/game/config/L2JMods.properties (revision 20855)
+++ dist/game/config/L2JMods.properties (working copy)
@@ -507,4 +507,11 @@
 
 # Enables .changepassword voiced command which allows the players to change their account's password ingame.
 # Default: False
-AllowChangePassword = False
\ No newline at end of file
+AllowChangePassword = False
+
+# ---------------------------------------------------------------------------
+# Email Change
+# ---------------------------------------------------------------------------
+# Enables .email voiced command which allows the players to change their account's email ingame.
+# Default: False
+AllowChangeEmail = False
Index: src/main/java/com/l2jserver/Config.java
===================================================================
--- src/main/java/com/l2jserver/Config.java (revision 20855)
+++ src/main/java/com/l2jserver/Config.java (working copy)
@@ -773,6 +773,7 @@
  public static int L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP;
  public static int L2JMOD_DUALBOX_CHECK_MAX_L2EVENT_PARTICIPANTS_PER_IP;
  public static Map<Integer, Integer> L2JMOD_DUALBOX_CHECK_WHITELIST;
+ public static boolean L2JMOD_ALLOW_CHANGE_EMAIL;
  public static boolean L2JMOD_ALLOW_CHANGE_PASSWORD;
  // --------------------------------------------------
  // NPC Settings
@@ -2506,6 +2507,8 @@
  }
  }
  }
+
+ L2JMOD_ALLOW_CHANGE_EMAIL = L2JModSettings.getBoolean("AllowChangeEmail", false);
  L2JMOD_ALLOW_CHANGE_PASSWORD = L2JModSettings.getBoolean("AllowChangePassword", false);
 
  // Load PvP L2Properties file (if exists)
Index: src/main/java/com/l2jserver/gameserver/LoginServerThread.java
===================================================================
--- src/main/java/com/l2jserver/gameserver/LoginServerThread.java (revision 20855)
+++ src/main/java/com/l2jserver/gameserver/LoginServerThread.java (working copy)
@@ -54,6 +54,7 @@
 import com.l2jserver.gameserver.network.gameserverpackets.AuthRequest;
 import com.l2jserver.gameserver.network.gameserverpackets.BlowFishKey;
 import com.l2jserver.gameserver.network.gameserverpackets.ChangeAccessLevel;
+import com.l2jserver.gameserver.network.gameserverpackets.ChangeEmail;
 import com.l2jserver.gameserver.network.gameserverpackets.ChangePassword;
 import com.l2jserver.gameserver.network.gameserverpackets.PlayerAuthRequest;
 import com.l2jserver.gameserver.network.gameserverpackets.PlayerInGame;
@@ -64,6 +65,7 @@
 import com.l2jserver.gameserver.network.gameserverpackets.ServerStatus;
 import com.l2jserver.gameserver.network.gameserverpackets.TempBan;
 import com.l2jserver.gameserver.network.loginserverpackets.AuthResponse;
+import com.l2jserver.gameserver.network.loginserverpackets.ChangeEmailResponse;
 import com.l2jserver.gameserver.network.loginserverpackets.ChangePasswordResponse;
 import com.l2jserver.gameserver.network.loginserverpackets.InitLS;
 import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
@@ -336,6 +338,9 @@
  case 0x06:
  new ChangePasswordResponse(incoming);
  break;
+ case 0x07:
+ new ChangeEmailResponse(incoming);
+ break;
  }
  }
  }
@@ -690,6 +695,25 @@
  }
 
  /**
+ * Send change email.
+ * @param accountName the account name
+ * @param charName the char name
+ * @param oldEmail the old pass
+ * @param newEmail the new pass
+ */
+ public void sendChangeEmail(String accountName, String charName, String oldEmail, String newEmail)
+ {
+ ChangeEmail ce = new ChangeEmail(accountName, charName, oldEmail, newEmail);
+ try
+ {
+ sendPacket(ce);
+ }
+ catch (IOException e)
+ {
+ }
+ }
+
+ /**
  * Gets the status string.
  * @return the status string
  */
Index: src/main/java/com/l2jserver/gameserver/network/gameserverpackets/ChangeEmail.java
===================================================================
--- src/main/java/com/l2jserver/gameserver/network/gameserverpackets/ChangeEmail.java (revision 0)
+++ src/main/java/com/l2jserver/gameserver/network/gameserverpackets/ChangeEmail.java (working copy)
@@ -0,0 +1,40 @@
+/*
+ * 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 com.l2jserver.gameserver.network.gameserverpackets;
+
+import com.l2jserver.util.network.BaseSendablePacket;
+
+/**
+ * @author UnAfraid, U3Games
+ */
+
+public class ChangeEmail extends BaseSendablePacket
+{
+ public ChangeEmail(String accountName, String characterName, String oldEmail, String newEmail)
+ {
+ writeC(0x0B);
+ writeS(accountName);
+ writeS(characterName);
+ writeS(oldEmail);
+ writeS(newEmail);
+ }
+
+ @Override
+ public byte[] getContent()
+ {
+ return getBytes();
+ }
+}
Index: src/main/java/com/l2jserver/gameserver/network/loginserverpackets/ChangeEmailResponse.java
===================================================================
--- src/main/java/com/l2jserver/gameserver/network/loginserverpackets/ChangeEmailResponse.java (revision 0)
+++ src/main/java/com/l2jserver/gameserver/network/loginserverpackets/ChangeEmailResponse.java (working copy)
@@ -0,0 +1,41 @@
+/*
+ * 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 com.l2jserver.gameserver.network.loginserverpackets;
+
+import com.l2jserver.gameserver.model.L2World;
+import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
+import com.l2jserver.util.network.BaseRecievePacket;
+
+/**
+ * @author Nik, U3Games
+ */
+
+public class ChangeEmailResponse extends BaseRecievePacket
+{
+ public ChangeEmailResponse(byte[] decrypt)
+ {
+ super(decrypt);
+ // boolean isSuccessful = readC() > 0;
+ String character = readS();
+ String msgToSend = readS();
+
+ L2PcInstance player = L2World.getInstance().getPlayer(character);
+ if (player != null)
+ {
+ player.sendMessage(msgToSend);
+ }
+ }
+}
\ No newline at end of file
Index: src/main/java/com/l2jserver/loginserver/GameServerThread.java
===================================================================
--- src/main/java/com/l2jserver/loginserver/GameServerThread.java (revision 20855)
+++ src/main/java/com/l2jserver/loginserver/GameServerThread.java (working copy)
@@ -34,6 +34,7 @@
 import com.l2jserver.loginserver.GameServerTable.GameServerInfo;
 import com.l2jserver.loginserver.network.L2JGameServerPacketHandler;
 import com.l2jserver.loginserver.network.L2JGameServerPacketHandler.GameServerState;
+import com.l2jserver.loginserver.network.loginserverpackets.ChangeEmailResponse;
 import com.l2jserver.loginserver.network.loginserverpackets.ChangePasswordResponse;
 import com.l2jserver.loginserver.network.loginserverpackets.InitLS;
 import com.l2jserver.loginserver.network.loginserverpackets.KickPlayer;
@@ -282,6 +283,11 @@
  sendPacket(new ChangePasswordResponse(successful, characterName, msgToSend));
  }
 
+ public void ChangeEmailResponse(byte successful, String characterName, String msgToSend)
+ {
+ sendPacket(new ChangeEmailResponse(successful, characterName, msgToSend));
+ }
+
  /**
  * @param hosts The gameHost to set.
  */
Index: src/main/java/com/l2jserver/loginserver/network/gameserverpackets/ChangeEmail.java
===================================================================
--- src/main/java/com/l2jserver/loginserver/network/gameserverpackets/ChangeEmail.java (revision 0)
+++ src/main/java/com/l2jserver/loginserver/network/gameserverpackets/ChangeEmail.java (working copy)
@@ -0,0 +1,130 @@
+/*
+ * 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 com.l2jserver.loginserver.network.gameserverpackets;
+
+import java.security.MessageDigest;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.util.Base64;
+import java.util.Collection;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import com.l2jserver.commons.database.pool.impl.ConnectionFactory;
+import com.l2jserver.loginserver.GameServerTable;
+import com.l2jserver.loginserver.GameServerTable.GameServerInfo;
+import com.l2jserver.loginserver.GameServerThread;
+import com.l2jserver.util.network.BaseRecievePacket;
+
+/**
+ * @author Nik, U3Games
+ */
+
+public class ChangeEmail extends BaseRecievePacket
+{
+ protected static Logger _log = Logger.getLogger(ChangeEmail.class.getName());
+ private static GameServerThread gst = null;
+
+ public ChangeEmail(byte[] decrypt)
+ {
+ super(decrypt);
+
+ String accountName = readS();
+ String characterName = readS();
+ String curEmail = readS();
+ String newEmail = readS();
+
+ // get the GameServerThread
+ Collection<GameServerInfo> serverList = GameServerTable.getInstance().getRegisteredGameServers().values();
+ for (GameServerInfo gsi : serverList)
+ {
+ if ((gsi.getGameServerThread() != null) && gsi.getGameServerThread().hasAccountOnGameServer(accountName))
+ {
+ gst = gsi.getGameServerThread();
+ }
+ }
+
+ if (gst == null)
+ {
+ return;
+ }
+
+ if ((curEmail == null) || (newEmail == null))
+ {
+ gst.ChangeEmailResponse((byte) 0, characterName, "Invalid email data! Try again.");
+ }
+ else
+ {
+ try
+ {
+ MessageDigest md = MessageDigest.getInstance("SHA");
+ byte[] raw = curEmail.getBytes("UTF-8");
+ raw = md.digest(raw);
+ byte[] _oldEmail = raw;
+ String _email = null;
+ int _newEmail = 0;
+
+ // SQL connection
+ try (Connection con = ConnectionFactory.getInstance().getConnection();
+ PreparedStatement ps = con.prepareStatement("SELECT email FROM accounts WHERE login=?"))
+ {
+ ps.setString(1, accountName);
+ try (ResultSet rs = ps.executeQuery())
+ {
+ if (rs.next())
+ {
+ _email = rs.getString("email");
+ }
+ }
+ }
+
+ if (curEmail.equals(_email))
+ {
+ byte[] email = newEmail.getBytes("UTF-8");
+ email = md.digest(email);
+
+ // SQL connection
+ try (Connection con = ConnectionFactory.getInstance().getConnection();
+ PreparedStatement ps = con.prepareStatement("UPDATE accounts SET email=? WHERE login=?"))
+ {
+ ps.setString(1, Base64.getEncoder().encodeToString(email));
+ ps.setString(2, accountName);
+ _newEmail = ps.executeUpdate();
+ }
+
+ _log.log(Level.INFO, "The email for account " + accountName + " has been changed from " + _oldEmail + " to " + email);
+ if (_newEmail > 0)
+ {
+ gst.ChangeEmailResponse((byte) 1, characterName, "You have successfully changed your email!");
+ }
+ else
+ {
+ gst.ChangeEmailResponse((byte) 0, characterName, "The email change was unsuccessful!");
+ }
+ }
+ else
+ {
+ gst.ChangeEmailResponse((byte) 0, characterName, "The typed current email doesn't match with your current one.");
+ }
+ }
+ catch (Exception e)
+ {
+ _log.warning("Error while changing email for account " + accountName + " requested by player " + characterName + "! " + e);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: src/main/java/com/l2jserver/loginserver/network/loginserverpackets/ChangeEmailResponse.java
===================================================================
--- src/main/java/com/l2jserver/loginserver/network/loginserverpackets/ChangeEmailResponse.java (revision 0)
+++ src/main/java/com/l2jserver/loginserver/network/loginserverpackets/ChangeEmailResponse.java (working copy)
@@ -0,0 +1,39 @@
+/*
+ * 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 com.l2jserver.loginserver.network.loginserverpackets;
+
+import com.l2jserver.util.network.BaseSendablePacket;
+
+/**
+ * @author Nik, U3Games
+ */
+
+public class ChangeEmailResponse extends BaseSendablePacket
+{
+ public ChangeEmailResponse(byte successful, String characterName, String msgToSend)
+ {
+ writeC(0x07);
+ // writeC(successful); //0 false, 1 true
+ writeS(characterName);
+ writeS(msgToSend);
+ }
+
+ @Override
+ public byte[] getContent()
+ {
+ return getBytes();
+ }
+}
\ No newline at end of file

CitarDATA:

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;
+ }
+}