예제 #1
0
  /**
   * Appends the walk version of the movement section of the update packet (sector 2,1).
   *
   * @param out the buffer to append to
   * @param direction the walking direction
   * @param attributesUpdate whether or not a player attributes update is required
   */
  public static void appendWalk(
      PacketBuffer.WriteBuffer out, int direction, boolean attributesUpdate) {
    out.writeBits(2, 1); // 1 - walking.

    /** Append the actual sector. */
    out.writeBits(3, direction);
    out.writeBit(attributesUpdate);
  }
예제 #2
0
  /**
   * Appends the walk version of the movement section of the update packet (sector 2,2).
   *
   * @param out the buffer to append to.
   * @param direction the walking direction.
   * @param direction2 the running direction.
   * @param attributesUpdate whether or not a player attributes update is required.
   */
  public static void appendRun(
      PacketBuffer.WriteBuffer out, int direction, int direction2, boolean attributesUpdate) {
    out.writeBits(2, 2); // 2 - running.

    /** Append the actual sector. */
    out.writeBits(3, direction);
    out.writeBits(3, direction2);
    out.writeBit(attributesUpdate);
  }
예제 #3
0
  /**
   * Adds a player to the local player list of another player.
   *
   * @param out the packet to write to.
   * @param player the host player.
   * @param other the player being added.
   */
  public static void addPlayer(PacketBuffer.WriteBuffer out, Player player, Player other) {
    out.writeBits(11, other.getSlot()); // Server slot.
    out.writeBit(true); // Yes, an update is required.
    out.writeBit(true); // Discard walking queue(?)

    // Write the relative position.
    Position delta = Misc.delta(player.getPosition(), other.getPosition());
    out.writeBits(5, delta.getY());
    out.writeBits(5, delta.getX());
  }
예제 #4
0
  /**
   * Appends the player placement version of the movement section of the update packet (sector 2,3).
   * Note that by others this was previously called the "teleport update".
   *
   * @param out the buffer to append to.
   * @param localX the local X coordinate.
   * @param localY the local Y coordinate.
   * @param z the Z coordinate.
   * @param discardMovementQueue whether or not the client should discard the movement queue.
   * @param attributesUpdate whether or not a plater attributes update is required.
   */
  public static void appendPlacement(
      PacketBuffer.WriteBuffer out,
      int localX,
      int localY,
      int z,
      boolean discardMovementQueue,
      boolean attributesUpdate) {
    out.writeBits(2, 3); // 3 - placement.

    /** Append the actual sector. */
    out.writeBits(2, z);
    out.writeBit(discardMovementQueue);
    out.writeBit(attributesUpdate);
    out.writeBits(7, localY);
    out.writeBits(7, localX);
  }
예제 #5
0
 /**
  * Appends the stand version of the movement section of the update packet (sector 2,0). Appending
  * this (instead of just a zero bit) automatically assumes that there is a required attribute
  * update afterwards.
  *
  * @param out the buffer to append to.
  */
 public static void appendStand(PacketBuffer.WriteBuffer out) {
   out.writeBits(2, 0); // 0 - no movement.
 }
예제 #6
0
  /**
   * Updates the player.
   *
   * @param player the player to update.
   */
  public static void update(Player player) {
    // XXX: The buffer sizes may need to be tuned.
    PacketBuffer.WriteBuffer out = PacketBuffer.newWriteBuffer(16384); // 8192
    PacketBuffer.WriteBuffer block = PacketBuffer.newWriteBuffer(8192); // 4096

    /** Initialize the update packet. */
    out.writeVariableShortPacketHeader(81);
    out.setAccessType(PacketBuffer.AccessType.BIT_ACCESS);

    /** Update this player. */
    PlayerUpdate.updateLocalPlayerMovement(player, out);

    if (player.getFlags().isUpdateRequired()) {
      PlayerUpdate.updateState(player, block, false, true);
    }

    /** Update other local players. */
    out.writeBits(8, player.getPlayers().size());
    for (Iterator<Player> i = player.getPlayers().iterator(); i.hasNext(); ) {
      Player other = i.next();
      if (other.getPosition().isViewableFrom(player.getPosition())
          && other.getSession().getStage() == Session.Stage.LOGGED_IN
          && !other.isNeedsPlacement()
          && other.isVisible()) {
        PlayerUpdate.updateOtherPlayerMovement(other, out);
        if (other.getFlags().isUpdateRequired()) {
          PlayerUpdate.updateState(other, block, false, false);
        }
      } else {
        out.writeBit(true);
        out.writeBits(2, 3);
        i.remove();
      }
    }

    int added = 0;

    /** Update the local player list. */
    for (int i = 0; i < World.getPlayers().getCapacity(); i++) {
      if (added == 15 || player.getPlayers().size() >= 220) {

        /** Player limit has been reached. */
        break;
      }
      Player other = World.getPlayers().get(i);
      if (other == null
          || other == player
          || other.getSession().getStage() != Session.Stage.LOGGED_IN
          || !other.isVisible()) {
        continue;
      }
      if (!player.getPlayers().contains(other)
          && other.getPosition().isViewableFrom(player.getPosition())) {
        added++;
        player.getPlayers().add(other);
        PlayerUpdate.addPlayer(out, player, other);
        PlayerUpdate.updateState(other, block, true, false);
      }
    }

    /** Append the attributes block to the main packet. */
    if (block.getBuffer().position() > 0) {
      out.writeBits(11, 2047);
      out.setAccessType(PacketBuffer.AccessType.BYTE_ACCESS);
      out.writeBytes(block.getBuffer());
    } else {
      out.setAccessType(PacketBuffer.AccessType.BYTE_ACCESS);
    }

    /** Finish the packet and send it. */
    out.finishVariableShortPacketHeader();
    player.getSession().encode(out);
  }