RequestBypassToServer.java 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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.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.Hero;
  34. import com.l2jserver.gameserver.model.entity.L2Event;
  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.ConfirmDlg;
  40. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  41. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  42. import com.l2jserver.gameserver.util.GMAudit;
  43. /**
  44. * This class ...
  45. *
  46. * @version $Revision: 1.12.4.5 $ $Date: 2005/04/11 10:06:11 $
  47. */
  48. public final class RequestBypassToServer extends L2GameClientPacket
  49. {
  50. private static final String _C__23_REQUESTBYPASSTOSERVER = "[C] 23 RequestBypassToServer";
  51. private static Logger _log = Logger.getLogger(RequestBypassToServer.class.getName());
  52. // S
  53. private String _command;
  54. @Override
  55. protected void readImpl()
  56. {
  57. _command = readS();
  58. }
  59. @Override
  60. protected void runImpl()
  61. {
  62. final L2PcInstance activeChar = getClient().getActiveChar();
  63. if (activeChar == null)
  64. return;
  65. if (!getClient().getFloodProtectors().getServerBypass().tryPerformAction(_command))
  66. return;
  67. if(_command.isEmpty())
  68. {
  69. _log.info(activeChar.getName()+" send empty requestbypass");
  70. activeChar.logout();
  71. return;
  72. }
  73. try
  74. {
  75. if (_command.startsWith("admin_")) //&& activeChar.getAccessLevel() >= Config.GM_ACCESSLEVEL)
  76. {
  77. String command = _command.split(" ")[0];
  78. IAdminCommandHandler ach = AdminCommandHandler.getInstance().getAdminCommandHandler(command);
  79. if (ach == null)
  80. {
  81. if ( activeChar.isGM() )
  82. activeChar.sendMessage("The command " + command.substring(6) + " does not exist!");
  83. _log.warning("No handler registered for admin command '" + command + "'");
  84. return;
  85. }
  86. if (!AdminCommandAccessRights.getInstance().hasAccess(command, activeChar.getAccessLevel()))
  87. {
  88. activeChar.sendMessage("You don't have the access rights to use this command!");
  89. _log.warning("Character " + activeChar.getName() + " tried to use admin command " + command + ", without proper access level!");
  90. return;
  91. }
  92. if (AdminCommandAccessRights.getInstance().requireConfirm(command))
  93. {
  94. activeChar.setAdminConfirmCmd(_command);
  95. ConfirmDlg dlg = new ConfirmDlg(SystemMessageId.S1);
  96. dlg.addString("Are you sure you want execute command "+_command.substring(6)+" ?");
  97. activeChar.sendPacket(dlg);
  98. }
  99. else
  100. {
  101. if (Config.GMAUDIT)
  102. GMAudit.auditGMAction(activeChar.getName()+" ["+activeChar.getObjectId()+"]", _command, (activeChar.getTarget() != null?activeChar.getTarget().getName():"no-target"));
  103. ach.useAdminCommand(_command, activeChar);
  104. }
  105. }
  106. else if (_command.equals("come_here") && ( activeChar.isGM()))
  107. {
  108. comeHere(activeChar);
  109. }
  110. else if (_command.startsWith("npc_"))
  111. {
  112. if(!activeChar.validateBypass(_command))
  113. return;
  114. int endOfId = _command.indexOf('_', 5);
  115. String id;
  116. if (endOfId > 0)
  117. id = _command.substring(4, endOfId);
  118. else
  119. id = _command.substring(4);
  120. try
  121. {
  122. L2Object object = L2World.getInstance().findObject(Integer.parseInt(id));
  123. if (_command.substring(endOfId+1).startsWith("event_participate"))
  124. L2Event.inscribePlayer(activeChar);
  125. else if (object instanceof L2Npc && endOfId > 0 && activeChar.isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false))
  126. ((L2Npc)object).onBypassFeedback(activeChar, _command.substring(endOfId+1));
  127. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  128. }
  129. catch (NumberFormatException nfe) {}
  130. }
  131. else if (_command.startsWith("summon_"))
  132. {
  133. if(!activeChar.validateBypass(_command))
  134. return;
  135. int endOfId = _command.indexOf('_', 8);
  136. String id;
  137. if (endOfId > 0)
  138. id = _command.substring(7, endOfId);
  139. else
  140. id = _command.substring(7);
  141. try
  142. {
  143. L2Object object = L2World.getInstance().findObject(Integer.parseInt(id));
  144. if (object instanceof L2MerchantSummonInstance && endOfId > 0 && activeChar.isInsideRadius(object, L2Npc.INTERACTION_DISTANCE, false, false))
  145. ((L2MerchantSummonInstance)object).onBypassFeedback(activeChar, _command.substring(endOfId+1));
  146. activeChar.sendPacket(ActionFailed.STATIC_PACKET);
  147. }
  148. catch (NumberFormatException nfe) {}
  149. }
  150. // Navigate through Manor windows
  151. else if (_command.startsWith("manor_menu_select"))
  152. {
  153. final IBypassHandler manor = BypassHandler.getInstance().getBypassHandler("manor_menu_select");
  154. if (manor != null)
  155. manor.useBypass(_command, activeChar, null);
  156. }
  157. else if (_command.startsWith("_bbs"))
  158. {
  159. if (Config.ENABLE_COMMUNITY_BOARD)
  160. {
  161. if (!CommunityServerThread.getInstance().sendPacket(new RequestShowCommunityBoard(activeChar.getObjectId(), _command)))
  162. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CB_OFFLINE));
  163. }
  164. else
  165. CommunityBoard.getInstance().handleCommands(getClient(), _command);
  166. }
  167. else if (_command.startsWith("_mail"))
  168. {
  169. if (!CommunityServerThread.getInstance().sendPacket(new RequestShowCommunityBoard(activeChar.getObjectId(), "_bbsmail")))
  170. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CB_OFFLINE));
  171. }
  172. else if (_command.startsWith("_friend"))
  173. {
  174. if (!CommunityServerThread.getInstance().sendPacket(new RequestShowCommunityBoard(activeChar.getObjectId(), "_bbsfriend")))
  175. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.CB_OFFLINE));
  176. }
  177. else if (_command.startsWith("Quest "))
  178. {
  179. if(!activeChar.validateBypass(_command))
  180. return;
  181. L2PcInstance player = getClient().getActiveChar();
  182. if (player == null) return;
  183. String p = _command.substring(6).trim();
  184. int idx = p.indexOf(' ');
  185. if (idx < 0)
  186. player.processQuestEvent(p, "");
  187. else
  188. player.processQuestEvent(p.substring(0, idx), p.substring(idx).trim());
  189. }
  190. else if (_command.startsWith("_match"))
  191. {
  192. L2PcInstance player = getClient().getActiveChar();
  193. if (player == null) return;
  194. String params = _command.substring(_command.indexOf("?")+1);
  195. StringTokenizer st = new StringTokenizer(params, "&");
  196. int heroclass = Integer.parseInt(st.nextToken().split("=")[1]);
  197. int heropage = Integer.parseInt(st.nextToken().split("=")[1]);
  198. int heroid = Hero.getInstance().getHeroByClass(heroclass);
  199. if( heroid > 0)
  200. {
  201. Hero.getInstance().showHeroFights(player, heroclass, heroid, heropage);
  202. }
  203. }
  204. else if (_command.startsWith("_diary"))
  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().showHeroDiary(player, heroclass, heroid, heropage);
  216. }
  217. }
  218. else
  219. {
  220. final IBypassHandler handler = BypassHandler.getInstance().getBypassHandler(_command);
  221. if (handler != null)
  222. handler.useBypass(_command, activeChar, null);
  223. else
  224. _log.log(Level.WARNING, getClient()+" sent not handled RequestBypassToServer: ["+_command+"]");
  225. }
  226. }
  227. catch (Exception e)
  228. {
  229. _log.log(Level.WARNING, getClient()+" sent bad RequestBypassToServer: \""+_command+"\"", e);
  230. if (activeChar.isGM())
  231. {
  232. StringBuilder sb = new StringBuilder(200);
  233. sb.append("<html><body>");
  234. sb.append("Bypass error: "+e+"<br1>");
  235. sb.append("Bypass command: "+_command+"<br1>");
  236. sb.append("StackTrace:<br1>");
  237. for (StackTraceElement ste : e.getStackTrace())
  238. sb.append(ste.toString()+"<br1>");
  239. sb.append("</body></html>");
  240. // item html
  241. NpcHtmlMessage msg = new NpcHtmlMessage(0,12807);
  242. msg.setHtml(sb.toString());
  243. msg.disableValidation();
  244. activeChar.sendPacket(msg);
  245. }
  246. }
  247. }
  248. /**
  249. * @param client
  250. */
  251. private static void comeHere(L2PcInstance activeChar)
  252. {
  253. L2Object obj = activeChar.getTarget();
  254. if (obj == null) return;
  255. if (obj instanceof L2Npc)
  256. {
  257. L2Npc temp = (L2Npc) obj;
  258. temp.setTarget(activeChar);
  259. temp.getAI().setIntention(CtrlIntention.AI_INTENTION_MOVE_TO, new L2CharPosition(activeChar.getX(),activeChar.getY(), activeChar.getZ(), 0 ));
  260. }
  261. }
  262. /* (non-Javadoc)
  263. * @see com.l2jserver.gameserver.clientpackets.ClientBasePacket#getType()
  264. */
  265. @Override
  266. public String getType()
  267. {
  268. return _C__23_REQUESTBYPASSTOSERVER;
  269. }
  270. }