RequestBypassToServer.java 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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 net.sf.l2j.gameserver.clientpackets;
  16. import java.util.StringTokenizer;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import net.sf.l2j.Config;
  20. import net.sf.l2j.gameserver.ai.CtrlIntention;
  21. import net.sf.l2j.gameserver.communitybbs.CommunityBoard;
  22. import net.sf.l2j.gameserver.datatables.AdminCommandAccessRights;
  23. import net.sf.l2j.gameserver.handler.AdminCommandHandler;
  24. import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  25. import net.sf.l2j.gameserver.model.GMAudit;
  26. import net.sf.l2j.gameserver.model.L2CharPosition;
  27. import net.sf.l2j.gameserver.model.L2Object;
  28. import net.sf.l2j.gameserver.model.L2World;
  29. import net.sf.l2j.gameserver.model.actor.instance.L2NpcInstance;
  30. import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance;
  31. import net.sf.l2j.gameserver.model.entity.L2Event;
  32. import net.sf.l2j.gameserver.serverpackets.ActionFailed;
  33. import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage;
  34. /**
  35. * This class ...
  36. *
  37. * @version $Revision: 1.12.4.5 $ $Date: 2005/04/11 10:06:11 $
  38. */
  39. public final class RequestBypassToServer extends L2GameClientPacket
  40. {
  41. private static final String _C__21_REQUESTBYPASSTOSERVER = "[C] 21 RequestBypassToServer";
  42. private static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
  43. // S
  44. private String _command;
  45. /**
  46. * @param decrypt
  47. */
  48. @Override
  49. protected void readImpl()
  50. {
  51. _command = readS();
  52. }
  53. @Override
  54. protected void runImpl()
  55. {
  56. L2PcInstance activeChar = getClient().getActiveChar();
  57. if (activeChar == null)
  58. return;
  59. try {
  60. if (_command.startsWith("admin_")) //&& activeChar.getAccessLevel() >= Config.GM_ACCESSLEVEL)
  61. {
  62. String command = _command.split(" ")[0];
  63. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getAdminCommandHandler(command);
  64. if (ach == null)
  65. {
  66. if ( activeChar.isGM() )
  67. activeChar.sendMessage("The command " + command.split("_")[0] + " does not exists!");
  68. _log.warning("No handler registered for admin command '" + command + "'");
  69. return;
  70. }
  71. if (!AdminCommandAccessRights.getInstance().hasAccess(command, activeChar.getAccessLevel()))
  72. {
  73. activeChar.sendMessage("You don't have the access right to use this command!");
  74. _log.warning("Character " + activeChar.getName() + " tryed to use admin command " + command + ", but have no access to it!");
  75. return;
  76. }
  77. if (Config.GMAUDIT)
  78. GMAudit.auditGMAction(activeChar.getName(), _command, (activeChar.getTarget() != null?activeChar.getTarget().getName():"no-target"));
  79. ach.useAdminCommand(_command, activeChar);
  80. }
  81. else if (_command.equals("come_here") && ( activeChar.isGM()))
  82. {
  83. comeHere(activeChar);
  84. }
  85. else if (_command.startsWith("player_help "))
  86. {
  87. playerHelp(activeChar, _command.substring(12));
  88. }
  89. else if (_command.startsWith("npc_"))
  90. {
  91. if(!activeChar.validateBypass(_command))
  92. return;
  93. int endOfId = _command.indexOf('_', 5);
  94. String id;
  95. if (endOfId > 0)
  96. id = _command.substring(4, endOfId);
  97. else
  98. id = _command.substring(4);
  99. try
  100. {
  101. L2Object object = L2World.getInstance().findObject(Integer.parseInt(id));
  102. if (_command.substring(endOfId+1).startsWith("event_participate")) L2Event.inscribePlayer(activeChar);
  103. else if (object instanceof L2NpcInstance && endOfId > 0 && activeChar.isInsideRadius(object, L2NpcInstance.INTERACTION_DISTANCE, false, false))
  104. {
  105. ((L2NpcInstance)object).onBypassFeedback(activeChar, _command.substring(endOfId+1));
  106. }
  107. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  108. }
  109. catch (NumberFormatException nfe) {}
  110. }
  111. // Draw a Symbol
  112. else if (_command.equals("menu_select?ask=-16&reply=1"))
  113. {
  114. L2Object object = activeChar.getTarget();
  115. if (object instanceof L2NpcInstance)
  116. {
  117. ((L2NpcInstance) object).onBypassFeedback(activeChar, _command);
  118. }
  119. }
  120. else if (_command.equals("menu_select?ask=-16&reply=2"))
  121. {
  122. L2Object object = activeChar.getTarget();
  123. if (object instanceof L2NpcInstance)
  124. {
  125. ((L2NpcInstance) object).onBypassFeedback(activeChar, _command);
  126. }
  127. }
  128. // Navigate through Manor windows
  129. else if (_command.startsWith("manor_menu_select?"))
  130. {
  131. L2Object object = activeChar.getTarget();
  132. if (object instanceof L2NpcInstance)
  133. {
  134. ((L2NpcInstance) object).onBypassFeedback(activeChar, _command);
  135. }
  136. }
  137. else if (_command.startsWith("bbs_"))
  138. {
  139. CommunityBoard.getInstance().handleCommands(getClient(), _command);
  140. }
  141. else if (_command.startsWith("_bbs"))
  142. {
  143. CommunityBoard.getInstance().handleCommands(getClient(), _command);
  144. }
  145. else if (_command.startsWith("Quest "))
  146. {
  147. if(!activeChar.validateBypass(_command))
  148. return;
  149. L2PcInstance player = getClient().getActiveChar();
  150. if (player == null) return;
  151. String p = _command.substring(6).trim();
  152. int idx = p.indexOf(' ');
  153. if (idx < 0)
  154. player.processQuestEvent(p, "");
  155. else
  156. player.processQuestEvent(p.substring(0, idx), p.substring(idx).trim());
  157. }
  158. }
  159. catch (Exception e)
  160. {
  161. _log.log(Level.WARNING, "Bad RequestBypassToServer: ", e);
  162. }
  163. // finally
  164. // {
  165. // activeChar.clearBypass();
  166. // }
  167. }
  168. /**
  169. * @param client
  170. */
  171. private void comeHere(L2PcInstance activeChar)
  172. {
  173. L2Object obj = activeChar.getTarget();
  174. if (obj == null) return;
  175. if (obj instanceof L2NpcInstance)
  176. {
  177. L2NpcInstance temp = (L2NpcInstance) obj;
  178. temp.setTarget(activeChar);
  179. temp.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO,
  180. new L2CharPosition(activeChar.getX(),activeChar.getY(), activeChar.getZ(), 0 ));
  181. // temp.moveTo(player.getX(),player.getY(), player.getZ(), 0 );
  182. }
  183. }
  184. private void playerHelp(L2PcInstance activeChar, String path)
  185. {
  186. if (path.indexOf("..") != -1)
  187. return;
  188. StringTokenizer st = new StringTokenizer(path);
  189. String[] cmd = st.nextToken().split("#");
  190. if (cmd.length > 1)
  191. {
  192. int itemId = 0;
  193. itemId = Integer.parseInt(cmd[1]);
  194. String filename = "data/html/help/"+cmd[0];
  195. NpcHtmlMessage html = new NpcHtmlMessage(1,itemId);
  196. html.setFile(filename);
  197. activeChar.sendPacket(html);
  198. }
  199. else
  200. {
  201. String filename = "data/html/help/"+path;
  202. NpcHtmlMessage html = new NpcHtmlMessage(1);
  203. html.setFile(filename);
  204. activeChar.sendPacket(html);
  205. }
  206. }
  207. /* (non-Javadoc)
  208. * @see net.sf.l2j.gameserver.clientpackets.ClientBasePacket#getType()
  209. */
  210. @Override
  211. public String getType()
  212. {
  213. return _C__21_REQUESTBYPASSTOSERVER;
  214. }
  215. }