AdminRepairChar.java 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. @Override
  37. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  38. {
  39. handleRepair(command);
  40. return true;
  41. }
  42. @Override
  43. public String[] getAdminCommandList()
  44. {
  45. return ADMIN_COMMANDS;
  46. }
  47. private void handleRepair(String command)
  48. {
  49. String[] parts = command.split(" ");
  50. if (parts.length != 2)
  51. {
  52. return;
  53. }
  54. String cmd = "UPDATE characters SET x=-84318, y=244579, z=-3730 WHERE char_name=?";
  55. java.sql.Connection connection = null;
  56. try
  57. {
  58. connection = L2DatabaseFactory.getInstance().getConnection();
  59. PreparedStatement statement = connection.prepareStatement(cmd);
  60. statement.setString(1, parts[1]);
  61. statement.execute();
  62. statement.close();
  63. statement = connection.prepareStatement("SELECT charId FROM characters where char_name=?");
  64. statement.setString(1, parts[1]);
  65. ResultSet rset = statement.executeQuery();
  66. int objId = 0;
  67. if (rset.next())
  68. {
  69. objId = rset.getInt(1);
  70. }
  71. rset.close();
  72. statement.close();
  73. if (objId == 0)
  74. {
  75. connection.close();
  76. return;
  77. }
  78. //connection = L2DatabaseFactory.getInstance().getConnection();
  79. statement = connection.prepareStatement("DELETE FROM character_shortcuts WHERE charId=?");
  80. statement.setInt(1, objId);
  81. statement.execute();
  82. statement.close();
  83. //connection = L2DatabaseFactory.getInstance().getConnection();
  84. statement = connection.prepareStatement("UPDATE items SET loc=\"INVENTORY\" WHERE owner_id=?");
  85. statement.setInt(1, objId);
  86. statement.execute();
  87. statement.close();
  88. connection.close();
  89. }
  90. catch (Exception e)
  91. {
  92. _log.log(Level.WARNING, "could not repair char:", e);
  93. }
  94. finally
  95. {
  96. try
  97. {
  98. connection.close();
  99. }
  100. catch (Exception e)
  101. {
  102. }
  103. }
  104. }
  105. }