Last active
November 21, 2015 15:11
-
-
Save u3games/44fcf25cc70ba2427900 to your computer and use it in GitHub Desktop.
L2JServer - Add/Change email system - Core
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment