Example #1
0
  @Override
  public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) {
    super.receiveCommand(command, side, sender, stream);
    if (side.isClient()) {
      if ("clearItemRequirements".equals(command)) {
        requiredToBuild = null;
      } else if ("setItemRequirements".equals(command)) {
        int size = stream.readUnsignedMedium();
        requiredToBuild = new ArrayList<RequirementItemStack>();
        for (int i = 0; i < size; i++) {
          int itemId = stream.readUnsignedShort();
          int itemDamage = stream.readShort();
          int stackSize = stream.readUnsignedMedium();
          boolean hasCompound = stackSize >= 0x800000;

          ItemStack stack = new ItemStack(Item.getItemById(itemId), 1, itemDamage);
          if (hasCompound) {
            stack.setTagCompound(NetworkUtils.readNBT(stream));
          }

          if (stack != null && stack.getItem() != null) {
            requiredToBuild.add(new RequirementItemStack(stack, stackSize & 0x7FFFFF));
          } else {
            BCLog.logger.error(
                "Corrupt ItemStack in TileBuilder.receiveCommand! This should not happen! (ID "
                    + itemId
                    + ", damage "
                    + itemDamage
                    + ")");
          }
        }
      }
    } else if (side.isServer()) {
      EntityPlayer player = (EntityPlayer) sender;
      if ("eraseFluidTank".equals(command)) {
        int id = stream.readInt();
        if (id < 0 || id >= fluidTanks.length) {
          return;
        }
        if (isUseableByPlayer(player) && player.getDistanceSq(xCoord, yCoord, zCoord) <= 64) {
          fluidTanks[id].setFluid(null);
          sendNetworkUpdate();
        }
      }
    }
  }
  private void processHeaderState(ByteBuf in) throws Http2Exception {
    if (in.readableBytes() < FRAME_HEADER_LENGTH) {
      // Wait until the entire frame header has been read.
      return;
    }

    // Read the header and prepare the unmarshaller to read the frame.
    payloadLength = in.readUnsignedMedium();
    if (payloadLength > maxFrameSize) {
      throw connectionError(
          PROTOCOL_ERROR, "Frame length: %d exceeds maximum: %d", payloadLength, maxFrameSize);
    }
    frameType = in.readByte();
    flags = new Http2Flags(in.readUnsignedByte());
    streamId = readUnsignedInt(in);

    switch (frameType) {
      case DATA:
        verifyDataFrame();
        break;
      case HEADERS:
        verifyHeadersFrame();
        break;
      case PRIORITY:
        verifyPriorityFrame();
        break;
      case RST_STREAM:
        verifyRstStreamFrame();
        break;
      case SETTINGS:
        verifySettingsFrame();
        break;
      case PUSH_PROMISE:
        verifyPushPromiseFrame();
        break;
      case PING:
        verifyPingFrame();
        break;
      case GO_AWAY:
        verifyGoAwayFrame();
        break;
      case WINDOW_UPDATE:
        verifyWindowUpdateFrame();
        break;
      case CONTINUATION:
        verifyContinuationFrame();
        break;
      default:
        // Unknown frame type, could be an extension.
        break;
    }

    // Start reading the payload for the frame.
    state = State.FRAME_PAYLOAD;
  }
 @Override
 public int readUnsignedMedium() {
   return buffer.readUnsignedMedium();
 }
Example #4
0
 /**
  * Creates and returns MplsLabel object from 20 leftmost bits in the incoming buffer. Moves reader
  * index by 3.
  *
  * @param buffer expecting 3 bytes with 20 leftmost bits as label
  * @return MplsLabel object
  */
 public static MplsLabel mplsLabelForByteBuf(final ByteBuf buffer) {
   return new MplsLabel(new Long(buffer.readUnsignedMedium() >> LABEL_OFFSET));
 }