RequestBypassToServer.java 10 KB

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