AdminMenu.java 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /*
  2. * Copyright (C) 2004-2015 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.data.xml.impl.AdminData;
  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.Location;
  31. import com.l2jserver.gameserver.model.actor.L2Character;
  32. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  33. import com.l2jserver.gameserver.network.SystemMessageId;
  34. /**
  35. * This class handles following admin commands: - handles every admin menu command
  36. * @version $Revision: 1.3.2.6.2.4 $ $Date: 2005/04/11 10:06:06 $
  37. */
  38. public class AdminMenu implements IAdminCommandHandler
  39. {
  40. private static final Logger _log = Logger.getLogger(AdminMenu.class.getName());
  41. private static final String[] ADMIN_COMMANDS =
  42. {
  43. "admin_char_manage",
  44. "admin_teleport_character_to_menu",
  45. "admin_recall_char_menu",
  46. "admin_recall_party_menu",
  47. "admin_recall_clan_menu",
  48. "admin_goto_char_menu",
  49. "admin_kick_menu",
  50. "admin_kill_menu",
  51. "admin_ban_menu",
  52. "admin_unban_menu"
  53. };
  54. @Override
  55. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  56. {
  57. if (command.equals("admin_char_manage"))
  58. {
  59. showMainPage(activeChar);
  60. }
  61. else if (command.startsWith("admin_teleport_character_to_menu"))
  62. {
  63. String[] data = command.split(" ");
  64. if (data.length == 5)
  65. {
  66. String playerName = data[1];
  67. L2PcInstance player = L2World.getInstance().getPlayer(playerName);
  68. if (player != null)
  69. {
  70. teleportCharacter(player, new Location(Integer.parseInt(data[2]), Integer.parseInt(data[3]), Integer.parseInt(data[4])), activeChar, "Admin is teleporting you.");
  71. }
  72. }
  73. showMainPage(activeChar);
  74. }
  75. else if (command.startsWith("admin_recall_char_menu"))
  76. {
  77. try
  78. {
  79. String targetName = command.substring(23);
  80. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  81. teleportCharacter(player, activeChar.getLocation(), activeChar, "Admin is teleporting you.");
  82. }
  83. catch (StringIndexOutOfBoundsException e)
  84. {
  85. }
  86. }
  87. else if (command.startsWith("admin_recall_party_menu"))
  88. {
  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, activeChar.getLocation(), activeChar, "Admin is teleporting you.");
  102. return true;
  103. }
  104. for (L2PcInstance pm : player.getParty().getMembers())
  105. {
  106. teleportCharacter(pm, activeChar.getLocation(), 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. try
  117. {
  118. String targetName = command.substring(23);
  119. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  120. if (player == null)
  121. {
  122. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  123. return true;
  124. }
  125. L2Clan clan = player.getClan();
  126. if (clan == null)
  127. {
  128. activeChar.sendMessage("Player is not in a clan.");
  129. teleportCharacter(player, activeChar.getLocation(), activeChar, "Admin is teleporting you.");
  130. return true;
  131. }
  132. for (L2PcInstance member : clan.getOnlineMembers(0))
  133. {
  134. teleportCharacter(member, activeChar.getLocation(), activeChar, "Your clan is being teleported by an Admin.");
  135. }
  136. }
  137. catch (Exception e)
  138. {
  139. _log.log(Level.WARNING, "", e);
  140. }
  141. }
  142. else if (command.startsWith("admin_goto_char_menu"))
  143. {
  144. try
  145. {
  146. String targetName = command.substring(21);
  147. L2PcInstance player = L2World.getInstance().getPlayer(targetName);
  148. activeChar.setInstanceId(player.getInstanceId());
  149. teleportToCharacter(activeChar, player);
  150. }
  151. catch (StringIndexOutOfBoundsException e)
  152. {
  153. }
  154. }
  155. else if (command.equals("admin_kill_menu"))
  156. {
  157. handleKill(activeChar);
  158. }
  159. else if (command.startsWith("admin_kick_menu"))
  160. {
  161. StringTokenizer st = new StringTokenizer(command);
  162. if (st.countTokens() > 1)
  163. {
  164. st.nextToken();
  165. String player = st.nextToken();
  166. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  167. String text;
  168. if (plyr != null)
  169. {
  170. plyr.logout();
  171. text = "You kicked " + plyr.getName() + " from the game.";
  172. }
  173. else
  174. {
  175. text = "Player " + player + " was not found in the game.";
  176. }
  177. activeChar.sendMessage(text);
  178. }
  179. showMainPage(activeChar);
  180. }
  181. else if (command.startsWith("admin_ban_menu"))
  182. {
  183. StringTokenizer st = new StringTokenizer(command);
  184. if (st.countTokens() > 1)
  185. {
  186. String subCommand = "admin_ban_char";
  187. if (!AdminData.getInstance().hasAccess(subCommand, activeChar.getAccessLevel()))
  188. {
  189. activeChar.sendMessage("You don't have the access right to use this command!");
  190. _log.warning("Character " + activeChar.getName() + " tryed to use admin command " + subCommand + ", but have no access to it!");
  191. return false;
  192. }
  193. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getHandler(subCommand);
  194. ach.useAdminCommand(subCommand + command.substring(14), activeChar);
  195. }
  196. showMainPage(activeChar);
  197. }
  198. else if (command.startsWith("admin_unban_menu"))
  199. {
  200. StringTokenizer st = new StringTokenizer(command);
  201. if (st.countTokens() > 1)
  202. {
  203. String subCommand = "admin_unban_char";
  204. if (!AdminData.getInstance().hasAccess(subCommand, activeChar.getAccessLevel()))
  205. {
  206. activeChar.sendMessage("You don't have the access right to use this command!");
  207. _log.warning("Character " + activeChar.getName() + " tryed to use admin command " + subCommand + ", but have no access to it!");
  208. return false;
  209. }
  210. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getHandler(subCommand);
  211. ach.useAdminCommand(subCommand + command.substring(16), activeChar);
  212. }
  213. showMainPage(activeChar);
  214. }
  215. return true;
  216. }
  217. @Override
  218. public String[] getAdminCommandList()
  219. {
  220. return ADMIN_COMMANDS;
  221. }
  222. private void handleKill(L2PcInstance activeChar)
  223. {
  224. handleKill(activeChar, null);
  225. }
  226. private void handleKill(L2PcInstance activeChar, String player)
  227. {
  228. L2Object obj = activeChar.getTarget();
  229. L2Character target = (L2Character) obj;
  230. String filename = "main_menu.htm";
  231. if (player != null)
  232. {
  233. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  234. if (plyr != null)
  235. {
  236. target = plyr;
  237. activeChar.sendMessage("You killed " + plyr.getName());
  238. }
  239. }
  240. if (target != null)
  241. {
  242. if (target instanceof L2PcInstance)
  243. {
  244. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar, null);
  245. filename = "charmanage.htm";
  246. }
  247. else if (Config.L2JMOD_CHAMPION_ENABLE && target.isChampion())
  248. {
  249. target.reduceCurrentHp((target.getMaxHp() * Config.L2JMOD_CHAMPION_HP) + 1, activeChar, null);
  250. }
  251. else
  252. {
  253. target.reduceCurrentHp(target.getMaxHp() + 1, activeChar, null);
  254. }
  255. }
  256. else
  257. {
  258. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  259. }
  260. AdminHtml.showAdminHtml(activeChar, filename);
  261. }
  262. private void teleportCharacter(L2PcInstance player, Location loc, L2PcInstance activeChar, String message)
  263. {
  264. if (player != null)
  265. {
  266. player.sendMessage(message);
  267. player.teleToLocation(loc, true);
  268. }
  269. showMainPage(activeChar);
  270. }
  271. private void teleportToCharacter(L2PcInstance activeChar, L2Object target)
  272. {
  273. L2PcInstance player = null;
  274. if (target instanceof L2PcInstance)
  275. {
  276. player = (L2PcInstance) target;
  277. }
  278. else
  279. {
  280. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  281. return;
  282. }
  283. if (player.getObjectId() == activeChar.getObjectId())
  284. {
  285. player.sendPacket(SystemMessageId.CANNOT_USE_ON_YOURSELF);
  286. }
  287. else
  288. {
  289. activeChar.setInstanceId(player.getInstanceId());
  290. activeChar.teleToLocation(player.getLocation(), true);
  291. activeChar.sendMessage("You're teleporting yourself to character " + player.getName());
  292. }
  293. showMainPage(activeChar);
  294. }
  295. /**
  296. * @param activeChar
  297. */
  298. private void showMainPage(L2PcInstance activeChar)
  299. {
  300. AdminHtml.showAdminHtml(activeChar, "charmanage.htm");
  301. }
  302. }