Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: Tricky on Jun 15th, 2011  |  syntax: None  |  size: 13.51 KB  |  hits: 23  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. /*
  2.  * Class PacketManager
  3.  *
  4.  * Version 1.0
  5.  *
  6.  * Sunday, August 17, 2008
  7.  *
  8.  * Created by Palidino76
  9.  */
  10.  
  11. package palidino76.rs2.io;
  12.  
  13. import palidino76.rs2.Server;
  14. import palidino76.rs2.Engine;
  15. import palidino76.rs2.util.Misc;
  16. import palidino76.rs2.io.packets.*;
  17. import palidino76.rs2.net.SocketListener;
  18. import palidino76.rs2.players.*;
  19. import palidino76.rs2.players.combat.*;
  20.  
  21. public class PacketManager {
  22.     /*
  23.      * Create all the packets for use.
  24.      */
  25.     public Walking walk = new Walking();
  26.     public PublicChat publicChat = new PublicChat();
  27.     public Commands command = new Commands();
  28.     public SwitchItems switchItems = new SwitchItems();
  29.     public ActionButtons actionButtons = new ActionButtons();
  30.     public Equipment equipment = new Equipment();
  31.     public ItemOption1 itemOption1 = new ItemOption1();
  32.     public ItemOperate itemOperate = new ItemOperate();
  33.     public DropItem dropItem = new DropItem();
  34.     public PickupItem pickupItem = new PickupItem();
  35.     public MagicOnPlayer magicOnPlayer = new MagicOnPlayer();
  36.     public PlayerOption1 playerOption1 = new PlayerOption1();
  37.     public PlayerOption2 playerOption2 = new PlayerOption2();
  38.     public PlayerOption3 playerOption3 = new PlayerOption3();
  39.     public NPCAttack npcAttack = new NPCAttack();
  40.     public NPCOption1 npcOption1 = new NPCOption1();
  41.     public NPCOption2 npcOption2 = new NPCOption2();
  42.     public NPCOption3 npcOption3 = new NPCOption3();
  43.     public Shopbuyconfig Shopbuyconfig = new Shopbuyconfig();
  44.     public ItemSelect itemSelect = new ItemSelect();
  45.     public ObjectOption1 objectOption1 = new ObjectOption1();
  46.     public ObjectOption2 objectOption2 = new ObjectOption2();
  47.     public SwitchItems2 switchItems2 = new SwitchItems2();
  48.     public ItemOnItem itemOnItem = new ItemOnItem();
  49.     public ItemOnObject ItemOnObject = new ItemOnObject();
  50.     public MagicOnItem magicOnItem = new MagicOnItem();
  51.     public ItemOnNPC ionpc = new ItemOnNPC();
  52.    
  53.     /**
  54.      * Handle any packets.
  55.      * <p>Handles all packets within the range of 0 - 255. Not every
  56.      * packet has been setup, you'll have to do some yourself.
  57.      * @param p The Player which the frame should be created for.
  58.      * @param packetId The packet id to handle.
  59.      * @param packetSize The number of bytes the packet contains.
  60.      */
  61.     public void parsePacket(Player p, int packetId, int packetSize) {
  62.         if (p == null) {
  63.             return;
  64.         }
  65.         if (p.clickDelay > 0 && packetId != 222) {
  66.             /*
  67.              * When delayed only allow chatting.
  68.              */
  69.             return;
  70.         }
  71.         switch (packetId) {
  72.             case 43:
  73.                 p.input.setInput(p.stream.readDWord());
  74.                 break;         
  75.  
  76.  
  77.                case 63:
  78.                   /*
  79.                    * Click here to continue.
  80.                   */
  81.                p.frames.removeChatboxInterface(p);
  82.                break;
  83.             case 129:
  84.                 int screenId = p.stream.readUnsignedByte();
  85.                 switch(screenId) {
  86.                 case 0:
  87.                 p.Resizable = false;
  88.                 break;
  89.  
  90.                 case 1:
  91.                 p.Resizable = true;
  92.                 break;
  93.  
  94.                 case 2:
  95.                 p.Resizable = true;
  96.                 break;
  97.                 }
  98.                 break;
  99.         case 3:
  100.             /*
  101.              * Equipping an item.
  102.              */
  103.              equipment.handlePacket(p, packetId, packetSize);
  104.              break;
  105.             case 199:
  106.                 /*
  107.                  *Npc Option 3
  108.                  */
  109.             npcOption3.handlePacket(p, packetId, packetSize);
  110.             break;
  111.  
  112.         case 12:
  113.         /*
  114.         *items on npc
  115.         */
  116.                                 ionpc.handlePacket(p, packetId, packetSize);
  117.                                 break;
  118.                     case 253:
  119.                 int playerId = p.stream.readUnsignedWord();
  120.                 playerId -= 33024;
  121.                 playerId = playerId / 256;
  122.                 playerId++;
  123.                 if (playerId < 0 || playerId >= Engine.players.length || Engine.players[playerId] == null) {
  124.                     return;
  125.                 }
  126.                 if (Engine.players[playerId].trade.getPartner() == p) {
  127.                     p.trade.tradePlayer(Engine.players[playerId]);
  128.                 }
  129.  
  130.                 break;
  131.                
  132.                 case 70:
  133.  
  134.             Magic.magicAop(p, packetId, packetSize);
  135.             break;
  136.            
  137.         case 115:
  138.             /*
  139.              * This packet is constantly sent almost like a ping to verify the still exists.
  140.              */
  141.             break;
  142.                     case 154:
  143.             /*
  144.              * Cast a spell on an item.
  145.              */
  146.              magicOnItem.handlePacket(p, packetId, packetSize);
  147.              break;
  148.              
  149.             case 40:
  150.              /*
  151.              * itemonitem.
  152.              */
  153.                         itemOnItem.handlePacket(p, packetId, packetSize);
  154.                         break;
  155.                
  156.         case 224:
  157.  
  158.             /*
  159.              * Item on Object
  160.              */
  161.             ItemOnObject.handlePacket(p, packetId, packetSize);
  162.             break;
  163.            
  164.         case 22:
  165.             /*
  166.              * Recieved every time updateReq is set to true.
  167.              */
  168.             p.stream.readDWord(); // Junk? Same value every time.
  169.             break;
  170.            
  171. case 60:
  172. p.objects();
  173. break;
  174.            
  175.                 case 30:
  176.             /*
  177.              * Pm's, Friends, Ignores.
  178.              */
  179.             long name = p.stream.readQWord();
  180.             if(p.friends.size() >= 200) {
  181.                 p.frames.sendMessage(p, "Your friends list is full.");
  182.                 break;
  183.             }
  184.             if(p.friends.contains((Long) name)) {
  185.                 p.frames.sendMessage(p, "Already on your friends list.");
  186.                 break;
  187.             }
  188.             p.friends.add((Long) name);
  189.             p.frames.sendFriend(p, name, p.getWorld(name));
  190.             break;
  191.         case 61:
  192.             name = p.stream.readQWord();
  193.             if(p.ignores.size() >= 100) {
  194.                 p.frames.sendMessage(p, "Your ignore list is full.");
  195.                 break;
  196.             }
  197.             if(p.ignores.contains((Long) name)) {
  198.                 p.frames.sendMessage(p, "Already on your ignore list.");
  199.                 break;
  200.             }
  201.             p.ignores.add((Long) name);
  202.             break;
  203.         case 132:
  204.             name = p.stream.readQWord();
  205.             p.friends.remove((Long) name);
  206.             break;
  207.         case 2:
  208.             name = p.stream.readQWord();
  209.             p.ignores.remove((Long) name);
  210.             break;
  211.         case 178:
  212.         if(p.checkMutedUsers(p.username) || p.checkMutedHosts(SocketListener.getAddress(p.socket.socket))){
  213.                 p.frames.sendMessage(p, "You are muted for breaking rules.Only admin can unmute you.");
  214.                 return;
  215.                 }
  216.             name = p.stream.readQWord();
  217.             int numChars = p.stream.readUnsignedByte();
  218.             String text = Misc.decryptPlayerChat(p.stream, numChars);
  219.             for(Player p2 : Engine.players) {
  220.                 if(p2 != null && p2.online) {
  221.                     if(Misc.stringToLong(p2.username) == name) {
  222.                         p2.frames.sendReceivedPrivateMessage(p2, Misc.stringToLong(p.username), p.rights, text);
  223.                         p.frames.sendSentPrivateMessage(p, name, text);
  224.                         return;
  225.                     }
  226.                 }
  227.             }
  228.             p.frames.sendMessage(p, "Player is unavailable.");
  229.             break;
  230.         case 99:
  231.             /*
  232.              * Unknown.
  233.              */
  234.             p.stream.readUnsignedWordBigEndianA();
  235.             p.stream.readUnsignedWordA();
  236.             break;
  237. case 24:
  238.                 int npcId = p.stream.readSignedWordA();
  239.                 int buttonId = p.stream.readSignedWordA();
  240.                 int interfaceId = p.stream.readUnsignedWord();
  241.                 if (interfaceId == 192) {
  242.                     p.magicNPC.magicOnNPC(npcId, buttonId);
  243.                 }
  244.                 break;
  245.         case 117:
  246.         case 248:
  247.         case 247: // Possibly a packet sent if the login  is successful.
  248.             /*
  249.              * Unknown.
  250.              */
  251.             break;
  252.         case 59:
  253.             /*
  254.              * Send every time you click your mouse.
  255.              */
  256.             p.stream.readUnsignedWord();
  257.             p.stream.readDWord_v1();
  258.             break;
  259.         case 49:
  260.             /*
  261.              * Main map walking.
  262.              */
  263.         case 119:
  264.             /*
  265.              * Minimap walking.
  266.              */
  267.                                          if(
  268.                                         p.interfaceId==335 ||
  269.                                         p.interfaceId==334) {
  270.                                         return;
  271.                                         }
  272.         case 138:
  273.             /*
  274.              * Other walking.
  275.              */
  276.                         p.wc.resetWoodcutting();
  277.                         p.ResetSkillSuff();
  278.             walk.handlePacket(p, packetId, packetSize);
  279.             break;
  280.  
  281.         case 222:
  282.             /*
  283.              * Public chatting.
  284.              */
  285.             publicChat.handlePacket(p, packetId, packetSize);
  286.             break;
  287.             case 107:
  288.             /*
  289.              * When you type text starting with ::, its sent with this packet Id rather than as
  290.              * Normal chat.
  291.              */
  292.             command.handlePacket(p, packetId, packetSize);
  293.             break;
  294.         case 167:
  295.             /*
  296.              * Switching items on interfaces.
  297.              */
  298.             switchItems.handlePacket(p, packetId, packetSize);
  299.             break;
  300.         case 233:
  301.         case 113:
  302.         case 21:
  303.         case 169:
  304.         case 232:
  305.                 case 214:
  306.                 case 90:
  307.                 case 173:
  308.                 case 226:
  309.                 case 102:
  310.                 case 78:
  311.                 case 133:
  312.             /*
  313.              * When you click an interface button this packet is sent.
  314.              */
  315.                 actionButtons.handlePacket(p, packetId, packetSize);
  316.             break;
  317.         case 203:
  318.         case 152:
  319.             /*
  320.              * Item options 1.
  321.              */
  322.             itemOption1.handlePacket(p, packetId, packetSize);
  323.             break;
  324.         case 186:
  325.             /*
  326.              * Item operating.
  327.              */
  328.             if(p.viewings == 0) {
  329.                 itemOperate.handlePacket(p, packetId, packetSize);
  330.                 } else {
  331.                
  332.                 Shopbuyconfig.handlePacket(p, packetId, packetSize);
  333.             }
  334.         case 211:
  335.             /*
  336.              * Dropping an item.
  337.              */
  338.             dropItem.handlePacket(p, packetId, packetSize);
  339.             break;
  340.         case 201:
  341.             /*
  342.              * Picking an item up.
  343.              */
  344.             pickupItem.handlePacket(p, packetId, packetSize);
  345.             break;
  346.         case 160:
  347.             /*
  348.              * First option on a player.
  349.              */
  350.             playerOption1.handlePacket(p, packetId, packetSize);
  351.             break;
  352.         case 37:
  353.             /*
  354.              * Second option on a player.
  355.              */
  356.             playerOption2.handlePacket(p, packetId, packetSize);
  357.             break;
  358.         case 227:
  359.             /*
  360.              * Third option on a player.
  361.              */
  362.             playerOption3.handlePacket(p, packetId, packetSize);
  363.             break;
  364.         case 123:
  365.             /*
  366.              * NPC attack option.
  367.              */
  368.             npcAttack.handlePacket(p, packetId, packetSize);
  369.             break;
  370.         case 7:
  371.             /*
  372.              * NPC first option.
  373.              */
  374.             npcOption1.handlePacket(p, packetId, packetSize);
  375.             break;
  376.         case 220:
  377.             /*
  378.              * Item eating, drinking, etc.
  379.              */
  380.             itemSelect.handlePacket(p, packetId, packetSize);
  381.             break;
  382.             case 134:
  383.  
  384.             /*
  385.              * Item eating, drinking, etc.
  386.              */
  387.             itemSelect.handlePacket(p, packetId, packetSize);
  388.             break;
  389.         case 158:
  390.             /*
  391.              * Object first option.
  392.              */
  393.             objectOption1.handlePacket(p, packetId, packetSize);
  394.             break;
  395.         case 165:
  396.             /*
  397.              * Settings buttons, such as music volume.
  398.              */
  399.             p.stream.readDWord_v2();
  400.             break;
  401.         case 108:
  402.             /*
  403.              * Remove open interfaces.
  404.              */
  405.             p.viewings = 0;
  406.         p.wc.resetWoodcutting();
  407.                 p.ResetSkillSuff();
  408.             p.frames.removeShownInterface(p);
  409.             break;
  410.         case 228:
  411.             /*
  412.              * Second object option.
  413.              */
  414.             objectOption2.handlePacket(p, packetId, packetSize);
  415.             break;
  416.         case 52:
  417.             /*
  418.              * Second NPC option.
  419.              */
  420.             npcOption2.handlePacket(p, packetId, packetSize);
  421.             break;
  422.         case 38:
  423.             /*
  424.              * Item examining.
  425.              */
  426.             p.frames.sendMessage(p, Engine.items.getItemDescription(p.stream.readUnsignedWordBigEndianA()));
  427.             break;
  428.         case 88:
  429.             /*
  430.              * NPC examining.
  431.              */
  432.             p.frames.sendMessage(p, Server.engine.getNPCDescription(p.stream.readUnsignedWord()));
  433.             break;
  434.            
  435.         case 84:
  436.             /*
  437.              * Object examining.
  438.              */
  439.             int object = p.stream.readUnsignedWordA();
  440.             p.frames.sendMessage(p, Engine.objects.getObjectDescription(object));
  441.             break;
  442.         case 47:
  443.             /*
  444.              * Idle packet.
  445.              */
  446.            p.disconnected[0] = true;
  447.             break;
  448.         case 179:
  449.             /*
  450.              * Switching items on interfaces.
  451.              */
  452.             switchItems2.handlePacket(p, packetId, packetSize);
  453.             break;
  454.         default:
  455.             Misc.println("[" + p.username + "] Unhandled packet: " + packetId);
  456.             break;
  457.         }
  458.  
  459.     }
  460. }