RequestBypassToServer.java 12 KB

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