- /*
- * Class PacketManager
- *
- * Version 1.0
- *
- * Sunday, August 17, 2008
- *
- * Created by Palidino76
- */
- package palidino76.rs2.io;
- import palidino76.rs2.Server;
- import palidino76.rs2.Engine;
- import palidino76.rs2.util.Misc;
- import palidino76.rs2.io.packets.*;
- import palidino76.rs2.net.SocketListener;
- import palidino76.rs2.players.*;
- import palidino76.rs2.players.combat.*;
- public class PacketManager {
- /*
- * Create all the packets for use.
- */
- public Walking walk = new Walking();
- public PublicChat publicChat = new PublicChat();
- public Commands command = new Commands();
- public SwitchItems switchItems = new SwitchItems();
- public ActionButtons actionButtons = new ActionButtons();
- public Equipment equipment = new Equipment();
- public ItemOption1 itemOption1 = new ItemOption1();
- public ItemOperate itemOperate = new ItemOperate();
- public DropItem dropItem = new DropItem();
- public PickupItem pickupItem = new PickupItem();
- public MagicOnPlayer magicOnPlayer = new MagicOnPlayer();
- public PlayerOption1 playerOption1 = new PlayerOption1();
- public PlayerOption2 playerOption2 = new PlayerOption2();
- public PlayerOption3 playerOption3 = new PlayerOption3();
- public NPCAttack npcAttack = new NPCAttack();
- public NPCOption1 npcOption1 = new NPCOption1();
- public NPCOption2 npcOption2 = new NPCOption2();
- public NPCOption3 npcOption3 = new NPCOption3();
- public Shopbuyconfig Shopbuyconfig = new Shopbuyconfig();
- public ItemSelect itemSelect = new ItemSelect();
- public ObjectOption1 objectOption1 = new ObjectOption1();
- public ObjectOption2 objectOption2 = new ObjectOption2();
- public SwitchItems2 switchItems2 = new SwitchItems2();
- public ItemOnItem itemOnItem = new ItemOnItem();
- public ItemOnObject ItemOnObject = new ItemOnObject();
- public MagicOnItem magicOnItem = new MagicOnItem();
- public ItemOnNPC ionpc = new ItemOnNPC();
- /**
- * Handle any packets.
- * <p>Handles all packets within the range of 0 - 255. Not every
- * packet has been setup, you'll have to do some yourself.
- * @param p The Player which the frame should be created for.
- * @param packetId The packet id to handle.
- * @param packetSize The number of bytes the packet contains.
- */
- public void parsePacket(Player p, int packetId, int packetSize) {
- if (p == null) {
- return;
- }
- if (p.clickDelay > 0 && packetId != 222) {
- /*
- * When delayed only allow chatting.
- */
- return;
- }
- switch (packetId) {
- case 43:
- p.input.setInput(p.stream.readDWord());
- break;
- case 63:
- /*
- * Click here to continue.
- */
- p.frames.removeChatboxInterface(p);
- break;
- case 129:
- int screenId = p.stream.readUnsignedByte();
- switch(screenId) {
- case 0:
- p.Resizable = false;
- break;
- case 1:
- p.Resizable = true;
- break;
- case 2:
- p.Resizable = true;
- break;
- }
- break;
- case 3:
- /*
- * Equipping an item.
- */
- equipment.handlePacket(p, packetId, packetSize);
- break;
- case 199:
- /*
- *Npc Option 3
- */
- npcOption3.handlePacket(p, packetId, packetSize);
- break;
- case 12:
- /*
- *items on npc
- */
- ionpc.handlePacket(p, packetId, packetSize);
- break;
- case 253:
- int playerId = p.stream.readUnsignedWord();
- playerId -= 33024;
- playerId = playerId / 256;
- playerId++;
- if (playerId < 0 || playerId >= Engine.players.length || Engine.players[playerId] == null) {
- return;
- }
- if (Engine.players[playerId].trade.getPartner() == p) {
- p.trade.tradePlayer(Engine.players[playerId]);
- }
- break;
- case 70:
- Magic.magicAop(p, packetId, packetSize);
- break;
- case 115:
- /*
- * This packet is constantly sent almost like a ping to verify the still exists.
- */
- break;
- case 154:
- /*
- * Cast a spell on an item.
- */
- magicOnItem.handlePacket(p, packetId, packetSize);
- break;
- case 40:
- /*
- * itemonitem.
- */
- itemOnItem.handlePacket(p, packetId, packetSize);
- break;
- case 224:
- /*
- * Item on Object
- */
- ItemOnObject.handlePacket(p, packetId, packetSize);
- break;
- case 22:
- /*
- * Recieved every time updateReq is set to true.
- */
- p.stream.readDWord(); // Junk? Same value every time.
- break;
- case 60:
- p.objects();
- break;
- case 30:
- /*
- * Pm's, Friends, Ignores.
- */
- long name = p.stream.readQWord();
- if(p.friends.size() >= 200) {
- p.frames.sendMessage(p, "Your friends list is full.");
- break;
- }
- if(p.friends.contains((Long) name)) {
- p.frames.sendMessage(p, "Already on your friends list.");
- break;
- }
- p.friends.add((Long) name);
- p.frames.sendFriend(p, name, p.getWorld(name));
- break;
- case 61:
- name = p.stream.readQWord();
- if(p.ignores.size() >= 100) {
- p.frames.sendMessage(p, "Your ignore list is full.");
- break;
- }
- if(p.ignores.contains((Long) name)) {
- p.frames.sendMessage(p, "Already on your ignore list.");
- break;
- }
- p.ignores.add((Long) name);
- break;
- case 132:
- name = p.stream.readQWord();
- p.friends.remove((Long) name);
- break;
- case 2:
- name = p.stream.readQWord();
- p.ignores.remove((Long) name);
- break;
- case 178:
- if(p.checkMutedUsers(p.username) || p.checkMutedHosts(SocketListener.getAddress(p.socket.socket))){
- p.frames.sendMessage(p, "You are muted for breaking rules.Only admin can unmute you.");
- return;
- }
- name = p.stream.readQWord();
- int numChars = p.stream.readUnsignedByte();
- String text = Misc.decryptPlayerChat(p.stream, numChars);
- for(Player p2 : Engine.players) {
- if(p2 != null && p2.online) {
- if(Misc.stringToLong(p2.username) == name) {
- p2.frames.sendReceivedPrivateMessage(p2, Misc.stringToLong(p.username), p.rights, text);
- p.frames.sendSentPrivateMessage(p, name, text);
- return;
- }
- }
- }
- p.frames.sendMessage(p, "Player is unavailable.");
- break;
- case 99:
- /*
- * Unknown.
- */
- p.stream.readUnsignedWordBigEndianA();
- p.stream.readUnsignedWordA();
- break;
- case 24:
- int npcId = p.stream.readSignedWordA();
- int buttonId = p.stream.readSignedWordA();
- int interfaceId = p.stream.readUnsignedWord();
- if (interfaceId == 192) {
- p.magicNPC.magicOnNPC(npcId, buttonId);
- }
- break;
- case 117:
- case 248:
- case 247: // Possibly a packet sent if the login is successful.
- /*
- * Unknown.
- */
- break;
- case 59:
- /*
- * Send every time you click your mouse.
- */
- p.stream.readUnsignedWord();
- p.stream.readDWord_v1();
- break;
- case 49:
- /*
- * Main map walking.
- */
- case 119:
- /*
- * Minimap walking.
- */
- if(
- p.interfaceId==335 ||
- p.interfaceId==334) {
- return;
- }
- case 138:
- /*
- * Other walking.
- */
- p.wc.resetWoodcutting();
- p.ResetSkillSuff();
- walk.handlePacket(p, packetId, packetSize);
- break;
- case 222:
- /*
- * Public chatting.
- */
- publicChat.handlePacket(p, packetId, packetSize);
- break;
- case 107:
- /*
- * When you type text starting with ::, its sent with this packet Id rather than as
- * Normal chat.
- */
- command.handlePacket(p, packetId, packetSize);
- break;
- case 167:
- /*
- * Switching items on interfaces.
- */
- switchItems.handlePacket(p, packetId, packetSize);
- break;
- case 233:
- case 113:
- case 21:
- case 169:
- case 232:
- case 214:
- case 90:
- case 173:
- case 226:
- case 102:
- case 78:
- case 133:
- /*
- * When you click an interface button this packet is sent.
- */
- actionButtons.handlePacket(p, packetId, packetSize);
- break;
- case 203:
- case 152:
- /*
- * Item options 1.
- */
- itemOption1.handlePacket(p, packetId, packetSize);
- break;
- case 186:
- /*
- * Item operating.
- */
- if(p.viewings == 0) {
- itemOperate.handlePacket(p, packetId, packetSize);
- } else {
- Shopbuyconfig.handlePacket(p, packetId, packetSize);
- }
- case 211:
- /*
- * Dropping an item.
- */
- dropItem.handlePacket(p, packetId, packetSize);
- break;
- case 201:
- /*
- * Picking an item up.
- */
- pickupItem.handlePacket(p, packetId, packetSize);
- break;
- case 160:
- /*
- * First option on a player.
- */
- playerOption1.handlePacket(p, packetId, packetSize);
- break;
- case 37:
- /*
- * Second option on a player.
- */
- playerOption2.handlePacket(p, packetId, packetSize);
- break;
- case 227:
- /*
- * Third option on a player.
- */
- playerOption3.handlePacket(p, packetId, packetSize);
- break;
- case 123:
- /*
- * NPC attack option.
- */
- npcAttack.handlePacket(p, packetId, packetSize);
- break;
- case 7:
- /*
- * NPC first option.
- */
- npcOption1.handlePacket(p, packetId, packetSize);
- break;
- case 220:
- /*
- * Item eating, drinking, etc.
- */
- itemSelect.handlePacket(p, packetId, packetSize);
- break;
- case 134:
- /*
- * Item eating, drinking, etc.
- */
- itemSelect.handlePacket(p, packetId, packetSize);
- break;
- case 158:
- /*
- * Object first option.
- */
- objectOption1.handlePacket(p, packetId, packetSize);
- break;
- case 165:
- /*
- * Settings buttons, such as music volume.
- */
- p.stream.readDWord_v2();
- break;
- case 108:
- /*
- * Remove open interfaces.
- */
- p.viewings = 0;
- p.wc.resetWoodcutting();
- p.ResetSkillSuff();
- p.frames.removeShownInterface(p);
- break;
- case 228:
- /*
- * Second object option.
- */
- objectOption2.handlePacket(p, packetId, packetSize);
- break;
- case 52:
- /*
- * Second NPC option.
- */
- npcOption2.handlePacket(p, packetId, packetSize);
- break;
- case 38:
- /*
- * Item examining.
- */
- p.frames.sendMessage(p, Engine.items.getItemDescription(p.stream.readUnsignedWordBigEndianA()));
- break;
- case 88:
- /*
- * NPC examining.
- */
- p.frames.sendMessage(p, Server.engine.getNPCDescription(p.stream.readUnsignedWord()));
- break;
- case 84:
- /*
- * Object examining.
- */
- int object = p.stream.readUnsignedWordA();
- p.frames.sendMessage(p, Engine.objects.getObjectDescription(object));
- break;
- case 47:
- /*
- * Idle packet.
- */
- p.disconnected[0] = true;
- break;
- case 179:
- /*
- * Switching items on interfaces.
- */
- switchItems2.handlePacket(p, packetId, packetSize);
- break;
- default:
- Misc.println("[" + p.username + "] Unhandled packet: " + packetId);
- break;
- }
- }
- }