RequestBypassToServer.java 9.1 KB

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