Noticias:

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

Menú Principal

[Comando] .email

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

Tema anterior - Siguiente tema

Swarlog

Lo acabo de crear ahora mismo, he utilizado de base el de cambiar password. Aun no lo he probado, pero creo que esta todo correctamente. Lo que sea me avisen, espero que les sea de utilidad.

Se trata de un comando para cambiar de correo electronico de vuestra cuenta, ponen en chat .email y listo! Ya habia varios sistemas antiguos, este lo he adaptado a la última versión de l2j-server High Five. Un saludo ^^

CitarCORE:

### Eclipse Workspace Patch 1.0
#P L2Dev_ChangeEmail_Core
Index: dist/game/config/L2JMods.properties
===================================================================
--- dist/game/config/L2JMods.properties (revision 13050)
+++ dist/game/config/L2JMods.properties (working copy)
@@ -492,7 +492,17 @@
 # Default: 127.0.0.1,0 (no limits from localhost)
 DualboxCheckWhitelist = 127.0.0.1,0
 
+
 # ---------------------------------------------------------------------------
+# Email Change
+# ---------------------------------------------------------------------------
+
+# Enables .email voiced command which allows the players to change their account's email ingame.
+# Requires custom modification in sql --> Data\dist\sql\login\custom\email.sql
+# Default: False
+AllowChangeEmail = False
+
+# ---------------------------------------------------------------------------
 # Password Change
 # ---------------------------------------------------------------------------
 
Index: java/com/l2jserver/gameserver/network/loginserverpackets/ChangeEmailResponse.java
===================================================================
--- java/com/l2jserver/gameserver/network/loginserverpackets/ChangeEmailResponse.java (revision 0)
+++ java/com/l2jserver/gameserver/network/loginserverpackets/ChangeEmailResponse.java (working copy)
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+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: java/com/l2jserver/loginserver/network/gameserverpackets/ChangeEmail.java
===================================================================
--- java/com/l2jserver/loginserver/network/gameserverpackets/ChangeEmail.java (revision 0)
+++ java/com/l2jserver/loginserver/network/gameserverpackets/ChangeEmail.java (working copy)
@@ -0,0 +1,127 @@
+/*
+ * 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.L2DatabaseFactory;
+import com.l2jserver.loginserver.GameServerTable;
+import com.l2jserver.loginserver.GameServerTable.GameServerInfo;
+import com.l2jserver.loginserver.GameServerThread;
+import com.l2jserver.util.network.BaseRecievePacket;
+
+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 = L2DatabaseFactory.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 = L2DatabaseFactory.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: java/com/l2jserver/gameserver/LoginServerThread.java
===================================================================
--- java/com/l2jserver/gameserver/LoginServerThread.java (revision 13050)
+++ 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;
@@ -345,6 +347,9 @@
  case 0x06:
  new ChangePasswordResponse(incoming);
  break;
+ case 0x07:
+ new ChangeEmailResponse(incoming);
+ break;
  }
  }
  }
@@ -704,6 +709,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: java/com/l2jserver/loginserver/GameServerThread.java
===================================================================
--- java/com/l2jserver/loginserver/GameServerThread.java (revision 13050)
+++ 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: java/com/l2jserver/gameserver/network/gameserverpackets/ChangeEmail.java
===================================================================
--- java/com/l2jserver/gameserver/network/gameserverpackets/ChangeEmail.java (revision 0)
+++ java/com/l2jserver/gameserver/network/gameserverpackets/ChangeEmail.java (working copy)
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+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: java/com/l2jserver/loginserver/network/loginserverpackets/ChangeEmailResponse.java
===================================================================
--- java/com/l2jserver/loginserver/network/loginserverpackets/ChangeEmailResponse.java (revision 0)
+++ java/com/l2jserver/loginserver/network/loginserverpackets/ChangeEmailResponse.java (working copy)
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+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
Index: java/com/l2jserver/Config.java
===================================================================
--- java/com/l2jserver/Config.java (revision 13050)
+++ java/com/l2jserver/Config.java (working copy)
@@ -770,6 +770,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
@@ -2500,6 +2501,8 @@
  }
  }
  }
+
+ L2JMOD_ALLOW_CHANGE_EMAIL = L2JModSettings.getBoolean("AllowChangeEmail", false);
  L2JMOD_ALLOW_CHANGE_PASSWORD = L2JModSettings.getBoolean("AllowChangePassword", false);
 
  // Load PvP L2Properties file (if exists)

CitarDATA:

### Eclipse Workspace Patch 1.0
#P L2Dev_ChangeEmail_Data
Index: dist/sql/login/custom/email.sql
===================================================================
--- dist/sql/login/custom/email.sql (revision 0)
+++ dist/sql/login/custom/email.sql (working copy)
@@ -0,0 +1 @@
+ALTER TABLE `accounts` ADD `email` VARCHAR(255) NULL DEFAULT NULL ;
\ No newline at end of file
Index: dist/game/data/html/mods/ChangeEmail.htm
===================================================================
--- dist/game/data/html/mods/ChangeEmail.htm (revision 0)
+++ dist/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: dist/game/data/scripts/handlers/voicedcommandhandlers/ChangeEmail.java
===================================================================
--- dist/game/data/scripts/handlers/voicedcommandhandlers/ChangeEmail.java (revision 0)
+++ dist/game/data/scripts/handlers/voicedcommandhandlers/ChangeEmail.java (working copy)
@@ -0,0 +1,107 @@
+/*
+ * 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.util.StringTokenizer;
+import java.util.logging.Level;
+
+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;
+
+public class ChangeEmail implements IVoicedCommandHandler
+{
+ 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);
+ try
+ {
+ String curpass = null, newpass = null, repeatnewpass = null;
+ if (st.hasMoreTokens())
+ {
+ curpass = st.nextToken();
+ }
+ if (st.hasMoreTokens())
+ {
+ newpass = st.nextToken();
+ }
+ if (st.hasMoreTokens())
+ {
+ repeatnewpass = st.nextToken();
+ }
+
+ if (!((curpass == null) || (newpass == null) || (repeatnewpass == null)))
+ {
+ if (!newpass.equals(repeatnewpass))
+ {
+ activeChar.sendMessage("The new email doesn't match with the repeated one!");
+ return false;
+ }
+ if (newpass.length() < 3)
+ {
+ activeChar.sendMessage("The new email is shorter than 3 chars! Please try with a longer one.");
+ return false;
+ }
+ if (newpass.length() > 30)
+ {
+ activeChar.sendMessage("The new email is longer than 30 chars! Please try with a shorter one.");
+ return false;
+ }
+
+ LoginServerThread.getInstance().sendChangeEmail(activeChar.getAccountName(), activeChar.getName(), curpass, newpass);
+ }
+ 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
+ {
+ // showHTML(activeChar);
+ String 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;
+ }
+
+ @Override
+ public String[] getVoicedCommandList()
+ {
+ return _voicedCommands;
+ }
+}
Index: .classpath
===================================================================
--- .classpath (revision 21974)
+++ .classpath (working copy)
@@ -1,8 +1,8 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <classpath>
- <classpathentry including="**/*.java" kind="src" path="dist/game/data/scripts" />
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8" />
- <classpathentry combineaccessrules="false" kind="src" path="/L2J_Server" />
- <classpathentry kind="lib" path="/L2J_Server/dist/libs/mmocore.jar" />
- <classpathentry kind="output" path="bin" />
-</classpath>
\ No newline at end of file
+ <classpathentry including="**/*.java" kind="src" path="dist/game/data/scripts"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
+ <classpathentry combineaccessrules="false" kind="src" path="/L2Dev_ChangeEmail_Core"/>
+ <classpathentry kind="lib" path="/L2Dev_ChangeEmail_Core/dist/libs/mmocore.jar"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
Index: dist/game/data/scripts/handlers/MasterHandler.java
===================================================================
--- dist/game/data/scripts/handlers/MasterHandler.java (revision 21974)
+++ dist/game/data/scripts/handlers/MasterHandler.java (working copy)
@@ -249,6 +249,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;
@@ -531,6 +532,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: dist/sql/login/custom/email.sql
===================================================================
--- dist/sql/login/custom/email.sql (revision 0)
+++ dist/sql/login/custom/email.sql (working copy)
@@ -0,0 +1 @@
+ALTER TABLE `accounts` ADD `email` VARCHAR(255) NULL DEFAULT NULL ;
\ No newline at end of file