AdminMenu.java 9.3 KB

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