protected void checkCloseFrameBody(ChannelHandlerContext ctx, ByteBuf buffer) {
    if (buffer == null || buffer.capacity() == 0) {
      return;
    }
    if (buffer.capacity() == 1) {
      protocolViolation(ctx, "Invalid close frame body");
    }

    // Save reader index
    int idx = buffer.readerIndex();
    buffer.readerIndex(0);

    // Must have 2 byte integer within the valid range
    int statusCode = buffer.readShort();
    if (statusCode >= 0 && statusCode <= 999
        || statusCode >= 1004 && statusCode <= 1006
        || statusCode >= 1012 && statusCode <= 2999) {
      protocolViolation(ctx, "Invalid close frame getStatus code: " + statusCode);
    }

    // May have UTF-8 message
    if (buffer.isReadable()) {

      try {
        new UTF8Output(buffer);
      } catch (UTF8Exception ex) {
        protocolViolation(ctx, "Invalid close frame reason text. Invalid UTF-8 bytes");
      }
    }

    // Restore reader index
    buffer.readerIndex(idx);
  }
Пример #2
0
 private void writeBuffer(byte[] data) {
   int newSize = 0;
   int oldSize = buffer.capacity();
   int length = data.length;
   if (buffer.writableBytes() <= length) {
     if (length > oldSize) {
       newSize = length * 2;
     } else {
       newSize = 2 * oldSize;
     }
     buffer.capacity(newSize);
   }
   buffer.writeBytes(data);
 }
Пример #3
0
 public MsgEchoPeerHandler(final int messageSize) {
   final ByteBuf byteBuf = Unpooled.buffer(messageSize);
   for (int i = 0; i < byteBuf.capacity(); i++) {
     byteBuf.writeByte((byte) i);
   }
   message = new UdtMessage(byteBuf);
 }
Пример #4
0
 /** Creates a client-side handler. */
 public EchoClientHandler() {
   firstMessage = Unpooled.buffer(EchoClient.SIZE);
   for (int i = 0; i < firstMessage.capacity(); i++) {
     firstMessage.writeByte((byte) i);
   }
   System.out.println(firstMessage.toString());
 }
Пример #5
0
 public ByteEchoPeerHandler(final int messageSize) {
   super(false);
   message = Unpooled.buffer(messageSize);
   for (int i = 0; i < message.capacity(); i++) {
     message.writeByte((byte) i);
   }
 }
Пример #6
0
 @Override
 public RequestFixture body(byte[] bytes, String contentType) {
   requestHeaders.add(HttpHeaderNames.CONTENT_TYPE, contentType);
   requestHeaders.add(HttpHeaderNames.CONTENT_LENGTH, bytes.length);
   requestBody.capacity(bytes.length).writeBytes(bytes);
   return this;
 }
Пример #7
0
  public ByteEchoClientHandler() {
    super(false);

    message = Unpooled.buffer(ByteEchoClient.SIZE);
    for (int i = 0; i < message.capacity(); i++) {
      message.writeByte((byte) i);
    }
  }
  private void testBuffer(ByteBuf buf, boolean isDirect) {
    assertEquals(11, buf.capacity());

    assertEquals(isDirect, buf.isDirect());

    assertEquals(0, buf.readableBytes());
    assertEquals(11, buf.writableBytes());
  }
Пример #9
0
 /** Creates a client-side handler. */
 public SctpEchoClientHandler(int firstMessageSize) {
   if (firstMessageSize <= 0) {
     throw new IllegalArgumentException("firstMessageSize: " + firstMessageSize);
   }
   firstMessage = Unpooled.buffer(firstMessageSize);
   for (int i = 0; i < firstMessage.capacity(); i++) {
     firstMessage.writeByte((byte) i);
   }
 }
Пример #10
0
 private void ensureWritable(int pos, int len) {
   int ni = pos + len;
   int cap = buffer.capacity();
   int over = ni - cap;
   if (over > 0) {
     buffer.writerIndex(cap);
     buffer.ensureWritable(over);
   }
   // We have to make sure that the writerindex is always positioned on the last bit of data set in
   // the buffer
   if (ni > buffer.writerIndex()) {
     buffer.writerIndex(ni);
   }
 }
Пример #11
0
  @Override
  public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    try {
      ByteBuf recvBuf = Unpooled.copiedBuffer((ByteBuf) msg);
      byte[] buf = new byte[recvBuf.capacity()];
      recvBuf.readBytes(buf);

      String request = new String(buf, CharsetUtil.UTF_8);
      System.out.println("받는 Data : " + request);

      broadCast(ctx, request);
    } finally {
      ReferenceCountUtil.release(msg);
    }
  }
Пример #12
0
 /** Read bytes into the given {@link ByteBuf} and return the amount. */
 private int doReadBytes(ByteBuf byteBuf) throws Exception {
   int writerIndex = byteBuf.writerIndex();
   int localReadAmount;
   if (byteBuf.hasMemoryAddress()) {
     localReadAmount =
         Native.readAddress(fd, byteBuf.memoryAddress(), writerIndex, byteBuf.capacity());
   } else {
     ByteBuffer buf = byteBuf.internalNioBuffer(writerIndex, byteBuf.writableBytes());
     localReadAmount = Native.read(fd, buf, buf.position(), buf.limit());
   }
   if (localReadAmount > 0) {
     byteBuf.writerIndex(writerIndex + localReadAmount);
   }
   return localReadAmount;
 }
Пример #13
0
  public ByteBuf getBytes(int var1, ByteBuf var2, int var3, int var4) {
    this.checkDstIndex(var1, var4, var3, var2.capacity());
    if (var2.hasArray()) {
      this.getBytes(var1, var2.array(), var2.arrayOffset() + var3, var4);
    } else if (var2.nioBufferCount() > 0) {
      ByteBuffer[] var5 = var2.nioBuffers(var3, var4);
      int var6 = var5.length;

      for (int var7 = 0; var7 < var6; ++var7) {
        ByteBuffer var8 = var5[var7];
        int var9 = var8.remaining();
        this.getBytes(var1, var8);
        var1 += var9;
      }
    } else {
      var2.setBytes(var3, (ByteBuf) this, var1, var4);
    }

    return this;
  }
Пример #14
0
  @SuppressWarnings("restriction")
  @Override
  public void encode(ByteBuf buf) {
    buf.writeLong(id); // Ulong but whatever
    // TODO: Not sure exactly how to approach writing unsigned ints!
    BitArray bitArray = new BitArray(8 * bitmask.length, bitmask); // Size in bits, byte[]
    buf.writeBytes(bitmask);

    if (bitArray.get(0)) {
      buf.writeLong(posX);
      buf.writeLong(posY);
      buf.writeLong(posZ);
    }
    if (bitArray.get(1)) {
      buf.writeFloat(pitch);
      buf.writeFloat(roll);
      buf.writeFloat(yaw);
    }
    if (bitArray.get(2)) {
      velocity.encode(buf);
    }
    if (bitArray.get(3)) {
      accel.encode(buf);
    }
    if (bitArray.get(4)) {
      extraVel.encode(buf);
    }
    if (bitArray.get(5)) {
      buf.writeFloat(lookPitch);
    }
    if (bitArray.get(6)) {
      buf.writeInt((int) physicsFlags);
    }
    if (bitArray.get(7)) {
      buf.writeByte(speedFlags);
    }
    if (bitArray.get(8)) {
      buf.writeInt((int) entityType);
    }
    if (bitArray.get(9)) {
      buf.writeByte(currentMode);
    }
    if (bitArray.get(10)) {
      buf.writeInt((int) lastShootTime);
    }
    if (bitArray.get(11)) {
      buf.writeInt((int) hitCounter);
    }
    if (bitArray.get(12)) {
      buf.writeInt((int) lastHitTime);
    }
    if (bitArray.get(13)) {
      app.encode(buf);
    }
    if (bitArray.get(14)) {
      buf.writeByte(flags1);
      buf.writeByte(flags2);
    }
    if (bitArray.get(15)) {
      buf.writeInt((int) rollTime);
    }
    if (bitArray.get(16)) {
      buf.writeInt(stunTime);
    }
    if (bitArray.get(17)) {
      buf.writeInt((int) slowedTime);
    }
    if (bitArray.get(18)) {
      buf.writeInt((int) makeBlueTime);
    }
    if (bitArray.get(19)) {
      buf.writeInt((int) speedUpTime);
    }
    if (bitArray.get(20)) {
      buf.writeFloat(slowPatchTime);
    }
    if (bitArray.get(21)) {
      buf.writeByte(classType);
    }
    if (bitArray.get(22)) {
      buf.writeByte(specialization);
    }
    if (bitArray.get(23)) {
      buf.writeFloat(chargedMP);
    }
    if (bitArray.get(24)) {
      buf.writeInt((int) nu1);
      buf.writeInt((int) nu2);
      buf.writeInt((int) nu3);
    }
    if (bitArray.get(25)) {
      buf.writeInt((int) nu4);
      buf.writeInt((int) nu5);
      buf.writeInt((int) nu6);
    }
    if (bitArray.get(26)) {
      rayHit.encode(buf);
    }
    if (bitArray.get(27)) {
      buf.writeFloat(HP);
    }
    if (bitArray.get(28)) {
      buf.writeFloat(MP);
    }
    if (bitArray.get(29)) {
      buf.writeFloat(blockPower);
    }
    if (bitArray.get(30)) {
      buf.writeFloat(maxHPMultiplier);
      buf.writeFloat(shootSpeed);
      buf.writeFloat(damageMultiplier);
      buf.writeFloat(armorMultiplier);
      buf.writeFloat(resistanceMultiplier);
    }
    if (bitArray.get(31)) {
      buf.writeByte(nu7);
    }
    if (bitArray.get(32)) {
      buf.writeByte(nu8);
    }
    if (bitArray.get(33)) {
      buf.writeInt((int) level);
    }
    if (bitArray.get(34)) {
      buf.writeInt((int) currentXP);
    }
    if (bitArray.get(35)) {
      buf.writeLong(parentOwner);
    }
    if (bitArray.get(36)) {
      buf.writeInt((int) na1);
      buf.writeInt((int) na2);
    }
    if (bitArray.get(37)) {
      buf.writeByte(na3);
    }
    if (bitArray.get(38)) {
      buf.writeInt((int) na4);
    }
    if (bitArray.get(39)) {
      buf.writeInt((int) na5);
      buf.writeInt((int) nu11);
      buf.writeInt((int) nu12);
    }
    if (bitArray.get(40)) {
      buf.writeInt((int) nu13);
      buf.writeInt((int) nu14);
      buf.writeInt((int) nu15);
      buf.writeInt((int) nu16);
      buf.writeInt((int) nu17);
      buf.writeInt((int) nu18);
    }
    if (bitArray.get(41)) {
      buf.writeInt((int) nu20);
      buf.writeInt((int) nu21);
      buf.writeInt((int) nu22);
    }
    if (bitArray.get(42)) {
      buf.writeByte(nu19);
    }
    if (bitArray.get(43)) {
      itemData.encode(buf);
    }
    if (bitArray.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = equipment[i];
        item.encode(buf);
      }
    }
    if (bitArray.get(45)) {
      byte[] utf8 = name.getBytes(Charsets.UTF_8);
      buf.writeBytes(new byte[4]); // TODO But why?
      buf.writeBytes(utf8);
      buf.writeBytes(new byte[16 - name.length()]);
    }
    if (bitArray.get(46)) {
      for (int i = 0; i < 11; i++) {
        buf.writeInt((int) skills[i]);
      }
    }
    if (bitArray.get(47)) {
      buf.writeInt((int) iceBlockFour);
    }

    buf.capacity(buf.writerIndex() + 1);
    if (buf.readerIndex() > 0) {
      System.out.println("I read something during an encode?!");
    }
  }
Пример #15
0
  @Override
  protected void doRead() {
    if (checkInputShutdown()) {
      return;
    }

    final ChannelPipeline pipeline = pipeline();

    // TODO: calculate size as in 3.x
    ByteBuf byteBuf = alloc().buffer();
    boolean closed = false;
    boolean read = false;
    boolean firedInboundBufferSuspeneded = false;
    try {
      for (; ; ) {
        int localReadAmount = doReadBytes(byteBuf);
        if (localReadAmount > 0) {
          read = true;
        } else if (localReadAmount < 0) {
          closed = true;
        }

        final int available = available();
        if (available <= 0) {
          break;
        }

        if (!byteBuf.isWritable()) {
          final int capacity = byteBuf.capacity();
          final int maxCapacity = byteBuf.maxCapacity();
          if (capacity == maxCapacity) {
            if (read) {
              read = false;
              pipeline.fireMessageReceived(byteBuf);
              byteBuf = alloc().buffer();
            }
          } else {
            final int writerIndex = byteBuf.writerIndex();
            if (writerIndex + available > maxCapacity) {
              byteBuf.capacity(maxCapacity);
            } else {
              byteBuf.ensureWritable(available);
            }
          }
        }
        if (!config().isAutoRead()) {
          // stop reading until next Channel.read() call
          // See https://github.com/netty/netty/issues/1363
          break;
        }
      }
    } catch (Throwable t) {
      if (read) {
        read = false;
        pipeline.fireMessageReceived(byteBuf);
      }

      if (t instanceof IOException) {
        closed = true;
        pipeline.fireExceptionCaught(t);
      } else {
        firedInboundBufferSuspeneded = true;
        pipeline.fireChannelReadSuspended();
        pipeline.fireExceptionCaught(t);
        unsafe().close(voidPromise());
      }
    } finally {
      if (read) {
        pipeline.fireMessageReceived(byteBuf);
      } else {
        // nothing read into the buffer so release it
        byteBuf.release();
      }
      if (closed) {
        inputShutdown = true;
        if (isOpen()) {
          if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) {
            pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE);
          } else {
            unsafe().close(unsafe().voidPromise());
          }
        }
      } else if (!firedInboundBufferSuspeneded) {
        pipeline.fireChannelReadSuspended();
      }
    }
  }
Пример #16
0
 @Override
 public ByteBuf capacity(int newCapacity) {
   return buf.capacity(newCapacity);
 }
Пример #17
0
 @Override
 public int capacity() {
   return buf.capacity();
 }
 public EchoClientHandler() {
   firstMessage = Unpooled.buffer(EchoClient.SIZE);
   for (int i = 0; i < firstMessage.capacity(); i++) {
     firstMessage.writeByte((byte) i);
   }
 }
Пример #19
0
  @Override
  public void decode(ByteBuf buf) {
    id = buf.readLong();
    byte[] bitSetBuf = new byte[8];
    buf.readBytes(bitSetBuf);
    this.bitSet = BitSet.valueOf(bitSetBuf);

    if (bitSet.get(0)) {
      position = readLongVector3(buf);
    }
    if (bitSet.get(1)) {
      orientation = readOrientation(buf);
    }
    if (bitSet.get(2)) {
      velocity = readFloatVector3(buf);
    }
    if (bitSet.get(3)) {
      accel = readFloatVector3(buf);
    }
    if (bitSet.get(4)) {
      extraVel = readFloatVector3(buf);
    }
    if (bitSet.get(5)) {
      lookPitch = buf.readFloat();
    }
    if (bitSet.get(6)) {
      physicsFlags = buf.readUnsignedInt();
    }
    if (bitSet.get(7)) {
      hostileType = buf.readByte();
    }
    if (bitSet.get(8)) {
      entityType = buf.readUnsignedInt();
    }
    if (bitSet.get(9)) {
      currentMode = buf.readByte();
    }
    if (bitSet.get(10)) {
      lastShootTime = buf.readUnsignedInt();
    }
    if (bitSet.get(11)) {
      hitCounter = buf.readUnsignedInt();
    }
    if (bitSet.get(12)) {
      lastHitTime = buf.readUnsignedInt();
    }
    if (bitSet.get(13)) {
      app.decode(buf);
    }
    if (bitSet.get(14)) {
      flags1 = buf.readByte();
      flags2 = buf.readByte();
    }
    if (bitSet.get(15)) {
      rollTime = buf.readUnsignedInt();
    }
    if (bitSet.get(16)) {
      stunTime = buf.readInt();
    }
    if (bitSet.get(17)) {
      slowedTime = buf.readUnsignedInt();
    }
    if (bitSet.get(18)) {
      makeBlueTime = buf.readUnsignedInt();
    }
    if (bitSet.get(19)) {
      speedUpTime = buf.readUnsignedInt();
    }
    if (bitSet.get(20)) {
      slowPatchTime = buf.readFloat();
    }
    if (bitSet.get(21)) {
      classType = buf.readByte();
    }
    if (bitSet.get(22)) {
      specialization = buf.readByte();
    }
    if (bitSet.get(23)) {
      chargedMP = buf.readFloat();
    }
    if (bitSet.get(24)) {
      nu1 = buf.readUnsignedInt();
      nu2 = buf.readUnsignedInt();
      nu3 = buf.readUnsignedInt();
    }
    if (bitSet.get(25)) {
      nu4 = buf.readUnsignedInt();
      nu5 = buf.readUnsignedInt();
      nu6 = buf.readUnsignedInt();
    }
    if (bitSet.get(26)) {
      rayHit = readFloatVector3(buf);
    }
    if (bitSet.get(27)) {
      HP = buf.readFloat();
    }
    if (bitSet.get(28)) {
      MP = buf.readFloat();
    }
    if (bitSet.get(29)) {
      blockPower = buf.readFloat();
    }
    if (bitSet.get(30)) {
      maxHPMultiplier = buf.readFloat();
      shootSpeed = buf.readFloat();
      damageMultiplier = buf.readFloat();
      armorMultiplier = buf.readFloat();
      resistanceMultiplier = buf.readFloat();
    }
    if (bitSet.get(31)) {
      nu7 = buf.readByte();
    }
    if (bitSet.get(32)) {
      nu8 = buf.readByte();
    }
    if (bitSet.get(33)) {
      level = buf.readUnsignedInt();
    }
    if (bitSet.get(34)) {
      currentXP = buf.readUnsignedInt();
    }
    if (bitSet.get(35)) {
      parentOwner = buf.readLong();
    }
    if (bitSet.get(36)) {
      na1 = buf.readUnsignedInt();
      na2 = buf.readUnsignedInt();
    }
    if (bitSet.get(37)) {
      na3 = buf.readByte();
    }
    if (bitSet.get(38)) {
      na4 = buf.readUnsignedInt();
    }
    if (bitSet.get(39)) {
      na5 = buf.readUnsignedInt();
      nu11 = buf.readUnsignedInt();
      nu12 = buf.readUnsignedInt();
    }
    if (bitSet.get(40)) {
      spawnPosition = readLongVector3(buf);
    }
    if (bitSet.get(41)) {
      nu20 = buf.readUnsignedInt();
      nu21 = buf.readUnsignedInt();
      nu22 = buf.readUnsignedInt();
    }
    if (bitSet.get(42)) {
      nu19 = buf.readByte();
    }
    if (bitSet.get(43)) {
      itemData.decode(buf);
    }
    if (bitSet.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = new GItem();
        item.decode(buf);
        equipment[i] = item;
      }
    }
    if (bitSet.get(45)) {
      name = new String(buf.readBytes(16).array(), Charsets.US_ASCII).trim();
    }
    if (bitSet.get(46)) {
      for (int i = 0; i < 11; i++) {
        skills[i] = buf.readUnsignedInt();
      }
    }
    if (bitSet.get(47)) {
      iceBlockFour = buf.readUnsignedInt();
    }

    debugCap = buf.capacity();
    buf.resetReaderIndex();
    buf.resetWriterIndex();
  }
Пример #20
0
  @Override
  protected void doRead() {
    if (checkInputShutdown()) {
      return;
    }

    final ChannelPipeline pipeline = pipeline();
    final ByteBuf byteBuf = pipeline.inboundByteBuffer();
    boolean closed = false;
    boolean read = false;
    boolean firedInboundBufferSuspeneded = false;
    try {
      for (; ; ) {
        int localReadAmount = doReadBytes(byteBuf);
        if (localReadAmount > 0) {
          read = true;
        } else if (localReadAmount < 0) {
          closed = true;
        }

        final int available = available();
        if (available <= 0) {
          break;
        }

        if (byteBuf.writable()) {
          continue;
        }

        final int capacity = byteBuf.capacity();
        final int maxCapacity = byteBuf.maxCapacity();
        if (capacity == maxCapacity) {
          if (read) {
            read = false;
            pipeline.fireInboundBufferUpdated();
            if (!byteBuf.writable()) {
              throw new IllegalStateException(
                  "an inbound handler whose buffer is full must consume at " + "least one byte.");
            }
          }
        } else {
          final int writerIndex = byteBuf.writerIndex();
          if (writerIndex + available > maxCapacity) {
            byteBuf.capacity(maxCapacity);
          } else {
            byteBuf.ensureWritableBytes(available);
          }
        }
      }
    } catch (Throwable t) {
      if (read) {
        read = false;
        pipeline.fireInboundBufferUpdated();
      }

      if (t instanceof IOException) {
        closed = true;
        pipeline.fireExceptionCaught(t);
      } else {
        firedInboundBufferSuspeneded = true;
        pipeline.fireInboundBufferSuspended();
        pipeline.fireExceptionCaught(t);
        unsafe().close(unsafe().voidFuture());
      }
    } finally {
      if (read) {
        pipeline.fireInboundBufferUpdated();
      }
      if (closed) {
        inputShutdown = true;
        if (isOpen()) {
          if (Boolean.TRUE.equals(config().getOption(ChannelOption.ALLOW_HALF_CLOSURE))) {
            pipeline.fireUserEventTriggered(ChannelInputShutdownEvent.INSTANCE);
          } else {
            unsafe().close(unsafe().voidFuture());
          }
        }
      } else if (!firedInboundBufferSuspeneded) {
        pipeline.fireInboundBufferSuspended();
      }
    }
  }
Пример #21
0
  @Override
  @SuppressWarnings("restriction")
  public void decode(ByteBuf buf) {
    id = buf.readLong();
    buf.readBytes(bitmask);
    BitArray bitArray =
        new BitArray(8 * bitmask.length, Bitops.flipBits(bitmask)); // Size in bits, byte[]
    // BitArray bitArray = new BitArray(bitmask);

    if (bitArray.get(0)) {
      posX = buf.readLong();
      posY = buf.readLong();
      posZ = buf.readLong();
    }
    if (bitArray.get(1)) {
      pitch = buf.readFloat();
      roll = buf.readFloat();
      yaw = buf.readFloat();
    }
    if (bitArray.get(2)) {
      velocity.decode(buf);
    }
    if (bitArray.get(3)) {
      accel.decode(buf);
    }
    if (bitArray.get(4)) {
      extraVel.decode(buf);
    }
    if (bitArray.get(5)) {
      lookPitch = buf.readFloat();
    }
    if (bitArray.get(6)) {
      physicsFlags = buf.readUnsignedInt();
    }
    if (bitArray.get(7)) {
      speedFlags = buf.readByte();
    }
    if (bitArray.get(8)) {
      entityType = buf.readUnsignedInt();
    }
    if (bitArray.get(9)) {
      currentMode = buf.readByte();
    }
    if (bitArray.get(10)) {
      lastShootTime = buf.readUnsignedInt();
    }
    if (bitArray.get(11)) {
      hitCounter = buf.readUnsignedInt();
    }
    if (bitArray.get(12)) {
      lastHitTime = buf.readUnsignedInt();
    }
    if (bitArray.get(13)) {
      app.decode(buf);
    }
    if (bitArray.get(14)) {
      flags1 = buf.readByte();
      flags2 = buf.readByte();
    }
    if (bitArray.get(15)) {
      rollTime = buf.readUnsignedInt();
    }
    if (bitArray.get(16)) {
      stunTime = buf.readInt();
    }
    if (bitArray.get(17)) {
      slowedTime = buf.readUnsignedInt();
    }
    if (bitArray.get(18)) {
      makeBlueTime = buf.readUnsignedInt();
    }
    if (bitArray.get(19)) {
      speedUpTime = buf.readUnsignedInt();
    }
    if (bitArray.get(20)) {
      slowPatchTime = buf.readFloat();
    }
    if (bitArray.get(21)) {
      classType = buf.readByte();
    }
    if (bitArray.get(22)) {
      specialization = buf.readByte();
    }
    if (bitArray.get(23)) {
      chargedMP = buf.readFloat();
    }
    if (bitArray.get(24)) {
      nu1 = buf.readUnsignedInt();
      nu2 = buf.readUnsignedInt();
      nu3 = buf.readUnsignedInt();
    }
    if (bitArray.get(25)) {
      nu4 = buf.readUnsignedInt();
      nu5 = buf.readUnsignedInt();
      nu6 = buf.readUnsignedInt();
    }
    if (bitArray.get(26)) {
      rayHit.decode(buf);
    }
    if (bitArray.get(27)) {
      HP = buf.readFloat();
    }
    if (bitArray.get(28)) {
      MP = buf.readFloat();
    }
    if (bitArray.get(29)) {
      blockPower = buf.readFloat();
    }
    if (bitArray.get(30)) {
      maxHPMultiplier = buf.readFloat();
      shootSpeed = buf.readFloat();
      damageMultiplier = buf.readFloat();
      armorMultiplier = buf.readFloat();
      resistanceMultiplier = buf.readFloat();
    }
    if (bitArray.get(31)) {
      nu7 = buf.readByte();
    }
    if (bitArray.get(32)) {
      nu8 = buf.readByte();
    }
    if (bitArray.get(33)) {
      level = buf.readUnsignedInt();
    }
    if (bitArray.get(34)) {
      currentXP = buf.readUnsignedInt();
    }
    if (bitArray.get(35)) {
      parentOwner = buf.readLong();
    }
    if (bitArray.get(36)) {
      na1 = buf.readUnsignedInt();
      na2 = buf.readUnsignedInt();
    }
    if (bitArray.get(37)) {
      na3 = buf.readByte();
    }
    if (bitArray.get(38)) {
      na4 = buf.readUnsignedInt();
    }
    if (bitArray.get(39)) {
      na5 = buf.readUnsignedInt();
      nu11 = buf.readUnsignedInt();
      nu12 = buf.readUnsignedInt();
    }
    if (bitArray.get(40)) {
      nu13 = buf.readUnsignedInt();
      nu14 = buf.readUnsignedInt();
      nu15 = buf.readUnsignedInt();
      nu16 = buf.readUnsignedInt();
      nu17 = buf.readUnsignedInt();
      nu18 = buf.readUnsignedInt();
    }
    if (bitArray.get(41)) {
      nu20 = buf.readUnsignedInt();
      nu21 = buf.readUnsignedInt();
      nu22 = buf.readUnsignedInt();
    }
    if (bitArray.get(42)) {
      nu19 = buf.readByte();
    }
    if (bitArray.get(43)) {
      itemData.decode(buf);
    }
    if (bitArray.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = new GItem();
        item.decode(buf);
        equipment[i] = item;
      }
    }
    if (bitArray.get(45)) {
      name = new String(buf.readBytes(16).array(), Charsets.US_ASCII).trim();
    }
    if (bitArray.get(46)) {
      for (int i = 0; i < 11; i++) {
        skills[i] = buf.readUnsignedInt();
      }
    }
    if (bitArray.get(47)) {
      iceBlockFour = buf.readUnsignedInt();
    }

    debugCap = buf.capacity();
    buf.resetReaderIndex();
    buf.resetWriterIndex();
  }
Пример #22
0
  @Override
  public void encode(ByteBuf buf) {
    // For testing purposes using default dummy entity :)
    /*boolean dummy = false;
    if (name.contains("dummy")) dummy = true;*/

    buf.writeLong(id); // Ulong but whatever
    buf.writeBytes(bitSet.toByteArray());
    buf.writeBytes(
        new byte
            [8 - bitSet.toByteArray().length]); // BitSet/BitArray are the stupidest classes ever :(
    if (bitSet.get(0)) {
      writeLongVector3(buf, position);
    }
    if (bitSet.get(1)) {
      writeOrientation(buf, orientation);
    }
    if (bitSet.get(2)) {
      writeFloatVector3(buf, velocity);
    }
    if (bitSet.get(3)) {
      writeFloatVector3(buf, accel);
    }
    if (bitSet.get(4)) {
      writeFloatVector3(buf, extraVel);
    }
    if (bitSet.get(5)) {
      buf.writeFloat(lookPitch);
    }
    if (bitSet.get(6)) {
      buf.writeInt((int) physicsFlags);
    }
    if (bitSet.get(7)) {
      buf.writeByte(hostileType);
    }
    if (bitSet.get(8)) {
      buf.writeInt((int) entityType);
    }
    if (bitSet.get(9)) {
      buf.writeByte(currentMode);
    }
    if (bitSet.get(10)) {
      buf.writeInt((int) lastShootTime);
    }
    if (bitSet.get(11)) {
      buf.writeInt((int) hitCounter);
    }
    if (bitSet.get(12)) {
      buf.writeInt((int) lastHitTime);
    }
    if (bitSet.get(13)) {
      app.encode(buf);
    }
    if (bitSet.get(14)) {
      buf.writeByte(flags1);
      buf.writeByte(flags2);
    }
    if (bitSet.get(15)) {
      buf.writeInt((int) rollTime);
    }
    if (bitSet.get(16)) {
      buf.writeInt(stunTime);
    }
    if (bitSet.get(17)) {
      buf.writeInt((int) slowedTime);
    }
    if (bitSet.get(18)) {
      buf.writeInt((int) makeBlueTime);
    }
    if (bitSet.get(19)) {
      buf.writeInt((int) speedUpTime);
    }
    if (bitSet.get(20)) {
      buf.writeFloat(slowPatchTime);
    }
    if (bitSet.get(21)) {
      buf.writeByte(classType);
    }
    if (bitSet.get(22)) {
      buf.writeByte(specialization);
    }
    if (bitSet.get(23)) {
      buf.writeFloat(chargedMP);
    }
    if (bitSet.get(24)) {
      buf.writeInt((int) nu1);
      buf.writeInt((int) nu2);
      buf.writeInt((int) nu3);
    }
    if (bitSet.get(25)) {
      buf.writeInt((int) nu4);
      buf.writeInt((int) nu5);
      buf.writeInt((int) nu6);
    }
    if (bitSet.get(26)) {
      writeFloatVector3(buf, rayHit);
    }
    if (bitSet.get(27)) {
      buf.writeFloat(HP);
    }
    if (bitSet.get(28)) {
      buf.writeFloat(MP);
    }
    if (bitSet.get(29)) {
      buf.writeFloat(blockPower);
    }
    if (bitSet.get(30)) {
      buf.writeFloat(maxHPMultiplier);
      buf.writeFloat(shootSpeed);
      buf.writeFloat(damageMultiplier);
      buf.writeFloat(armorMultiplier);
      buf.writeFloat(resistanceMultiplier);
    }
    if (bitSet.get(31)) {
      buf.writeByte(nu7);
    }
    if (bitSet.get(32)) {
      buf.writeByte(nu8);
    }
    if (bitSet.get(33)) {
      buf.writeInt((int) level);
    }
    if (bitSet.get(34)) {
      buf.writeInt((int) currentXP);
    }
    if (bitSet.get(35)) {
      buf.writeLong(parentOwner);
    }
    if (bitSet.get(36)) {
      buf.writeInt((int) na1);
      buf.writeInt((int) na2);
    }
    if (bitSet.get(37)) {
      buf.writeByte(na3);
    }
    if (bitSet.get(38)) {
      buf.writeInt((int) na4);
    }
    if (bitSet.get(39)) {
      buf.writeInt((int) na5);
      buf.writeInt((int) nu11);
      buf.writeInt((int) nu12);
    }
    if (bitSet.get(40)) {
      writeLongVector3(buf, spawnPosition);
    }
    if (bitSet.get(41)) {
      buf.writeInt((int) nu20);
      buf.writeInt((int) nu21);
      buf.writeInt((int) nu22);
    }
    if (bitSet.get(42)) {
      buf.writeByte(nu19);
    }
    if (bitSet.get(43)) {
      itemData.encode(buf);
    }
    if (bitSet.get(44)) {
      for (int i = 0; i < 13; i++) {
        GItem item = equipment[i];
        item.encode(buf);
      }
    }
    if (bitSet.get(45)) {
      byte[] ascii = name.getBytes(Charsets.US_ASCII);
      buf.writeBytes(ascii);
      buf.writeBytes(new byte[16 - name.length()]);
    }
    if (bitSet.get(46)) {
      for (int i = 0; i < 11; i++) {
        buf.writeInt((int) skills[i]);
      }
    }
    if (bitSet.get(47)) {
      buf.writeInt((int) iceBlockFour);
    }

    buf.capacity(buf.writerIndex() + 1);
    if (buf.readerIndex() > 0) {
      Glydar.getServer().getLogger().warning("Data read during encode.");
    }
  }
Пример #23
0
 public InvocationBuilder responseBody(byte[] bytes, String contentType) {
   responseHeaders.add(HttpHeaders.Names.CONTENT_TYPE, contentType);
   responseBody.capacity(bytes.length).writeBytes(bytes);
   return this;
 }
Пример #24
0
 public InvocationBuilder body(byte[] bytes, String contentType) {
   requestHeaders.add(HttpHeaders.Names.CONTENT_TYPE, contentType);
   requestHeaders.add(HttpHeaders.Names.CONTENT_LENGTH, bytes.length);
   requestBody.capacity(bytes.length).writeBytes(bytes);
   return this;
 }
Пример #25
0
  @Override
  @SuppressFBWarnings("DLS_DEAD_LOCAL_STORE")
  public void rewriteClientbound(ByteBuf packet, int oldId, int newId) {
    super.rewriteClientbound(packet, oldId, newId);

    // Special cases
    int readerIndex = packet.readerIndex();
    int packetId = DefinedPacket.readVarInt(packet);
    int packetIdLength = packet.readerIndex() - readerIndex;
    if (packetId == 0x0D /* Collect Item */) {
      DefinedPacket.readVarInt(packet);
      rewriteVarInt(packet, oldId, newId, packet.readerIndex());
    } else if (packetId == 0x1B /* Attach Entity */) {
      rewriteInt(packet, oldId, newId, readerIndex + packetIdLength + 4);
    } else if (packetId == 0x13 /* Destroy Entities */) {
      int count = DefinedPacket.readVarInt(packet);
      int[] ids = new int[count];
      for (int i = 0; i < count; i++) {
        ids[i] = DefinedPacket.readVarInt(packet);
      }
      packet.readerIndex(readerIndex + packetIdLength);
      packet.writerIndex(readerIndex + packetIdLength);
      DefinedPacket.writeVarInt(count, packet);
      for (int id : ids) {
        if (id == oldId) {
          id = newId;
        } else if (id == newId) {
          id = oldId;
        }
        DefinedPacket.writeVarInt(id, packet);
      }
    } else if (packetId == 0x0E /* Spawn Object */) {

      DefinedPacket.readVarInt(packet);
      int type = packet.readUnsignedByte();

      if (type == 60 || type == 90) {
        packet.skipBytes(14);
        int position = packet.readerIndex();
        int readId = packet.readInt();
        int changedId = -1;
        if (readId == oldId) {
          packet.setInt(position, newId);
          changedId = newId;
        } else if (readId == newId) {
          packet.setInt(position, oldId);
          changedId = oldId;
        }
        if (changedId != -1) {
          if (changedId == 0 && readId != 0) { // Trim off the extra data
            packet.readerIndex(readerIndex);
            packet.writerIndex(packet.readableBytes() - 6);
          } else if (changedId != 0 && readId == 0) { // Add on the extra data
            packet.readerIndex(readerIndex);
            packet.capacity(packet.readableBytes() + 6);
            packet.writerIndex(packet.readableBytes() + 6);
          }
        }
      }
    } else if (packetId == 0x0C /* Spawn Player */) {
      DefinedPacket.readVarInt(packet); // Entity ID
      int idLength = packet.readerIndex() - readerIndex - packetIdLength;
      UUID uuid = DefinedPacket.readUUID(packet);
      ProxiedPlayer player;
      if ((player = BungeeCord.getInstance().getPlayerByOfflineUUID(uuid)) != null) {
        int previous = packet.writerIndex();
        packet.readerIndex(readerIndex);
        packet.writerIndex(readerIndex + packetIdLength + idLength);
        DefinedPacket.writeUUID(player.getUniqueId(), packet);
        packet.writerIndex(previous);
      }
    } else if (packetId == 0x42 /* Combat Event */) {
      int event = packet.readUnsignedByte();
      if (event == 1 /* End Combat*/) {
        DefinedPacket.readVarInt(packet);
        rewriteInt(packet, oldId, newId, packet.readerIndex());
      } else if (event == 2 /* Entity Dead */) {
        int position = packet.readerIndex();
        rewriteVarInt(packet, oldId, newId, packet.readerIndex());
        packet.readerIndex(position);
        DefinedPacket.readVarInt(packet);
        rewriteInt(packet, oldId, newId, packet.readerIndex());
      }
    }
    packet.readerIndex(readerIndex);
  }
 @Override
 public ByteBuf capacity(int var1) {
   return a.capacity(var1);
 }