AdminMenu.java 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.datatables.AdminTable;
  25. import com.l2jserver.gameserver.handler.AdminCommandHandler;
  26. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  27. import com.l2jserver.gameserver.model.L2Clan;
  28. import com.l2jserver.gameserver.model.L2Object;
  29. import com.l2jserver.gameserver.model.L2World;
  30. import com.l2jserver.gameserver.model.actor.L2Character;
  31. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  32. import com.l2jserver.gameserver.network.SystemMessageId;
  33. /**
  34. * This class handles following admin commands: - handles every admin menu command
  35. * @version $Revision: 1.3.2.6.2.4 $ $Date: 2005/04/11 10:06:06 $
  36. */
  37. public class AdminMenu implements IAdminCommandHandler
  38. {
  39. private static final Logger _log = Logger.getLogger(AdminMenu.class.getName());
  40. private static final String[] ADMIN_COMMANDS =
  41. {
  42. "admin_char_manage",
  43. "admin_teleport_character_to_menu",
  44. "admin_recall_char_menu",
  45. "admin_recall_party_menu",
  46. "admin_recall_clan_menu",
  47. "admin_goto_char_menu",
  48. "admin_kick_menu",
  49. "admin_kill_menu",
  50. "admin_ban_menu",
  51. "admin_unban_menu"
  52. };
  53. @Override
  54. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  55. {
  56. if (command.equals("admin_char_manage"))
  57. {
  58. showMainPage(activeChar);
  59. }
  60. else if (command.startsWith("admin_teleport_character_to_menu"))
  61. {
  62. String[] data = command.split(" ");
  63. if (data.length == 5)
  64. {
  65. String playerName = data[1];
  66. L2PcInstance player = L2World.getInstance().getPlayer(playerName);
  67. if (player != null)
  68. {
  69. teleportCharacter(player, Integer.parseInt(data[2]), Integer.parseInt(data[3]), Integer.parseInt(data[4]), activeChar, "Admin is teleporting you.");
  70. }
  71. }
  72. showMainPage(activeChar);
  73. }
  74. else if (command.startsWith("admin_recall_char_menu"))
  75. {
  76. try
  77. {
  78. String targetName = command.substring(23);
  79. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  80. teleportCharacter(player, activeChar.getX(), activeChar.getY(), activeChar.getZ(), activeChar, "Admin is teleporting you.");
  81. }
  82. catch (StringIndexOutOfBoundsException e)
  83. {
  84. }
  85. }
  86. else if (command.startsWith("admin_recall_party_menu"))
  87. {
  88. int x = activeChar.getX(), y = activeChar.getY(), z = activeChar.getZ();
  89. try
  90. {
  91. String targetName = command.substring(24);
  92. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  93. if (player == null)
  94. {
  95. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  96. return true;
  97. }
  98. if (!player.isInParty())
  99. {
  100. activeChar.sendMessage("Player is not in party.");
  101. teleportCharacter(player, x, y, z, activeChar, "Admin is teleporting you.");
  102. return true;
  103. }
  104. for (L2PcInstance pm : player.getParty().getMembers())
  105. {
  106. teleportCharacter(pm, x, y, z, activeChar, "Your party is being teleported by an Admin.");
  107. }
  108. }
  109. catch (Exception e)
  110. {
  111. _log.log(Level.WARNING, "", e);
  112. }
  113. }
  114. else if (command.startsWith("admin_recall_clan_menu"))
  115. {
  116. int x = activeChar.getX(), y = activeChar.getY(), z = activeChar.getZ();
  117. try
  118. {
  119. String targetName = command.substring(23);
  120. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  121. if (player == null)
  122. {
  123. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  124. return true;
  125. }
  126. L2Clan clan = player.getClan();
  127. if (clan == null)
  128. {
  129. activeChar.sendMessage("Player is not in a clan.");
  130. teleportCharacter(player, x, y, z, activeChar, "Admin is teleporting you.");
  131. return true;
  132. }
  133. for (L2PcInstance member : clan.getOnlineMembers(0))
  134. {
  135. teleportCharacter(member, x, y, z, activeChar, "Your clan is being teleported by an Admin.");
  136. }
  137. }
  138. catch (Exception e)
  139. {
  140. _log.log(Level.WARNING, "", e);
  141. }
  142. }
  143. else if (command.startsWith("admin_goto_char_menu"))
  144. {
  145. try
  146. {
  147. String targetName = command.substring(21);
  148. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  149. activeChar.setInstanceId(player.getInstanceId());
  150. teleportToCharacter(activeChar, player);
  151. }
  152. catch (StringIndexOutOfBoundsException e)
  153. {
  154. }
  155. }
  156. else if (command.equals("admin_kill_menu"))
  157. {
  158. handleKill(activeChar);
  159. }
  160. else if (command.startsWith("admin_kick_menu"))
  161. {
  162. StringTokenizer st = new StringTokenizer(command);
  163. if (st.countTokens() > 1)
  164. {
  165. st.nextToken();
  166. String player = st.nextToken();
  167. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  168. String text;
  169. if (plyr != null)
  170. {
  171. plyr.logout();
  172. text = "You kicked " + plyr.getName() + " from the game.";
  173. }
  174. else
  175. {
  176. text = "Player " + player + " was not found in the game.";
  177. }
  178. activeChar.sendMessage(text);
  179. }
  180. showMainPage(activeChar);
  181. }
  182. else if (command.startsWith("admin_ban_menu"))
  183. {
  184. StringTokenizer st = new StringTokenizer(command);
  185. if (st.countTokens() > 1)
  186. {
  187. String subCommand = "admin_ban_char";
  188. if (!AdminTable.getInstance().hasAccess(subCommand, activeChar.getAccessLevel()))
  189. {
  190. activeChar.sendMessage("You don't have the access right to use this command!");
  191. _log.warning("Character " + activeChar.getName() + " tryed to use admin command " + subCommand + ", but have no access to it!");
  192. return false;
  193. }
  194. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getHandler(subCommand);
  195. ach.useAdminCommand(subCommand + command.substring(14), activeChar);
  196. }
  197. showMainPage(activeChar);
  198. }
  199. else if (command.startsWith("admin_unban_menu"))
  200. {
  201. StringTokenizer st = new StringTokenizer(command);
  202. if (st.countTokens() > 1)
  203. {
  204. String subCommand = "admin_unban_char";
  205. if (!AdminTable.getInstance().hasAccess(subCommand, activeChar.getAccessLevel()))
  206. {
  207. activeChar.sendMessage("You don't have the access right to use this command!");
  208. _log.warning("Character " + activeChar.getName() + " tryed to use admin command " + subCommand + ", but have no access to it!");
  209. return false;
  210. }
  211. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getHandler(subCommand);
  212. ach.useAdminCommand(subCommand + command.substring(16), activeChar);
  213. }
  214. showMainPage(activeChar);
  215. }
  216. return true;
  217. }
  218. @Override
  219. public String[] getAdminCommandList()
  220. {
  221. return ADMIN_COMMANDS;
  222. }
  223. private void handleKill(L2PcInstance activeChar)
  224. {
  225. handleKill(activeChar, null);
  226. }
  227. private void handleKill(L2PcInstance activeChar, String player)
  228. {
  229. L2Object obj = activeChar.getTarget();
  230. L2Character target = (L2Character) obj;
  231. String filename = "main_menu.htm";
  232. if (player != null)
  233. {
  234. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  235. if (plyr != null)
  236. {
  237. target = plyr;
  238. activeChar.sendMessage("You killed " + plyr.getName());
  239. }
  240. }
  241. if (target != null)
  242. {
  243. if (target instanceof L2PcInstance)
  244. {
  245. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar, null);
  246. filename = "charmanage.htm";
  247. }
  248. else if (Config.L2JMOD_CHAMPION_ENABLE && target.isChampion())
  249. {
  250. target.reduceCurrentHp((target.getMaxHp() * Config.L2JMOD_CHAMPION_HP) + 1, activeChar, null);
  251. }
  252. else
  253. {
  254. target.reduceCurrentHp(target.getMaxHp() + 1, activeChar, null);
  255. }
  256. }
  257. else
  258. {
  259. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  260. }
  261. AdminHtml.showAdminHtml(activeChar, filename);
  262. }
  263. private void teleportCharacter(L2PcInstance player, int x, int y, int z, L2PcInstance activeChar, String message)
  264. {
  265. if (player != null)
  266. {
  267. player.sendMessage(message);
  268. player.teleToLocation(x, y, z, true);
  269. }
  270. showMainPage(activeChar);
  271. }
  272. private void teleportToCharacter(L2PcInstance activeChar, L2Object target)
  273. {
  274. L2PcInstance player = null;
  275. if (target instanceof L2PcInstance)
  276. {
  277. player = (L2PcInstance) target;
  278. }
  279. else
  280. {
  281. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  282. return;
  283. }
  284. if (player.getObjectId() == activeChar.getObjectId())
  285. {
  286. player.sendPacket(SystemMessageId.CANNOT_USE_ON_YOURSELF);
  287. }
  288. else
  289. {
  290. activeChar.setInstanceId(player.getInstanceId());
  291. activeChar.teleToLocation(player.getX(), player.getY(), player.getZ(), true);
  292. activeChar.sendMessage("You're teleporting yourself to character " + player.getName());
  293. }
  294. showMainPage(activeChar);
  295. }
  296. /**
  297. * @param activeChar
  298. */
  299. private void showMainPage(L2PcInstance activeChar)
  300. {
  301. AdminHtml.showAdminHtml(activeChar, "charmanage.htm");
  302. }
  303. }