AdminRepairChar.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * This program is free software: you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation, either version 3 of the License, or (at your option) any later
  5. * version.
  6. *
  7. * This program is distributed in the hope that it will be useful, but WITHOUT
  8. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  9. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  10. * details.
  11. *
  12. * You should have received a copy of the GNU General Public License along with
  13. * this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. package handlers.admincommandhandlers;
  16. import java.sql.PreparedStatement;
  17. import java.sql.ResultSet;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import com.l2jserver.L2DatabaseFactory;
  21. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  22. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  23. /**
  24. * This class handles following admin commands: - delete = deletes target
  25. *
  26. * @version $Revision: 1.1.2.6.2.3 $ $Date: 2005/04/11 10:05:59 $
  27. */
  28. public class AdminRepairChar implements IAdminCommandHandler
  29. {
  30. private static Logger _log = Logger.getLogger(AdminRepairChar.class.getName());
  31. private static final String[] ADMIN_COMMANDS =
  32. {
  33. "admin_restore",
  34. "admin_repair"
  35. };
  36. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  37. {
  38. handleRepair(command);
  39. return true;
  40. }
  41. public String[] getAdminCommandList()
  42. {
  43. return ADMIN_COMMANDS;
  44. }
  45. private void handleRepair(String command)
  46. {
  47. String[] parts = command.split(" ");
  48. if (parts.length != 2)
  49. {
  50. return;
  51. }
  52. String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?";
  53. java.sql.Connection connection = null;
  54. try
  55. {
  56. connection = L2DatabaseFactory.getInstance().getConnection();
  57. PreparedStatement statement = connection.prepareStatement(cmd);
  58. statement.setString(1, parts[1]);
  59. statement.execute();
  60. statement.close();
  61. statement = connection.prepareStatement("SELECT charId FROM characters where char_name=?");
  62. statement.setString(1, parts[1]);
  63. ResultSet rset = statement.executeQuery();
  64. int objId = 0;
  65. if (rset.next())
  66. {
  67. objId = rset.getInt(1);
  68. }
  69. rset.close();
  70. statement.close();
  71. if (objId == 0)
  72. {
  73. connection.close();
  74. return;
  75. }
  76. //connection = L2DatabaseFactory.getInstance().getConnection();
  77. statement = connection.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?");
  78. statement.setInt(1, objId);
  79. statement.execute();
  80. statement.close();
  81. //connection = L2DatabaseFactory.getInstance().getConnection();
  82. statement = connection.prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=?");
  83. statement.setInt(1, objId);
  84. statement.execute();
  85. statement.close();
  86. connection.close();
  87. }
  88. catch (Exception e)
  89. {
  90. _log.log(Level.WARNING, "could not repair char:", e);
  91. }
  92. finally
  93. {
  94. try
  95. {
  96. connection.close();
  97. }
  98. catch (Exception e)
  99. {
  100. }
  101. }
  102. }
  103. }