Thread: All 377 Server > Client Packets

Page 1 of 2 12 LastLast
Results 1 to 10 of 19
  1. #1 All 377 Server > Client Packets 
    Donator

    Major's Avatar
    Join Date
    Jan 2011
    Posts
    1,627
    Thanks
    671
    Thanked 932 Times in 460 Posts
    Rep Power
    2258
    Unless i somehow missed some these should be all the Server > Client packets there are.

    Buffer/"Stream" class used: http://pastie.org/5087157

    Packet lengths:

    Code:
    	public static final int PACKET_LENGTHS[] = { 0, 0, 4, 6, 0, 0, 0, 0, 0, 0,
    			3, 0, 0, 0, 0, 0, 0, 0, 6, 0, 0, 6, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0,
    			0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 0, 0, 0, 0, 0, 0, 0, 6, 2, 0, 0, -2,
    			0, 0, 0, 0, 0, 6, 0, 0, 0, -1, 0, 0, 0, 4, 0, 0, 0, -2, 0, 0, 0, 2,
    			23, 0, 9, 0, 0, 0, 3, 0, 0, 0, 0, 0, 2, 0, -2, 0, 0, 0, 0, 0, 0, 0,
    			0, 0, 0, 0, 0, 0, 0, 0, 7, 5, 0, 2, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0,
    			0, 7, 0, 0, 0, 1, 3, 0, 4, 0, 0, 0, 0, 0, -2, -1, 0, 0, 0, 0, 0, 0,
    			4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 1, -1, 2, 2, 0, 0, 4, 0,
    			0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 15, 3, -2, 0, 0,
    			8, 6, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 6, 4, 3, 0, 14, 0, 0, -2, 0,
    			3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 4, 2, 2, 0, 4, 0, 0, 0, -2, 0, 0, 0,
    			0, 0, -2, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 5, 0, 1,
    			1, 4, 0, 2, 0 };
    }
    Code:
    Packet 2 > Interface Animation - Packet 200 in 317
            Sets an interface's model animation. 
    	       int interfaceId = inStream.getLEUShortA();
    	       int animationId = inStream.getShortA();
    
    Packet 3 > ??? - Packet 166 in 317
            Something to do with Camera position/cutscenes
                    anInt874 = inStream.getUByte(); // Effects x camera position
                    anInt875 = inStream.getUByte(); // Effects y camera position
                    anInt876 = inStream.getUShort(); // Effects z camera position
                    anInt877 = inStream.getUByte();
                    anInt878 = inStream.getUByte();
    
    Packet 5 > Logout - 109 in 317
    
    Packet 6 > ??? - Packet 187 in 317
           Sets inputDialogState = 2;
    
    Packet 10 > Send Siderbar Interface - Packet 71 in 317
            int sidebarIcon = inStream.getUByteS();
            int interfaceId = inStream.getBEUShortA();
    
    Packet 13 > Player/Npc Animation Reset - Packet 1 in 317
            Loops through all players/npcs and sets their animations to -1
    
    Packet 18 > ???
            More interface related shit
                    int unknown = inStream.getUShort();
                    int interfaceId = inStream.getBEUShortA();
                    int unknown2 = inStream.getLEUShort();
    
    Packet 21 > Interface Item - Packet 246 in 317
            Displays an item model inside an interface. 
                   int itemScale = inStream.getUShort();
    	       int itemId = inStream.getLEUShort();
    	       int interfaceId = inStream.getLEUShortA();
    
    Packet 26 > Send Sound - Packet 174 in 317
            Has some fancy check different to 317 if (delay == 65535) then delay is set to 0, else (delay = delay + Sound.someArray[songId]) - (maybe song lengths? TODO check this)
                    int songId = inStream.getUShort();
                    int volume = inStream.getUByte();
                    int delay = inStream.getUShort();
    
    Packet 29 > ???
            Some interface related crap.
    
    Packet 40 > ??? - Packet 64 in 317
            Something related to Global Objects... mass spawning or something.
                    bigRegionY = inStream.getUByteS();
                    bigRegionX = inStream.getNegUByte();
    
    Packet 41 > ??? - Packet 105 in 317
                    int offset = stream.getUByte();
                    int unknown = stream.getUShort();
                    int offset2 = stream.getUByte();
    
    Packet 49 > Skill level - Packet 134 in 317
    	       int skillId = inStream.getNegUByte();
    	       int skillLevel = inStream.getUByte();
    	       int skillExperience = inStream.getLEInt();
    
    Packet 50 > Send Walkable Interface - Packet 208 in 318
            int interfaceId = inStream.getShort();
    
    Packet 53 > Construct Map Region
                    mapRegionY = inStream.getBEUShortA();
                    mapRegionX = inStream.getBEUShortA();
    
    Packet 58 > ??? - Packet 27 in 317
            Sets inputDialogState = 1;
    
    Packet 59 > Send Still Graphic - Packet 4 in 317
                    int offset = stream.getUByte();
                    int graphicId = stream.getUShort();
                    int height = stream.getUByte();
                    int delay = stream.getUShort();
    
    Packet 61 > Reset X Destination (lolnaming) - Packet 78 in 317
    
    Packet 63 > Send Message - Packet 253 in 317
                    String message = inStream.getStr();
    
    Packet 67 > Camera Shake (or something) - Packet 35 in 317
            Often known as the Camera shake/"Eartquake" packet. Need to check all the naming as it doesn't look right...
                    int customCameraSlot = inStream.getUByte(); //"Shake type" ???
                    int unknown = inStream.getUByte(); //magnitude1 ?
                    int lowestYaw = inStream.getUByte(); //magnitude2 ?
                    int unknown2 = inStream.getUByte(); //magnitude3 ?
    
    Packet 71 > Npc Updating/Handling - Packet 65 in 317
            Calls a method which updates Npcs/read spawn requests/reads update masks
    
    Packet 75 > Set big region/"Send Position" - Packet 85 in 317
                    bigRegionX = inStream.getNegUByte();
                    bigRegionY = inStream.getUByteA();
    
    Packet 76 > Send Welcome Screen Info ???
                    unknown = inStream.getLEUShort();
                    unknown2 = inStream.getLEUShortA();
                    inStream.getUShort();
                    unknown3 = inStream.getUShort();
                    unknown4 = inStream.getLEUShort();
                    welcomeScreenUnreadPMCount = inStream.getBEUShortA();
                    unknown5 = inStream.getBEUShortA();
                    memberCredit = inStream.getUShort();
                    lastLoginIP = inStream.getBEInt();
                    unknown6 = inStream.getLEUShortA();
                    inStream.getUByteA();
    
    Packet 78 > Send Add Friend
                    long nameAsLong = inStream.getLong();
                    int world = inStream.getUByte(); //World the player being added is on
    
    Packet 82 > Change Interface Hidden State (bad naming) - Packet 171 in 317
            Changes an interface's Hidden Until Mouseover state (the interface will not be shown until the player moves his mouse over it) //TODO check this
                    boolean hidden = inStream.getUByte() == 1;
                    int interfaceId = inStream.getUShort();
    
    
    Packet 88 > ??? Packet 151 (Send Object) or 101 (probably 101) in 317.
                    int xyOffset = stream.getUByteS();
                    int bits = stream.getUByteS(); (For obj type/rotation).
    
    Packet 90 > Update Players - Packet 81 in 317
            Updates our player movement/other player movement/current player/refreshes update masks.
    
    Packet 106 > ??? - Packet 215 in 217
    	Something to do with Ground Items.
    	       int xyOffset = stream.getUByteA();
    	       int itemCount = stream.getLEUShortA();
    	       int itemId = stream.getBEUShortA();
    	       int playerId = stream.getBEUShortA();
    
    Packet 107 > Send Ground Item - Packet 44 in 317
                    int id = stream.getUShort();
                    int xyOffset = stream.getNegUByte();
                    int count = stream.getBEUShortA();
    
    Packet 109 > Show Interface? - Packet 97 in 317??? TODO check this
                    int interfaceId = inStream.getUShort();
    
    Packet 113 > Reset button state - Packet 68 in 317
            Something to do with Session settings/configs..?
    
    Packet 115 > ??? - Packet 87 in 317
            Something to do with session sittings (often called 'configs')
                    int settingState = inStream.getME2Int();
                    int settingId = inStream.getLEUShort();
    
    Packet 121 > ??? - Packet 84 in 317
    		int unknown = stream.getUByte();
                    int x = bigRegionX + (unknown >> 4 & 7);
                    int y = bigRegionY + (unknown & 7);
        	        int unknown2 = stream.getUShort(); (Something to do with Item id - "item.id != (unknown2 & 0x7fff)")
        	        int unknown3 = stream.getUShort(); (Something to do with Item count - "item.itemCount != unknown3)")
        	        int unknown4 = stream.getUShort();
    
    Packet 125 > Send Run Energy - Packet 110 in 317
            playerEnergy = inStream.getUByte();
    
    Packet 126 > Initialize Player - Packet 249 in 317
            Sends the player's membership status and their current index on the server's player list.
                    isMember = inStream.getUByte();
                    playerId = inStream.getLEUShort();
    
    Packet 128 > Display Inventory Overlay - Packet 248 in 317
            int interfaceId = inStream.getBEUShortA();
            int invOverlayId = inStream.getLEUShortA();
    
    Packet 134 > Send Update Items - Packet 53 in 317
                    int interfaceId = inStream.getUShort();
                    int itemAmount = inStream.getSmarts();
                    int itemId = inStream.getUShort();
                    int itemCount = inStream.getUByte();
    
    Packet 135 > Send Private Message - Packet 196 in 317
                    long fromPlayer = inStream.getLong(); //The player the PM is from
                    int chatId = inStream.getLEInt();
                    int fromPlayersRights = inStream.getUByte(); //The rights of the player the PM is from
    
    Packet 142 > ??? - Packet 160 in 317
    	Something else to do with objects.
    		animation Id = stream.getUShort();
    		unknown = stream.getUByteA();
    		xyOffset = stream.getUByte();
    
    Packet 148 > End Cutscene/Reset Camera - Packet 107 in 317
    
    
    Packet 152 > ??? - 151 (Send Object) or 101 in 317
    	Something else to do with object spawning.
    		int bits = stream.getNegUByte();
                    int id = stream.getLEUShortA();  (Needs confirming).
                    int offset = stream.getUByteA();
    
    Packet 156 > Set Minimap State - Packet 99 in 317
                    int minimapState = inStream.getUByte();
    
    Packet 157 > Send player option?? - Packet 104 in 317
            Sends a player option when the player is right clicked.
                    int slotPos = inStream.getNegUByte(); // slot position on the interface
                    String actionString = inStream.getStr(); //The string i.e. "follow" (double check this)
                    int putAtTop = inStream.getUByte(); // Move the slot to the top?? check this
    
    Packet 158 > Show dialogue interface?? - Packet 218 in 317
            Check this.
                    int id = inStream.getLEShort();
    
    Packet 159 > Show Interface - Packet 97 in 317
                    int interfaceId = inStream.getLEUShortA();
    
    Packet 162 > Send Interface Media (Type 2) - Packet 75 in 317 (Often called 'send npc head')
            Sets 'RSInterface.getInterface(entity)' mediaType to '2' and mediaId to 'frame'.
                    int frame = inStream.getBEUShortA();
                    int entity = inStream.getLEUShort();
    
    Packet 166 > Set Interface Offset - Packet 70 in 317
            Sets the offset for drawing of an interface. 
                    int yOffset = inStream.getLEShort();
                    int xOffset = inStream.getLEShort();
                    int interfaceId = inStream.getUShort();
    
    Packet 167 > ??? - Packet 177 in 317
            Something cutscene related.
                    unknown = inStream.getUByte();
                    unknown2 = inStream.getUByte();
                    unknown3 = inStream.getUShort();
                    unknown4 = inStream.getUByte();
                    unknown5 = inStream.getUByte();
    
    Packet 174 > Send Weight - Packet 240 in 317
            userWeight = inStream.getShort();
    
    Packet 181 > ??? - Packet 117 in 317
    	Projectile spawning or something?
    		int angle = stream.getUByte();
                    int x = bigRegionX + (angle >> 4 & 7);
                    int y = bigRegionY + (angle & 7);
                    int offsetY = x + stream.getByte();
                    int offsetX = y + stream.getByte();
                    int lockOn = stream.getShort();
                    int id = stream.getUShort();
                    int startHeight = stream.getUByte() * 4;
                    int endHeight = stream.getUByte() * 4;
                    int delay = stream.getUShort();
                    nt speed = stream.getUShort();
                    int slope = stream.getUByte();
                    int radius = stream.getUByte();
    
    Packet 182 > Set Session setting (retard naming) - Packet 36 in 317
            Applies a config change or something.
                    int settingId = inStream.getBEUShortA();
                    byte sessionValue = inStream.getByteS();
    
    Packet 183 > ??? - Packet 60 in 317
            Something to speed up mass object/etc updates or something?
                    bigRegionX = inStream.getUByte();
                    bigRegionY = inStream.getUByteA();
            Then while (inStream.offset < packetSize)
                    int opcode = inStream.getUByte();
                    parsePacketGroup(inStream, opcode);
    
    Packet 186 > Interface Model Rotation - Packet 230 in 317
            Changes the zoom and rotation of the interface id's media. 
                    int rotation1 = inStream.getBEUShortA();
                    int interfaceId = inStream.getLEUShortA();
                    int zoom = inStream.getBEUShortA();
                    int rotation2 = inStream.getLEUShort();
    
    Packet 190 > System Update - Packet 114 in 317
            systemUpdateTime = inStream.getLEUShort() * 30;
    
    Packet 199 > ??? Packet 254 in 317
            Something to do with head icon drawing
                    headIconDrawType = inStream.getUByte();
            Then if headIconDrawType == 1
                    unknown = inStream.getUShort();
            Else if headIconDrawType >= 2 and <= 6
                    unknown1 = inStream.getUShort();
                    unknown2 = inStream.getUShort();
                    unknown3 = inStream.getUByte();
            Else if headIconDrawType == 10
                    otherPlayerId = inStream.getUShort();
    
    Packet 200 > Set Scroll Position - Packet 79 in 317
            Sets the scroll position if an Interface.
                    int interfaceId = inStream.getUShort();
                    int scrollPosition = inStream.getLEUShortA();
    
    Packet 201 > Update Chat Settings - Packet 206 in 317
            Updates chat settings (Public/Private/Trade).
                    publicChatMode = inStream.getUByte();
                    privateChatMode = inStream.getUByte();
                    tradeMode = inStream.getUByte();
    
    Packet 203 > ??? - Packet 147 in 317 //lol recheck this
    	Something related to object spawning.
    		int objId = stream.getUShort();
    		int unknown = stream.getUByte();
                    byte unknown2 = stream.getNegByte();
                    int xyOffset = stream.getUByteA();
                    byte unknown4 = stream.getByteA();
                    int unknown5 = stream.getBEUShortA();
                    int playerId = stream.getLEUShort();
                    byte unknown6 = stream.getByte();
                    byte unknown7 = stream.getByteA();
                    int playerId = stream.getUShort();
    
    Packet 206 > Send Update Items
                    int interfaceId = inStream.getUShort();
                    int itemAmount = inStream.getUShort();
                    int itemCount = inStream.getNegUByte();
            Then if (itemCount == 255)
                    itemCount = inStream.getBEInt();
    
    Packet 208 > Remove Ground Item - Packet 156 in 317
    	        int id = stream.getBEUShortA();
                    int xyOffset = stream.getUByteA();
    
    Packet 216 > Send Interface Media (Type 1) - Packet 8 in 317
            Changes the interface's media type to 1, and the media id to (specified id).
                    int mediaId = inStream.getLEUShortA();
                    int interfaceId = inStream.getLEUShortA();
    
    Packet 218 > Set Interface Colour - Packet 122 in 317
            Changes the colour of an interface.
                    int interfaceId = inStream.getUShort();
                    int colour = inStream.getBEUShortA();
    
    Packet 220 > Play Song - Packet 74 in 317
            Plays a song if (song != currentSong && musicEnabled && !lowMem && prevSong == 0) - prevSong == 0... Send Initial song?? TODO
                    int song = inStream.getLEUShortA();
    
    
    Packet 222 > Load Map Region
    	       mapRegionX = inStream.getUShort();
    	       mapRegionY = inStream.getLEUShortA();
    
    Packet 226 > Send Add Ignore - Packet 214 in 317
                    userIgnoreCount = packetSize / 8;
                    for (int k8 = 0; k8 < userIgnoreCount; k8++) {
                            ignoreListAsLongs[k8] = inStream.getLong();
                    }
    
    Packet 232 > Set Interface Text - Packet 126 in 317
                    int interfaceId = inStream.getLEUShortA();
                    String interfaceText = inStream.getStr();
    
    Packet 233 > ???
            TODO play around with this for a while, see what it is.
                    unknown = inStream.getUByte();
    
    Packet 238 > Flash Sidebar - Packet 24 in 317
            Causes a sidebar icon to start flashing.
                    flashingSidebarId = inStream.getUByte();
    
    Packet 246 > Send Inventory Overlay Interface - Packet 142 in 317
            int interfaceId = inStream.getLEUShortA();
    
    Packet 249 > Play Song 2 (TODO) - Packet 121 in 317
            Identical to Packet 220 except it also sets the previous song id
                    int song = inStream.getLEUShort();
                    int prevSong = inStream.getMediumInt();
    
    Packet 251 > Send Friend List Status - Packet 221 in 317
            networkFriendServerStatus = inStream.getUByte();
    
    Packet 252 > Change Tab - Packet 106 in 316
            tabId = inStream.getNegUByte();
    
    Packet 253 > Open SomeInterface - (Doesn't exist in 317, I think - Could be fullscreen related?)
            int interfaceId = inStream.getLEUShort();
            int interfaceId2 = inStream.getBEUShortA();
    
    Packet 255 > Send Interface Media (Type 3) (often called 'Send player head')
            int interfaceId = inStream.getLEUShortA();
    
    Packet 41, 59, 88, 106, 107, 121, 142, 152, 181, 203, 208
            parsePacketGroup(inStream, opcode);
    Quote Originally Posted by Graham View Post
    Some more server->client packets not in the original post/without good descriptions:

    packet 40 = reset items and objects in an 8x8 region, sets current 'placement' 8x8 region
    packet 183 = set current 'placement' 8x8 region, also optionally allows grouping of item,object,projectile,etc. packets within this one
    packet 75 = set current 'placement' 8x8 region
    packet 219 = reset items on interface
    Reply With Quote  
     


  2. #2  
    Donator

    Emma Watson's Avatar
    Join Date
    Nov 2010
    Age
    18
    Posts
    2,676
    Thanks
    820
    Thanked 388 Times in 263 Posts
    Rep Power
    562
    Thanks Major.

    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Jun 2010
    Age
    26
    Posts
    4,372
    Thanks
    4
    Thanked 280 Times in 230 Posts
    Rep Power
    0
    Good Job.
    Reply With Quote  
     

  4. #4  
    Registered Member

    Join Date
    Nov 2010
    Posts
    291
    Thanks
    73
    Thanked 112 Times in 55 Posts
    Rep Power
    139
    Some things for Hyperion:

    Spoiler for Code:
    ActionSender:
    Code:
    package org.hyperion.rs2.net;
    
    import org.hyperion.rs2.Constants;
    import org.hyperion.rs2.model.Item;
    import org.hyperion.rs2.model.Palette;
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.model.Skills;
    import org.hyperion.rs2.model.Palette.PaletteTile;
    import org.hyperion.rs2.model.container.Equipment;
    import org.hyperion.rs2.model.container.Inventory;
    import org.hyperion.rs2.model.container.impl.EquipmentContainerListener;
    import org.hyperion.rs2.model.container.impl.InterfaceContainerListener;
    import org.hyperion.rs2.model.container.impl.WeaponContainerListener;
    import org.hyperion.rs2.net.Packet.Type;
    
    /**
     * A utility class for sending packets.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class ActionSender {
    
    	/**
    	 * The player.
    	 */
    	private Player player;
    
    	/**
    	 * Creates an action sender for the specified player.
    	 * 
    	 * @param player
    	 *            The player to create the action sender for.
    	 */
    	public ActionSender(Player player) {
    		this.player = player;
    	}
    
    	/**
    	 * Sends an inventory interface.
    	 * 
    	 * @param interfaceId
    	 *            The interface id.
    	 * @param inventoryInterfaceId
    	 *            The inventory interface id.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendInterfaceInventory(int interfaceId,
    			int inventoryInterfaceId) {
    		player.getInterfaceState().interfaceOpened(interfaceId);
    		player.write(new PacketBuilder(128).putShortA(interfaceId).putLEShortA(
    				inventoryInterfaceId).toPacket());
    		return this;
    	}
    
    	public ActionSender resetCameraPosition() {
    		player.write(new PacketBuilder(148).toPacket());
    		return this;
    	}
    
    	public ActionSender resetButtons() {
    		player.write(new PacketBuilder(113).toPacket());
    		return this;
    	}
    
    	public ActionSender resetItems(int interfaceId) {
    		player.write(new PacketBuilder(219).putLEInt(interfaceId).toPacket());
    		return this;
    	}
    
    	public ActionSender sendConfig(int id, int value) {
    		if (value > 254) {
    			player.write(new PacketBuilder(115).putInt2(value).putLEShort(id)
    					.toPacket());
    		} else {
    			player.write(new PacketBuilder(182).putShortA(id)
    					.putByteS((byte) value).toPacket());
    		}
    		return this;
    	}
    
    	public ActionSender sendInterface(int interfaceId) {
    		player
    				.write(new PacketBuilder(159).putLEShortA(interfaceId)
    						.toPacket());
    		return this;
    	}
    
    	public ActionSender sendClearScreen() {
    		player
    				.write(new PacketBuilder(29).toPacket());
    		return this;
    	}
    
    	public ActionSender sendChatInterface(int interfaceId) {
    		player
    				.write(new PacketBuilder(109).putShort(interfaceId)
    						.toPacket());
    		return this;
    	}
    
    	public ActionSender sendInterfaceConfig(int interfaceId, boolean active) {
    		player.write(new PacketBuilder(82).put((byte) (active ? 0 : 1))
    				.putShort(interfaceId).toPacket());
    		return this;
    	}
    
    	public ActionSender sendInterfaceAnimation(int interfaceId, int animation) {
    		player.write(new PacketBuilder(2).putLEShort(interfaceId)
    				.putShort(animation).toPacket());
    		return this;
    	}
    
    	public ActionSender sendPlayerHead(int id) {
    		player.write(new PacketBuilder(255).putLEShortA(id).toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends all the login packets.
    	 * 
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendLogin() {
    		player.setActive(true);
    
    		resetCameraPosition();
    		resetButtons();
    
    		sendWelcomeScreen();
    
    		sendDetails();
    		sendMessage("Welcome to RuneScape.");
    
    		sendMapRegion();
    		sendSidebarInterfaces();
    		sendSkills();
    		// player.write(new PacketBuilder(251).put((byte)2).toPacket());
    
    		InterfaceContainerListener inventoryListener = new InterfaceContainerListener(
    				player, Inventory.INTERFACE);
    		player.getInventory().addListener(inventoryListener);
    
    		InterfaceContainerListener equipmentListener = new InterfaceContainerListener(
    				player, Equipment.INTERFACE);
    		player.getEquipment().addListener(equipmentListener);
    		player.getEquipment().addListener(
    				new EquipmentContainerListener(player));
    		player.getEquipment().addListener(new WeaponContainerListener(player));
    
    		sendInterfaceConfig(12323, true);
    		sendConfig(300, 857);
    		sendConfig(301, 1);
    
    		sendInteractionOption("Attack", 1, false);
    		// player.write(new
    		// PacketBuilder(82).put((byte)0).putShort(12323).toPacket());
    
    		// for (int i = 12325; i <= 12334; i ++) {
    		// player.write(new
    		// PacketBuilder(166).putLEShort(500).putLEShort(0).putShort(i).toPacket());
    		// }
    
    		return this;
    	}
    
    	public ActionSender sendWelcomeScreen() {
    		PacketBuilder packet = new PacketBuilder(76);
    		packet.putLEShort(0); // Days ago requested recovery question changes.
    		packet.putLEShortA(0);
    		packet.putShort(0);
    		packet.putShort(0);
    		packet.putLEShort(0);
    		packet.putShortA(0); // Unread messages.
    		packet.putShortA(0);
    		packet.putShort(30); // Days of membership credit remaining.
    		packet.putLEInt(0); // Last IP.
    		packet.putLEShort(0);
    		packet.putByteS((byte) 1); // Membership
    		sendFullScreenInterface(15244, 5993);
    		player.write(packet.toPacket());
    		return this;
    	}
    
    	public ActionSender sendFullScreenInterface(int interfaceID,
    			int bgInterfaceID) {
    		player.write(new PacketBuilder(253).putLEShort(bgInterfaceID)
    				.putShortA(interfaceID).toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends the packet to construct a map region.
    	 * 
    	 * @param palette
    	 *            The palette of map regions.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendConstructMapRegion(Palette palette) {
    		player.setLastKnownRegion(player.getLocation());
    		PacketBuilder bldr = new PacketBuilder(53, Type.VARIABLE_SHORT);
    		bldr.putShortA(player.getLocation().getRegionX() + 6);
    		bldr.startBitAccess();
    		for (int z = 0; z < 4; z++) {
    			for (int x = 0; x < 13; x++) {
    				for (int y = 0; y < 13; y++) {
    					PaletteTile tile = palette.getTile(x, y, z);
    					bldr.putBits(1, tile != null ? 1 : 0);
    					if (tile != null) {
    						bldr.putBits(26, tile.getX() << 14 | tile.getY() << 3
    								| tile.getZ() << 24 | tile.getRotation() << 1);
    					}
    				}
    			}
    		}
    		bldr.finishBitAccess();
    		bldr.putShort(player.getLocation().getRegionY() + 6);
    		player.write(bldr.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends the initial login packet (e.g. members, player id).
    	 * 
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendDetails() {
    		// player.write(new PacketBuilder(249).putByteA(player.isMembers() ? 1 :
    		// 0).putLEShortA(player.getIndex()).toPacket());
    		// player.write(new PacketBuilder(107).toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends the player's skills.
    	 * 
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendSkills() {
    		for (int i = 0; i < Skills.SKILL_COUNT; i++) {
    			sendSkill(i);
    		}
    		return this;
    	}
    
    	/**
    	 * Sends a specific skill.
    	 * 
    	 * @param skill
    	 *            The skill to send.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendSkill(int skill) {
    		PacketBuilder bldr = new PacketBuilder(49);
    		bldr.putByteC((byte) skill);
    		bldr.put((byte) player.getSkills().getLevel(skill));
    		bldr.putInt((int) player.getSkills().getExperience(skill));
    		player.write(bldr.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends all the sidebar interfaces.
    	 * 
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendSidebarInterfaces() {
    		final int[] icons = Constants.SIDEBAR_INTERFACES[0];
    		final int[] interfaces = Constants.SIDEBAR_INTERFACES[1];
    		for (int i = 0; i < icons.length; i++) {
    			sendSidebarInterface(icons[i], interfaces[i]);
    		}
    		return this;
    	}
    
    	/**
    	 * Sends a specific sidebar interface.
    	 * 
    	 * @param icon
    	 *            The sidebar icon.
    	 * @param interfaceId
    	 *            The interface id.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendSidebarInterface(int icon, int interfaceId) {
    		player.write(new PacketBuilder(10).putByteS((byte) icon).putShortA(
    				interfaceId).toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends a message.
    	 * 
    	 * @param message
    	 *            The message to send.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendMessage(String message) {
    		player.write(new PacketBuilder(63, Type.VARIABLE).putRS2String(message)
    				.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends the map region load command.
    	 * 
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendMapRegion() {
    		player.setLastKnownRegion(player.getLocation());
    		player.write(new PacketBuilder(222).putShort(
    				player.getLocation().getRegionY() + 6).putLEShortA(
    				player.getLocation().getRegionX() + 6).toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends the logout packet.
    	 * 
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendLogout() {
    		player.write(new PacketBuilder(5).toPacket()); // TODO IoFuture
    		return this;
    	}
    
    	/**
    	 * Sends a packet to update a group of items.
    	 * 
    	 * @param interfaceId
    	 *            The interface id.
    	 * @param items
    	 *            The items.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendUpdateItems(int interfaceId, Item[] items) {
    		PacketBuilder bldr = new PacketBuilder(206, Type.VARIABLE_SHORT);
    		bldr.putShort(interfaceId);
    		bldr.putShort(items.length);
    		for (Item item : items) {
    			if (item != null) {
    				bldr.putLEShortA(item.getId() + 1);
    				int count = item.getCount();
    				if (count > 254) {
    					bldr.putByteC((byte) 255);
    					bldr.putLEInt(count);
    				} else {
    					bldr.putByteC((byte) count);
    				}
    			} else {
    				bldr.putLEShortA(0);
    				bldr.putByteC((byte) 0);
    			}
    		}
    		player.write(bldr.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends a packet to update a single item.
    	 * 
    	 * @param interfaceId
    	 *            The interface id.
    	 * @param slot
    	 *            The slot.
    	 * @param item
    	 *            The item.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendUpdateItem(int interfaceId, int slot, Item item) {
    		PacketBuilder bldr = new PacketBuilder(134, Type.VARIABLE_SHORT);
    		bldr.putShort(interfaceId).putSmart(slot);
    		if (item != null) {
    			bldr.putShort(item.getId() + 1);
    			int count = item.getCount();
    			if (count > 254) {
    				bldr.put((byte) 255);
    				bldr.putInt(count);
    			} else {
    				bldr.put((byte) count);
    			}
    		} else {
    			bldr.putShort(0);
    			bldr.put((byte) 0);
    		}
    		player.write(bldr.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends a packet to update multiple (but not all) items.
    	 * 
    	 * @param interfaceId
    	 *            The interface id.
    	 * @param slots
    	 *            The slots.
    	 * @param items
    	 *            The item array.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendUpdateItems(int interfaceId, int[] slots,
    			Item[] items) {
    		PacketBuilder bldr = new PacketBuilder(134, Type.VARIABLE_SHORT)
    				.putShort(interfaceId);
    		for (int slot : slots) {
    			Item item = items[slot];
    			bldr.putSmart(slot);
    			if (item != null) {
    				bldr.putShort(item.getId() + 1);
    				int count = item.getCount();
    				if (count > 254) {
    					bldr.put((byte) 255);
    					bldr.putInt(count);
    				} else {
    					bldr.put((byte) count);
    				}
    			} else {
    				bldr.putShort(0);
    				bldr.put((byte) 0);
    			}
    		}
    		player.write(bldr.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends the enter amount interface.
    	 * 
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendEnterAmountInterface() {
    		player.write(new PacketBuilder(58).toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends the player an option.
    	 * 
    	 * @param slot
    	 *            The slot to place the option in the menu.
    	 * @param top
    	 *            Flag which indicates the item should be placed at the top.
    	 * @param option
    	 *            Option string which is the actual text.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendInteractionOption(String option, int slot,
    			boolean top) {
    		PacketBuilder bldr = new PacketBuilder(157, Type.VARIABLE);
    		bldr.putByteC((byte) slot);
    		bldr.putRS2String(option);
    		bldr.put(top ? (byte) 0 : (byte) 1);
    		player.write(bldr.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends a string.
    	 * 
    	 * @param id
    	 *            The interface id.
    	 * @param string
    	 *            The string.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendString(int id, String string) {
    		PacketBuilder bldr = new PacketBuilder(232, Type.VARIABLE_SHORT);
    		bldr.putLEShortA(id);
    		bldr.putRS2String(string);
    		player.write(bldr.toPacket());
    		return this;
    	}
    
    	/**
    	 * Sends a model in an interface.
    	 * 
    	 * @param id
    	 *            The interface id.
    	 * @param zoom
    	 *            The zoom.
    	 * @param model
    	 *            The model id.
    	 * @return The action sender instance, for chaining.
    	 */
    	public ActionSender sendInterfaceModel(int id, int zoom, int model) {
    		PacketBuilder bldr = new PacketBuilder(21);
    		bldr.putShort(zoom).putLEShort(model).putLEShortA(id);
    		player.write(bldr.toPacket());
    		return this;
    	}
    }
    Packets:

    WieldPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.model.Item;
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.model.container.Equipment;
    import org.hyperion.rs2.model.container.Inventory;
    import org.hyperion.rs2.model.container.Equipment.EquipmentType;
    import org.hyperion.rs2.net.Packet;
    
    /**
     * Handles the 'wield' option on items.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class WieldPacketHandler implements PacketHandler {
    
    	public void handle(Player player, Packet packet) {
    		int interfaceId = packet.getLEShort() & 0xFFFF;
    		int id = packet.getLEShort() & 0xFFFF;
    		int slot = packet.getShortA() & 0xFFFF;
    		switch (interfaceId) {
    		case Inventory.INTERFACE:
    			if (slot >= 0 && slot < Inventory.SIZE) {
    				Item item = player.getInventory().get(slot);
    				if (item != null && item.getId() == id) {
    					EquipmentType type = Equipment.getType(item);
    					Item oldEquip = null;
    					boolean stackable = item.getDefinition().isStackable();
    					if (player.getEquipment().isSlotUsed(type.getSlot())
    							&& !stackable) {
    						oldEquip = player.getEquipment().get(type.getSlot());
    						player.getEquipment().set(type.getSlot(), null);
    					}
    					player.getInventory().set(slot, null);
    					if (oldEquip != null) {
    						player.getInventory().add(oldEquip);
    					}
    					if (!stackable) {
    						player.getEquipment().set(type.getSlot(), item);
    					} else {
    						player.getEquipment().add(item);
    					}
    				}
    			}
    			break;
    		}
    	}
    
    }
    WalkingPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.net.Packet;
    
    /**
     * A packet which handles walking requests.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class WalkingPacketHandler implements PacketHandler {
    
    	public void handle(Player player, Packet packet) {
    		int size = packet.getLength();
    		if (packet.getOpcode() == 213) {
    			size -= 14;
    		}
    	
    		player.getActionSender().sendClearScreen();
    		player.getWalkingQueue().reset();
    		player.getActionQueue().clearNonWalkableActions();
    		player.resetInteractingEntity();
    
    		final int steps = (size - 5) / 2;
    		final int[][] path = new int[steps][2];
    
    		final int firstX = packet.getLEShortA();
    		final boolean runSteps = packet.getByte() == 1;
    		final int firstY = packet.getLEShortA();
    
    		for (int i = 0; i < steps; i++) {
    			path[i][0] = packet.getByte();
    			path[i][1] = packet.getByteS();
    		}
    
    		player.getWalkingQueue().setRunningQueue(runSteps);
    		player.getWalkingQueue().addStep(firstX, firstY);
    
    		for (int i = 0; i < steps; i++) {
    			path[i][0] += firstX;
    			path[i][1] += firstY;
    			player.getWalkingQueue().addStep(path[i][0], path[i][1]);
    		}
    		player.getWalkingQueue().finish();
    	}
    
    }
    SwitchItemPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.model.container.Bank;
    import org.hyperion.rs2.model.container.Inventory;
    import org.hyperion.rs2.net.Packet;
    
    /**
     * Switch item packet handler.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class SwitchItemPacketHandler implements PacketHandler {
    
    	@Override
    	public void handle(Player player, Packet packet) {
    		int interfaceId = packet.getLEShortA();
    		packet.getByteC();
    		int fromSlot = packet.getLEShortA();
    		int toSlot = packet.getLEShort();
    
    		switch (interfaceId) {
    		case Bank.PLAYER_INVENTORY_INTERFACE:
    		case Inventory.INTERFACE:
    			if (fromSlot >= 0 && fromSlot < Inventory.SIZE && toSlot >= 0
    					&& toSlot < Inventory.SIZE && toSlot != fromSlot) {
    				player.getInventory().swap(fromSlot, toSlot);
    			}
    			break;
    		case Bank.BANK_INVENTORY_INTERFACE:
    			if (fromSlot >= 0 && fromSlot < Bank.SIZE && toSlot >= 0
    					&& toSlot < Bank.SIZE && toSlot != fromSlot) {
    				if (player.getSettings().isSwapping()) {
    					player.getBank().swap(fromSlot, toSlot);
    				} else {
    					player.getBank().insert(fromSlot, toSlot);
    				}
    			}
    			break;
    		}
    	}
    
    }
    PlayerOptionPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.Constants;
    import org.hyperion.rs2.action.impl.AttackAction;
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.model.World;
    import org.hyperion.rs2.net.Packet;
    
    public class PlayerOptionPacketHandler implements PacketHandler {
    
    	@Override
    	public void handle(Player player, Packet packet) {
    		switch (packet.getOpcode()) {
    		case 245:
    			/*
    			 * Option 1.
    			 */
    			option1(player, packet);
    			break;
    		case 37:
    			/*
    			 * Option 2.
    			 */
    			option2(player, packet);
    			break;
    		case 227:
    			/*
    			 * Option 3.
    			 */
    			option3(player, packet);
    			break;
    		}
    	}
    
    	/**
    	 * Handles the first option on a player option menu.
    	 * 
    	 * @param player
    	 * @param packet
    	 */
    	private void option1(final Player player, Packet packet) {
    		int id = packet.getLEShortA() & 0xFFFF;
    		System.out.println(id);
    		if (id < 0 || id >= Constants.MAX_PLAYERS) {
    			return;
    		}
    		Player victim = (Player) World.getWorld().getPlayers().get(id);
    		if (victim != null
    				&& player.getLocation().isWithinInteractionDistance(
    						victim.getLocation())) {
    			player.getActionQueue().addAction(new AttackAction(player, victim));
    		}
    	}
    
    	/**
    	 * Handles the second option on a player option menu.
    	 * 
    	 * @param player
    	 * @param packet
    	 */
    	private void option2(Player player, Packet packet) {
    		int id = packet.getShort() & 0xFFFF;
    		if (id < 0 || id >= Constants.MAX_PLAYERS) {
    			return;
    		}
    	}
    
    	/**
    	 * Handles the third option on a player option menu.
    	 * 
    	 * @param player
    	 * @param packet
    	 */
    	private void option3(Player player, Packet packet) {
    		int id = packet.getLEShortA() & 0xFFFF;
    		if (id < 0 || id >= Constants.MAX_PLAYERS) {
    			return;
    		}
    	}
    
    }
    ObjectOptionPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.model.Location;
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.net.Packet;
    
    /**
     * Object option packet handler.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class ObjectOptionPacketHandler implements PacketHandler {
    
    	/**
    	 * Option 1 opcode.
    	 */
    	private static final int OPTION_1 = 181, OPTION_2 = 241, OPTION_3 = 50;
    
    	@Override
    	public void handle(Player player, Packet packet) {
    		switch (packet.getOpcode()) {
    		case OPTION_1:
    			handleOption1(player, packet);
    			break;
    		case OPTION_2:
    			handleOption2(player, packet);
    			break;
    		case OPTION_3:
    			handleOption3(player, packet);
    			break;
    		}
    	}
    
    	/**
    	 * Handles the option 1 packet.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleOption1(Player player, Packet packet) {
    		int x = packet.getShortA() & 0xFFFF;
    		int y = packet.getLEShort() & 0xFFFF;
    		int id = packet.getLEShort() & 0xFFFF;
    		Location loc = Location.create(x, y, player.getLocation().getZ());
    		player.getActionSender().sendMessage("" + loc + " id: " + id);
    	}
    
    	/**
    	 * Handles the option 2 packet.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleOption2(Player player, Packet packet) {
    		int id = packet.getShortA() & 0xFFFF;
    		int x = packet.getShort() & 0xFFFF;
    		int y = packet.getShortA() & 0xFFFF;
    		Location loc = Location.create(x, y, player.getLocation().getZ());
    		player.getActionSender().sendMessage("" + loc + " id: " + id);
    	}
    
    	/**
    	 * Handles the option 3 packet.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleOption3(Player player, Packet packet) {
    		int y = packet.getShortA() & 0xFFFF;
    		int id = packet.getLEShort() & 0xFFFF;
    		int x = packet.getLEShortA() & 0xFFFF;
    		Location loc = Location.create(x, y, player.getLocation().getZ());
    		player.getActionSender().sendMessage("" + loc + " id: " + id);
    	}
    }
    ItemOptionPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.model.container.Bank;
    import org.hyperion.rs2.model.container.Container;
    import org.hyperion.rs2.model.container.Equipment;
    import org.hyperion.rs2.model.container.Inventory;
    import org.hyperion.rs2.net.Packet;
    
    /**
     * Remove item options.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class ItemOptionPacketHandler implements PacketHandler {
    
    	/**
    	 * Option 1 opcode.
    	 */
    	private static final int OPTION_1 = 3;
    
    	/**
    	 * Option 2 opcode.
    	 */
    	private static final int OPTION_2 = 177;
    
    	/**
    	 * Option 3 opcode.
    	 */
    	private static final int OPTION_3 = 91;
    
    	/**
    	 * Option 4 opcode.
    	 */
    	private static final int OPTION_4 = 231;
    
    	/**
    	 * Option 5 opcode.
    	 */
    	private static final int OPTION_5 = 158;
    
    	public void handle(Player player, Packet packet) {
    		switch (packet.getOpcode()) {
    		case OPTION_1:
    			handleItemOption1(player, packet);
    			break;
    		case OPTION_2:
    			handleItemOption2(player, packet);
    			break;
    		case OPTION_3:
    			handleItemOption3(player, packet);
    			break;
    		case OPTION_4:
    			handleItemOption4(player, packet);
    			break;
    		case OPTION_5:
    			handleItemOption5(player, packet);
    			break;
    		}
    	}
    
    	/**
    	 * Handles item option 1.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleItemOption1(Player player, Packet packet) {
    		int id = packet.getShortA() & 0xFFFF;
    		int interfaceId = packet.getShort() & 0xFFFF;
    		int slot = packet.getShort() & 0xFFFF;
    
    		switch (interfaceId) {
    		case Equipment.INTERFACE:
    			if (slot >= 0 && slot < Equipment.SIZE) {
    				if (!Container.transfer(player.getEquipment(), player
    						.getInventory(), slot, id)) {
    					// indicate it failed
    				}
    			}
    			break;
    		case Bank.PLAYER_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Inventory.SIZE) {
    				Bank.deposit(player, slot, id, 1);
    			}
    			break;
    		case Bank.BANK_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Bank.SIZE) {
    				Bank.withdraw(player, slot, id, 1);
    			}
    			break;
    		}
    	}
    
    	/**
    	 * Handles item option 2.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleItemOption2(Player player, Packet packet) {
    		int slot = packet.getShortA() & 0xFFFF;
    		int id = packet.getLEShort() & 0xFFFF;
    		int interfaceId = packet.getLEShort() & 0xFFFF;
    
    		switch (interfaceId) {
    		case Bank.PLAYER_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Inventory.SIZE) {
    				Bank.deposit(player, slot, id, 5);
    			}
    			break;
    		case Bank.BANK_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Bank.SIZE) {
    				Bank.withdraw(player, slot, id, 5);
    			}
    			break;
    		}
    	}
    
    	/**
    	 * Handles item option 3.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleItemOption3(Player player, Packet packet) {
    		int id = packet.getLEShort() & 0xFFFF;
    		int slot = packet.getLEShortA() & 0xFFFF;
    		int interfaceId = packet.getShort() & 0xFFFF;
    
    		switch (interfaceId) {
    		case Bank.PLAYER_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Inventory.SIZE) {
    				Bank.deposit(player, slot, id, 10);
    			}
    			break;
    		case Bank.BANK_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Bank.SIZE) {
    				Bank.withdraw(player, slot, id, 10);
    			}
    			break;
    		}
    	}
    
    	/**
    	 * Handles item option 4.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleItemOption4(Player player, Packet packet) {
    		int interfaceId = packet.getLEShortA() & 0xFFFF;
    		int slot = packet.getLEShort() & 0xFFFF;
    		int id = packet.getShort() & 0xFFFF;
    
    		switch (interfaceId) {
    		case Bank.PLAYER_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Inventory.SIZE) {
    				Bank.deposit(player, slot, id, player.getInventory().getCount(
    						id));
    			}
    			break;
    		case Bank.BANK_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Bank.SIZE) {
    				Bank.withdraw(player, slot, id, player.getBank().getCount(id));
    			}
    			break;
    		}
    	}
    
    	/**
    	 * Handles item option 5.
    	 * 
    	 * @param player
    	 *            The player.
    	 * @param packet
    	 *            The packet.
    	 */
    	private void handleItemOption5(Player player, Packet packet) {
    		int slot = packet.getLEShortA() & 0xFFFF;
    		int id = packet.getLEShortA() & 0xFFFF;
    		int interfaceId = packet.getLEShort() & 0xFFFF;
    
    		switch (interfaceId) {
    		case Bank.PLAYER_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Inventory.SIZE) {
    				player.getInterfaceState().openEnterAmountInterface(
    						interfaceId, slot, id);
    			}
    			break;
    		case Bank.BANK_INVENTORY_INTERFACE:
    			if (slot >= 0 && slot < Bank.SIZE) {
    				player.getInterfaceState().openEnterAmountInterface(
    						interfaceId, slot, id);
    			}
    			break;
    		}
    	}
    
    }
    EnterAmountPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.net.Packet;
    
    /**
     * A packet sent when the player enters a custom amount for banking etc.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class EnterAmountPacketHandler implements PacketHandler {
    
    	@Override
    	public void handle(Player player, Packet packet) {
    		int amount = packet.getInt();
    		if (player.getInterfaceState().isEnterAmountInterfaceOpen()) {
    			player.getInterfaceState().closeEnterAmountInterface(amount);
    		}
    	}
    
    }
    ChatPacketHandler:
    Code:
    package org.hyperion.rs2.packet;
    
    import org.hyperion.rs2.model.ChatMessage;
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.net.Packet;
    import org.hyperion.rs2.util.TextUtils;
    
    /**
     * Handles public chat messages.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class ChatPacketHandler implements PacketHandler {
    
    	private static final int CHAT_QUEUE_SIZE = 4;
    
    	public void handle(Player player, Packet packet) {
    		int effects = packet.getByteC() & 0xFF;
    		int colour = packet.getByteA() & 0xFF;
    		int size = packet.getLength() - 2;
    		byte[] rawChatData = new byte[size];
    		packet.get(rawChatData);
    		if (player.getChatMessageQueue().size() >= CHAT_QUEUE_SIZE) {
    			return;
    		}
    		String unpacked = TextUtils.textUnpack(rawChatData, size);
    		unpacked = TextUtils.filterText(unpacked);
    		unpacked = TextUtils.optimizeText(unpacked);
    		byte[] packed = new byte[size];
    		TextUtils.textPack(packed, unpacked);
    		player.getChatMessageQueue().add(
    				new ChatMessage(effects, colour, packed));
    	}
    
    }

    Updating:

    PlayerUpdateTask:
    Code:
    package org.hyperion.rs2.task.impl;
    
    import java.util.Iterator;
    
    import org.hyperion.rs2.GameEngine;
    import org.hyperion.rs2.model.Appearance;
    import org.hyperion.rs2.model.ChatMessage;
    import org.hyperion.rs2.model.Entity;
    import org.hyperion.rs2.model.Item;
    import org.hyperion.rs2.model.Location;
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.model.UpdateFlags;
    import org.hyperion.rs2.model.World;
    import org.hyperion.rs2.model.UpdateFlags.UpdateFlag;
    import org.hyperion.rs2.model.container.Container;
    import org.hyperion.rs2.model.container.Equipment;
    import org.hyperion.rs2.model.container.Equipment.EquipmentType;
    import org.hyperion.rs2.net.Packet;
    import org.hyperion.rs2.net.PacketBuilder;
    import org.hyperion.rs2.task.Task;
    
    /**
     * A task which creates and sends the player update block.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class PlayerUpdateTask implements Task {
    
    	/**
    	 * The player.
    	 */
    	private Player player;
    
    	/**
    	 * Creates an update task.
    	 * 
    	 * @param player
    	 *            The player.
    	 */
    	public PlayerUpdateTask(Player player) {
    		this.player = player;
    	}
    
    	public void execute(GameEngine context) {
    		/*
    		 * If the map region changed send the new one. We do this immediately as
    		 * the client can begin loading it before the actual packet is received.
    		 */
    		if (player.isMapRegionChanging()) {
    			player.getActionSender().sendMapRegion();
    		}
    
    		/*
    		 * The update block packet holds update blocks and is send after the
    		 * main packet.
    		 */
    		PacketBuilder updateBlock = new PacketBuilder();
    
    		/*
    		 * The main packet is written in bits instead of bytes and holds
    		 * information about the local list, players to add and remove, movement
    		 * and which updates are required.
    		 */
    		PacketBuilder packet = new PacketBuilder(90, Packet.Type.VARIABLE_SHORT);
    		packet.startBitAccess();
    
    		/*
    		 * Updates this player.
    		 */
    		updateThisPlayerMovement(packet);
    		updatePlayer(updateBlock, player, false, true);
    
    		/*
    		 * Write the current size of the player list.
    		 */
    		packet.putBits(8, player.getLocalPlayers().size());
    
    		/*
    		 * Iterate through the local player list.
    		 */
    		for (Iterator<Player> it$ = player.getLocalPlayers().iterator(); it$
    				.hasNext();) {
    			/*
    			 * Get the next player.
    			 */
    			Player otherPlayer = it$.next();
    
    			/*
    			 * If the player should still be in our list.
    			 */
    			if (World.getWorld().getPlayers().contains(otherPlayer)
    					&& !otherPlayer.isTeleporting()
    					&& otherPlayer.getLocation().isWithinDistance(
    							player.getLocation())) {
    				/*
    				 * Update the movement.
    				 */
    				updatePlayerMovement(packet, otherPlayer);
    
    				/*
    				 * Check if an update is required, and if so, send the update.
    				 */
    				if (otherPlayer.getUpdateFlags().isUpdateRequired()) {
    					updatePlayer(updateBlock, otherPlayer, false, false);
    				}
    			} else {
    				/*
    				 * Otherwise, remove the player from the list.
    				 */
    				it$.remove();
    
    				/*
    				 * Tell the client to remove the player from the list.
    				 */
    				packet.putBits(1, 1);
    				packet.putBits(2, 3);
    			}
    		}
    
    		/*
    		 * Loop through every player.
    		 */
    		for (Player otherPlayer : World.getWorld().getRegionManager()
    				.getLocalPlayers(player)) {
    			/*
    			 * Check if there is room left in the local list.
    			 */
    			if (player.getLocalPlayers().size() >= 255) {
    				/*
    				 * There is no more room left in the local list. We cannot add
    				 * more players, so we just ignore the extra ones. They will be
    				 * added as other players get removed.
    				 */
    				break;
    			}
    
    			/*
    			 * If they should not be added ignore them.
    			 */
    			if (otherPlayer == player
    					|| player.getLocalPlayers().contains(otherPlayer)) {
    				continue;
    			}
    
    			/*
    			 * Add the player to the local list if it is within distance.
    			 */
    			player.getLocalPlayers().add(otherPlayer);
    
    			/*
    			 * Add the player in the packet.
    			 */
    			addNewPlayer(packet, otherPlayer);
    
    			/*
    			 * Update the player, forcing the appearance flag.
    			 */
    			updatePlayer(updateBlock, otherPlayer, true, false);
    		}
    
    		/*
    		 * Check if the update block is not empty.
    		 */
    		if (!updateBlock.isEmpty()) {
    			/*
    			 * Write a magic id indicating an update block follows.
    			 */
    			packet.putBits(11, 2047);
    			packet.finishBitAccess();
    
    			/*
    			 * Add the update block at the end of this packet.
    			 */
    			packet.put(updateBlock.toPacket().getPayload());
    		} else {
    			/*
    			 * Terminate the packet normally.
    			 */
    			packet.finishBitAccess();
    		}
    
    		/*
    		 * Write the packet.
    		 */
    		player.write(packet.toPacket());
    	}
    
    	/**
    	 * Updates a non-this player's movement.
    	 * 
    	 * @param packet
    	 *            The packet.
    	 * @param otherPlayer
    	 *            The player.
    	 */
    	public void updatePlayerMovement(PacketBuilder packet, Player otherPlayer) {
    		/*
    		 * Check which type of movement took place.
    		 */
    		if (otherPlayer.getSprites().getPrimarySprite() == -1) {
    			/*
    			 * If no movement did, check if an update is required.
    			 */
    			if (otherPlayer.getUpdateFlags().isUpdateRequired()) {
    				/*
    				 * Signify that an update happened.
    				 */
    				packet.putBits(1, 1);
    
    				/*
    				 * Signify that there was no movement.
    				 */
    				packet.putBits(2, 0);
    			} else {
    				/*
    				 * Signify that nothing changed.
    				 */
    				packet.putBits(1, 0);
    			}
    		} else if (otherPlayer.getSprites().getSecondarySprite() == -1) {
    			/*
    			 * The player moved but didn't run. Signify that an update is
    			 * required.
    			 */
    			packet.putBits(1, 1);
    
    			/*
    			 * Signify we moved one tile.
    			 */
    			packet.putBits(2, 1);
    
    			/*
    			 * Write the primary sprite (i.e. walk direction).
    			 */
    			packet.putBits(3, otherPlayer.getSprites().getPrimarySprite());
    
    			/*
    			 * Write a flag indicating if a block update happened.
    			 */
    			packet.putBits(1,
    					otherPlayer.getUpdateFlags().isUpdateRequired() ? 1 : 0);
    		} else {
    			/*
    			 * The player ran. Signify that an update happened.
    			 */
    			packet.putBits(1, 1);
    
    			/*
    			 * Signify that we moved two tiles.
    			 */
    			packet.putBits(2, 2);
    
    			/*
    			 * Write the primary sprite (i.e. walk direction).
    			 */
    			packet.putBits(3, otherPlayer.getSprites().getPrimarySprite());
    
    			/*
    			 * Write the secondary sprite (i.e. run direction).
    			 */
    			packet.putBits(3, otherPlayer.getSprites().getSecondarySprite());
    
    			/*
    			 * Write a flag indicating if a block update happened.
    			 */
    			packet.putBits(1,
    					otherPlayer.getUpdateFlags().isUpdateRequired() ? 1 : 0);
    		}
    	}
    
    	/**
    	 * Adds a new player.
    	 * 
    	 * @param packet
    	 *            The packet.
    	 * @param otherPlayer
    	 *            The player.
    	 */
    	public void addNewPlayer(PacketBuilder packet, Player otherPlayer) {
    		/*
    		 * Write the player index.
    		 */
    		packet.putBits(11, otherPlayer.getIndex());
    
    		int yPos = otherPlayer.getLocation().getY()
    				- player.getLocation().getY();
    		int xPos = otherPlayer.getLocation().getX()
    				- player.getLocation().getX();
    
    		packet.putBits(5, xPos);
    
    		/*
    		 * Write two flags here: the first indicates an update is required (this
    		 * is always true as we add the appearance after adding a player) and
    		 * the second to indicate we should discard client-side walk queues.
    		 */
    		packet.putBits(1, 1);
    		packet.putBits(1, 1);
    
    		/*
    		 * Write the x and y offsets.
    		 */
    		packet.putBits(5, yPos);
    	}
    
    	private static void appendHit2Update(final Player p,
    			final PacketBuilder updateBlock) {
    		updateBlock.put((byte) p.getDamage().getHitDamage2());
    		updateBlock.putByteS((byte) p.getDamage().getHitType2());
    		updateBlock.put((byte) p.getSkills().getLevel(3));
    		updateBlock.putByteC(p.getSkills().getLevelForExperience(3));
    	}
    
    	private static void appendHitUpdate(final Player p,
    			final PacketBuilder updateBlock) {
    		updateBlock.put((byte) p.getDamage().getHitDamage1());
    		updateBlock.putByteA(p.getDamage().getHitType1());
    		updateBlock.putByteC(p.getSkills().getLevel(3));
    		updateBlock.put((byte) p.getSkills().getLevelForExperience(3));
    	}
    
    	/**
    	 * Updates a player.
    	 * 
    	 * @param packet
    	 *            The packet.
    	 * @param otherPlayer
    	 *            The other player.
    	 * @param forceAppearance
    	 *            The force appearance flag.
    	 * @param noChat
    	 *            Indicates chat should not be relayed to this player.
    	 */
    	public void updatePlayer(PacketBuilder packet, Player otherPlayer,
    			boolean forceAppearance, boolean noChat) {
    		/*
    		 * If no update is required and we don't have to force an appearance
    		 * update, don't write anything.
    		 */
    		if (!otherPlayer.getUpdateFlags().isUpdateRequired()
    				&& !forceAppearance) {
    			return;
    		}
    
    		/*
    		 * We can used the cached update block!
    		 */
    		synchronized (otherPlayer) {
    			if (otherPlayer.hasCachedUpdateBlock() && otherPlayer != player
    					&& !forceAppearance && !noChat) {
    				packet.put(otherPlayer.getCachedUpdateBlock().getPayload()
    						.flip());
    				return;
    			}
    
    			/*
    			 * We have to construct and cache our own block.
    			 */
    			PacketBuilder block = new PacketBuilder();
    
    			/*
    			 * Calculate the bitmask.
    			 */
    			int mask = 0;
    			final UpdateFlags flags = otherPlayer.getUpdateFlags();
    
    			// TODO mask 0x400
    			if (flags.get(UpdateFlag.ANIMATION)) {
    				mask |= 0x8;
    			}
    			if (flags.get(UpdateFlag.FORCED_CHAT)) {
    				mask |= 0x10;
    			}
    			if (flags.get(UpdateFlag.FACE_ENTITY)) {
    				mask |= 0x1;
    			}
    			if (flags.get(UpdateFlag.FACE_COORDINATE)) {
    				mask |= 0x2;
    			}
    			if (flags.get(UpdateFlag.GRAPHICS)) {
    				mask |= 0x200;
    			}
    			if (flags.get(UpdateFlag.APPEARANCE) || forceAppearance) {
    				mask |= 0x4;
    			}
    			if (flags.get(UpdateFlag.CHAT) && !noChat) {
    				mask |= 0x40;
    			}
    			if (flags.get(UpdateFlag.HIT)) {
    				// mask |= 0x20;
    			}
    			if (flags.get(UpdateFlag.HIT_2)) {
    				// mask |= 0x200;
    			}
    
    			/*
    			 * Check if the bitmask would overflow a byte.
    			 */
    			if (mask >= 0xff) {
    				/*
    				 * Write it as a short and indicate we have done so.
    				 */
    				mask |= 0x20;
    				block.put((byte) (mask & 0xFF));
    				block.put((byte) (mask >> 8));
    			} else {
    				/*
    				 * Write it as a byte.
    				 */
    				block.put((byte) (mask));
    			}
    
    			/*
    			 * Append the appropriate updates.
    			 */
    			if (flags.get(UpdateFlag.ANIMATION)) {
    				appendAnimationUpdate(block, otherPlayer);
    			}
    			if (flags.get(UpdateFlag.FORCED_CHAT)) {
    				// chat
    			}
    			if (flags.get(UpdateFlag.FACE_ENTITY)) {
    				Entity entity = otherPlayer.getInteractingEntity();
    				block.putShortA(entity == null ? -1 : entity.getClientIndex());
    			}
    			if (flags.get(UpdateFlag.FACE_COORDINATE)) {
    				Location loc = otherPlayer.getFaceLocation();
    				if (loc == null) {
    					block.putShort(0);
    					block.putShort(0);
    				} else {
    					block.putShort(loc.getX() * 2 + 1);
    					block.putShort(loc.getY() * 2 + 1);
    				}
    			}
    			if (flags.get(UpdateFlag.GRAPHICS)) {
    				appendGraphicsUpdate(block, otherPlayer);
    			}
    			if (flags.get(UpdateFlag.APPEARANCE) || forceAppearance) {
    				appendPlayerAppearanceUpdate(block, otherPlayer);
    			}
    			if (flags.get(UpdateFlag.CHAT) && !noChat) {
    				appendChatUpdate(block, otherPlayer);
    			}
    			if (flags.get(UpdateFlag.HIT)) {
    				// appendHitUpdate(otherPlayer, block);
    			}
    			if (flags.get(UpdateFlag.HIT_2)) {
    				// appendHit2Update(otherPlayer, block);
    			}
    
    			/*
    			 * Convert the block builder to a packet.
    			 */
    			Packet blockPacket = block.toPacket();
    
    			/*
    			 * Now it is over, cache the block if we can.
    			 */
    			if (otherPlayer != player && !forceAppearance && !noChat) {
    				otherPlayer.setCachedUpdateBlock(blockPacket);
    			}
    
    			/*
    			 * And finally append the block at the end.
    			 */
    			packet.put(blockPacket.getPayload());
    		}
    	}
    
    	/**
    	 * Appends an animation update.
    	 * 
    	 * @param block
    	 *            The update block.
    	 * @param otherPlayer
    	 *            The player.
    	 */
    	private void appendAnimationUpdate(PacketBuilder block, Player otherPlayer) {
    		block.putShort(otherPlayer.getCurrentAnimation().getId());
    		block.putByteS((byte) otherPlayer.getCurrentAnimation().getDelay());
    	}
    
    	/**
    	 * Appends a graphics update.
    	 * 
    	 * @param block
    	 *            The update block.
    	 * @param otherPlayer
    	 *            The player.
    	 */
    	private void appendGraphicsUpdate(PacketBuilder block, Player otherPlayer) {
    		block.putShortA(otherPlayer.getCurrentGraphic().getId());
    		block.putInt2(otherPlayer.getCurrentGraphic().getDelay());
    	}
    
    	/**
    	 * Appends a chat text update.
    	 * 
    	 * @param packet
    	 *            The packet.
    	 * @param otherPlayer
    	 *            The player.
    	 */
    	private void appendChatUpdate(PacketBuilder packet, Player otherPlayer) {
    		ChatMessage cm = otherPlayer.getCurrentChatMessage();
    
    		byte[] bytes = cm.getText();
    
    		packet.putShort(((cm.getColour() & 0xFF) << 8)
    				+ (cm.getEffects() & 0xFF));
    		packet.putByteC((byte) otherPlayer.getRights().toInteger());
    		packet.putByteA(bytes.length);
    		for (byte aByte : bytes) {
    			packet.putByteA(aByte);
    		}
    	}
    
    	/**
    	 * Appends an appearance update.
    	 * 
    	 * @param packet
    	 *            The packet.
    	 * @param otherPlayer
    	 *            The player.
    	 */
    	private void appendPlayerAppearanceUpdate(PacketBuilder packet,
    			Player otherPlayer) {
    		Appearance app = otherPlayer.getAppearance();
    		Container eq = otherPlayer.getEquipment();
    
    		PacketBuilder playerProps = new PacketBuilder();
    		playerProps.put((byte) app.getGender()); // gender
    		playerProps.put((byte) -1); // skull icon
    		playerProps.put((byte) -1); // prayer icon
    
    		for (int i = 0; i < 4; i++) {
    			if (eq.isSlotUsed(i)) {
    				playerProps.putShort((short) 0x200 + eq.get(i).getId());
    			} else {
    				playerProps.put((byte) 0);
    			}
    		}
    		if (eq.isSlotUsed(Equipment.SLOT_CHEST)) {
    			playerProps.putShort((short) 0x200
    					+ eq.get(Equipment.SLOT_CHEST).getId());
    		} else {
    			playerProps.putShort((short) 0x100 + app.getChest()); // chest
    		}
    		if (eq.isSlotUsed(Equipment.SLOT_SHIELD)) {
    			playerProps.putShort((short) 0x200
    					+ eq.get(Equipment.SLOT_SHIELD).getId());
    		} else {
    			playerProps.put((byte) 0);
    		}
    		Item chest = eq.get(Equipment.SLOT_CHEST);
    		if (chest != null) {
    			if (!Equipment.is(EquipmentType.PLATEBODY, chest)) {
    				playerProps.putShort((short) 0x100 + app.getArms());
    			} else {
    				playerProps.putShort((short) 0x200 + chest.getId());
    			}
    		} else {
    			playerProps.putShort((short) 0x100 + app.getArms());
    		}
    		if (eq.isSlotUsed(Equipment.SLOT_BOTTOMS)) {
    			playerProps.putShort((short) 0x200
    					+ eq.get(Equipment.SLOT_BOTTOMS).getId());
    		} else {
    			playerProps.putShort((short) 0x100 + app.getLegs());
    		}
    		Item helm = eq.get(Equipment.SLOT_HELM);
    		if (helm != null) {
    			if (!Equipment.is(EquipmentType.FULL_HELM, helm)
    					&& !Equipment.is(EquipmentType.FULL_MASK, helm)) {
    				playerProps.putShort((short) 0x100 + app.getHead());
    			} else {
    				playerProps.put((byte) 0);
    			}
    		} else {
    			playerProps.putShort((short) 0x100 + app.getHead());
    		}
    		if (eq.isSlotUsed(Equipment.SLOT_GLOVES)) {
    			playerProps.putShort((short) 0x200
    					+ eq.get(Equipment.SLOT_GLOVES).getId());
    		} else {
    			playerProps.putShort((short) 0x100 + app.getHands());
    		}
    		if (eq.isSlotUsed(Equipment.SLOT_BOOTS)) {
    			playerProps.putShort((short) 0x200
    					+ eq.get(Equipment.SLOT_BOOTS).getId());
    		} else {
    			playerProps.putShort((short) 0x100 + app.getFeet());
    		}
    		boolean fullHelm = false;
    		if (helm != null) {
    			fullHelm = !Equipment.is(EquipmentType.FULL_HELM, helm);
    		}
    		if (fullHelm || app.getGender() == 1) {
    			playerProps.put((byte) 0);
    		} else {
    			playerProps.putShort((short) 0x100 + app.getBeard());
    		}
    
    		playerProps.put((byte) app.getHairColour()); // hairc
    		playerProps.put((byte) app.getTorsoColour()); // torsoc
    		playerProps.put((byte) app.getLegColour()); // legc
    		playerProps.put((byte) app.getFeetColour()); // feetc
    		playerProps.put((byte) app.getSkinColour()); // skinc
    
    		Item weapon = eq.get(Equipment.SLOT_WEAPON);
    		playerProps.putShort((short) Equipment.getStandAnim(weapon)); // stand
    		playerProps.putShort((short) 0x337); // stand turn
    		playerProps.putShort((short) Equipment.getWalkAnim(weapon)); // walk
    		playerProps.putShort((short) 0x334); // turn 180
    		playerProps.putShort((short) 0x335); // turn 90 cw
    		playerProps.putShort((short) 0x336); // turn 90 ccw
    		playerProps.putShort((short) Equipment.getRunAnim(weapon)); // run
    
    		playerProps.putLong(otherPlayer.getNameAsLong()); // player name
    		playerProps.put((byte) otherPlayer.getSkills().getCombatLevel()); // combat
    																			// level
    		playerProps.putShort(0); // (skill-level instead of combat-level)
    									// otherPlayer.getSkills().getTotalLevel());
    									// // total level
    
    		Packet propsPacket = playerProps.toPacket();
    
    		byte[] buffer = new byte[propsPacket.getLength()];
    		propsPacket.getReverse(buffer, 0, propsPacket.getLength());
    
    		packet.put((byte) propsPacket.getLength());
    		packet.put(buffer);
    	}
    
    	/**
    	 * Updates this player's movement.
    	 * 
    	 * @param packet
    	 *            The packet.
    	 */
    	private void updateThisPlayerMovement(PacketBuilder packet) {
    		/*
    		 * Check if the player is teleporting.
    		 */
    		if (player.isTeleporting() || player.isMapRegionChanging()) {
    			/*
    			 * They are, so an update is required.
    			 */
    			packet.putBits(1, 1);
    
    			/*
    			 * This value indicates the player teleported.
    			 */
    			packet.putBits(2, 3);
    
    			/*
    			 * This indicates that the client should discard the walking queue.
    			 */
    			packet.putBits(1, player.isTeleporting() ? 1 : 0);
    
    			/*
    			 * This is the new player height.
    			 */
    			packet.putBits(2, player.getLocation().getZ());
    
    			/*
    			 * These are the positions.
    			 */
    			packet.putBits(7, player.getLocation().getLocalY(
    					player.getLastKnownRegion()));
    			packet.putBits(7, player.getLocation().getLocalX(
    					player.getLastKnownRegion()));
    
    			/*
    			 * This flag indicates if an update block is appended.
    			 */
    			packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1
    					: 0);
    		} else {
    			/*
    			 * Otherwise, check if the player moved.
    			 */
    			if (player.getSprites().getPrimarySprite() == -1) {
    				/*
    				 * The player didn't move. Check if an update is required.
    				 */
    				if (player.getUpdateFlags().isUpdateRequired()) {
    					/*
    					 * Signifies an update is required.
    					 */
    					packet.putBits(1, 1);
    
    					/*
    					 * But signifies that we didn't move.
    					 */
    					packet.putBits(2, 0);
    				} else {
    					/*
    					 * Signifies that nothing changed.
    					 */
    					packet.putBits(1, 0);
    				}
    			} else {
    				/*
    				 * Check if the player was running.
    				 */
    				if (player.getSprites().getSecondarySprite() == -1) {
    					/*
    					 * The player walked, an update is required.
    					 */
    					packet.putBits(1, 1);
    
    					/*
    					 * This indicates the player only walked.
    					 */
    					packet.putBits(2, 1);
    
    					/*
    					 * This is the player's walking direction.
    					 */
    					packet.putBits(3, player.getSprites().getPrimarySprite());
    
    					/*
    					 * This flag indicates an update block is appended.
    					 */
    					packet.putBits(1, player.getUpdateFlags()
    							.isUpdateRequired() ? 1 : 0);
    				} else {
    					/*
    					 * The player ran, so an update is required.
    					 */
    					packet.putBits(1, 1);
    
    					/*
    					 * This indicates the player ran.
    					 */
    					packet.putBits(2, 2);
    
    					/*
    					 * This is the walking direction.
    					 */
    					packet.putBits(3, player.getSprites().getPrimarySprite());
    
    					/*
    					 * And this is the running direction.
    					 */
    					packet.putBits(3, player.getSprites().getSecondarySprite());
    
    					/*
    					 * And this flag indicates an update block is appended.
    					 */
    					packet.putBits(1, player.getUpdateFlags()
    							.isUpdateRequired() ? 1 : 0);
    				}
    			}
    		}
    	}
    
    }
    NPCUpdateTask:
    Code:
    package org.hyperion.rs2.task.impl;
    
    import java.util.Iterator;
    
    import org.hyperion.rs2.GameEngine;
    import org.hyperion.rs2.model.NPC;
    import org.hyperion.rs2.model.Player;
    import org.hyperion.rs2.model.UpdateFlags;
    import org.hyperion.rs2.model.World;
    import org.hyperion.rs2.model.UpdateFlags.UpdateFlag;
    import org.hyperion.rs2.net.Packet;
    import org.hyperion.rs2.net.PacketBuilder;
    import org.hyperion.rs2.task.Task;
    
    /**
     * A task which creates and sends the NPC update block.
     * 
     * @author Graham Edgecombe
     * 
     */
    public class NPCUpdateTask implements Task {
    
    	/**
    	 * The player.
    	 */
    	private Player player;
    
    	/**
    	 * Creates an npc update task.
    	 * 
    	 * @param player
    	 *            The player.
    	 */
    	public NPCUpdateTask(Player player) {
    		this.player = player;
    	}
    
    	public void execute(GameEngine context) {
    		/*
    		 * The update block holds the update masks and data, and is written
    		 * after the main block.
    		 */
    		PacketBuilder updateBlock = new PacketBuilder();
    
    		/*
    		 * The main packet holds information about adding, moving and removing
    		 * NPCs.
    		 */
    		PacketBuilder packet = new PacketBuilder(71, Packet.Type.VARIABLE_SHORT);
    		packet.startBitAccess();
    
    		/*
    		 * Write the current size of the npc list.
    		 */
    		packet.putBits(8, player.getLocalNPCs().size());
    
    		/*
    		 * Iterate through the local npc list.
    		 */
    		for (Iterator<NPC> it$ = player.getLocalNPCs().iterator(); it$
    				.hasNext();) {
    			/*
    			 * Get the next NPC.
    			 */
    			NPC npc = it$.next();
    
    			/*
    			 * If the NPC should still be in our list.
    			 */
    			if (World.getWorld().getNPCs().contains(npc)
    					&& !npc.isTeleporting()
    					&& npc.getLocation().isWithinDistance(player.getLocation())) {
    				/*
    				 * Update the movement.
    				 */
    				updateNPCMovement(packet, npc);
    
    				/*
    				 * Check if an update is required, and if so, send the update.
    				 */
    				if (npc.getUpdateFlags().isUpdateRequired()) {
    					updateNPC(updateBlock, npc);
    				}
    			} else {
    				/*
    				 * Otherwise, remove the NPC from the list.
    				 */
    				it$.remove();
    
    				/*
    				 * Tell the client to remove the NPC from the list.
    				 */
    				packet.putBits(1, 1);
    				packet.putBits(2, 3);
    			}
    		}
    
    		/*
    		 * Loop through all NPCs in the world.
    		 */
    		for (NPC npc : World.getWorld().getRegionManager().getLocalNpcs(player)) {
    			/*
    			 * Check if there is room left in the local list.
    			 */
    			if (player.getLocalNPCs().size() >= 255) {
    				/*
    				 * There is no more room left in the local list. We cannot add
    				 * more NPCs, so we just ignore the extra ones. They will be
    				 * added as other NPCs get removed.
    				 */
    				break;
    			}
    
    			/*
    			 * If they should not be added ignore them.
    			 */
    			if (player.getLocalNPCs().contains(npc)) {
    				continue;
    			}
    
    			/*
    			 * Add the npc to the local list if it is within distance.
    			 */
    			player.getLocalNPCs().add(npc);
    
    			/*
    			 * Add the npc in the packet.
    			 */
    			addNewNPC(packet, npc);
    
    			/*
    			 * Check if an update is required.
    			 */
    			if (npc.getUpdateFlags().isUpdateRequired()) {
    
    				/*
    				 * If so, update the npc.
    				 */
    				updateNPC(updateBlock, npc);
    
    			}
    		}
    
    		/*
    		 * Check if the update block isn't empty.
    		 */
    		if (!updateBlock.isEmpty()) {
    			/*
    			 * If so, put a flag indicating that an update block follows.
    			 */
    			packet.putBits(14, 16383);
    			packet.finishBitAccess();
    
    			/*
    			 * And append the update block.
    			 */
    			packet.put(updateBlock.toPacket().getPayload());
    		} else {
    			/*
    			 * Terminate the packet normally.
    			 */
    			packet.finishBitAccess();
    		}
    
    		/*
    		 * Write the packet.
    		 */
    		player.write(packet.toPacket());
    	}
    
    	/**
    	 * Adds a new NPC.
    	 * 
    	 * @param packet
    	 *            The main packet.
    	 * @param npc
    	 *            The npc to add.
    	 */
    	private void addNewNPC(PacketBuilder packet, NPC npc) {
    		/*
    		 * Write the NPC's index.
    		 */
    		packet.putBits(14, npc.getIndex());
    
    		/*
    		 * Calculate the x and y offsets.
    		 */
    		int yPos = npc.getLocation().getY() - player.getLocation().getY();
    		int xPos = npc.getLocation().getX() - player.getLocation().getX();
    
    		packet.putBits(1, npc.getUpdateFlags().isUpdateRequired() ? 1 : 0);
    
    		/*
    		 * And write them.
    		 */
    		packet.putBits(5, yPos);
    		packet.putBits(5, xPos);
    
    		/*
    		 * TODO unsure, but probably discards the client-side walk queue.
    		 */
    		packet.putBits(1, 0);
    
    		/*
    		 * We now write the NPC type id.
    		 */
    		packet.putBits(13, npc.getDefinition().getId());
    	}
    
    	/**
    	 * Update an NPC's movement.
    	 * 
    	 * @param packet
    	 *            The main packet.
    	 * @param npc
    	 *            The npc.
    	 */
    	private void updateNPCMovement(PacketBuilder packet, NPC npc) {
    		/*
    		 * Check if the NPC is running.
    		 */
    		if (npc.getSprites().getSecondarySprite() == -1) {
    			/*
    			 * They are not, so check if they are walking.
    			 */
    			if (npc.getSprites().getPrimarySprite() == -1) {
    				/*
    				 * They are not walking, check if the NPC needs an update.
    				 */
    				if (npc.getUpdateFlags().isUpdateRequired()) {
    					/*
    					 * Indicate an update is required.
    					 */
    					packet.putBits(1, 1);
    
    					/*
    					 * Indicate we didn't move.
    					 */
    					packet.putBits(2, 0);
    				} else {
    					/*
    					 * Indicate no update or movement is required.
    					 */
    					packet.putBits(1, 0);
    				}
    			} else {
    				/*
    				 * They are walking, so indicate an update is required.
    				 */
    				packet.putBits(1, 1);
    
    				/*
    				 * Indicate the NPC is walking 1 tile.
    				 */
    				packet.putBits(2, 1);
    
    				/*
    				 * And write the direction.
    				 */
    				packet.putBits(3, npc.getSprites().getPrimarySprite());
    
    				/*
    				 * And write the update flag.
    				 */
    				packet.putBits(1, npc.getUpdateFlags().isUpdateRequired() ? 1
    						: 0);
    			}
    		} else {
    			/*
    			 * They are running, so indicate an update is required.
    			 */
    			packet.putBits(1, 1);
    
    			/*
    			 * Indicate the NPC is running 2 tiles.
    			 */
    			packet.putBits(2, 2);
    
    			/*
    			 * And write the directions.
    			 */
    			packet.putBits(3, npc.getSprites().getPrimarySprite());
    			packet.putBits(3, npc.getSprites().getSecondarySprite());
    
    			/*
    			 * And write the update flag.
    			 */
    			packet.putBits(1, npc.getUpdateFlags().isUpdateRequired() ? 1 : 0);
    		}
    	}
    
    	/**
    	 * Update an NPC.
    	 * 
    	 * @param packet
    	 *            The update block.
    	 * @param npc
    	 *            The npc.
    	 */
    	private void updateNPC(PacketBuilder packet, NPC npc) {
    		/*
    		 * Calculate the mask.
    		 */
    		int mask = 0;
    		final UpdateFlags flags = npc.getUpdateFlags();
    
    		if (flags.get(UpdateFlag.ANIMATION)) {
    			// mask |= 0x10;
    		}
    		if (flags.get(UpdateFlag.HIT)) {
    			// mask |= 0x8;
    		}
    		if (flags.get(UpdateFlag.GRAPHICS)) {
    			// mask |= 0x80;
    		}
    		if (flags.get(UpdateFlag.FACE_ENTITY)) {
    			// mask |= 0x20;
    		}
    		if (flags.get(UpdateFlag.FORCED_CHAT)) {
    			// mask |= 0x1;
    		}
    		if (flags.get(UpdateFlag.HIT_2)) {
    			// mask |= 0x40;
    		}
    		if (flags.get(UpdateFlag.TRANSFORM)) {
    			// mask |= 0x2;
    		}
    		if (flags.get(UpdateFlag.FACE_COORDINATE)) {
    			// mask |= 0x4;
    		}
    
    		/*
    		 * And write the mask.
    		 */
    		packet.put((byte) mask);
    
    		if (flags.get(UpdateFlag.ANIMATION)) {
    			// packet.putLEShort(npc.getCurrentAnimation().getId());
    			// packet.put((byte) npc.getCurrentAnimation().getDelay());
    		}
    		if (flags.get(UpdateFlag.HIT)) {
    
    		}
    		if (flags.get(UpdateFlag.GRAPHICS)) {
    			// packet.putShort(npc.getCurrentGraphic().getId());
    			// packet.putInt(npc.getCurrentGraphic().getDelay());
    		}
    		if (flags.get(UpdateFlag.FACE_ENTITY)) {
    			// Entity entity = npc.getInteractingEntity();
    			// packet.putShort(entity == null ? -1 : entity.getClientIndex());
    		}
    		if (flags.get(UpdateFlag.FORCED_CHAT)) {
    
    		}
    		if (flags.get(UpdateFlag.HIT_2)) {
    
    		}
    		if (flags.get(UpdateFlag.TRANSFORM)) {
    
    		}
    		if (flags.get(UpdateFlag.FACE_COORDINATE)) {
    			// Location loc = npc.getFaceLocation();
    			// if(loc == null) {
    			// packet.putLEShort(0);
    			// packet.putLEShort(0);
    			// } else {
    			// packet.putLEShort(loc.getX() * 2 + 1);
    			// packet.putLEShort(loc.getY() * 2 + 1);
    			// }
    		}
    	}
    
    }

    configuration.cfg:
    Code:
    # Hyperion configuration file
    
    # world loader
    worldLoader: org.hyperion.rs2.GenericWorldLoader
    
    # login server
    loginServer: localhost
    # world password
    nodePassword: changeme
    # world id
    nodeId: 1
    
    # quiet
    # 40, 248, 19, 140, 187, 78, 6, 110, 244, 22
    packetHandlers[40]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[248]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[19]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[140]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[187]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[78]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[6]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[110]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[244]: org.hyperion.rs2.packet.QuietPacketHandler
    packetHandlers[22]: org.hyperion.rs2.packet.QuietPacketHandler
    
    # object click
    # 181, 241, 50
    packetHandlers[50]: org.hyperion.rs2.packet.ObjectOptionPacketHandler
    packetHandlers[241]: org.hyperion.rs2.packet.ObjectOptionPacketHandler
    packetHandlers[181]: org.hyperion.rs2.packet.ObjectOptionPacketHandler
    
    # player option
    # 49
    packetHandlers[245]: org.hyperion.rs2.packet.PlayerOptionPacketHandler
    
    # chat
    # 49
    packetHandlers[49]: org.hyperion.rs2.packet.ChatPacketHandler
    
    # walking
    # 213, 28, 247
    packetHandlers[213]: org.hyperion.rs2.packet.WalkingPacketHandler
    packetHandlers[28]: org.hyperion.rs2.packet.WalkingPacketHandler
    packetHandlers[247]: org.hyperion.rs2.packet.WalkingPacketHandler
    
    # equipment
    # 24
    packetHandlers[24]: org.hyperion.rs2.packet.WieldPacketHandler
    
    # items
    # 3, 177, 91, 231, 158
    packetHandlers[3]: org.hyperion.rs2.packet.ItemOptionPacketHandler
    packetHandlers[177]: org.hyperion.rs2.packet.ItemOptionPacketHandler
    packetHandlers[91]: org.hyperion.rs2.packet.ItemOptionPacketHandler
    packetHandlers[231]: org.hyperion.rs2.packet.ItemOptionPacketHandler
    packetHandlers[158]: org.hyperion.rs2.packet.ItemOptionPacketHandler
    
    # input
    # 75
    packetHandlers[75]: org.hyperion.rs2.packet.EnterAmountPacketHandler
    
    # action buttons
    # 79
    packetHandlers[79]: org.hyperion.rs2.packet.ActionButtonPacketHandler
    
    # commands
    # 56
    packetHandlers[56]: org.hyperion.rs2.packet.CommandPacketHandler


    Or if I missed any: http://www.rune-server.org/runescape...7-packets.html

    Or you could just use: http://www.rune-server.org/runescape...ion-377-a.html
    Reply With Quote  
     

  5. #5  
    Registered Member K-Shadow's Avatar
    Join Date
    Mar 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0
    Nice job, may use these later on.
    Reply With Quote  
     

  6. #6  
    Donator

    Major's Avatar
    Join Date
    Jan 2011
    Posts
    1,627
    Thanks
    671
    Thanked 932 Times in 460 Posts
    Rep Power
    2258
    Nice job Cyberus .
    Reply With Quote  
     

  7. #7  
    Programmer, Veteran and Respected Member



    Join Date
    Mar 2007
    Posts
    4,852
    Thanks
    2,130
    Thanked 2,814 Times in 956 Posts
    Rep Power
    4471
    Some more server->client packets not in the original post/without good descriptions:

    packet 40 = reset items and objects in an 8x8 region, sets current 'placement' 8x8 region
    packet 183 = set current 'placement' 8x8 region, also optionally allows grouping of item,object,projectile,etc. packets within this one
    packet 75 = set current 'placement' 8x8 region
    packet 219 = reset items on interface
    .
    Reply With Quote  
     

  8. Thankful user:


  9. #8  
    Donator


    Join Date
    Dec 2010
    Posts
    5,360
    Thanks
    644
    Thanked 2,186 Times in 1,162 Posts
    Rep Power
    2256
    Quote Originally Posted by Graham View Post
    Some more server->client packets not in the original post/without good descriptions:

    packet 40 = reset items and objects in an 8x8 region, sets current 'placement' 8x8 region
    packet 183 = set current 'placement' 8x8 region, also optionally allows grouping of item,object,projectile,etc. packets within this one
    packet 75 = set current 'placement' 8x8 region
    packet 219 = reset items on interface
    happen to know what

    Code:
    Packet 203 > ??? - Packet 147 in 317
    is used for?
    Reply With Quote  
     

  10. #9  
    Donator

    Major's Avatar
    Join Date
    Jan 2011
    Posts
    1,627
    Thanks
    671
    Thanked 932 Times in 460 Posts
    Rep Power
    2258
    Quote Originally Posted by Harlan View Post
    happen to know what

    Code:
    Packet 203 > ??? - Packet 147 in 317
    is used for?
    I've no idea other than something obviously related to Object Spawning.

    Try messing around with it and seeing what happens.

    Code:
    if (opcode == 203) { //317 - 147
                int objId = stream.getUShort();
                int i = stream.getUByte();
                int objType = i >> 2;
                int face = i & 3;
                int type = anIntArray1032[objType];
                byte b = stream.getNegByte();
                int offset = stream.getUByteA();
                int regionX = bigRegionX + (offset >> 4 & 7);
                int regionY = bigRegionY + (offset & 7);
                byte b2 = stream.getByteA();
                int j = stream.getBEUShortA();
                int playerId = stream.getLEUShort();
                byte b3 = stream.getByte();
                byte b4 = stream.getByteA();
                int k = stream.getUShort();
                Player player;
                if (playerId == this.playerId) {
    				player = sessionPlayer;
    			} else {
    				player = sessionPlayers[playerId];
    			}
                if (player != null) {
                    ObjectDefinition objectDef = ObjectDefinition.forId(objId);
                    int current = intGroundArray[plane][regionX][regionY];
                    int right = intGroundArray[plane][regionX + 1][regionY];
                    int diagonal = intGroundArray[plane][regionX + 1][regionY + 1];
                    int up = intGroundArray[plane][regionX][regionY + 1];
                    Model model = objectDef.renderObject(objType, face, current, right, diagonal, up, -1);
                    if (model != null) {
                        createObjectSpawnRequest(regionX, regionY, plane, -1, 0, 0, j + 1, k + 1, type);
                        player.anInt1764 = k + currentTime;
                        player.anInt1765 = j + currentTime;
                        player.aModel_1746 = model;
                        int objSizeX = objectDef.sizeX;
                        int objSizeY = objectDef.sizeY;
                        if (face == 1 || face == 3) {
                            objSizeX = objectDef.sizeY;
                            objSizeY = objectDef.sizeX;
                        }
                        player.anInt1743 = regionX * 128 + objSizeX * 64;
                        player.anInt1745 = regionY * 128 + objSizeY * 64;
                        player.anInt1744 = getFloorDrawHeight(player.anInt1743, player.anInt1745, plane);
                        if (b2 > b) {
                            byte byte4 = b2;
                            b2 = b;
                            b = byte4;
                        }
                        if (b4 > b3) {
                            byte byte5 = b4;
                            b4 = b3;
                            b3 = byte5;
                        }
                        player.anInt1768 = regionX + b2;
                        player.anInt1770 = regionX + b;
                        player.anInt1769 = regionY + b4;
                        player.anInt1771 = regionY + b3;
                    }
                }
            }
    Reply With Quote  
     

  11. #10  
    Registered Member Jizz n d run's Avatar
    Join Date
    Nov 2009
    Age
    17
    Posts
    457
    Thanks
    81
    Thanked 89 Times in 55 Posts
    Rep Power
    14
    I didnt understand anything , what you just released ,Major.
    But looks like , hard work ,GJ
    Reply With Quote  
     


Page 1 of 2 12 LastLast
Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Server to Client Packets
    By Tenzin in forum Configuration
    Replies: 13
    Last Post: 11-04-2011, 06:08 AM
  2. Server to Client Packets
    By Jimmy in forum Requests
    Replies: 2
    Last Post: 05-03-2011, 02:50 AM
  3. Replies: 4
    Last Post: 09-30-2010, 11:26 PM
  4. All Server to Client Packets
    By Linux in forum Snippets
    Replies: 4
    Last Post: 07-17-2010, 06:09 AM
  5. Known 459 Packets[Client -> Server]
    By Stewie in forum Snippets
    Replies: 4
    Last Post: 03-02-2010, 07:28 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •