Răsfoiți Sursa

Core support for [DP8369]

Nik 13 ani în urmă
părinte
comite
d09758476c

+ 7 - 0
L2J_Server_BETA/dist/game/config/l2jmods.properties

@@ -446,3 +446,10 @@ DualboxCheckMaxL2EventParticipantsPerIP = 0
 # will be 1+2=3. Use 0 or negative value for unlimited number of connections.
 # Default: 127.0.0.1,0 (no limits from localhost)
 DualboxCheckWhitelist = 127.0.0.1,0
+
+# ---------------------------------------------------------------------------
+# Password Change
+# ---------------------------------------------------------------------------
+# Enables .changepassword voiced command which allows the players to change their account's password ingame.
+# Default: False
+AllowChangePassword = False

+ 2 - 0
L2J_Server_BETA/java/com/l2jserver/Config.java

@@ -753,6 +753,7 @@ public final class Config
 	public static int L2JMOD_DUALBOX_CHECK_MAX_OLYMPIAD_PARTICIPANTS_PER_IP;
 	public static int L2JMOD_DUALBOX_CHECK_MAX_L2EVENT_PARTICIPANTS_PER_IP;
 	public static TIntIntHashMap L2JMOD_DUALBOX_CHECK_WHITELIST;
+	public static boolean L2JMOD_ALLOW_CHANGE_PASSWORD;
 	
 	//--------------------------------------------------
 	// NPC Settings
@@ -2610,6 +2611,7 @@ public final class Config
 							}
 						}
 					}
+					L2JMOD_ALLOW_CHANGE_PASSWORD = Boolean.parseBoolean(L2JModSettings.getProperty("AllowChangePassword", "False"));
 				}
 				catch (Exception e)
 				{

+ 19 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/LoginServerThread.java

@@ -51,6 +51,7 @@ import com.l2jserver.gameserver.network.SystemMessageId;
 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;
@@ -60,6 +61,7 @@ import com.l2jserver.gameserver.network.gameserverpackets.SendMail;
 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.ChangePasswordResponse;
 import com.l2jserver.gameserver.network.loginserverpackets.InitLS;
 import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
 import com.l2jserver.gameserver.network.loginserverpackets.LoginServerFail;
@@ -346,6 +348,9 @@ public class LoginServerThread extends Thread
 							RequestCharacters rc = new RequestCharacters(decrypt);
 							getCharsOnServer(rc.getAccount());
 							break;
+						case 0x06:
+							new ChangePasswordResponse(decrypt);
+							break;
 					}
 				}
 			}
@@ -644,6 +649,20 @@ public class LoginServerThread extends Thread
 		}
 	}
 	
+	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
 	 */

+ 42 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/network/gameserverpackets/ChangePassword.java

@@ -0,0 +1,42 @@
+/*
+ * 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 java.io.IOException;
+
+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() throws IOException
+	{
+		return getBytes();
+	}
+}

+ 37 - 0
L2J_Server_BETA/java/com/l2jserver/gameserver/network/loginserverpackets/ChangePasswordResponse.java

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

+ 6 - 0
L2J_Server_BETA/java/com/l2jserver/loginserver/GameServerThread.java

@@ -31,6 +31,7 @@ import com.l2jserver.Config;
 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.ChangePasswordResponse;
 import com.l2jserver.loginserver.network.loginserverpackets.InitLS;
 import com.l2jserver.loginserver.network.loginserverpackets.KickPlayer;
 import com.l2jserver.loginserver.network.loginserverpackets.LoginServerFail;
@@ -272,6 +273,11 @@ public class GameServerThread extends Thread
 		sendPacket(new RequestCharacters(account));
 	}
 	
+	public void ChangePasswordResponse(byte successful, String characterName, String msgToSend)
+	{
+		sendPacket(new ChangePasswordResponse(successful, characterName, msgToSend));
+	}
+	
 	/**
 	 * @param gameHost The gameHost to set.
 	 */

+ 15 - 1
L2J_Server_BETA/java/com/l2jserver/loginserver/network/L2JGameServerPacketHandler.java

@@ -18,7 +18,18 @@ import java.util.logging.Logger;
 
 import com.l2jserver.Config;
 import com.l2jserver.loginserver.GameServerThread;
-import com.l2jserver.loginserver.network.gameserverpackets.*;
+import com.l2jserver.loginserver.network.gameserverpackets.BlowFishKey;
+import com.l2jserver.loginserver.network.gameserverpackets.ChangeAccessLevel;
+import com.l2jserver.loginserver.network.gameserverpackets.ChangePassword;
+import com.l2jserver.loginserver.network.gameserverpackets.GameServerAuth;
+import com.l2jserver.loginserver.network.gameserverpackets.PlayerAuthRequest;
+import com.l2jserver.loginserver.network.gameserverpackets.PlayerInGame;
+import com.l2jserver.loginserver.network.gameserverpackets.PlayerLogout;
+import com.l2jserver.loginserver.network.gameserverpackets.PlayerTracert;
+import com.l2jserver.loginserver.network.gameserverpackets.ReplyCharacters;
+import com.l2jserver.loginserver.network.gameserverpackets.RequestSendMail;
+import com.l2jserver.loginserver.network.gameserverpackets.RequestTempBan;
+import com.l2jserver.loginserver.network.gameserverpackets.ServerStatus;
 import com.l2jserver.loginserver.network.loginserverpackets.LoginServerFail;
 import com.l2jserver.util.network.BaseRecievePacket;
 
@@ -93,6 +104,9 @@ public class L2JGameServerPacketHandler
 					case 0x0A:
 						msg = new RequestTempBan(data);
 						break;
+					case 0x0B:
+						new ChangePassword(data);
+						break;
 					default:
 						_log.warning("Unknown Opcode ("+Integer.toHexString(opcode).toUpperCase()+") in state "+state.name()+" from GameServer, closing connection.");
 						server.forceClose(LoginServerFail.NOT_AUTHED);

+ 119 - 0
L2J_Server_BETA/java/com/l2jserver/loginserver/network/gameserverpackets/ChangePassword.java

@@ -0,0 +1,119 @@
+/*
+ * 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.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.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!");
+						L2DatabaseFactory.close(con);
+					}
+				}
+				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);
+			}
+		}
+	}
+}

+ 41 - 0
L2J_Server_BETA/java/com/l2jserver/loginserver/network/loginserverpackets/ChangePasswordResponse.java

@@ -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.loginserver.network.loginserverpackets;
+
+import java.io.IOException;
+
+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() throws IOException
+	{
+		return getBytes();
+	}
+	
+}