Guest User

RQBp.java

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