AdminMenu.java 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  30. /**
  31. * This class handles following admin commands:
  32. * - handles every admin menu command
  33. *
  34. * @version $Revision: 1.3.2.6.2.4 $ $Date: 2005/04/11 10:06:06 $
  35. */
  36. public class AdminMenu implements IAdminCommandHandler
  37. {
  38. private static final Logger _log = Logger.getLogger(AdminMenu.class.getName());
  39. private static final String[] ADMIN_COMMANDS =
  40. {
  41. "admin_char_manage",
  42. "admin_teleport_character_to_menu",
  43. "admin_recall_char_menu",
  44. "admin_recall_party_menu",
  45. "admin_recall_clan_menu",
  46. "admin_goto_char_menu",
  47. "admin_kick_menu",
  48. "admin_kill_menu",
  49. "admin_ban_menu",
  50. "admin_unban_menu"
  51. };
  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(SystemMessage.getSystemMessage(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(SystemMessage.getSystemMessage(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().getAdminCommandHandler(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().getAdminCommandHandler(subCommand);
  200. ach.useAdminCommand(subCommand+command.substring(16), activeChar);
  201. }
  202. showMainPage(activeChar);
  203. }
  204. return true;
  205. }
  206. public String[] getAdminCommandList()
  207. {
  208. return ADMIN_COMMANDS;
  209. }
  210. private void handleKill(L2PcInstance activeChar)
  211. {
  212. handleKill(activeChar, null);
  213. }
  214. private void handleKill(L2PcInstance activeChar, String player)
  215. {
  216. L2Object obj = activeChar.getTarget();
  217. L2Character target = (L2Character) obj;
  218. String filename = "main_menu.htm";
  219. if (player != null)
  220. {
  221. L2PcInstance plyr = L2World.getInstance().getPlayer(player);
  222. if (plyr != null)
  223. target = plyr;
  224. activeChar.sendMessage("You killed " + plyr.getName());
  225. }
  226. if (target != null)
  227. {
  228. if (target instanceof L2PcInstance)
  229. {
  230. target.reduceCurrentHp(target.getMaxHp() + target.getMaxCp() + 1, activeChar, null);
  231. filename = "charmanage.htm";
  232. }
  233. else if (Config.L2JMOD_CHAMPION_ENABLE && target.isChampion())
  234. target.reduceCurrentHp(target.getMaxHp() * Config.L2JMOD_CHAMPION_HP + 1, activeChar, null);
  235. else
  236. target.reduceCurrentHp(target.getMaxHp() + 1, activeChar, null);
  237. }
  238. else
  239. {
  240. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  241. }
  242. AdminHelpPage.showHelpPage(activeChar, filename);
  243. }
  244. private void teleportCharacter(L2PcInstance player, int x, int y, int z, L2PcInstance activeChar, String message)
  245. {
  246. if (player != null)
  247. {
  248. player.sendMessage(message);
  249. player.teleToLocation(x, y, z, true);
  250. }
  251. showMainPage(activeChar);
  252. }
  253. private void teleportToCharacter(L2PcInstance activeChar, L2Object target)
  254. {
  255. L2PcInstance player = null;
  256. if (target instanceof L2PcInstance)
  257. player = (L2PcInstance) target;
  258. else
  259. {
  260. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.INCORRECT_TARGET));
  261. return;
  262. }
  263. if (player.getObjectId() == activeChar.getObjectId())
  264. player.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CANNOT_USE_ON_YOURSELF));
  265. else
  266. {
  267. activeChar.setInstanceId(player.getInstanceId());
  268. activeChar.teleToLocation(player.getX(), player.getY(), player.getZ(), true);
  269. activeChar.sendMessage("You're teleporting yourself to character " + player.getName());
  270. }
  271. showMainPage(activeChar);
  272. }
  273. /**
  274. * @param activeChar
  275. */
  276. private void showMainPage(L2PcInstance activeChar)
  277. {
  278. AdminHelpPage.showHelpPage(activeChar, "charmanage.htm");
  279. }
  280. }