RequestBypassToServer.java 11 KB

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