RequestBypassToServer.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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.L2CastleChamberlainInstance;
  32. import com.l2jserver.gameserver.model.actor.instance.L2ManorManagerInstance;
  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. /*if(!activeChar.validateBypass(_command))
  150. return;*/
  151. L2Object object = activeChar.getLastFolkNPC();
  152. if ((object instanceof L2ManorManagerInstance || object instanceof L2CastleChamberlainInstance)
  153. && activeChar.isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false))
  154. ((L2Npc) object).onBypassFeedback(activeChar, _command);
  155. }
  156. else if (_command.startsWith("bbs_"))
  157. {
  158. if (Config.ENABLE_COMMUNITY_BOARD)
  159. {
  160. if (!CommunityServerThread.getInstance().sendPacket(new RequestShowCommunityBoard(activeChar.getObjectId(), _command)))
  161. activeChar.sendPacket(new SystemMessage(SystemMessageId.CB_OFFLINE));
  162. }
  163. else
  164. CommunityBoard.getInstance().handleCommands(getClient(), _command);
  165. }
  166. else if (_command.startsWith("_bbsloc"))
  167. {
  168. CommunityBoard.getInstance().handleCommands(getClient(), _command);
  169. }
  170. else if (_command.startsWith("_bbs"))
  171. {
  172. if (Config.ENABLE_COMMUNITY_BOARD)
  173. {
  174. if (!CommunityServerThread.getInstance().sendPacket(new RequestShowCommunityBoard(activeChar.getObjectId(), _command)))
  175. activeChar.sendPacket(new SystemMessage(SystemMessageId.CB_OFFLINE));
  176. }
  177. else
  178. CommunityBoard.getInstance().handleCommands(getClient(), _command);
  179. }
  180. else if (_command.startsWith("_mail"))
  181. {
  182. if (!CommunityServerThread.getInstance().sendPacket(new RequestShowCommunityBoard(activeChar.getObjectId(), "_bbsmail")))
  183. activeChar.sendPacket(new SystemMessage(SystemMessageId.CB_OFFLINE));
  184. }
  185. else if (_command.startsWith("_friend"))
  186. {
  187. if (!CommunityServerThread.getInstance().sendPacket(new RequestShowCommunityBoard(activeChar.getObjectId(), "_bbsfriend")))
  188. activeChar.sendPacket(new SystemMessage(SystemMessageId.CB_OFFLINE));
  189. }
  190. else if (_command.startsWith("Quest "))
  191. {
  192. if(!activeChar.validateBypass(_command))
  193. return;
  194. L2PcInstance player = getClient().getActiveChar();
  195. if (player == null) return;
  196. String p = _command.substring(6).trim();
  197. int idx = p.indexOf(' ');
  198. if (idx < 0)
  199. player.processQuestEvent(p, "");
  200. else
  201. player.processQuestEvent(p.substring(0, idx), p.substring(idx).trim());
  202. }
  203. else if (_command.startsWith("OlympiadArenaChange"))
  204. {
  205. Olympiad.bypassChangeArena(_command, activeChar);
  206. }
  207. else if (_command.startsWith("_match"))
  208. {
  209. L2PcInstance player = getClient().getActiveChar();
  210. if (player == null) return;
  211. String params = _command.substring(_command.indexOf("?")+1);
  212. StringTokenizer st = new StringTokenizer(params, "&");
  213. int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
  214. int heropage = Integer.parseInt(st.nextToken().split("=")[1]);
  215. int heroid = Hero.getInstance().getHeroByClass(heroclass);
  216. if( heroid > 0)
  217. {
  218. Hero.getInstance().showHeroFights(player, heroclass, heroid, heropage);
  219. }
  220. }
  221. else if (_command.startsWith("_diary"))
  222. {
  223. L2PcInstance player = getClient().getActiveChar();
  224. if (player == null) return;
  225. String params = _command.substring(_command.indexOf("?")+1);
  226. StringTokenizer st = new StringTokenizer(params, "&");
  227. int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
  228. int heropage = Integer.parseInt(st.nextToken().split("=")[1]);
  229. int heroid = Hero.getInstance().getHeroByClass(heroclass);
  230. if( heroid > 0)
  231. {
  232. Hero.getInstance().showHeroDiary(player, heroclass, heroid, heropage);
  233. }
  234. }
  235. else if (_command.startsWith("voice "))
  236. {
  237. // only voice commands allowed in bypass
  238. if (_command.length() > 7
  239. && _command.charAt(6) == '.')
  240. {
  241. final String vc, vparams;
  242. int endOfCommand = _command.indexOf(" ", 7);
  243. if (endOfCommand > 0)
  244. {
  245. vc = _command.substring(7, endOfCommand).trim();
  246. vparams = _command.substring(endOfCommand).trim();
  247. }
  248. else
  249. {
  250. vc = _command.substring(7).trim();
  251. vparams = null;
  252. }
  253. if (vc.length() > 0)
  254. {
  255. IVoicedCommandHandler vch = VoicedCommandHandler.getInstance().getVoicedCommandHandler(vc);
  256. if (vch != null)
  257. vch.useVoicedCommand(vc, activeChar, vparams);
  258. }
  259. }
  260. }
  261. }
  262. catch (Exception e)
  263. {
  264. _log.log(Level.WARNING, getClient()+" sent bad RequestBypassToServer: \""+_command+"\"", e);
  265. if (activeChar.isGM())
  266. {
  267. StringBuilder sb = new StringBuilder(200);
  268. sb.append("<html><body>");
  269. sb.append("Bypass error: "+e+"<br1>");
  270. sb.append("Bypass command: "+_command+"<br1>");
  271. sb.append("StackTrace:<br1>");
  272. for (StackTraceElement ste : e.getStackTrace())
  273. sb.append(ste.toString()+"<br1>");
  274. sb.append("</body></html>");
  275. // item html
  276. NpcHtmlMessage msg = new NpcHtmlMessage(0,12807);
  277. msg.setHtml(sb.toString());
  278. msg.disableValidation();
  279. activeChar.sendPacket(msg);
  280. }
  281. }
  282. }
  283. /**
  284. * @param client
  285. */
  286. private void comeHere(L2PcInstance activeChar)
  287. {
  288. L2Object obj = activeChar.getTarget();
  289. if (obj == null) return;
  290. if (obj instanceof L2Npc)
  291. {
  292. L2Npc temp = (L2Npc) obj;
  293. temp.setTarget(activeChar);
  294. temp.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(activeChar.getX(),activeChar.getY(), activeChar.getZ(), 0 ));
  295. }
  296. }
  297. private void playerHelp(L2PcInstance activeChar, String path)
  298. {
  299. if (path.indexOf("..") != -1)
  300. return;
  301. StringTokenizer st = new StringTokenizer(path);
  302. String[] cmd = st.nextToken().split("#");
  303. if (cmd.length > 1)
  304. {
  305. int itemId = 0;
  306. itemId = Integer.parseInt(cmd[1]);
  307. String filename = "data/html/help/"+cmd[0];
  308. NpcHtmlMessage html = new NpcHtmlMessage(1,itemId);
  309. html.setFile(activeChar.getHtmlPrefix(), filename);
  310. html.disableValidation();
  311. activeChar.sendPacket(html);
  312. }
  313. else
  314. {
  315. String filename = "data/html/help/"+path;
  316. NpcHtmlMessage html = new NpcHtmlMessage(1);
  317. html.setFile(activeChar.getHtmlPrefix(), filename);
  318. html.disableValidation();
  319. activeChar.sendPacket(html);
  320. }
  321. }
  322. /* (non-Javadoc)
  323. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  324. */
  325. @Override
  326. public String getType()
  327. {
  328. return _C__21_REQUESTBYPASSTOSERVER;
  329. }
  330. }