/**
  * Appends an animation update.
  *
  * @param block The update block.
  * @param otherPlayer The player.
  */
 private void appendAnimationUpdate(PacketBuilder block, Player otherPlayer) {
   // TODO: CHEAP FIX!! Caused errors if you attacked someone and clicked away
   Animation anim =
       otherPlayer.getCurrentAnimation() != null
           ? otherPlayer.getCurrentAnimation()
           : Animation.create(-1, 0);
   block.putShort(anim.getId());
   block.putByteS((byte) anim.getDelay());
 }
 /**
  * Appends a chat text update.
  *
  * @param block The packet.
  * @param otherPlayer The player.
  */
 private void appendChatUpdate(PacketBuilder block, Player otherPlayer) {
   final ChatMessage chatMessage = otherPlayer.getCurrentChatMessage();
   block.putShortA(chatMessage.getEffects());
   block.putByteC(otherPlayer.getRights().toInteger());
   byte[] chatStr = new byte[256];
   chatStr[0] = (byte) chatMessage.getText().length();
   int offset =
       2
           + ChatUtils.encryptPlayerChat(
               chatStr, 0, 1, chatMessage.getText().length(), chatMessage.getText().getBytes());
   block.putByteC(offset);
   block.put(chatStr, 0, offset);
 }
  @Override
  public void handle(Player player, Packet packet) {
    final int id = packet.getShort() & 0xFFFF;
    final int slot = packet.getShortA() & 0xFFFF;
    final int interfaceId = packet.getShortA() & 0xFFFF;

    switch (interfaceId) {
      case Inventory.INTERFACE:
        if (slot >= 0 && slot < Inventory.SIZE) {
          final Item item = player.getInventory().get(slot);
          if (item != null && item.getId() == id) {
            final EquipmentType type = Equipment.getType(item);
            Item oldEquip = null;
            final boolean stackable = false;
            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;
    }
  }
Example #4
0
 @Override
 public void execute() {
   Iterator<Player> it = WarriorsGuild.IN_GAME.iterator();
   while (it.hasNext()) {
     Player p = it.next();
     p.getInventory().remove(REMOVE);
     p.getActionSender().sendMessage("Ten of your tokens crumble away.");
     Item item = p.getInventory().getById(WarriorsGuild.TOKENS);
     if (item == null || item.getCount() < 10) {
       p.getWarriorsGuild().outOfTokens(); // Registers a 25 seconds
       // event.. ;)
     }
   }
 }
 /**
  * Adds a new player.
  *
  * @param packet The packet.
  * @param otherPlayer The player.
  */
 public void addNewPlayer(PacketBuilder packet, Player otherPlayer) {
   packet.putBits(11, otherPlayer.getIndex());
   int yPos = otherPlayer.getLocation().getY() - player.getLocation().getY();
   int xPos = otherPlayer.getLocation().getX() - player.getLocation().getX();
   if (xPos < 0) {
     xPos += 32;
   }
   if (yPos < 0) {
     yPos += 32;
   }
   packet.putBits(5, xPos);
   packet.putBits(1, 1);
   packet.putBits(3, 1);
   packet.putBits(1, 1);
   packet.putBits(5, yPos);
 }
 @Override
 public void execute(GameEngine context) {
   final Queue<ChatMessage> messages = player.getChatMessageQueue();
   if (messages.size() > 0) {
     player.getUpdateFlags().flag(UpdateFlag.CHAT);
     final ChatMessage message = player.getChatMessageQueue().poll();
     player.setCurrentChatMessage(message);
   } else {
     player.setCurrentChatMessage(null);
   }
   player.getWalkingQueue().processNextMovement();
 }
 /**
  * Updates a non-this player's movement.
  *
  * @param packet The packet.
  * @param otherPlayer The player.
  */
 public void updatePlayerMovement(PacketBuilder packet, Player otherPlayer) {
   if (otherPlayer.getSprites().getPrimarySprite() == -1) {
     if (otherPlayer.getUpdateFlags().isUpdateRequired()) {
       packet.putBits(1, 1);
       packet.putBits(2, 0);
     } else {
       packet.putBits(1, 0);
     }
   } else if (otherPlayer.getSprites().getSecondarySprite() == -1) {
     packet.putBits(1, 1);
     packet.putBits(2, 1);
     packet.putBits(3, otherPlayer.getSprites().getPrimarySprite());
     packet.putBits(1, otherPlayer.getUpdateFlags().isUpdateRequired() ? 1 : 0);
   } else {
     packet.putBits(1, 1);
     packet.putBits(2, 2);
     packet.putBits(3, otherPlayer.getSprites().getPrimarySprite());
     packet.putBits(3, otherPlayer.getSprites().getSecondarySprite());
     packet.putBits(1, otherPlayer.getUpdateFlags().isUpdateRequired() ? 1 : 0);
   }
 }
  /**
   * 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
    if ((app.getGender() & 0x2) == 2) {
      playerProps.put((byte) 0);
      playerProps.put((byte) 0);
    }
    playerProps.put((byte) -1); // skull icon
    playerProps.put((byte) -1); // prayer icon

    if (!otherPlayer.getAppearance().isNpc()) {
      for (int i = 0; i < 4; i++) {
        if (eq.isSlotUsed(i)) {
          playerProps.putShort((short) 32768 + eq.get(i).getDefinition().getEquipId());
        } else {
          playerProps.put((byte) 0);
        }
      }
      if (eq.isSlotUsed(Equipment.SLOT_CHEST)) {
        playerProps.putShort(
            (short) 32768 + eq.get(Equipment.SLOT_CHEST).getDefinition().getEquipId());
      } else {
        playerProps.putShort((short) 0x100 + app.getChest()); // chest
      }
      if (eq.isSlotUsed(Equipment.SLOT_SHIELD)) {
        playerProps.putShort(
            (short) 32768 + eq.get(Equipment.SLOT_SHIELD).getDefinition().getEquipId());
      } else {
        playerProps.put((byte) 0);
      }
      final 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) 32768 + chest.getDefinition().getEquipId());
        }
      } else {
        playerProps.putShort((short) 0x100 + app.getArms());
      }
      if (eq.isSlotUsed(Equipment.SLOT_BOTTOMS)) {
        playerProps.putShort(
            (short) 32768 + eq.get(Equipment.SLOT_BOTTOMS).getDefinition().getEquipId());
      } else {
        playerProps.putShort((short) 0x100 + app.getLegs());
      }
      final 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) 32768 + eq.get(Equipment.SLOT_GLOVES).getDefinition().getEquipId());
      } else {
        playerProps.putShort((short) 0x100 + app.getHands());
      }
      if (eq.isSlotUsed(Equipment.SLOT_BOOTS)) {
        playerProps.putShort(
            (short) 32768 + eq.get(Equipment.SLOT_BOOTS).getDefinition().getEquipId());
      } 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());
      }
    } else {
      playerProps.putShort(-1);
      playerProps.putShort(otherPlayer.getAppearance().getNpcIndex());
    }

    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.standAnimation(weapon)); // stand
    playerProps.putShort((short) 0x337); // stand turn
    playerProps.putShort((short) Equipment.walkAnimation(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.runAnimation(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();
    packet.put((byte) (propsPacket.getLength() & 0xff));
    packet.putBytes(propsPacket.getPayload(), 0, propsPacket.getLength());
  }
 /**
  * Appends a graphics update.
  *
  * @param block The update block.
  * @param otherPlayer The player.
  */
 private void appendGraphicsUpdate(PacketBuilder block, Player otherPlayer) {
   block.putShort(otherPlayer.getCurrentGraphic().getId());
   block.putInt1(otherPlayer.getCurrentGraphic().getDelay());
 }
Example #10
0
 private static void appendFaceCoordinateUpdate(final Player p, final PacketBuilder updateBlock) {
   updateBlock.putLEShort(p.getLocation().getX()).putShortA(p.getLocation().getY());
 }
Example #11
0
 private static void appendHit2Update(final Player p, final PacketBuilder updateBlock) {
   updateBlock.putByteS((byte) p.getDamage().getHitDamage2());
   updateBlock.putByteA(p.getDamage().getHitType2());
 }
Example #12
0
  @Override
  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.
     */
    final 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.
     */
    final PacketBuilder updatePacket = new PacketBuilder(216, Packet.Type.VARIABLE_SHORT);
    updatePacket.startBitAccess();

    /*
     * Updates this player.
     */
    updateThisPlayerMovement(updatePacket);
    updatePlayer(updateBlock, player, false);

    /*
     * Write the current size of the player list.
     */
    updatePacket.putBits(8, player.getLocalPlayers().size());

    /*
     * Iterate through the local player list.
     */
    for (final Iterator<Player> it$ = player.getLocalPlayers().iterator(); it$.hasNext(); ) {
      /*
       * Get the next player.
       */
      final 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(), 16)) {

        /*
         * Update the movement.
         */
        updatePlayerMovement(updatePacket, otherPlayer);

        /*
         * Check if an update is required, and if so, send the update.
         */
        if (otherPlayer.getUpdateFlags().isUpdateRequired()) {
          updatePlayer(updateBlock, otherPlayer, false);
        }
      } else {
        /*
         * Otherwise, remove the player from the list.
         */
        it$.remove();

        /*
         * Tell the client to remove the player from the list.
         */
        updatePacket.putBits(1, 1);
        updatePacket.putBits(2, 3);
      }
    }
    /*
     * Loop through every player.
     */
    for (final 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(updatePacket, otherPlayer);
      /*
       * Update the player, forcing the appearance flag.
       */
      updatePlayer(updateBlock, otherPlayer, true);
    }

    /*
     * Check if the update block is not empty.
     */
    if (!updateBlock.isEmpty()) {
      /*
       * Write a magic id indicating an update block follows.
       */
      updatePacket.putBits(11, 2047);
      updatePacket.finishBitAccess();
      /*
       * Add the update block at the end of this packet.
       */
      updatePacket.put(updateBlock.toPacket().getPayload());
    } else {
      /*
       * Terminate the packet normally.
       */
      updatePacket.finishBitAccess();
    }
    /*
     * Write the packet.
     */
    player.write(updatePacket.toPacket());
  }
Example #13
0
  /**
   * Updates a player.
   *
   * @param packet The packet.
   * @param otherPlayer The other player.
   * @param forceAppearance The force appearance flag.
   */
  public void updatePlayer(PacketBuilder packet, Player otherPlayer, boolean forceAppearance) {
    /*
     * 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) {
      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 = 0x0;
      final UpdateFlags flags = otherPlayer.getUpdateFlags();
      if (flags.get(UpdateFlag.FACE_ENTITY)) {
        mask |= 0x20;
      }
      if (flags.get(UpdateFlag.GRAPHICS)) {
        mask |= 0x400;
      }
      if (flags.get(UpdateFlag.CHAT)) {
        mask |= 0x8;
      }
      if (flags.get(UpdateFlag.ANIMATION)) {
        mask |= 0x1;
      }
      if (flags.get(UpdateFlag.APPEARANCE) || forceAppearance) {
        mask |= 0x80;
      }
      if (flags.get(UpdateFlag.HIT)) {
        mask |= 0x2;
      }
      if (flags.get(UpdateFlag.HIT_2)) {
        mask |= 0x200;
      } /*
        if (flags.get(UpdateFlag.FACE_COORDINATE)) {
            mask |= 0x40;
        }*/

      /*
       * Check if the bitmask would overflow a byte.
       */
      if (mask >= 0x100) {
        /*
         * Write it as a short and indicate we have done so.
         */
        mask |= 0x10;
        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.FACE_ENTITY)) {
        Entity entity = otherPlayer.getInteractingEntity();
        block.putShort(entity == null ? -1 : entity.getClientIndex());
      }
      if (flags.get(UpdateFlag.GRAPHICS)) {
        appendGraphicsUpdate(block, otherPlayer);
      }
      if (flags.get(UpdateFlag.CHAT)) {
        appendChatUpdate(block, otherPlayer);
      }
      if (flags.get(UpdateFlag.ANIMATION)) {
        appendAnimationUpdate(block, otherPlayer);
      }
      if (flags.get(UpdateFlag.APPEARANCE) || forceAppearance) {
        appendPlayerAppearanceUpdate(block, otherPlayer);
      }
      if (flags.get(UpdateFlag.HIT)) {
        appendHitUpdate(otherPlayer, block);
      }
      if (flags.get(UpdateFlag.HIT_2)) {
        appendHit2Update(otherPlayer, block);
      } /*
        if (flags.get(UpdateFlag.FACE_COORDINATE)) {
            appendFaceCoordinateUpdate(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) {
        otherPlayer.setCachedUpdateBlock(blockPacket);
      }

      /*
       * And finally append the block at the end.
       */
      packet.put(blockPacket.getPayload());
    }
  }
Example #14
0
 /**
  * Updates this player's movement.
  *
  * @param packet The packet.
  */
 private void updateThisPlayerMovement(final PacketBuilder packet) {
   if (player.isTeleporting() || player.isMapRegionChanging()) {
     packet.putBits(1, 1);
     packet.putBits(2, 3);
     packet.putBits(7, player.getLocation().getLocalX(player.getLastKnownRegion()));
     packet.putBits(1, 1);
     packet.putBits(2, player.getLocation().getZ());
     packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
     packet.putBits(7, player.getLocation().getLocalY(player.getLastKnownRegion()));
   } else {
     if (player.getSprites().getPrimarySprite() == -1) {
       packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
       if (player.getUpdateFlags().isUpdateRequired()) {
         packet.putBits(2, 0);
       }
     } else {
       if (player.getSprites().getSecondarySprite() != -1) {
         packet.putBits(1, 1);
         packet.putBits(2, 2);
         packet.putBits(3, player.getSprites().getPrimarySprite());
         packet.putBits(3, player.getSprites().getSecondarySprite());
         packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
       } else {
         packet.putBits(1, 1);
         packet.putBits(2, 1);
         packet.putBits(3, player.getSprites().getPrimarySprite());
         packet.putBits(1, player.getUpdateFlags().isUpdateRequired() ? 1 : 0);
       }
     }
   }
 }
  @Override
  public void handle(Player player, Packet packet) {
    int button = packet.getShort();
    int interfaceId = packet.getShort();
    packet.getLEShortA();
    if (interfaceId != player.getInterfaceState().getCurrentInterface()) {
      player.getActionSender().sendCloseInterface();
      System.out.println("AMFG HACKERS.");
      return;
    }
    DialogueLoader dl = player.getCurrentDialogueLoader();
    switch (interfaceId) {
        /** DialougeLoader. */
      case 64:
      case 65:
      case 66:
      case 67:
      case 241:
      case 242:
      case 243:
      case 244:
        if (dl == null || player.getNextDialogueIds() == null) {
          /*
           * If the next dialogue ID's are null, we've most likely set
           * them null.
           */
          /*
           * We close all interfaces.
           */
          player.getActionSender().sendCloseInterface();
          /*
           * Check if the Monk of Entrana just searched us.
           */
          Object entranaTraveling = player.getTemporaryAttribute("EntranaShipTraveling");
          if (entranaTraveling != null) {
            if ((Boolean) entranaTraveling) {
              ShipTraveling.travel(player, ShipLocation.PORT_SARIM, ShipLocation.ENTRANA);
            }
            player.removeTemporaryAttribute("EntranaShipTraveling");
          }
          break;
        }
        int nextDialogueId = player.getNextDialogueIds()[0];
        DialogueLoader.getNextDialogue(player, dl, nextDialogueId);
        break;
        /** Options. */
      case 228: // Two options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Yes.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // NO.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
        }
        break;
      case 230: // Three options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Option 1.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // Option 2.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
          case 3: // Option 3.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[2]);
            return;
        }
        break;
      case 232: // Four options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Option 1.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // Option 2.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
          case 3: // Option 3.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[2]);
            return;
          case 4: // Option 4.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[3]);
            return;
        }
        break;
      case 234: // Five options interface.
        if (dl == null) {
          player.getActionSender().sendCloseInterface();
          break;
        }
        switch (button) {
          case 1: // Option 1.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[0]);
            return;
          case 2: // Option 2.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[1]);
            return;
          case 3: // Option 3.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[2]);
            return;
          case 4: // Option 4.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[3]);
            return;
          case 5: // Option 5.
            DialogueLoader.getNextDialogue(player, dl, player.getNextDialogueIds()[4]);
            return;
        }
        break;
        /*
         * Interface with one line of info.
         */
      case 101:
        Object entranaTraveling1 = player.getTemporaryAttribute("EntranaShipTraveling");
        if (entranaTraveling1 != null) {
          boolean canTravel = (Boolean) entranaTraveling1;
          if (canTravel) {
            String[] lines = {"All is satisfactory. You may board the boat now."};
            DialogueLoader.dialogue(
                player,
                player.getInteractingEntity() == null
                    ? new NPC(NPCDefinition.forId(657))
                    : player.getInteractingEntity(),
                Emotes.DEFAULT,
                lines);
            player.setNextDialogueIds(null);
          } else {
            String[] lines = {
              "Grr! I see you brought some illegal items! Get", "out of my sight immediately!"
            };
            DialogueLoader.dialogue(
                player,
                player.getInteractingEntity() == null
                    ? new NPC(NPCDefinition.forId(657))
                    : player.getInteractingEntity(),
                Emotes.ANGER2,
                lines);
            player.setNextDialogueIds(null);
          }
          return;
        }
        player.getActionSender().sendCloseInterface();
        break;
        /*
         * Only used for Construction at the moment..
         */
      case 233:
        if (player.getConstruction().getBuildingRoom() == null) {
          switch (button) {
              /*
               * Enter your house.
               */
            case 1:
              player.getConstruction().enterHouse(false);
              break;
              /*
               * Enter your house (building mode)
               */
            case 2:
              player.getConstruction().enterHouse(true);
              break;
              /*
               * Enter friends house.
               */
            case 3:
              player.getInterfaceState().openEnterNameInterface(interfaceId);
              break;
          }
        } else {
          switch (button) {
              /*
               * Rotate clockwise
               */
            case 1:
              player
                  .getActionSender()
                  .sendMessage(
                      "I almost had this, but spend 2 days fixing it. Its a delayed feature for now.");
              player.getActionSender().sendCloseInterface();
              // player.getConstruction().spawnRoomForRotation(true);
              break;
              /*
               * Rotate anti clockwise
               */
            case 2:
              player
                  .getActionSender()
                  .sendMessage(
                      "I almost had this, but spend 2 days fixing it. Its a delayed feature for now.");
              player.getActionSender().sendCloseInterface();
              // player.getConstruction().spawnRoomForRotation(false);
              break;
              /*
               * Build.
               */
            case 3:
              for (GameObject object : player.getConstruction().getBuildingRoom().getHotspots()) {
                Location local =
                    Location.create(
                        object.getLocation().getX()
                            + player.getConstruction().getBuildingRoom().getX(),
                        object.getLocation().getY()
                            + player.getConstruction().getBuildingRoom().getY(),
                        object.getLocation().getZ());
                player
                    .getActionSender()
                    .sendDestroyLocalObject(object.getType(), object.getRotation(), local);
              }
              player
                  .getConstruction()
                  .getHouse()
                  .addRoomAndReload(player.getConstruction().getBuildingRoom());
              player.getInventory().remove(new Item(995, player.getConstruction().getRoomPrice()));
              player.getConstruction().setBuildingRoom(null, -1);
              break;
              /*
               * Cancel..
               */
            case 4:
              for (GameObject object : player.getConstruction().getBuildingRoom().getHotspots()) {
                Location local =
                    Location.create(
                        object.getLocation().getX()
                            + player.getConstruction().getBuildingRoom().getX(),
                        object.getLocation().getY()
                            + player.getConstruction().getBuildingRoom().getY(),
                        object.getLocation().getZ());
                player
                    .getActionSender()
                    .sendDestroyLocalObject(object.getType(), object.getRotation(), local);
              }
              player.getConstruction().setBuildingRoom(null, -1);
              player.getActionSender().sendCloseInterface();
              break;
          }
        }
        break;
      case Cooking.COOKING_INTERFACE:
        Cooking.handleInterfaceButtons(player, button);
        break;
        /*
         * Entering the barrows tunnels.
         */
      case 229:
        Object obj = player.getTemporaryAttribute("InterfaceOption");
        if (obj != null) {
          InterfaceOption option = (InterfaceOption) obj;
          switch (option) {
            case BARROWS:
              switch (button) {
                case 1:
                  Barrows.teleportToTunnels(player);
                  player.getActionSender().sendCloseInterface();
                  break;
                case 2:
                  player.getActionSender().sendCloseInterface();
                  break;
              }
              break;
            case CONSTRUCTION:
              switch (button) {
                  /*
                   * Yes
                   */
                case 1:
                  player.getConstruction().remove();
                  player.getActionSender().sendCloseInterface();
                  break;
                  /*
                   * No
                   */
                case 2:
                  player.getActionSender().sendCloseInterface();
                  break;
              }
              break;
          }
        }

        break;
      case 231: // Three options.
        switch (player.getJewellery().getGemType()) {
          case RING_OF_DUELING:
            /*
             * Ring of dueling rubbing.
             */
            switch (button) {
              case 1: // Teleport to Castle Wars.
                player.getJewellery().gemTeleport(player, Location.create(2440, 3089, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 2: // Teleport to Duel Arena.
                player.getJewellery().gemTeleport(player, Location.create(3316, 3235, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 3: // Nowhere.
                player.getActionSender().sendCloseInterface();
                break;
            }
            break;
          case GAMES_NECKLACE:
            /*
             * Games necklace rubbing.
             */
            switch (button) {
              case 1: // Burthope games room (Burthope for now)
                player.getJewellery().gemTeleport(player, Location.create(2926, 3559, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 2: // Barbarian outpost.
                player.getJewellery().gemTeleport(player, Location.create(2541, 3546, 0));
                player.getActionSender().sendCloseInterface();
                break;
              case 3: // Nowhere.
                player.getActionSender().sendCloseInterface();
                break;
            }
            break;
        }

        break;

        /*
         * Glory teleporting.
         */
      case 238:
        switch (button) {
            /*
             * Edgewille.
             */
          case 1:
            player.getJewellery().gemTeleport(player, Location.create(3089, 3496, 0));
            player.getActionSender().sendCloseInterface();
            break;
            /*
             * Karamja.
             */
          case 2:
            player.getJewellery().gemTeleport(player, Location.create(2918, 3176, 0));
            player.getActionSender().sendCloseInterface();
            break;
            /*
             * Draynor Village
             */
          case 3:
            player.getJewellery().gemTeleport(player, Location.create(3105, 3249, 0));
            player.getActionSender().sendCloseInterface();
            break;
            /*
             * Al-Kharid
             */
          case 4:
            player.getJewellery().gemTeleport(player, Location.create(3293, 3163, 0));
            player.getActionSender().sendCloseInterface();
            break;
          case 5:
            player.getActionSender().sendCloseInterface();
            break;
        }
        break;
        /*
         * Hard leather body interface.
         */
      case 309:
        if (Crafting.hardLeatherBodies(player, button)) {
          return;
        }
        break;
        /*
         * All Dragon leathers are configured in this interface. Fletching is
         * done in this interface as well.
         */
      case 304:
        if (player.getCraftingVariables().isCrafting()) {
          Crafting.dragonLeatherCrafting(player, button);
        } else if (player.getFletchingVariables().isFletching()) {
          Fletching.handleChatboxInterface(304, player, button);
        }
        break;
      case 303:
        Fletching.handleChatboxInterface(303, player, button);
        break;
        /*
         * Destroy items.
         */
      case 94:
        switch (button) {
          case 4:
            player
                .getInventory()
                .remove(player.getDestroyingItem()[1], new Item(player.getDestroyingItem()[0]));
            player.getActionSender().sendCloseInterface();
            break;
          case 5:
            player.getActionSender().sendCloseInterface();
            break;
        }
        break;
      default:
        System.out.println("Unhandled chatbox interface: " + interfaceId + " " + button);
        player.getActionSender().sendCloseInterface();
    }
  }
Example #16
0
 /**
  * Handles an incoming packet.
  *
  * @param packet The incoming packet.
  */
 public void handlePacket(LoginPacket packet) {
   final IoBuffer buf = packet.getPayload();
   switch (packet.getOpcode()) {
     case LoginPacket.CHECK_LOGIN:
       {
         final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf));
         final String password = IoBufferUtils.getRS2String(buf);
         final LoginResult res =
             server.getLoader().checkLogin(new PlayerDetails(null, name, password, 0, null, null));
         if (res.getReturnCode() == 2) {
           final PlayerData pd = new PlayerData(name, res.getPlayer().getRights().toInteger());
           NodeManager.getNodeManager().register(pd, this);
         }
         final IoBuffer resp = IoBuffer.allocate(16);
         resp.setAutoExpand(true);
         IoBufferUtils.putRS2String(resp, name);
         resp.put((byte) res.getReturnCode());
         resp.flip();
         session.write(new LoginPacket(LoginPacket.CHECK_LOGIN_RESPONSE, resp));
         break;
       }
     case LoginPacket.LOAD:
       {
         final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf));
         final Player p = new Player(new PlayerDetails(null, name, "", 0, null, null));
         final int code = server.getLoader().loadPlayer(p) ? 1 : 0;
         final IoBuffer resp = IoBuffer.allocate(1024);
         resp.setAutoExpand(true);
         IoBufferUtils.putRS2String(resp, name);
         resp.put((byte) code);
         if (code == 1) {
           final IoBuffer data = IoBuffer.allocate(16);
           data.setAutoExpand(true);
           p.serialize(data);
           data.flip();
           resp.putShort((short) data.remaining());
           resp.put(data);
         }
         resp.flip();
         session.write(new LoginPacket(LoginPacket.LOAD_RESPONSE, resp));
         break;
       }
     case LoginPacket.SAVE:
       {
         final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf));
         final int dataLength = buf.getUnsignedShort();
         final byte[] data = new byte[dataLength];
         buf.get(data);
         final IoBuffer dataBuffer = IoBuffer.allocate(dataLength);
         dataBuffer.put(data);
         dataBuffer.flip();
         final Player p = new Player(new PlayerDetails(null, name, "", 0, null, null));
         p.deserialize(dataBuffer);
         final int code = server.getLoader().savePlayer(p) ? 1 : 0;
         final IoBuffer resp = IoBuffer.allocate(16);
         resp.setAutoExpand(true);
         IoBufferUtils.putRS2String(resp, name);
         resp.put((byte) code);
         resp.flip();
         session.write(new LoginPacket(LoginPacket.SAVE_RESPONSE, resp));
         break;
       }
     case LoginPacket.DISCONNECT:
       {
         final String name = NameUtils.formatNameForProtocol(IoBufferUtils.getRS2String(buf));
         final PlayerData p = NodeManager.getNodeManager().getPlayer(name);
         if (p != null) {
           NodeManager.getNodeManager().unregister(p);
         }
       }
       break;
   }
 }
Example #17
0
 private static void appendHitUpdate(Player p, PacketBuilder updateBlock) {
   updateBlock.putByteS((byte) p.getDamage().getHitDamage1());
   updateBlock.putByteS((byte) p.getDamage().getHitType1());
   final int hpRatio = p.getSkills().getLevel(3) * 255 / p.getSkills().getLevelForExperience(3);
   updateBlock.putByteS((byte) hpRatio);
 }