RequestBypassToServer.java 12 KB

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