Noticias:

No tienes permiso para ver los enlaces. Para poder verlos Registrate o Conectate.

Menú Principal

Command changepassword

Iniciado por Swarlog, Jun 25, 2025, 09:42 PM

Tema anterior - Siguiente tema

Swarlog

CitarCORE:

Index: java/com/l2jserver/gameserver/LoginServerThread.java
===================================================================
--- java/com/l2jserver/gameserver/LoginServerThread.java	(revision 5708)
+++ java/com/l2jserver/gameserver/LoginServerThread.java	(working copy)
@@ -45,6 +45,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.ChangePassword;
 import com.l2jserver.gameserver.network.gameserverpackets.PlayerAuthRequest;
 import com.l2jserver.gameserver.network.gameserverpackets.PlayerInGame;
 import com.l2jserver.gameserver.network.gameserverpackets.PlayerLogout;
@@ -55,6 +56,7 @@
 import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
 import com.l2jserver.gameserver.network.loginserverpackets.LoginServerFail;
 import com.l2jserver.gameserver.network.loginserverpackets.PlayerAuthResponse;
+import com.l2jserver.gameserver.network.loginserverpackets.ChangePasswordResponse;
 import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
 import com.l2jserver.gameserver.network.serverpackets.LoginFail;
 import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
@@ -334,6 +336,9 @@
 							KickPlayer kp = new KickPlayer(decrypt);
 							doKickPlayer(kp.getAccount());
 							break;
+						case 0x06:
+							new ChangePasswordResponse(decrypt);
+							break;
 					}
 				}
 			}
@@ -559,6 +564,20 @@
 		}
 	}
 	
+	public void sendChangePassword(String accountName, String charName, String oldpass, String newpass)
+	{
+		ChangePassword cp = new ChangePassword(accountName, charName, oldpass, newpass);
+		try
+		{
+			sendPacket(cp);
+		}
+		catch (IOException e)
+		{
+			if (Config.DEBUG)
+				_log.log(Level.WARNING, "", e);
+		}
+	}
+	
 	/**
 	 * @return
 	 */
Index: java/com/l2jserver/gameserver/network/gameserverpackets/ChangePassword.java
===================================================================
--- java/com/l2jserver/gameserver/network/gameserverpackets/ChangePassword.java	(revision 0)
+++ java/com/l2jserver/gameserver/network/gameserverpackets/ChangePassword.java	(working copy)
@@ -0,0 +1,38 @@
+/*
+ * 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
+ */
+public class ChangePassword extends BaseSendablePacket
+{
+	public ChangePassword(String accountName, String characterName, String oldPass, String newPass)
+	{
+		writeC(0x0B);
+		writeS(accountName);
+		writeS(characterName);
+		writeS(oldPass);
+		writeS(newPass);
+	}
+
+	@Override
+	public byte[] getContent()
+	{
+		return getBytes();
+	}
+}
\ No newline at end of file
Index: java/com/l2jserver/gameserver/network/loginserverpackets/ChangePasswordResponse.java
===================================================================
--- java/com/l2jserver/gameserver/network/loginserverpackets/ChangePasswordResponse.java	(revision 0)
+++ java/com/l2jserver/gameserver/network/loginserverpackets/ChangePasswordResponse.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 ChangePasswordResponse extends BaseRecievePacket
+{
+
+	public ChangePasswordResponse(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/GameServerThread.java
===================================================================
--- java/com/l2jserver/loginserver/GameServerThread.java	(revision 5708)
+++ java/com/l2jserver/loginserver/GameServerThread.java	(working copy)
@@ -33,6 +33,7 @@
 import com.l2jserver.loginserver.GameServerTable.GameServerInfo;
 import com.l2jserver.loginserver.gameserverpackets.BlowFishKey;
 import com.l2jserver.loginserver.gameserverpackets.ChangeAccessLevel;
+import com.l2jserver.loginserver.gameserverpackets.ChangePassword;
 import com.l2jserver.loginserver.gameserverpackets.GameServerAuth;
 import com.l2jserver.loginserver.gameserverpackets.PlayerAuthRequest;
 import com.l2jserver.loginserver.gameserverpackets.PlayerInGame;
@@ -40,6 +41,7 @@
 import com.l2jserver.loginserver.gameserverpackets.PlayerTracert;
 import com.l2jserver.loginserver.gameserverpackets.ServerStatus;
 import com.l2jserver.loginserver.loginserverpackets.AuthResponse;
+import com.l2jserver.loginserver.loginserverpackets.ChangePasswordResponse;
 import com.l2jserver.loginserver.loginserverpackets.InitLS;
 import com.l2jserver.loginserver.loginserverpackets.KickPlayer;
 import com.l2jserver.loginserver.loginserverpackets.LoginServerFail;
@@ -166,6 +168,9 @@
 					case 07:
 						onReceivePlayerTracert(data);
 						break;
+					case 0x0B:
+						new ChangePassword(data);
+						break;
 					default:
 						_log.warning("Unknown Opcode ("+Integer.toHexString(packetType).toUpperCase()+") from GameServer, closing connection.");
 						forceClose(LoginServerFail.NOT_AUTHED);
@@ -658,6 +663,20 @@
 		}
 	}
 	
+	public void ChangePasswordResponse(byte successful, String characterName, String msgToSend)
+	{
+		ChangePasswordResponse cp = new ChangePasswordResponse(successful, characterName, msgToSend);
+		try
+		{
+			sendPacket(cp);
+		}
+		catch (IOException e)
+		{
+			// TODO Auto-generated catch block
+			e.printStackTrace();
+		}
+	}
+	
 	/**
 	 * @param gameHost The gameHost to set.
 	 */
Index: java/com/l2jserver/loginserver/gameserverpackets/ChangePassword.java
===================================================================
--- java/com/l2jserver/loginserver/gameserverpackets/ChangePassword.java	(revision 0)
+++ java/com/l2jserver/loginserver/gameserverpackets/ChangePassword.java	(working copy)
@@ -0,0 +1,131 @@
+/*
+ * 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.gameserverpackets;
+
+import java.security.MessageDigest;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+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.Base64;
+import com.l2jserver.util.network.BaseRecievePacket;
+
+/**
+ * @author Nik
+ */
+public class ChangePassword extends BaseRecievePacket
+{
+	protected static Logger _log = Logger.getLogger(ChangePassword.class.getName());
+	private static GameServerThread gst = null;
+	
+	public ChangePassword(byte[] decrypt)
+	{
+		super(decrypt);
+		
+		String accountName = readS();
+		String characterName = readS();
+		String curpass = readS();
+		String newpass = 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 ((curpass == null) || (newpass == null))
+		{
+			gst.ChangePasswordResponse((byte) 0, characterName, "Invalid password data! Try again.");
+		}
+		else
+		{
+			Connection con = null;
+			try
+			{
+				MessageDigest md = MessageDigest.getInstance("SHA");
+				
+				byte[] raw = curpass.getBytes("UTF-8");
+				raw = md.digest(raw);
+				String curpassEnc = Base64.encodeBytes(raw);
+				String pass = null;
+				int passUpdated = 0;
+				
+				// SQL connection
+				con = L2DatabaseFactory.getInstance().getConnection();
+				PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
+				statement.setString(1, accountName);
+				ResultSet rset = statement.executeQuery();
+				if (rset.next())
+				{
+					pass = rset.getString("password");
+				}
+				rset.close();
+				statement.close();
+				
+				if (curpassEnc.equals(pass))
+				{
+					byte[] password = newpass.getBytes("UTF-8");
+					password = md.digest(password);
+					
+					// SQL connection
+					PreparedStatement ps = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?");
+					ps.setString(1, Base64.encodeBytes(password));
+					ps.setString(2, accountName);
+					passUpdated = ps.executeUpdate();
+					ps.close();
+					
+					_log.log(Level.INFO, "The password for account " + accountName + " has been changed from " + curpassEnc + " to " + Base64.encodeBytes(password));
+					if (passUpdated > 0)
+					{
+						gst.ChangePasswordResponse((byte) 1, characterName, "You have successfully changed your password!");
+					}
+					else
+					{
+						gst.ChangePasswordResponse((byte) 0, characterName, "The password change was unsuccessful!");
+					}
+				}
+				else
+				{
+					gst.ChangePasswordResponse((byte) 0, characterName, "The typed current password doesn't match with your current one.");
+				}
+			}
+			catch (Exception e)
+			{
+				_log.warning("Error while changing password for account " + accountName + " requested by player " + characterName + "! " + e);
+			}
+			finally
+			{
+				// close the database connection at the end
+				L2DatabaseFactory.close(con);
+			}
+		}
+	}
+}
\ No newline at end of file
Index: java/com/l2jserver/loginserver/loginserverpackets/ChangePasswordResponse.java
===================================================================
--- java/com/l2jserver/loginserver/loginserverpackets/ChangePasswordResponse.java	(revision 0)
+++ java/com/l2jserver/loginserver/loginserverpackets/ChangePasswordResponse.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.loginserver.loginserverpackets;
+
+import com.l2jserver.util.network.BaseSendablePacket;
+
+/**
+ * @author Nik
+ */
+public class ChangePasswordResponse extends BaseSendablePacket
+{
+	public ChangePasswordResponse(byte successful, String characterName, String msgToSend)
+	{
+		writeC(0x06);
+		// writeC(successful); //0 false, 1 true
+		writeS(characterName);
+		writeS(msgToSend);
+	}
+	
+	@Override
+	public byte[] getContent()
+	{
+		return getBytes();
+	}
+}
\ No newline at end of file

CitarDATA:

Index: dist/game/data/html/mods/ChangePassword.htm
===================================================================
--- dist/game/data/html/mods/ChangePassword.htm	(revision 0)
+++ dist/game/data/html/mods/ChangePassword.htm	(working copy)
@@ -0,0 +1,10 @@
+<html><body>
+<center>
+<td>
+<tr>Current Password:</tr><tr><edit type="password" var="oldpass" width=150></tr><br>
+<tr>New Password</tr><tr><edit type="password" var="newpass" width=150></tr><br>
+<tr>Repeat New Password</tr><tr><edit type="password" var="repeatnewpass" width=150></tr><br>
+<td>
+<button value="Change Password" action="bypass -h voice .changepassword $oldpass $newpass $repeatnewpass" width=160 height=25 back="L2UI_ct1.button_df" fore="L2UI_ct1.button_df">
+</center>
+</body></html>
\ No newline at end of file
Index: dist/game/data/scripts/handlers/MasterHandler.java
===================================================================
--- dist/game/data/scripts/handlers/MasterHandler.java	(revision 9149)
+++ dist/game/data/scripts/handlers/MasterHandler.java	(working copy)
@@ -240,6 +240,7 @@
 import handlers.usercommandhandlers.PartyInfo;
 import handlers.usercommandhandlers.Time;
 import handlers.voicedcommandhandlers.Banking;
+import handlers.voicedcommandhandlers.ChangePassword;
 import handlers.voicedcommandhandlers.ChatAdmin;
 import handlers.voicedcommandhandlers.Debug;
 import handlers.voicedcommandhandlers.Lang;
@@ -548,6 +549,7 @@
 			VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new Lang());
 		if (Config.L2JMOD_DEBUG_VOICE_COMMAND)
 			VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new Debug());
+		VoicedCommandHandler.getInstance().registerVoicedCommandHandler(new ChangePassword());
 		_log.config("Loaded " + VoicedCommandHandler.getInstance().size() + " VoicedHandlers");
 	}
 	
Index: dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
===================================================================
--- dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java	(revision 0)
+++ dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java	(working copy)
@@ -0,0 +1,99 @@
+/*
+ * 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;
+
+
+/**
+ *
+ * @author Nik
+ *
+ */
+public class ChangePassword implements IVoicedCommandHandler
+{
+        private static final String[] _voicedCommands =
+        {
+                "changepassword"
+        };
+       
+        public boolean useVoicedCommand(String command, L2PcInstance activeChar, String target)
+        {
+                if (target != null)
+                {
+                        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 password doesn't match with the repeated one!");
+                                                return false;
+                                        }
+                                        if (newpass.length() < 3)
+                                        {
+                                                activeChar.sendMessage("The new password is shorter than 3 chars! Please try with a longer one.");
+                                                return false;
+                                        }
+                                        if (newpass.length() > 30)
+                                        {
+                                                activeChar.sendMessage("The new password is longer than 30 chars! Please try with a shorter one.");
+                                                return false;
+                                        }
+                                   
+                                        LoginServerThread.getInstance().sendChangePassword(activeChar.getAccountName(), activeChar.getName(), curpass, newpass);
+                                }
+                                else
+                                {
+                                        activeChar.sendMessage("Invalid password data! You have to fill all boxes.");
+                                        return false;
+                                }
+                        }
+                        catch (Exception e)
+                        {
+                                activeChar.sendMessage("A problem occured while changing password!");
+                                _log.log(Level.WARNING, "", e);
+                        }
+                }
+                else
+                {
+                        //showHTML(activeChar);
+                        String html = HtmCache.getInstance().getHtm("en", "data/html/mods/ChangePassword.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(1, html));
+                        return true;
+                }
+                return true;
+        }
+
+        public String[] getVoicedCommandList()
+        {
+                return _voicedCommands;
+        }
+}
\ No newline at end of file

Original Author(s): Nik & UnAfraid

CitarADAPTACIÓN:

Para liberar lag del servidor. Añadido tiempo de reuso del comando para editar contraseña de la cuenta.

diff --git a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
index f31bf55..ced0f5a 100644
--- a/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
+++ b/L2J_DataPack/dist/game/data/scripts/handlers/voicedcommandhandlers/ChangePassword.java
@@ -18,7 +18,9 @@
  */
 package handlers.voicedcommandhandlers;
 
+import java.util.Map;
 import java.util.StringTokenizer;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.logging.Level;
 
 import com.l2jserver.gameserver.LoginServerThread;
@@ -32,6 +34,8 @@
  */
 public class ChangePassword implements IVoicedCommandHandler
 {
+	private static final Map<Integer, Long> REUSES = new ConcurrentHashMap<>();
+	private static final int REUSE = 30 * 60 * 1000; // 30 Min
 	private static final String[] _voicedCommands =
 	{
 		"changepassword"
@@ -77,6 +81,13 @@
 						return false;
 					}
 					
+					final Long timeStamp = REUSES.get(activeChar.getObjectId());
+					if ((timeStamp != null) && ((System.currentTimeMillis() - REUSE) < timeStamp.longValue()))
+					{
+						activeChar.sendMessage("You cannot change the password so often!");
+						return false;
+					}
+					REUSES.put(activeChar.getObjectId(), System.currentTimeMillis());
 					LoginServerThread.getInstance().sendChangePassword(activeChar.getAccountName(), activeChar.getName(), curpass, newpass);
 				}
 				else