Advertisement
Guest User

command core

a guest
Nov 26th, 2014
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 13.40 KB | None | 0 0
  1. Index: java/com/l2jserver/gameserver/LoginServerThread.java
  2. ===================================================================
  3. --- java/com/l2jserver/gameserver/LoginServerThread.java    (revision 5708)
  4. +++ java/com/l2jserver/gameserver/LoginServerThread.java    (working copy)
  5. @@ -45,6 +45,7 @@
  6.  import com.l2jserver.gameserver.network.gameserverpackets.AuthRequest;
  7.  import com.l2jserver.gameserver.network.gameserverpackets.BlowFishKey;
  8.  import com.l2jserver.gameserver.network.gameserverpackets.ChangeAccessLevel;
  9. +import com.l2jserver.gameserver.network.gameserverpackets.ChangePassword;
  10.  import com.l2jserver.gameserver.network.gameserverpackets.PlayerAuthRequest;
  11.  import com.l2jserver.gameserver.network.gameserverpackets.PlayerInGame;
  12.  import com.l2jserver.gameserver.network.gameserverpackets.PlayerLogout;
  13. @@ -55,6 +56,7 @@
  14.  import com.l2jserver.gameserver.network.loginserverpackets.KickPlayer;
  15.  import com.l2jserver.gameserver.network.loginserverpackets.LoginServerFail;
  16.  import com.l2jserver.gameserver.network.loginserverpackets.PlayerAuthResponse;
  17. +import com.l2jserver.gameserver.network.loginserverpackets.ChangePasswordResponse;
  18.  import com.l2jserver.gameserver.network.serverpackets.CharSelectionInfo;
  19.  import com.l2jserver.gameserver.network.serverpackets.LoginFail;
  20.  import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  21. @@ -334,6 +336,9 @@
  22.                             KickPlayer kp = new KickPlayer(decrypt);
  23.                             doKickPlayer(kp.getAccount());
  24.                             break;
  25. +                       case 0x06:
  26. +                           new ChangePasswordResponse(decrypt);
  27. +                           break;
  28.                     }
  29.                 }
  30.             }
  31. @@ -559,6 +564,20 @@
  32.         }
  33.     }
  34.    
  35. +   public void sendChangePassword(String accountName, String charName, String oldpass, String newpass)
  36. +   {
  37. +       ChangePassword cp = new ChangePassword(accountName, charName, oldpass, newpass);
  38. +       try
  39. +       {
  40. +           sendPacket(cp);
  41. +       }
  42. +       catch (IOException e)
  43. +       {
  44. +           if (Config.DEBUG)
  45. +               _log.log(Level.WARNING, "", e);
  46. +       }
  47. +   }
  48. +  
  49.     /**
  50.      * @return
  51.      */
  52. Index: java/com/l2jserver/gameserver/network/gameserverpackets/ChangePassword.java
  53. ===================================================================
  54. --- java/com/l2jserver/gameserver/network/gameserverpackets/ChangePassword.java (revision 0)
  55. +++ java/com/l2jserver/gameserver/network/gameserverpackets/ChangePassword.java (working copy)
  56. @@ -0,0 +1,38 @@
  57. +/*
  58. + * This program is free software: you can redistribute it and/or modify it under
  59. + * the terms of the GNU General Public License as published by the Free Software
  60. + * Foundation, either version 3 of the License, or (at your option) any later
  61. + * version.
  62. + *
  63. + * This program is distributed in the hope that it will be useful, but WITHOUT
  64. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  65. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  66. + * details.
  67. + *
  68. + * You should have received a copy of the GNU General Public License along with
  69. + * this program. If not, see <http://www.gnu.org/licenses/>.
  70. + */
  71. +package com.l2jserver.gameserver.network.gameserverpackets;
  72. +
  73. +import com.l2jserver.util.network.BaseSendablePacket;
  74. +
  75. +/**
  76. + * @author UnAfraid
  77. + */
  78. +public class ChangePassword extends BaseSendablePacket
  79. +{
  80. +   public ChangePassword(String accountName, String characterName, String oldPass, String newPass)
  81. +   {
  82. +       writeC(0x0B);
  83. +       writeS(accountName);
  84. +       writeS(characterName);
  85. +       writeS(oldPass);
  86. +       writeS(newPass);
  87. +   }
  88. +
  89. +   @Override
  90. +   public byte[] getContent()
  91. +   {
  92. +       return getBytes();
  93. +   }
  94. +}
  95. \ No newline at end of file
  96. Index: java/com/l2jserver/gameserver/network/loginserverpackets/ChangePasswordResponse.java
  97. ===================================================================
  98. --- java/com/l2jserver/gameserver/network/loginserverpackets/ChangePasswordResponse.java    (revision 0)
  99. +++ java/com/l2jserver/gameserver/network/loginserverpackets/ChangePasswordResponse.java    (working copy)
  100. @@ -0,0 +1,37 @@
  101. +/*
  102. + * This program is free software: you can redistribute it and/or modify it under
  103. + * the terms of the GNU General Public License as published by the Free Software
  104. + * Foundation, either version 3 of the License, or (at your option) any later
  105. + * version.
  106. + *
  107. + * This program is distributed in the hope that it will be useful, but WITHOUT
  108. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  109. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  110. + * details.
  111. + *
  112. + * You should have received a copy of the GNU General Public License along with
  113. + * this program. If not, see <http://www.gnu.org/licenses/>.
  114. + */
  115. +package com.l2jserver.gameserver.network.loginserverpackets;
  116. +
  117. +import com.l2jserver.gameserver.model.L2World;
  118. +import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  119. +import com.l2jserver.util.network.BaseRecievePacket;
  120. +
  121. +
  122. +public class ChangePasswordResponse extends BaseRecievePacket
  123. +{
  124. +
  125. +   public ChangePasswordResponse(byte[] decrypt)
  126. +   {
  127. +       super(decrypt);
  128. +       //boolean isSuccessful = readC() > 0;
  129. +       String character = readS();
  130. +       String msgToSend = readS();
  131. +      
  132. +       L2PcInstance player = L2World.getInstance().getPlayer(character);
  133. +      
  134. +       if (player != null)
  135. +           player.sendMessage(msgToSend);
  136. +   }
  137. +}
  138. \ No newline at end of file
  139. Index: java/com/l2jserver/loginserver/GameServerThread.java
  140. ===================================================================
  141. --- java/com/l2jserver/loginserver/GameServerThread.java    (revision 5708)
  142. +++ java/com/l2jserver/loginserver/GameServerThread.java    (working copy)
  143. @@ -33,6 +33,7 @@
  144.  import com.l2jserver.loginserver.GameServerTable.GameServerInfo;
  145.  import com.l2jserver.loginserver.gameserverpackets.BlowFishKey;
  146.  import com.l2jserver.loginserver.gameserverpackets.ChangeAccessLevel;
  147. +import com.l2jserver.loginserver.gameserverpackets.ChangePassword;
  148.  import com.l2jserver.loginserver.gameserverpackets.GameServerAuth;
  149.  import com.l2jserver.loginserver.gameserverpackets.PlayerAuthRequest;
  150.  import com.l2jserver.loginserver.gameserverpackets.PlayerInGame;
  151. @@ -40,6 +41,7 @@
  152.  import com.l2jserver.loginserver.gameserverpackets.PlayerTracert;
  153.  import com.l2jserver.loginserver.gameserverpackets.ServerStatus;
  154.  import com.l2jserver.loginserver.loginserverpackets.AuthResponse;
  155. +import com.l2jserver.loginserver.loginserverpackets.ChangePasswordResponse;
  156.  import com.l2jserver.loginserver.loginserverpackets.InitLS;
  157.  import com.l2jserver.loginserver.loginserverpackets.KickPlayer;
  158.  import com.l2jserver.loginserver.loginserverpackets.LoginServerFail;
  159. @@ -166,6 +168,9 @@
  160.                     case 07:
  161.                         onReceivePlayerTracert(data);
  162.                         break;
  163. +                   case 0x0B:
  164. +                       new ChangePassword(data);
  165. +                       break;
  166.                     default:
  167.                         _log.warning("Unknown Opcode ("+Integer.toHexString(packetType).toUpperCase()+") from GameServer, closing connection.");
  168.                         forceClose(LoginServerFail.NOT_AUTHED);
  169. @@ -658,6 +663,20 @@
  170.         }
  171.     }
  172.    
  173. +   public void ChangePasswordResponse(byte successful, String characterName, String msgToSend)
  174. +   {
  175. +       ChangePasswordResponse cp = new ChangePasswordResponse(successful, characterName, msgToSend);
  176. +       try
  177. +       {
  178. +           sendPacket(cp);
  179. +       }
  180. +       catch (IOException e)
  181. +       {
  182. +           // TODO Auto-generated catch block
  183. +           e.printStackTrace();
  184. +       }
  185. +   }
  186. +  
  187.     /**
  188.      * @param gameHost The gameHost to set.
  189.      */
  190. Index: java/com/l2jserver/loginserver/gameserverpackets/ChangePassword.java
  191. ===================================================================
  192. --- java/com/l2jserver/loginserver/gameserverpackets/ChangePassword.java    (revision 0)
  193. +++ java/com/l2jserver/loginserver/gameserverpackets/ChangePassword.java    (working copy)
  194. @@ -0,0 +1,131 @@
  195. +/*
  196. + * This program is free software: you can redistribute it and/or modify it under
  197. + * the terms of the GNU General Public License as published by the Free Software
  198. + * Foundation, either version 3 of the License, or (at your option) any later
  199. + * version.
  200. + *
  201. + * This program is distributed in the hope that it will be useful, but WITHOUT
  202. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  203. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  204. + * details.
  205. + *
  206. + * You should have received a copy of the GNU General Public License along with
  207. + * this program. If not, see <http://www.gnu.org/licenses/>.
  208. + */
  209. +package com.l2jserver.loginserver.gameserverpackets;
  210. +
  211. +import java.security.MessageDigest;
  212. +import java.sql.Connection;
  213. +import java.sql.PreparedStatement;
  214. +import java.sql.ResultSet;
  215. +import java.util.Collection;
  216. +import java.util.logging.Level;
  217. +import java.util.logging.Logger;
  218. +
  219. +import com.l2jserver.L2DatabaseFactory;
  220. +import com.l2jserver.loginserver.GameServerTable;
  221. +import com.l2jserver.loginserver.GameServerTable.GameServerInfo;
  222. +import com.l2jserver.loginserver.GameServerThread;
  223. +import com.l2jserver.Base64;
  224. +import com.l2jserver.util.network.BaseRecievePacket;
  225. +
  226. +/**
  227. + * @author Nik
  228. + */
  229. +public class ChangePassword extends BaseRecievePacket
  230. +{
  231. +   protected static Logger _log = Logger.getLogger(ChangePassword.class.getName());
  232. +   private static GameServerThread gst = null;
  233. +  
  234. +   public ChangePassword(byte[] decrypt)
  235. +   {
  236. +       super(decrypt);
  237. +      
  238. +       String accountName = readS();
  239. +       String characterName = readS();
  240. +       String curpass = readS();
  241. +       String newpass = readS();
  242. +      
  243. +       // get the GameServerThread
  244. +       Collection<GameServerInfo> serverList = GameServerTable.getInstance().getRegisteredGameServers().values();
  245. +       for (GameServerInfo gsi : serverList)
  246. +       {
  247. +           if ((gsi.getGameServerThread() != null) && gsi.getGameServerThread().hasAccountOnGameServer(accountName))
  248. +           {
  249. +               gst = gsi.getGameServerThread();
  250. +           }
  251. +       }
  252. +      
  253. +       if (gst == null)
  254. +       {
  255. +           return;
  256. +       }
  257. +      
  258. +       if ((curpass == null) || (newpass == null))
  259. +       {
  260. +           gst.ChangePasswordResponse((byte) 0, characterName, "Invalid password data! Try again.");
  261. +       }
  262. +       else
  263. +       {
  264. +           Connection con = null;
  265. +           try
  266. +           {
  267. +               MessageDigest md = MessageDigest.getInstance("SHA");
  268. +              
  269. +               byte[] raw = curpass.getBytes("UTF-8");
  270. +               raw = md.digest(raw);
  271. +               String curpassEnc = Base64.encodeBytes(raw);
  272. +               String pass = null;
  273. +               int passUpdated = 0;
  274. +              
  275. +               // SQL connection
  276. +               con = L2DatabaseFactory.getInstance().getConnection();
  277. +               PreparedStatement statement = con.prepareStatement("SELECT password FROM accounts WHERE login=?");
  278. +               statement.setString(1, accountName);
  279. +               ResultSet rset = statement.executeQuery();
  280. +               if (rset.next())
  281. +               {
  282. +                   pass = rset.getString("password");
  283. +               }
  284. +               rset.close();
  285. +               statement.close();
  286. +              
  287. +               if (curpassEnc.equals(pass))
  288. +               {
  289. +                   byte[] password = newpass.getBytes("UTF-8");
  290. +                   password = md.digest(password);
  291. +                  
  292. +                   // SQL connection
  293. +                   PreparedStatement ps = con.prepareStatement("UPDATE accounts SET password=? WHERE login=?");
  294. +                   ps.setString(1, Base64.encodeBytes(password));
  295. +                   ps.setString(2, accountName);
  296. +                   passUpdated = ps.executeUpdate();
  297. +                   ps.close();
  298. +                  
  299. +                   _log.log(Level.INFO, "The password for account " + accountName + " has been changed from " + curpassEnc + " to " + Base64.encodeBytes(password));
  300. +                   if (passUpdated > 0)
  301. +                   {
  302. +                       gst.ChangePasswordResponse((byte) 1, characterName, "You have successfully changed your password!");
  303. +                   }
  304. +                   else
  305. +                   {
  306. +                       gst.ChangePasswordResponse((byte) 0, characterName, "The password change was unsuccessful!");
  307. +                   }
  308. +               }
  309. +               else
  310. +               {
  311. +                   gst.ChangePasswordResponse((byte) 0, characterName, "The typed current password doesn't match with your current one.");
  312. +               }
  313. +           }
  314. +           catch (Exception e)
  315. +           {
  316. +               _log.warning("Error while changing password for account " + accountName + " requested by player " + characterName + "! " + e);
  317. +           }
  318. +           finally
  319. +           {
  320. +               // close the database connection at the end
  321. +               L2DatabaseFactory.close(con);
  322. +           }
  323. +       }
  324. +   }
  325. +}
  326. \ No newline at end of file
  327. Index: java/com/l2jserver/loginserver/loginserverpackets/ChangePasswordResponse.java
  328. ===================================================================
  329. --- java/com/l2jserver/loginserver/loginserverpackets/ChangePasswordResponse.java   (revision 0)
  330. +++ java/com/l2jserver/loginserver/loginserverpackets/ChangePasswordResponse.java   (working copy)
  331. @@ -0,0 +1,37 @@
  332. +/*
  333. + * This program is free software: you can redistribute it and/or modify it under
  334. + * the terms of the GNU General Public License as published by the Free Software
  335. + * Foundation, either version 3 of the License, or (at your option) any later
  336. + * version.
  337. + *
  338. + * This program is distributed in the hope that it will be useful, but WITHOUT
  339. + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  340. + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  341. + * details.
  342. + *
  343. + * You should have received a copy of the GNU General Public License along with
  344. + * this program. If not, see <http://www.gnu.org/licenses/>.
  345. + */
  346. +package com.l2jserver.loginserver.loginserverpackets;
  347. +
  348. +import com.l2jserver.util.network.BaseSendablePacket;
  349. +
  350. +/**
  351. + * @author Nik
  352. + */
  353. +public class ChangePasswordResponse extends BaseSendablePacket
  354. +{
  355. +   public ChangePasswordResponse(byte successful, String characterName, String msgToSend)
  356. +   {
  357. +       writeC(0x06);
  358. +       // writeC(successful); //0 false, 1 true
  359. +       writeS(characterName);
  360. +       writeS(msgToSend);
  361. +   }
  362. +  
  363. +   @Override
  364. +   public byte[] getContent()
  365. +   {
  366. +       return getBytes();
  367. +   }
  368. +}
  369. \ No newline at end of file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement