Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.rs.net.decoders;
- import com.rs.game.Animation;
- import com.rs.game.Graphics;
- import com.rs.game.World;
- import com.rs.game.WorldObject;
- import com.rs.game.WorldTile;
- import com.rs.game.item.FloorItem;
- import com.rs.game.item.Item;
- import com.rs.game.minigames.clanwars.ClanWars;
- import com.rs.game.npc.NPC;
- import com.rs.game.npc.familiar.Familiar;
- import com.rs.game.npc.familiar.Familiar.SpecialAttack;
- import com.rs.game.player.ChatMessage;
- import com.rs.game.player.CoordsEvent;
- import com.rs.game.player.Inventory;
- import com.rs.game.player.LogicPacket;
- import com.rs.game.player.Player;
- import com.rs.game.player.PublicChatMessage;
- import com.rs.game.player.RouteEvent;
- import com.rs.game.player.Skills;
- import com.rs.game.player.actions.Firemaking;
- import com.rs.game.player.actions.PlayerCombat;
- import com.rs.game.player.actions.PlayerFollow;
- import com.rs.game.player.actions.Summoning;
- import com.rs.game.player.clans.ClansManager;
- import com.rs.game.player.clans.clancitadels.ClanCitadel;
- import com.rs.game.player.content.Commands;
- import com.rs.game.player.content.FortuneWell;
- import com.rs.game.player.content.FriendChatsManager;
- import com.rs.game.player.content.Magic;
- import com.rs.game.player.content.SkillCapeCustomizer;
- import com.rs.io.InputStream;
- import com.rs.io.OutputStream;
- import com.rs.net.Session;
- import com.rs.net.decoders.handlers.ButtonHandler;
- import com.rs.net.decoders.handlers.InventoryOptionsHandler;
- import com.rs.net.decoders.handlers.NPCHandler;
- import com.rs.net.decoders.handlers.ObjectHandler;
- import com.rs.utils.Colors;
- import com.rs.utils.DisplayNames;
- import com.rs.utils.ItemExamines;
- import com.rs.utils.StarterMap;
- import com.rs.utils.Utils;
- import com.rs.utils.huffman.Huffman;
- import com.rs.game.player.content.Shop;
- import com.rs.game.player.dialogues.Banker;
- public final class WorldPacketsDecoder extends Decoder {
- private static final byte[] PACKET_SIZES = new byte[104];
- private final static int WALKING_PACKET = 8;
- private final static int MINI_WALKING_PACKET = 58;
- public final static int ACTION_BUTTON1_PACKET = 14;
- private final static int PLAYER_OPTION_5_PACKET = 77;
- public final static int ACTION_BUTTON2_PACKET = 67;
- private final static int ENTER_LONG_TEXT_PACKET = 48;
- public final static int ACTION_BUTTON3_PACKET = 5;
- public final static int ACTION_BUTTON4_PACKET = 55;
- public final static int ACTION_BUTTON5_PACKET = 68;
- public final static int ACTION_BUTTON6_PACKET = 90;
- public final static int ACTION_BUTTON7_PACKET = 6;
- public final static int ACTION_BUTTON8_PACKET = 32;
- public final static int ACTION_BUTTON9_PACKET = 27;
- public final static int WORLD_MAP_CLICK = 38;
- public final static int ACTION_BUTTON10_PACKET = 96;
- public final static int RECEIVE_PACKET_COUNT_PACKET = 33;
- private final static int PUBLIC_QUICK_CHAT_PACKET = 86;
- private final static int SEND_FRIEND_QUICK_CHAT_PACKET = 0;
- private final static int MAGIC_ON_ITEM_PACKET = -1;
- private final static int PLAYER_OPTION_4_PACKET = 17;
- private final static int MOVE_CAMERA_PACKET = 103;
- private final static int INTERFACE_ON_OBJECT = 37;
- private final static int CLICK_PACKET = -1;
- private final static int CLOSE_INTERFACE_PACKET = 54;
- private final static int COMMANDS_PACKET = 60;
- private final static int ITEM_ON_ITEM_PACKET = 3;
- private final static int SCREEN_PACKET = 98;
- private final static int CHAT_TYPE_PACKET = 83;
- private final static int CHAT_PACKET = 53;
- private final static int ADD_FRIEND_PACKET = 89;
- private final static int ADD_IGNORE_PACKET = 4;
- private final static int MOVE_MOUSE_PACKET = -1;
- private final static int KEY_TYPED_PACKET = -1;
- private final static int REMOVE_IGNORE_PACKET = 73;
- private final static int JOIN_FRIEND_CHAT_PACKET = 36;
- private final static int CHANGE_FRIEND_CHAT_PACKET = 22;
- private final static int KICK_FRIEND_CHAT_PACKET = 74;
- private final static int REMOVE_FRIEND_PACKET = 24;
- private final static int SEND_FRIEND_MESSAGE_PACKET = 82;
- private final static int OBJECT_CLICK1_PACKET = 26;
- private final static int OBJECT_CLICK2_PACKET = 59;
- private final static int OBJECT_CLICK3_PACKET = 40;
- private final static int OBJECT_CLICK4_PACKET = 23;
- private final static int OBJECT_CLICK5_PACKET = 80;
- private final static int OBJECT_EXAMINE_PACKET = 25;
- private final static int GROUND_ITEM_EXAMINE_PACKET = 102;
- private final static int NPC_CLICK1_PACKET = 31;
- private final static int NPC_CLICK2_PACKET = 101;
- private final static int NPC_CLICK3_PACKET = 34;
- private final static int NPC_CLICK4_PACKET = 65;
- private final static int ATTACK_NPC = 20;
- private final static int PLAYER_OPTION_1_PACKET = 42;
- private final static int PLAYER_OPTION_2_PACKET = 46;
- private final static int PLAYER_OPTION_6_PACKET = 49;
- private final static int ITEM_TAKE_PACKET = 57;
- private final static int GROUND_ITEM_INTERACT_PACKET = 62;
- private final static int DIALOGUE_CONTINUE_PACKET = 72;
- private final static int ENTER_INTEGER_PACKET = 81;
- private final static int ENTER_NAME_PACKET = 29;
- private final static int ENTER_STRING_PACKET = -1;
- private final static int SWITCH_INTERFACE_ITEM_PACKET = 76;
- private final static int INTERFACE_ON_PLAYER = 50;
- private final static int INTERFACE_ON_NPC = 66;
- private final static int COLOR_ID_PACKET = 97;
- private final static int CLAN_INVITATION_PACKET = 56;
- private final static int PING_PACKET = 21;
- private final static int LOGIN_PACKET = 30;
- private static final int NPC_EXAMINE_PACKET = 9;
- @SuppressWarnings("unused")
- private final static int CLAN_NAME_AND_MOTTO_PACKET = 48;
- @SuppressWarnings("unused")
- private final static int CLAN_FORUM_THREAD_PACKET = 18;
- private final static int GE_SEARCH_PACKET = 71;
- private final static int UNID_PACKET = 39;
- static {
- loadPacketSizes();
- }
- public static void loadPacketSizes() {
- PACKET_SIZES[0] = -1;
- PACKET_SIZES[1] = -2;
- PACKET_SIZES[2] = -1;
- PACKET_SIZES[3] = 16;
- PACKET_SIZES[4] = -1;
- PACKET_SIZES[5] = 8;
- PACKET_SIZES[6] = 8;
- PACKET_SIZES[7] = 3;
- PACKET_SIZES[8] = -1;
- PACKET_SIZES[9] = 3;
- PACKET_SIZES[10] = -1;
- PACKET_SIZES[11] = -1;
- PACKET_SIZES[12] = -1;
- PACKET_SIZES[13] = 7;
- PACKET_SIZES[14] = 8;
- PACKET_SIZES[15] = 6;
- PACKET_SIZES[16] = 2;
- PACKET_SIZES[17] = 3;
- PACKET_SIZES[18] = -1;
- PACKET_SIZES[19] = -2;
- PACKET_SIZES[20] = 3;
- PACKET_SIZES[21] = 0;
- PACKET_SIZES[22] = -1;
- PACKET_SIZES[23] = 9;
- PACKET_SIZES[24] = -1;
- PACKET_SIZES[25] = 9;
- PACKET_SIZES[26] = 9;
- PACKET_SIZES[27] = 8;
- PACKET_SIZES[28] = 4;
- PACKET_SIZES[29] = -1;
- PACKET_SIZES[30] = 0;
- PACKET_SIZES[31] = 3;
- PACKET_SIZES[32] = 8;
- PACKET_SIZES[33] = 4;
- PACKET_SIZES[34] = 3;
- PACKET_SIZES[35] = -1;
- PACKET_SIZES[36] = -1;
- PACKET_SIZES[37] = 17;
- PACKET_SIZES[38] = 4;
- PACKET_SIZES[39] = 4;
- PACKET_SIZES[40] = 9;
- PACKET_SIZES[41] = -1;
- PACKET_SIZES[42] = 3;
- PACKET_SIZES[43] = 7;
- PACKET_SIZES[44] = -2;
- PACKET_SIZES[45] = 7;
- PACKET_SIZES[46] = 3;
- PACKET_SIZES[47] = 4;
- PACKET_SIZES[48] = -1;
- PACKET_SIZES[49] = 3;
- PACKET_SIZES[50] = 11;
- PACKET_SIZES[51] = 3;
- PACKET_SIZES[52] = -1;
- PACKET_SIZES[53] = -1;
- PACKET_SIZES[54] = 0;
- PACKET_SIZES[55] = 8;
- PACKET_SIZES[56] = 3;
- PACKET_SIZES[57] = 7;
- PACKET_SIZES[58] = -1;
- PACKET_SIZES[59] = 9;
- PACKET_SIZES[60] = -1;
- PACKET_SIZES[61] = 7;
- PACKET_SIZES[62] = 7;
- PACKET_SIZES[63] = 12;
- PACKET_SIZES[64] = 4;
- PACKET_SIZES[65] = 3;
- PACKET_SIZES[66] = 11;
- PACKET_SIZES[67] = 8;
- PACKET_SIZES[68] = 8;
- PACKET_SIZES[69] = 15;
- PACKET_SIZES[70] = 1;
- PACKET_SIZES[71] = 2;
- PACKET_SIZES[72] = 6;
- PACKET_SIZES[73] = -1;
- PACKET_SIZES[74] = -1;
- PACKET_SIZES[75] = -2;
- PACKET_SIZES[76] = 16;
- PACKET_SIZES[77] = 3;
- PACKET_SIZES[78] = 1;
- PACKET_SIZES[79] = 3;
- PACKET_SIZES[80] = 9;
- PACKET_SIZES[81] = 4;
- PACKET_SIZES[82] = -2;
- PACKET_SIZES[83] = 1;
- PACKET_SIZES[84] = 1;
- PACKET_SIZES[85] = 3;
- PACKET_SIZES[86] = -1;
- PACKET_SIZES[87] = 4;
- PACKET_SIZES[88] = 3;
- PACKET_SIZES[89] = -1;
- PACKET_SIZES[90] = 8;
- PACKET_SIZES[91] = -2;
- PACKET_SIZES[92] = -1;
- PACKET_SIZES[93] = -1;
- PACKET_SIZES[94] = 9;
- PACKET_SIZES[95] = -2;
- PACKET_SIZES[96] = 8;
- PACKET_SIZES[97] = 2;
- PACKET_SIZES[98] = 6;
- PACKET_SIZES[99] = 2;
- PACKET_SIZES[100] = -2;
- PACKET_SIZES[101] = 3;
- PACKET_SIZES[102] = 7;
- PACKET_SIZES[103] = 4;
- }
- private Player player;
- private int chatType;
- public WorldPacketsDecoder(Session session, Player player) {
- super(session);
- this.player = player;
- }
- @Override
- public void decode(InputStream stream) {
- while (stream.getRemaining() > 0 && session.getChannel().isConnected()
- && !player.hasFinished()) {
- int packetId = stream.readPacket(player);
- if (packetId >= PACKET_SIZES.length || packetId < 0)
- break;
- int length = PACKET_SIZES[packetId];
- if (length == -1)
- length = stream.readUnsignedByte();
- else if (length == -2)
- length = stream.readUnsignedShort();
- else if (length == -3)
- length = stream.readInt();
- else if (length == -4) {
- length = stream.getRemaining();
- }
- if (length > stream.getRemaining())
- length = stream.getRemaining();
- int startOffset = stream.getOffset();
- processPackets(packetId, stream, length);
- stream.setOffset(startOffset + length);
- }
- }
- @SuppressWarnings("unused")
- public static void decodeLogicPacket(final Player player, LogicPacket packet) {
- int packetId = packet.getId();
- InputStream stream = new InputStream(packet.getData());
- if (packetId == PLAYER_OPTION_5_PACKET) {
- boolean unknown = stream.readByte() == 1;
- int playerIndex = stream.readUnsignedShortLE128();
- Player other = World.getPlayers().get(playerIndex);
- if (other == null || other.isDead() || other.hasFinished() || !player.getMapRegionsIds().contains(other.getRegionId()))
- return;
- if (player.isLocked()) {
- return;
- }
- if (!other.withinDistance(player, 14)) {
- player.getPackets().sendGameMessage("Unable to find player: " + other.getDisplayName() + ".");
- return;
- }
- if (player.getRights() > 0) {
- player.getDialogueManager().startDialogue("ModPanel", playerIndex);
- return;
- }
- player.getDialogueManager().startDialogue("SupportPanel", playerIndex);
- } else if (packetId == WALKING_PACKET || packetId == MINI_WALKING_PACKET) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
- return;
- long currentTime = Utils.currentTimeMillis();
- if (player.isLocked())
- return;
- if (player.getFreezeDelay() >= currentTime) {
- player.sgm("A magical force prevents you from moving.");
- return;
- }
- int length = stream.getLength();
- int baseX = stream.readUnsignedShort128();
- boolean forceRun = stream.readUnsigned128Byte() == 1;
- int baseY = stream.readUnsignedShort128();
- int steps = (length - 5) / 2;
- if (steps > 25)
- steps = 25;
- player.stopAll();
- if (forceRun)
- player.setRun(forceRun);
- for (int step = 0; step < steps; step++)
- if (!player.addWalkSteps(baseX + stream.readUnsignedByte(), baseY + stream.readUnsignedByte(), 25, true))
- break;
- //if (player.isTeleporting()) {
- // player.getActionManager().getAction().stop(player);
- //}
- } else if (packetId == INTERFACE_ON_OBJECT) {
- boolean forceRun = stream.readByte128() == 1;
- int itemId = stream.readShortLE128();
- int y = stream.readShortLE128();
- int objectId = stream.readIntV2();
- int interfaceHash = stream.readInt();
- final int interfaceId = interfaceHash >> 16;
- int slot = stream.readShortLE();
- int x = stream.readShort128();
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion()
- || player.isDead())
- return;
- long currentTime = Utils.currentTimeMillis();
- if (player.getLockDelay() >= currentTime
- || player.getEmotesManager().getNextEmoteEnd() >= currentTime)
- return;
- final WorldTile tile = new WorldTile(x, y, player.getPlane());
- int regionId = tile.getRegionId();
- if (!player.getMapRegionsIds().contains(regionId))
- return;
- WorldObject mapObject = World.getObjectWithId(tile, objectId);
- if (mapObject == null || mapObject.getId() != objectId)
- return;
- final WorldObject object = !player.isAtDynamicRegion() ? mapObject
- : new WorldObject(objectId, mapObject.getType(),
- mapObject.getRotation(), x, y, player.getPlane());
- final Item item = player.getInventory().getItem(slot);
- if (player.isDead()
- || Utils.getInterfaceDefinitionsSize() <= interfaceId)
- return;
- if (player.getLockDelay() > Utils.currentTimeMillis())
- return;
- if (!player.getInterfaceManager().containsInterface(interfaceId))
- return;
- if (item == null || item.getId() != itemId)
- return;
- player.stopAll(false); // false
- if (forceRun)
- player.setRun(forceRun);
- switch (interfaceId) {
- case Inventory.INVENTORY_INTERFACE: // inventory
- ObjectHandler.handleItemOnObject(player, object, interfaceId, item);
- break;
- }
- } else if (packetId == PLAYER_OPTION_2_PACKET) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
- return;
- boolean unknown = stream.readByte() == 1;
- int playerIndex = stream.readUnsignedShortLE128();
- Player p2 = World.getPlayers().get(playerIndex);
- if (p2 == null || p2.isDead() || p2.hasFinished()
- || !player.getMapRegionsIds().contains(p2.getRegionId()))
- return;
- if (player.isLocked())
- return;
- player.stopAll(false);
- player.getActionManager().setAction(new PlayerFollow(p2));
- } else if (packetId == PLAYER_OPTION_6_PACKET) {
- boolean unknown = stream.readByte() == 1;
- int playerIndex = stream.readUnsignedShortLE128();
- Player p2 = World.getPlayers().get(playerIndex);
- if (p2 == null || p2.isDead() || p2.hasFinished()
- || !player.getMapRegionsIds().contains(p2.getRegionId()))
- return;
- if (player.isLocked())
- return;
- player.stopAll(false);
- player.faceEntity(p2);
- player.setNextAnimation(new Animation(11547));
- } else if (packetId == PLAYER_OPTION_4_PACKET) {
- boolean unknown = stream.readByte() == 1;
- int playerIndex = stream.readUnsignedShortLE128();
- Player p2 = World.getPlayers().get(playerIndex);
- if (p2 == null || p2.isDead() || p2.hasFinished()
- || !player.getMapRegionsIds().contains(p2.getRegionId()))
- return;
- if (player.isLocked())
- return;
- player.stopAll(false);
- if (player.isCantTrade()) {
- player.sgm("You are busy.");
- return;
- }
- if (player.getRights() != 2 && p2.getRights() != 2) {
- if (player.isIronMan()) {
- player.sgm("You cannot do this as an Iron Man!");
- return;
- }
- if (p2.isIronMan()) {
- player.sgm(p2.getDisplayName()+" is an Iron Man and cannot trade!");
- return;
- }
- if (player.isNew()) {
- player.sgm("You must have a total level of 150 and have played for 30 minutes to trade.");
- return;
- }
- }
- if (p2.getInterfaceManager().containsScreenInter()) {
- player.sgm("The other player is busy.");
- return;
- }
- if (player.getX() == p2.getX() && player.getY() == p2.getY()) {
- if (!player.addWalkSteps(player.getX() - 1, player.getY(), 1))
- if (!player.addWalkSteps(player.getX() + 1, player.getY(),
- 1))
- if (!player.addWalkSteps(player.getX(),
- player.getY() + 1, 1))
- player.addWalkSteps(player.getX(),
- player.getY() - 1, 1);
- }
- if (player.getX() == p2.getX() && player.getY() == p2.getY()) {
- player.sgm("Unable to trade here.");
- return;
- }
- if (!p2.withinDistance(player, 14)) {
- player.sgm("Unable to find player: "
- + p2.getDisplayName() + ".");
- return;
- }
- if (p2.getTemporaryAttributtes().get("TradeTarget") == player) {
- p2.getTemporaryAttributtes().remove("TradeTarget");
- player.getTrade().openTrade(p2);
- player.faceEntity(p2);
- p2.faceEntity(player);
- p2.getTrade().openTrade(player);
- return;
- }
- player.getTemporaryAttributtes().put("TradeTarget", p2);
- player.sgm("Sending " + p2.getDisplayName() + " a trade request...");
- p2.getPackets().sendTradeRequestMessage(player);
- player.faceEntity(p2);
- } else if (packetId == PLAYER_OPTION_1_PACKET) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
- return;
- if (player.isLocked())
- return;
- boolean unknown = stream.readByte() == 1;
- int playerIndex = stream.readUnsignedShortLE128();
- Player p2 = World.getPlayers().get(playerIndex);
- if (p2 == null || p2.isDead() || p2.hasFinished()
- || !player.getMapRegionsIds().contains(p2.getRegionId()))
- return;
- if (player.getLockDelay() > Utils.currentTimeMillis()
- || !player.getControlerManager().canPlayerOption1(p2))
- return;
- if (!player.isCanPvp())
- return;
- if (!player.getControlerManager().canAttack(p2))
- return;
- if (!player.isCanPvp() || !p2.isCanPvp()) {
- player.sgm("You can only attack players in a player-vs-player area.", true);
- return;
- }
- if (p2.isNew()) {
- player.sgm("You can not attack new players.", true);
- return;
- }
- if (!p2.isAtMultiArea() || !player.isAtMultiArea()) {
- if (player.getAttackedBy() != p2 && player.isUnderCombat(0)) {
- player.faceEntity(p2);
- player.sgm("You are already in combat.", true);
- return;
- }
- if (p2.getAttackedBy() != player && p2.isUnderCombat(0)) {
- if (p2.getAttackedBy() instanceof NPC)
- p2.setAttackedBy(player);
- else {
- player.sgm("That player is already in combat.", true);
- player.faceEntity(p2);
- return;
- }
- }
- }
- player.stopAll(false);
- player.getActionManager().setAction(new PlayerCombat(p2));
- } else if (packetId == ATTACK_NPC) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
- return;
- if (player.isLocked())
- return;
- int npcIndex = stream.readUnsignedShort128();
- boolean forceRun = stream.read128Byte() == 1;
- if (forceRun)
- player.setRun(forceRun);
- NPC npc = World.getNPCs().get(npcIndex);
- if (npc == null || npc.isDead() || npc.hasFinished()
- || !player.getMapRegionsIds().contains(npc.getRegionId()) || !npc.getDefinitions().hasAttackOption()) {
- return;
- }
- if (!player.getControlerManager().canAttack(npc))
- return;
- if (npc instanceof Familiar) {
- Familiar familiar = (Familiar) npc;
- if (familiar == player.getFamiliar()) {
- player.sgm("You can't attack your own familiar.", true);
- return;
- }
- if (!familiar.canAttack(player)) {
- player.sgm("You can't attack this npc.", true);
- return;
- }
- } else if (!npc.isForceMultiAttacked()) {
- if (!npc.isAtMultiArea() || !player.isAtMultiArea()) {
- if (player.getAttackedBy() != npc && player.isUnderCombat(0)) {
- player.faceEntity(npc);
- player.sgm("You are already in combat.", true);
- return;
- }
- if (npc.getAttackedBy() != player
- && npc.getAttackedByDelay() > Utils.currentTimeMillis()) {
- player.faceEntity(npc);
- player.sgm("This npc is already in combat.", true);
- return;
- }
- }
- }
- player.stopAll(false);
- player.getActionManager().setAction(new PlayerCombat(npc));
- } else if (packetId == INTERFACE_ON_PLAYER) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion()
- || player.isDead())
- return;
- if (player.isLocked())
- return;
- int junk1 = stream.readUnsignedShort();
- int playerIndex = stream.readUnsignedShort();
- int interfaceHash = stream.readIntV2();
- int junk2 = stream.readUnsignedShortLE128();
- boolean unknown = stream.read128Byte() == 1;
- final int itemId = stream.readUnsignedShort();
- int interfaceId = interfaceHash >> 16;
- int componentId = interfaceHash - (interfaceId << 16);
- int interfaceSlot = stream.readUnsignedShortLE128();
- if (Utils.getInterfaceDefinitionsSize() <= interfaceId)
- return;
- if (!player.getInterfaceManager().containsInterface(interfaceId))
- return;
- if (componentId == 65535)
- componentId = -1;
- if (componentId != -1
- && Utils.getInterfaceDefinitionsComponentsSize(interfaceId) <= componentId)
- return;
- Player p2 = World.getPlayers().get(playerIndex);
- if (p2 == null || p2.isDead() || p2.hasFinished()
- || !player.getMapRegionsIds().contains(p2.getRegionId()))
- return;
- player.stopAll(true);
- switch (interfaceId) {
- case 1110:
- if (componentId == 87)
- ClansManager.invite(player, p2);
- break;
- case Inventory.INVENTORY_INTERFACE:// Item on player
- InventoryOptionsHandler.handleItemOnPlayer(player, p2, junk1);
- break;
- case 662:
- case 747:
- if (player.getFamiliar() == null)
- return;
- player.resetWalkSteps();
- if ((interfaceId == 747 && componentId == 15)
- || (interfaceId == 662 && componentId == 65)
- || (interfaceId == 662 && componentId == 74)
- || interfaceId == 747 && componentId == 18) {
- if ((interfaceId == 662 && componentId == 74
- || interfaceId == 747 && componentId == 24 || interfaceId == 747
- && componentId == 18)) {
- if (player.getFamiliar().getSpecialAttack() != SpecialAttack.ENTITY)
- return;
- }
- if (!player.isCanPvp() || !p2.isCanPvp()) {
- player.sgm("You can only attack players in a player-vs-player area.");
- return;
- }
- if (p2.isNew()) {
- player.sgm(Colors.red+ "You cannot attack new players.");
- return;
- }
- if (!player.getFamiliar().canAttack(p2)) {
- player.sgm("You can only use your familiar in a multi-zone area.");
- return;
- } else {
- player.getFamiliar().setSpecial(
- interfaceId == 662 && componentId == 74
- || interfaceId == 747
- && componentId == 18);
- player.getFamiliar().setTarget(p2);
- }
- }
- break;
- case 193:
- switch (componentId) {
- case 28:
- case 32:
- case 24:
- case 20:
- case 30:
- case 34:
- case 26:
- case 22:
- case 29:
- case 33:
- case 25:
- case 21:
- case 31:
- case 35:
- case 27:
- case 23:
- if (Magic.checkCombatSpell(player, componentId, 1, false)) {
- player.setNextFaceWorldTile(new WorldTile(p2
- .getCoordFaceX(p2.getSize()), p2
- .getCoordFaceY(p2.getSize()), p2.getPlane()));
- if (!player.getControlerManager().canAttack(p2))
- return;
- if (!player.isCanPvp() || !p2.isCanPvp()) {
- player.sgm("You can only attack players in a player-vs-player area.", true);
- return;
- }
- if (p2.isNew()) {
- player.sgm("You cannot attack new players.");
- return;
- }
- if (!p2.isAtMultiArea() || !player.isAtMultiArea()) {
- if (player.getAttackedBy() != p2 && player.getAttackedByDelay() > Utils.currentTimeMillis()) {
- player.sgm("That "
- + (player.getAttackedBy() instanceof Player ? "player"
- : "npc")
- + " is already in combat.", true);
- return;
- }
- if (p2.getAttackedBy() != player
- && p2.getAttackedByDelay() > Utils
- .currentTimeMillis()) {
- if (p2.getAttackedBy() instanceof NPC)
- p2.setAttackedBy(player);
- else {
- player.sgm("That player is already in combat.", true);
- return;
- }
- }
- }
- player.getActionManager().setAction(
- new PlayerCombat(p2));
- }
- break;
- }
- case 430:
- switch (componentId) {
- case 42:
- player.setNextFaceWorldTile(new WorldTile(p2
- .getCoordFaceX(p2.getSize()), p2.getCoordFaceY(p2
- .getSize()), p2.getPlane()));
- if (Magic.checkCombatSpell(player, componentId, 1, false)) {
- if (p2 instanceof Player) {
- if (player.getSkills().getLevel(Skills.MAGIC) < 93) {
- player.sgm("Your Magic level is not high enough for this spell.");
- return;
- } else if (player.getSkills().getLevel(
- Skills.DEFENCE) < 40) {
- player.sgm("You need a Defence level of 40 for this spell");
- return;
- }
- Long lastVeng = (Long) p2.getTemporaryAttributtes()
- .get("LAST_VENG");
- if (lastVeng != null
- && lastVeng + 30000 > Utils
- .currentTimeMillis()) {
- player.sgm("That player already has vengeance.");
- return;
- }
- player.stopAll();
- player.setNextAnimation(new Animation(4411));
- p2.setNextGraphics(new Graphics(725, 0, 100));
- p2.setCastVeng(true);
- p2.getTemporaryAttributtes().put("LAST_VENG",
- Utils.currentTimeMillis());
- p2.sgm("You recieve vengeance from "
- + player.getDisplayName() + ".");
- }
- }
- break;
- }
- case 192:
- switch (componentId) {
- case 25: // air strike
- case 28: // water strike
- case 30: // earth strike
- case 32: // fire strike
- case 34: // air bolt
- case 39: // water bolt
- case 42: // earth bolt
- case 45: // fire bolt
- case 49: // air blast
- case 52: // water blast
- case 58: // earth blast
- case 63: // fire blast
- case 70: // air wave
- case 73: // water wave
- case 77: // earth wave
- case 80: // fire wave
- case 86: // teleblock
- case 84: // air surge
- case 87: // water surge
- case 89: // earth surge
- case 91: // fire surge
- case 99: // storm of armadyl
- case 36: // bind
- case 66: // Sara Strike
- case 67: // Guthix Claws
- case 68: // Flame of Zammy
- case 55: // snare
- case 81: // entangle
- if (Magic.checkCombatSpell(player, componentId, 1, false)) {
- player.setNextFaceWorldTile(new WorldTile(p2
- .getCoordFaceX(p2.getSize()), p2
- .getCoordFaceY(p2.getSize()), p2.getPlane()));
- if (!player.getControlerManager().canAttack(p2))
- return;
- if (!player.isCanPvp() || !p2.isCanPvp()) {
- player.sgm("You can only attack players in a player-vs-player area.");
- return;
- }
- if (!p2.isAtMultiArea() || !player.isAtMultiArea()) {
- if (player.getAttackedBy() != p2
- && player.getAttackedByDelay() > Utils
- .currentTimeMillis()) {
- player.sgm("That "
- + (player.getAttackedBy() instanceof Player ? "player"
- : "npc")
- + " is already in combat.");
- return;
- }
- if (p2.getAttackedBy() != player
- && p2.getAttackedByDelay() > Utils
- .currentTimeMillis()) {
- if (p2.getAttackedBy() instanceof NPC)
- p2.setAttackedBy(player);
- else {
- player.sgm("That player is already in combat.");
- return;
- }
- }
- }
- player.getActionManager().setAction(
- new PlayerCombat(p2));
- }
- break;
- }
- break;
- }
- } else if (packetId == INTERFACE_ON_NPC) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion()
- || player.isDead())
- return;
- if (player.getLockDelay() > Utils.currentTimeMillis())
- return;
- boolean unknown = stream.readByte() == 1;
- int interfaceHash = stream.readInt();
- int npcIndex = stream.readUnsignedShortLE();
- int interfaceSlot = stream.readUnsignedShortLE128();
- int junk2 = stream.readUnsignedShortLE();
- int interfaceId = interfaceHash >> 16;
- int componentId = interfaceHash - (interfaceId << 16);
- if (Utils.getInterfaceDefinitionsSize() <= interfaceId)
- return;
- if (!player.getInterfaceManager().containsInterface(interfaceId))
- return;
- if (componentId == 65535)
- componentId = -1;
- if (componentId != -1
- && Utils.getInterfaceDefinitionsComponentsSize(interfaceId) <= componentId)
- return;
- NPC npc = World.getNPCs().get(npcIndex);
- if (npc == null || npc.isDead() || npc.hasFinished()
- || !player.getMapRegionsIds().contains(npc.getRegionId()))
- return;
- player.stopAll(false);
- if (interfaceId != Inventory.INVENTORY_INTERFACE) {
- if (!npc.getDefinitions().hasAttackOption()) {
- player.sgm("You can't attack this npc.");
- return;
- }
- }
- switch (interfaceId) {
- case Inventory.INVENTORY_INTERFACE:
- Item item = player.getInventory().getItem(interfaceSlot);
- if (item == null
- || !player.getControlerManager().processItemOnNPC(npc,
- item))
- return;
- InventoryOptionsHandler.handleItemOnNPC(player, npc, item);
- break;
- case 1165:
- Summoning.attackDreadnipTarget(npc, player);
- break;
- case 662:
- case 747:
- if (player.getFamiliar() == null)
- return;
- player.resetWalkSteps();
- if ((interfaceId == 747 && componentId == 15)
- || (interfaceId == 662 && componentId == 65)
- || (interfaceId == 662 && componentId == 74)
- || interfaceId == 747 && componentId == 18
- || interfaceId == 747 && componentId == 24) {
- if ((interfaceId == 662 && componentId == 74 || interfaceId == 747
- && componentId == 18)) {
- if (player.getFamiliar().getSpecialAttack() != SpecialAttack.ENTITY)
- return;
- }
- if (npc instanceof Familiar) {
- Familiar familiar = (Familiar) npc;
- if (familiar == player.getFamiliar()) {
- player.sgm("You can't attack your own familiar.");
- return;
- }
- if (!player.getFamiliar()
- .canAttack(familiar.getOwner())) {
- player.sgm("You can only attack players in a player-vs-player area.");
- return;
- }
- }
- if (!player.getFamiliar().canAttack(npc)) {
- player.sgm("You can only use your familiar in a multi-zone area.");
- return;
- } else {
- player.getFamiliar().setSpecial(
- interfaceId == 662 && componentId == 74
- || interfaceId == 747
- && componentId == 18);
- player.getFamiliar().setTarget(npc);
- }
- }
- break;
- case 193:
- switch (componentId) {
- case 28:
- case 32:
- case 24:
- case 20:
- case 30:
- case 34:
- case 26:
- case 22:
- case 29:
- case 33:
- case 25:
- case 21:
- case 31:
- case 35:
- case 27:
- case 23:
- if (Magic.checkCombatSpell(player, componentId, 1, false)) {
- player.setNextFaceWorldTile(new WorldTile(npc
- .getCoordFaceX(npc.getSize()), npc
- .getCoordFaceY(npc.getSize()), npc.getPlane()));
- if (!player.getControlerManager().canAttack(npc))
- return;
- if (npc instanceof Familiar) {
- Familiar familiar = (Familiar) npc;
- if (familiar == player.getFamiliar()) {
- player.sgm("You can't attack your own familiar.");
- return;
- }
- if (!familiar.canAttack(player)) {
- player.sgm("You can't attack this npc.");
- return;
- }
- } else if (!npc.isForceMultiAttacked()) {
- if (!npc.isAtMultiArea() || !player.isAtMultiArea()) {
- if (player.getAttackedBy() != npc
- && player.getAttackedByDelay() > Utils
- .currentTimeMillis()) {
- player.sgm("You are already in combat.");
- return;
- }
- if (npc.getAttackedBy() != player
- && npc.getAttackedByDelay() > Utils
- .currentTimeMillis()) {
- player.sgm("This npc is already in combat.");
- return;
- }
- }
- }
- player.getActionManager().setAction(
- new PlayerCombat(npc));
- }
- break;
- }
- case 192:
- switch (componentId) {
- case 25: // air strike
- case 28: // water strike
- case 30: // earth strike
- case 32: // fire strike
- case 34: // air bolt
- case 39: // water bolt
- case 42: // earth bolt
- case 45: // fire bolt
- case 49: // air blast
- case 52: // water blast
- case 58: // earth blast
- case 63: // fire blast
- case 70: // air wave
- case 73: // water wave
- case 77: // earth wave
- case 80: // fire wave
- case 84: // air surge
- case 87: // water surge
- case 89: // earth surge
- case 66: // Sara Strike
- case 67: // Guthix Claws
- case 68: // Flame of Zammy
- case 93:
- case 91: // fire surge
- case 99: // storm of Armadyl
- case 36: // bind
- case 55: // snare
- case 81: // entangle
- if (Magic.checkCombatSpell(player, componentId, 1, false)) {
- player.setNextFaceWorldTile(new WorldTile(npc
- .getCoordFaceX(npc.getSize()), npc
- .getCoordFaceY(npc.getSize()), npc.getPlane()));
- if (!player.getControlerManager().canAttack(npc))
- return;
- if (npc instanceof Familiar) {
- Familiar familiar = (Familiar) npc;
- if (familiar == player.getFamiliar()) {
- player.sgm("You can't attack your own familiar.");
- return;
- }
- if (!familiar.canAttack(player)) {
- player.sgm("You can't attack this npc.");
- return;
- }
- } else if (!npc.isForceMultiAttacked()) {
- if (!npc.isAtMultiArea() || !player.isAtMultiArea()) {
- if (player.getAttackedBy() != npc
- && player.getAttackedByDelay() > Utils
- .currentTimeMillis()) {
- player.sgm("You are already in combat.");
- return;
- }
- if (npc.getAttackedBy() != player
- && npc.getAttackedByDelay() > Utils
- .currentTimeMillis()) {
- player.sgm("This npc is already in combat.");
- return;
- }
- }
- }
- player.getActionManager().setAction(
- new PlayerCombat(npc));
- }
- break;
- }
- break;
- }
- } else if (packetId == NPC_CLICK1_PACKET) {
- if (player.isLocked())
- return;
- NPCHandler.handleOption1(player, stream);
- } else if (packetId == NPC_CLICK2_PACKET) {
- if (player.isLocked())
- return;
- NPCHandler.handleOption2(player, stream);
- } else if (packetId == NPC_CLICK3_PACKET) {
- if (player.isLocked())
- return;
- NPCHandler.handleOption3(player, stream);
- } else if (packetId == NPC_CLICK4_PACKET) {
- if (player.isLocked())
- return;
- NPCHandler.handleOption4(player, stream);
- } else if (packetId == OBJECT_CLICK1_PACKET) {
- if (player.isLocked())
- return;
- ObjectHandler.handleOption(player, stream, 1);
- } else if (packetId == OBJECT_CLICK2_PACKET) {
- if (player.isLocked())
- return;
- ObjectHandler.handleOption(player, stream, 2);
- } else if (packetId == OBJECT_CLICK3_PACKET) {
- if (player.isLocked())
- return;
- ObjectHandler.handleOption(player, stream, 3);
- } else if (packetId == OBJECT_CLICK4_PACKET) {
- if (player.isLocked())
- return;
- ObjectHandler.handleOption(player, stream, 4);
- } else if (packetId == OBJECT_CLICK5_PACKET) {
- if (player.isLocked())
- return;
- ObjectHandler.handleOption(player, stream, 5);
- }
- if (packetId == ITEM_TAKE_PACKET) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
- return;
- long currentTime = Utils.currentTimeMillis();
- if (player.getLockDelay() > currentTime)
- return;
- int y = stream.readUnsignedShort();
- int x = stream.readUnsignedShortLE();
- final int id = stream.readUnsignedShort();
- boolean forceRun = stream.read128Byte() == 1;
- final WorldTile tile = new WorldTile(x, y, player.getPlane());
- final int regionId = tile.getRegionId();
- if (!player.getMapRegionsIds().contains(regionId))
- return;
- final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
- if (item == null)
- return;
- player.stopAll(false);
- if (forceRun)
- player.setRun(forceRun);
- player.setRouteEvent(new RouteEvent(tile, ()));
- player.setCoordsEvent(new CoordsEvent(tile, () -> {
- @Override
- public void run() {
- if (item == null)
- return;
- if (player.getRights() == 2 && item.getOwner() != null)
- player.sgm("This item was dropped by: "
- + item.getOwner()
- + "; display name: "
- + item.getOwner());
- if (item.getOwner() != null) {
- if (!player.getUsername().equalsIgnoreCase(item.getOwner())
- && player.isIronMan()) {
- player.sgm("You cannot do this as an Iron Man!");
- return;
- }
- }
- player.setNextFaceWorldTile(tile);
- player.addWalkSteps(tile.getX(), tile.getY(), 1);
- World.removeGroundItem(player, item);
- }
- }));
- return;
- }
- if (packetId == GROUND_ITEM_INTERACT_PACKET) {
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
- return;
- long currentTime = Utils.currentTimeMillis();
- if (player.getLockDelay() > currentTime)
- return;
- int y = stream.readUnsignedShort();
- int x = stream.readUnsignedShortLE();
- final int id = stream.readUnsignedShort();
- boolean forceRun = stream.read128Byte() == 1;
- final WorldTile tile = new WorldTile(x, y, player.getPlane());
- final int regionId = tile.getRegionId();
- if (!player.getMapRegionsIds().contains(regionId))
- return;
- final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
- if (item == null)
- return;
- player.stopAll(false);
- if (forceRun)
- player.setRun(forceRun);
- player.setRouteEvent(new RouteEvent(tile, ()));
- player.setCoordsEvent(new CoordsEvent(tile, new Runnable() {
- @Override
- public void run() {
- if (item == null)
- return;
- if (item.getOwner() != null) {
- if (!player.getUsername().equalsIgnoreCase(item.getOwner()) && player.isIronMan()) {
- player.sgm("You cannot do this as an Iron Man!");
- return;
- }
- }
- player.setNextFaceWorldTile(tile);
- player.addWalkSteps(tile.getX(), tile.getY(), 1);
- if (Firemaking.isFiremaking(player, item.getId())) {
- World.removeGroundItem(player, item);
- return;
- }
- }
- }));
- System.out.println("Item id: "+item.getId()+".");
- return;
- }
- }
- @SuppressWarnings("unused")
- public void processPackets(final int packetId, InputStream stream, int length) {
- player.setPacketsDecoderPing(Utils.currentTimeMillis());
- if (packetId == PING_PACKET) {
- OutputStream packet = new OutputStream(0);
- packet.writePacket(player, 153);
- player.getSession().write(packet);
- }
- else if (packetId == MOVE_MOUSE_PACKET) {
- // USELESS PACKET
- }
- else if (packetId == LOGIN_PACKET) {
- // USELESS PACKET
- }
- else if (packetId == KEY_TYPED_PACKET) {
- // USELESS PACKET
- }
- else if (packetId == RECEIVE_PACKET_COUNT_PACKET) {
- stream.readInt();
- }
- else if (packetId == ITEM_ON_ITEM_PACKET) {
- player.increaseAFKTimer();
- InventoryOptionsHandler.handleItemOnItem(player, stream);
- } else if (packetId == MAGIC_ON_ITEM_PACKET) {
- player.increaseAFKTimer();
- int inventoryInter = stream.readInt() >> 16;
- int itemId = stream.readShort128();
- stream.readShort();
- stream.readShortLE();
- int interfaceSet = stream.readIntV1();
- int spellId = interfaceSet & 0xFFF;
- int magicInter = interfaceSet >> 16;
- } else if (packetId == CLOSE_INTERFACE_PACKET) {
- player.increaseAFKTimer();
- if (player.hasStarted() && !player.hasFinished() && !player.isRunning()) {
- player.run();
- player.getInterfaceManager().openGameTab(1);
- return;
- }
- player.stopAll();
- } else if (packetId == MOVE_CAMERA_PACKET) {
- player.increaseAFKTimer();
- stream.readUnsignedShort();
- stream.readUnsignedShort();
- } else if (packetId == SCREEN_PACKET) {
- int displayMode = stream.readUnsignedByte();
- player.setScreenWidth(stream.readUnsignedShort());
- player.setScreenHeight(stream.readUnsignedShort());
- if (!player.hasStarted() || player.hasFinished()
- || displayMode == player.getDisplayMode()
- || !player.getInterfaceManager().containsInterface(742))
- return;
- player.setDisplayMode(displayMode);
- player.getInterfaceManager().removeAll();
- player.getInterfaceManager().sendInterfaces();
- player.getInterfaceManager().sendInterface(742);
- } else if (packetId == CLICK_PACKET) {
- player.increaseAFKTimer();
- int mouseHash = stream.readShortLE128();
- int mouseButton = mouseHash >> 15;
- int time = mouseHash - (mouseButton << 15); // time
- int positionHash = stream.readIntV1();
- int y = positionHash >> 16; // y;
- int x = positionHash - (y << 16); // x
- if (time <= 1 || x < 0 || x > player.getScreenWidth() || y < 0
- || y > player.getScreenHeight()) {
- return;
- }
- } else if (packetId == DIALOGUE_CONTINUE_PACKET) {
- player.increaseAFKTimer();
- int junk = stream.readShortLE();
- int interfaceHash = stream.readIntV1();
- int interfaceId = interfaceHash >> 16;
- stream.readShort128();
- if (Utils.getInterfaceDefinitionsSize() <= interfaceId)
- return;
- int componentId = interfaceHash - (interfaceId << 16);
- player.getDialogueManager().continueDialogue(interfaceId,
- componentId);
- } else if (packetId == WORLD_MAP_CLICK) {
- player.increaseAFKTimer();
- int coordinateHash = stream.readInt();
- int x = coordinateHash >> 14;
- int y = coordinateHash & 0x3fff;
- int plane = coordinateHash >> 28;
- Integer hash = (Integer) player.getTemporaryAttributtes().get(
- "worldHash");
- if (hash == null || coordinateHash != hash)
- player.getTemporaryAttributtes().put("worldHash",
- coordinateHash);
- else {
- player.getTemporaryAttributtes().remove("worldHash");
- player.getHintIconsManager().addHintIcon(x, y, plane, 20, 0, 2,
- -1, true);
- player.getPackets().sendConfig(1159, coordinateHash);
- }
- } else if (packetId == ACTION_BUTTON1_PACKET
- || packetId == ACTION_BUTTON2_PACKET
- || packetId == ACTION_BUTTON4_PACKET
- || packetId == ACTION_BUTTON5_PACKET
- || packetId == ACTION_BUTTON6_PACKET
- || packetId == ACTION_BUTTON7_PACKET
- || packetId == ACTION_BUTTON8_PACKET
- || packetId == ACTION_BUTTON3_PACKET
- || packetId == ACTION_BUTTON9_PACKET
- || packetId == ACTION_BUTTON10_PACKET) {
- player.increaseAFKTimer();
- ButtonHandler.handleButtons(player, stream, packetId);
- } else if (packetId == GE_SEARCH_PACKET) {
- player.increaseAFKTimer();
- int itemId = stream.readUnsignedShort();
- player.getGEManager().chooseItem(itemId);
- } else if (packetId == ENTER_NAME_PACKET) {
- player.increaseAFKTimer();
- if (!player.isRunning() || player.isDead())
- return;
- String value = stream.readString();
- if (value.equals(""))
- return;
- if (player.getInterfaceManager().containsInterface(1108))
- player.getFriendsIgnores().setChatPrefix(value);
- else if (player.getTemporaryAttributtes().get("yellcolor") == Boolean.TRUE) {
- if (value.length() != 6) {
- player.getDialogueManager()
- .startDialogue("SimpleMessage",
- "The HEX yell color you wanted to pick can not be longer or shorter than 6.");
- return;
- }
- if (Utils.containsInvalidCharacter(value)
- || value.contains("_")) {
- player.getDialogueManager()
- .startDialogue("SimpleMessage",
- "The requested yell color can only contain numeric and regular characters.");
- return;
- } else {
- player.setYellColor(value);
- player.setVCredits(player.getVCredits() - 1);
- player.getDialogueManager().startDialogue(
- "SimpleMessage",
- "Your yell color has been changed to <col="
- + player.getYellColor() + ">"
- + player.getYellColor() + "</col>.");
- }
- player.getTemporaryAttributtes()
- .put("yellcolor", Boolean.FALSE);
- } else if (player.getTemporaryAttributtes().remove("setclan") != null)
- ClansManager.createClan(player, value);
- else if (player.getTemporaryAttributtes().remove("joinguestclan") != null)
- ClansManager.connectToClan(player, value, true);
- else if (player.getTemporaryAttributtes().remove("banclanplayer") != null)
- ClansManager.banPlayer(player, value);
- else if (player.getTemporaryAttributtes().remove("unbanclanplayer") != null)
- ClansManager.unbanPlayer(player, value);
- else if (player.getTemporaryAttributtes().get("view_name") == Boolean.TRUE) {
- player.getTemporaryAttributtes().remove("view_name");
- Player other = World.getPlayerByDisplayName(value);
- if (other == null) {
- player.getPackets()
- .sendGameMessage("Couldn't find player.");
- return;
- }
- ClanWars clan = other.getCurrentFriendChat() != null ? other
- .getCurrentFriendChat().getClanWars() : null;
- if (clan == null) {
- player.sgm("This player's clan is not in war.");
- return;
- }
- if (clan.getSecondTeam().getOwnerDisplayName() != other
- .getCurrentFriendChat().getOwnerDisplayName())
- player.getTemporaryAttributtes().put("view_prefix", 1);
- player.getTemporaryAttributtes().put("view_clan", clan);
- ClanWars.enter(player);
- } else if (player.getTemporaryAttributtes().remove("setdisplay") != null) {
- if (Utils.invalidAccountName(Utils
- .formatPlayerNameForProtocol(value))) {
- player.sgm("Invalid name!");
- return;
- }
- if (!DisplayNames.setDisplayName(player, value)) {
- player.sgm("Name already in use!");
- return;
- }
- player.getDialogueManager().startDialogue(
- "SimpleMessage",
- "Your display name has been changed to "
- + player.getDisplayName() + "!");
- }
- } else if (packetId == ENTER_STRING_PACKET) {
- player.increaseAFKTimer();
- if (!player.isRunning() || player.isDead())
- return;
- String value = stream.readString();
- if (value.equals(""))
- return;
- if (player.getTemporaryAttributtes().get("target_citadel") == Boolean.TRUE) {
- final Player target = World.getPlayerByDisplayName(value);
- player.getTemporaryAttributtes().remove("target_citadel");
- if (target == null)
- player.getDialogueManager()
- .startDialogue("SimpleMessage",
- "You can't join this players citadel, they are currently busy.");
- if (!target.isAtDynamicRegion()) {
- player.getDialogueManager()
- .startDialogue("SimpleMessage",
- "You can't join this players citadel, they aren't even there!");
- return;
- } else {
- ClanCitadel.joinCitadel(player, target);
- player.getTemporaryAttributtes().put("JoinCitadel",
- Boolean.FALSE);
- }
- }
- } else if (packetId == ENTER_LONG_TEXT_PACKET) {
- player.increaseAFKTimer();
- if (!player.isRunning() || player.isDead())
- return;
- String value = stream.readString();
- if (value.equals(""))
- return;
- if (player.getTemporaryAttributtes().remove("entering_note") == Boolean.TRUE) {
- player.getNotes().add(value);
- return;
- }
- if (player.getTemporaryAttributtes().remove("editing_note") == Boolean.TRUE) {
- player.getNotes().edit(value);
- return;
- }
- if (player.getTemporaryAttributtes().remove("referral") == Boolean.TRUE) {
- StarterMap.getSingleton().enterInformation(player, value);
- return;
- }
- if (player.getInterfaceManager().containsInterface(1103)) {
- ClansManager.setClanMottoInterface(player, value);
- return;
- }
- } else if (packetId == ENTER_INTEGER_PACKET) {
- player.increaseAFKTimer();
- if (!player.isRunning() || player.isDead())
- return;
- int value = stream.readInt();
- stream.readInt();
- if ((player.getInterfaceManager().containsInterface(762) && player
- .getInterfaceManager().containsInterface(763))
- || player.getInterfaceManager().containsInterface(11)) {
- if (value < 0)
- return;
- Integer bank_item_X_Slot = (Integer) player
- .getTemporaryAttributtes().remove("bank_item_X_Slot");
- if (bank_item_X_Slot == null)
- return;
- player.getBank().setLastX(value);
- player.getBank().refreshLastX();
- if (player.getTemporaryAttributtes().remove("bank_isWithdraw") != null)
- player.getBank().withdrawItem(bank_item_X_Slot, value);
- else
- player.getBank()
- .depositItem(
- bank_item_X_Slot,
- value,
- player.getInterfaceManager()
- .containsInterface(11) ? false
- : true);
- } else if (player.getInterfaceManager().containsInterface(206)
- && player.getInterfaceManager().containsInterface(207)) {
- if (value < 0)
- return;
- Integer pc_item_X_Slot = (Integer) player
- .getTemporaryAttributtes().remove("pc_item_X_Slot");
- if (pc_item_X_Slot == null)
- return;
- if (player.getTemporaryAttributtes().remove("pc_isRemove") != null)
- player.getPriceCheckManager().removeItem(pc_item_X_Slot,
- value);
- else
- player.getPriceCheckManager()
- .addItem(pc_item_X_Slot, value);
- } else if (player.getInterfaceManager().containsInterface(671)
- && player.getInterfaceManager().containsInterface(665)) {
- if (player.getFamiliar() == null
- || player.getFamiliar().getBob() == null)
- return;
- if (value < 0)
- return;
- Integer bob_item_X_Slot = (Integer) player
- .getTemporaryAttributtes().remove("bob_item_X_Slot");
- if (bob_item_X_Slot == null)
- return;
- if (player.getTemporaryAttributtes().remove("bob_isRemove") != null)
- player.getFamiliar().getBob()
- .removeItem(bob_item_X_Slot, value);
- else
- player.getFamiliar().getBob()
- .addItem(bob_item_X_Slot, value);
- } else if (player.getInterfaceManager().containsInterface(335)
- && player.getInterfaceManager().containsInterface(336)) {
- if (player.getTemporaryAttributtes().remove("trade_money") != null) {
- Integer trade_X_money = (Integer) player
- .getTemporaryAttributtes().remove("trade_X_money");
- if (value <= 0 || trade_X_money == null
- || player.getMoneyPouch().getTotal() == 0)
- return;
- if (value >= player.getMoneyPouch().getTotal())
- value = player.getMoneyPouch().getTotal();
- player.getTrade().addPouch(trade_X_money, value);
- }
- if (value < 0)
- return;
- Integer trade_item_X_Slot = (Integer) player.getTemporaryAttributtes().remove("trade_item_X_Slot");
- if (trade_item_X_Slot == null)
- return;
- if (player.getTemporaryAttributtes().remove("trade_isRemove") != null)
- player.getTrade().removeItem(trade_item_X_Slot, value);
- else
- player.getTrade().addItem(trade_item_X_Slot, value);
- }
- if (player.getTemporaryAttributtes().get("well_donate") != null) {
- if (value < 0) {
- player.getTemporaryAttributtes().remove("well_donate");
- return;
- }
- if (player.getTemporaryAttributtes().get("well_donate") == Boolean.TRUE) {
- player.getTemporaryAttributtes().put("well_donate", Boolean.FALSE);
- FortuneWell.handleBoost(player, value);
- player.getTemporaryAttributtes().remove("well_donate");
- }
- return;
- }
- if (player.getTemporaryAttributtes().get("xpSkillTarget") != null) {
- int xpTarget = value;
- Integer skillId = (Integer) player.getTemporaryAttributtes().remove("xpSkillTarget");
- if (xpTarget < player.getSkills().getXp(player.getSkills().getSkillIdByTargetId(skillId))
- || player.getSkills().getXp(player.getSkills().getSkillIdByTargetId(skillId)) >= 500000000) {
- return;
- }
- if (xpTarget > 500000000) {
- xpTarget = 500000000;
- }
- player.getSkills().setSkillTarget(false, skillId, xpTarget);
- return;
- }
- if (player.getTemporaryAttributtes().get("levelSkillTarget") != null) {
- int levelTarget = value;
- Integer skillId = (Integer) player.getTemporaryAttributtes().remove("levelSkillTarget");
- int curLevel = player.getSkills().getLevel(player.getSkills().getSkillIdByTargetId(skillId));
- if (curLevel >= (skillId == 24 ? 120 : 99)) {
- return;
- }
- if (levelTarget > (skillId == 24 ? 120 : 99)) {
- levelTarget = skillId == 24 ? 120 : 99;
- }
- if (levelTarget < player.getSkills().getLevel(player.getSkills().getSkillIdByTargetId(skillId))) {
- return;
- }
- player.getSkills().setSkillTarget(true, skillId, levelTarget);
- return;
- }
- if (player.getTemporaryAttributtes().get("money_vault_put") != null) {
- if (value < 0) {
- player.getTemporaryAttributtes().remove("money_vault_put");
- return;
- }
- if (player.getTemporaryAttributtes().get("money_vault_put") == Boolean.TRUE) {
- player.getTemporaryAttributtes().put("money_vault_put", Boolean.FALSE);
- Banker.handleVaultPut(player, value);
- player.getTemporaryAttributtes().remove("money_vault_put");
- }
- return;
- }
- if (player.getTemporaryAttributtes().get("money_vault_take") != null) {
- if (value < 0) {
- player.getTemporaryAttributtes().remove("money_vault_take");
- return;
- }
- if (player.getTemporaryAttributtes().get("money_vault_take") == Boolean.TRUE) {
- player.getTemporaryAttributtes().put("money_vault_take", Boolean.FALSE);
- Banker.handleVaultTake(player, value);
- player.getTemporaryAttributtes().remove("money_vault_take");
- }
- return;
- }
- if (player.getTemporaryAttributtes().get("edit_price") != null) {
- if (value < 0) {
- player.getTemporaryAttributtes().remove("edit_price");
- return;
- }
- if (player.getTemporaryAttributtes().get("edit_price") == Boolean.TRUE) {
- player.getTemporaryAttributtes().put("edit_price", Boolean.FALSE);
- player.getGeManager().modifyPricePerItem(value);
- player.getTemporaryAttributtes().remove("edit_price");
- }
- return;
- }
- if (player.getTemporaryAttributtes().get("edit_quantity") != null) {
- if (value < 0) {
- player.getTemporaryAttributtes().remove("edit_quantity");
- return;
- }
- if (player.getTemporaryAttributtes().get("edit_quantity") == Boolean.TRUE) {
- player.getTemporaryAttributtes().put("edit_quantity", Boolean.FALSE);
- player.getGeManager().modifyAmount(value);
- player.getTemporaryAttributtes().remove("edit_quantity");
- }
- return;
- }
- if (player.getTemporaryAttributtes().get("money_pouch_remove") == Boolean.TRUE) {
- player.getMoneyPouch().withdrawPouch(value);
- player.getTemporaryAttributtes().put("money_pouch_remove", Boolean.FALSE);
- player.getTemporaryAttributtes().remove("money_pouch_remove");
- return;
- }
- } else if (packetId == SWITCH_INTERFACE_ITEM_PACKET) {
- player.increaseAFKTimer();
- stream.readShortLE128();
- int fromInterfaceHash = stream.readIntV1();
- int toInterfaceHash = stream.readInt();
- int fromSlot = stream.readUnsignedShort();
- int toSlot = stream.readUnsignedShortLE128();
- stream.readUnsignedShortLE();
- int toInterfaceId = toInterfaceHash >> 16;
- int toComponentId = toInterfaceHash - (toInterfaceId << 16);
- int fromInterfaceId = fromInterfaceHash >> 16;
- int fromComponentId = fromInterfaceHash - (fromInterfaceId << 16);
- if (fromInterfaceId == 1265
- && toInterfaceId == 1266
- && player.getTemporaryAttributtes().get("shop_buying") != null) {
- if ((boolean) player.getTemporaryAttributtes().get(
- "shop_buying") == true) {
- Shop shop = (Shop) player.getTemporaryAttributtes().get(
- "Shop");
- if (shop == null)
- return;
- shop.buy(player, fromSlot, 1);
- }
- }
- if (Utils.getInterfaceDefinitionsSize() <= fromInterfaceId
- || Utils.getInterfaceDefinitionsSize() <= toInterfaceId)
- return;
- if (!player.getInterfaceManager()
- .containsInterface(fromInterfaceId)
- || !player.getInterfaceManager().containsInterface(
- toInterfaceId))
- return;
- if (fromComponentId != -1
- && Utils.getInterfaceDefinitionsComponentsSize(fromInterfaceId) <= fromComponentId)
- return;
- if (toComponentId != -1
- && Utils.getInterfaceDefinitionsComponentsSize(toInterfaceId) <= toComponentId)
- return;
- if (fromInterfaceId == Inventory.INVENTORY_INTERFACE
- && fromComponentId == 0
- && toInterfaceId == Inventory.INVENTORY_INTERFACE
- && toComponentId == 0) {
- toSlot -= 28;
- if (toSlot < 0
- || toSlot >= player.getInventory()
- .getItemsContainerSize()
- || fromSlot >= player.getInventory()
- .getItemsContainerSize())
- return;
- player.getInventory().switchItem(fromSlot, toSlot);
- } else if (fromInterfaceId == 763 && fromComponentId == 0
- && toInterfaceId == 763 && toComponentId == 0) {
- if (toSlot >= player.getInventory().getItemsContainerSize()
- || fromSlot >= player.getInventory()
- .getItemsContainerSize())
- return;
- player.getInventory().switchItem(fromSlot, toSlot);
- } else if (fromInterfaceId == 762 && toInterfaceId == 762) {
- player.getBank().switchItem(fromSlot, toSlot, fromComponentId,
- toComponentId);
- } else if (fromInterfaceId == 34 && toInterfaceId == 34)
- player.getNotes().switchNotes(fromSlot, toSlot);
- }
- else if (packetId == WALKING_PACKET
- || packetId == MINI_WALKING_PACKET
- || packetId == ITEM_TAKE_PACKET
- || packetId == PLAYER_OPTION_2_PACKET
- || packetId == PLAYER_OPTION_4_PACKET
- || packetId == PLAYER_OPTION_6_PACKET
- || packetId == PLAYER_OPTION_1_PACKET
- || packetId == PLAYER_OPTION_5_PACKET
- || packetId == ATTACK_NPC
- || packetId == INTERFACE_ON_PLAYER
- || packetId == INTERFACE_ON_NPC
- || packetId == NPC_CLICK1_PACKET
- || packetId == NPC_CLICK2_PACKET
- || packetId == NPC_CLICK3_PACKET
- || packetId == NPC_CLICK4_PACKET
- || packetId == OBJECT_CLICK1_PACKET
- || packetId == SWITCH_INTERFACE_ITEM_PACKET
- || packetId == OBJECT_CLICK2_PACKET
- || packetId == OBJECT_CLICK3_PACKET
- || packetId == OBJECT_CLICK4_PACKET
- || packetId == OBJECT_CLICK5_PACKET
- || packetId == INTERFACE_ON_OBJECT) {
- player.addLogicPacketToQueue(new LogicPacket(packetId, length, stream));
- player.increaseAFKTimer();
- }
- if (packetId == OBJECT_EXAMINE_PACKET) {
- player.increaseAFKTimer();
- ObjectHandler.handleOption(player, stream, -1);
- return;
- }
- if (packetId == GROUND_ITEM_EXAMINE_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted() || !player.clientHasLoadedMapRegion() || player.isDead())
- return;
- int y = stream.readUnsignedShort();
- int x = stream.readUnsignedShortLE();
- final int id = stream.readUnsignedShort();
- final WorldTile tile = new WorldTile(x, y, player.getPlane());
- final int regionId = tile.getRegionId();
- if (!player.getMapRegionsIds().contains(regionId))
- return;
- final FloorItem item = World.getRegion(regionId).getGroundItem(id, tile, player);
- if (item == null)
- return;
- player.sgm(ItemExamines.getExamine(item));
- return;
- }
- if (packetId == NPC_EXAMINE_PACKET) {
- player.increaseAFKTimer();
- NPCHandler.handleExamine(player, stream);
- return;
- }
- if (packetId == JOIN_FRIEND_CHAT_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- FriendChatsManager.joinChat(stream.readString(), player);
- return;
- }
- if (packetId == KICK_FRIEND_CHAT_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- player.setLastPublicMessage(Utils.currentTimeMillis() + 800);
- player.kickPlayerFromFriendsChannel(stream.readString());
- }
- if (packetId == CHANGE_FRIEND_CHAT_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted()
- || !player.getInterfaceManager().containsInterface(1108))
- return;
- player.getFriendsIgnores().changeRank(stream.readString(),
- stream.readUnsignedByte128());
- }
- if (packetId == ADD_FRIEND_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- player.getFriendsIgnores().addFriend(stream.readString());
- }
- if (packetId == REMOVE_FRIEND_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- player.getFriendsIgnores().removeFriend(stream.readString());
- }
- if (packetId == ADD_IGNORE_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- player.getFriendsIgnores().addIgnore(stream.readString(),
- stream.readUnsignedByte() == 1);
- }
- if (packetId == UNID_PACKET) {
- //System.err.println("Unidentified packet: "+packetId+".");
- return;
- }
- if (packetId == REMOVE_IGNORE_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- player.getFriendsIgnores().removeIgnore(stream.readString());
- return;
- }
- if (packetId == SEND_FRIEND_MESSAGE_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- if (player.getMuted() > Utils.currentTimeMillis()) {
- player.sgm("You're currently muted. Please re-check in however long you were muted for!");
- return;
- }
- String username = stream.readString();
- Player p2 = World.getPlayerByDisplayName(username);
- String message1 = Huffman.readEncryptedMessage(150, stream);
- if (player.getPassword() != null) {
- if (message1.contains(player.getPassword())) {
- player.getPackets().sendGameMessage("Don't give out your password to anyone.");
- return;
- }
- }
- if (message1 == null || message1.replaceAll(" ", "").equals(""))
- return;
- if (message1.startsWith("::") || message1.startsWith(";;")) {
- Commands.processCommand(player, message1.replace("::", "")
- .replace(";;", ""), false, false);
- return;
- }
- if (message1.contains("hdr"))
- return;
- if (p2 == null) {
- player.sgm("Could not find "+p2+".");
- return;
- }
- player.getFriendsIgnores().sendMessage(p2, Utils.fixChatMessage(player.filter(message1)));
- } else if (packetId == SEND_FRIEND_QUICK_CHAT_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- String username = stream.readString();
- int fileId = stream.readUnsignedShort();
- if (fileId > 1163)
- return;
- byte[] data = null;
- if (length > 3 + username.length()) {
- data = new byte[length - (3 + username.length())];
- stream.readBytes(data);
- }
- data = Utils.completeQuickMessage(player, fileId, data);
- Player p2 = World.getPlayerByDisplayName(username);
- if (p2 == null)
- return;
- } else if (packetId == PUBLIC_QUICK_CHAT_PACKET) {
- player.increaseAFKTimer();
- if (!player.hasStarted())
- return;
- if (player.getLastPublicMessage() > Utils.currentTimeMillis())
- return;
- player.setLastPublicMessage(Utils.currentTimeMillis() + 300);
- boolean secondClientScript = stream.readByte() == 1;
- int fileId = stream.readUnsignedShort();
- if (fileId > 1163)
- return;
- byte[] data = null;
- if (length > 3) {
- data = new byte[length - 3];
- stream.readBytes(data);
- }
- } else if (packetId == CHAT_TYPE_PACKET) {
- chatType = stream.readUnsignedByte();
- } else if (packetId == CHAT_PACKET) {
- if (!player.hasStarted())
- return;
- if (player.getLastPublicMessage() > Utils.currentTimeMillis())
- return;
- player.setLastPublicMessage(Utils.currentTimeMillis() + 300);
- int colorEffect = stream.readUnsignedByte();
- int moveEffect = stream.readUnsignedByte();
- String message = Huffman.readEncryptedMessage(200, stream);
- if (message == null || message.replaceAll(" ", "").equals(""))
- return;
- if (message.length() >= 81)
- return;
- if (message.startsWith("::") || message.startsWith(";;")) {
- Commands.processCommand(player, message.replace("::", "").replace(";;", ""), false, false);
- return;
- }
- if (player.getMuted() > Utils.currentTimeMillis()) {
- player.sgm("You are temporary muted due to breaking a rule!");
- return;
- }
- if (message.startsWith("hdr"))
- return;
- int effects = (colorEffect << 8) | (moveEffect & 0xff) & ~0x8000;
- if (chatType == 1) {
- player.sendFriendsChannelMessage(Utils.fixChatMessage(player.filter(message)));
- } else if (chatType == 2) {
- player.sendClanChannelMessage(new ChatMessage(Utils.fixChatMessage(player.filter(message))));
- } else if (chatType == 3) {
- player.sendGuestClanChannelMessage(new ChatMessage(Utils.fixChatMessage(player.filter(message))));
- } else {
- player.sendPublicChatMessage(new PublicChatMessage(Utils.fixChatMessage(player.filter(message)), effects));
- }
- player.setLastMsg(message);
- } else if (packetId == COMMANDS_PACKET) {
- if (!player.isRunning())
- return;
- boolean clientCommand = stream.readUnsignedByte() == 1;
- boolean unknown = stream.readUnsignedByte() == 1;
- String command = stream.readString();
- if (!Commands.processCommand(player, command, true, clientCommand))
- System.out.println("Command: " + command);
- } else if (packetId == CLAN_INVITATION_PACKET) {
- boolean unknown = stream.readByte() == 1;
- int playerIndex = stream.readUnsignedShortLE128();
- Player p2 = World.getPlayers().get(playerIndex);
- if (p2 == null || p2.isDead() || p2.hasFinished()
- || !player.getMapRegionsIds().contains(p2.getRegionId()))
- return;
- if (player.getLockDelay() > Utils.currentTimeMillis())
- return;
- if (!p2.withinDistance(player, 14)) {
- player.sgm("Unable to find player: " + p2.getDisplayName()+".");
- return;
- }
- player.stopAll(false);
- ClansManager.viewInvite(player, p2);
- } else if (packetId == COLOR_ID_PACKET) {
- if (!player.hasStarted())
- return;
- int colorId = stream.readUnsignedShort();
- if (player.getTemporaryAttributtes().get("SkillcapeCustomize") != null)
- SkillCapeCustomizer.handleSkillCapeCustomizerColor(player, colorId);
- else if (player.getTemporaryAttributtes().get("MotifCustomization") != null)
- ClansManager.setMottifColor(player, colorId);
- } /**else {
- Logger.log(this, "Missing a packet, ID: " + packetId + ".");
- }*/
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement