@Override
    public OFQueueOpFailedErrorMsg readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 4
      byte version = bb.readByte();
      if (version != (byte) 0x4)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_13(4), got=" + version);
      // fixed value property type == 1
      byte type = bb.readByte();
      if (type != (byte) 0x1)
        throw new OFParseError("Wrong type: Expected=OFType.ERROR(1), got=" + type);
      int length = U16.f(bb.readShort());
      if (length < MINIMUM_LENGTH)
        throw new OFParseError(
            "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property errType == 9
      short errType = bb.readShort();
      if (errType != (short) 0x9)
        throw new OFParseError(
            "Wrong errType: Expected=OFErrorType.QUEUE_OP_FAILED(9), got=" + errType);
      OFQueueOpFailedCode code = OFQueueOpFailedCodeSerializerVer13.readFrom(bb);
      byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start));

      OFQueueOpFailedErrorMsgVer13 queueOpFailedErrorMsgVer13 =
          new OFQueueOpFailedErrorMsgVer13(xid, code, data);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", queueOpFailedErrorMsgVer13);
      return queueOpFailedErrorMsgVer13;
    }
    @Override
    public OFEchoRequest readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 1
      byte version = bb.readByte();
      if (version != (byte) 0x1)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_10(1), got=" + version);
      // fixed value property type == 2
      byte type = bb.readByte();
      if (type != (byte) 0x2)
        throw new OFParseError("Wrong type: Expected=OFType.ECHO_REQUEST(2), got=" + type);
      int length = U16.f(bb.readShort());
      if (length < MINIMUM_LENGTH)
        throw new OFParseError(
            "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      byte[] data = ChannelUtils.readBytes(bb, length - (bb.readerIndex() - start));

      OFEchoRequestVer10 echoRequestVer10 = new OFEchoRequestVer10(xid, data);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", echoRequestVer10);
      return echoRequestVer10;
    }
 @Override
 public void readFrom(ChannelBuffer data) {
   super.readFrom(data);
   this.virtualLanPriorityCodePoint = data.readByte();
   data.readShort(); // pad
   data.readByte(); // pad
 }
Пример #4
0
  /**
   * Returns linked list of sub objects.
   *
   * @param cb of type channel buffer
   * @return linked list of sub objects
   * @throws PcepParseException while parsing subobjects from channel buffer
   */
  protected static LinkedList<PcepValueType> parseSubObjects(ChannelBuffer cb)
      throws PcepParseException {

    LinkedList<PcepValueType> llSubObjects = new LinkedList<PcepValueType>();

    while (0 < cb.readableBytes()) {

      // check the Type of the Subobjects.
      byte yType = cb.readByte();
      yType = (byte) (yType & (YTYPE_SHIFT_VALUE));
      byte hLength = cb.readByte();

      PcepValueType subObj;
      switch (yType) {
        case IPv4SubObject.TYPE:
          subObj = IPv4SubObject.read(cb);
          break;

        default:
          throw new PcepParseException("Invalid sub object. Type: " + (int) yType);
      }

      // Check for the padding
      int pad = hLength % 4;
      if (0 < pad) {
        pad = 4 - pad;
        if (pad <= cb.readableBytes()) {
          cb.skipBytes(pad);
        }
      }
      llSubObjects.add(subObj);
    }
    return llSubObjects;
  }
Пример #5
0
 @Override
 protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
     throws Exception {
   if (opcode == -1) {
     if (buffer.readableBytes() >= 1) {
       opcode = buffer.readByte() & 0xFF;
       opcode = (opcode - cipher.getNextValue()) & 0xFF;
       size = Client.PACKET_SIZES[opcode];
     } else {
       return null;
     }
   }
   if (size == -1) {
     if (buffer.readableBytes() >= 1) {
       size = buffer.readByte() & 0xFF;
     } else {
       return null;
     }
   }
   if (buffer.readableBytes() >= size) {
     final byte[] data = new byte[size];
     buffer.readBytes(data);
     final ChannelBuffer payload = ChannelBuffers.buffer(size);
     payload.writeBytes(data);
     try {
       return new Packet(opcode, Type.FIXED, payload);
     } finally {
       opcode = -1;
       size = -1;
     }
   }
   return null;
 }
Пример #6
0
 private String readLine(ChannelBuffer buffer, int maxLineLength) throws TooLongFrameException {
   StringBuilder sb = new StringBuilder(64);
   int lineLength = 0;
   while (true) {
     byte nextByte = buffer.readByte();
     if (nextByte == HttpCodecUtil.CR) {
       nextByte = buffer.readByte();
       if (nextByte == HttpCodecUtil.LF) {
         return sb.toString();
       }
     } else if (nextByte == HttpCodecUtil.LF) {
       return sb.toString();
     } else {
       if (lineLength >= maxLineLength) {
         // TODO: Respond with Bad Request and discard the traffic
         // or close the connection.
         // No need to notify the upstream handlers - just log.
         // If decoding a response, just throw an exception.
         throw new TooLongFrameException(
             "An HTTP line is larger than " + maxLineLength + " bytes.");
       }
       lineLength++;
       sb.append((char) nextByte);
     }
   }
 }
Пример #7
0
  @Test
  public void testEndianness() {
    ChannelBuffer buffer;
    int value = 12;

    // ByteOrder.BIG_ENDIAN
    buffer = ChannelBuffers.buffer(ByteOrder.BIG_ENDIAN, 4);
    buffer.writeInt(value);
    for (int i = 0; i < 4; i++) {
      byte b = buffer.readByte();
      System.out.println(b);
    }

    // ByteOrder.LITTLE_ENDIAN
    buffer = ChannelBuffers.buffer(ByteOrder.LITTLE_ENDIAN, 4);
    buffer.writeInt(value);
    for (int i = 0; i < 4; i++) {
      byte b = buffer.readByte();
      System.out.println(b);
    }

    // ByteOrder.nativeOrder()
    buffer = ChannelBuffers.buffer(ByteOrder.nativeOrder(), 4);
    buffer.writeInt(value);
    for (int i = 0; i < 4; i++) {
      byte b = buffer.readByte();
      System.out.println(b);
    }
  }
Пример #8
0
  /**
   * Reads from the channel buffer and returns Object of PcepTEObject.
   *
   * @param cb of type channel buffer
   * @return Object of PcepTEObject
   * @throws PcepParseException if mandatory fields are missing
   */
  public static PcepTEObject read(ChannelBuffer cb) throws PcepParseException {
    log.debug("read");

    PcepObjectHeader teObjHeader;
    byte yProtocolId;
    // 2-flags
    boolean bRFlag;
    boolean bSFlag;
    int iTEId;
    LinkedList<PcepValueType> llOptionalTlv;

    teObjHeader = PcepObjectHeader.read(cb);

    // take only TEObject buffer.
    ChannelBuffer tempCb = cb.readBytes(teObjHeader.getObjLen() - OBJECT_HEADER_LENGTH);

    yProtocolId = tempCb.readByte();
    // ignore first two bytes of Flags
    tempCb.readShort();

    Integer iTemp = (int) tempCb.readByte(); // read 3rd byte Flag
    bSFlag = ((iTemp & FLAG_SET_S_FLAG) == FLAG_SET_S_FLAG) ? true : false;
    bRFlag = ((iTemp & FLAG_SET_R_FLAG) == FLAG_SET_R_FLAG) ? true : false;

    iTEId = tempCb.readInt();

    // parse optional TLV
    llOptionalTlv = parseOptionalTlv(tempCb);

    return new PcepTEObjectVer1(teObjHeader, yProtocolId, bRFlag, bSFlag, iTEId, llOptionalTlv);
  }
  /**
   * Handles a received {@link MBeanServerConnection} invocation
   *
   * @param channel The channel the request was received on
   * @param remoteAddress The remote address of the caller
   * @param buffer THe buffer received
   */
  public static void handleJMXRequest(
      Channel channel, SocketAddress remoteAddress, ChannelBuffer buffer) {
    buffer.resetReaderIndex();
    /* The request write */
    //		cb.writeByte(OpCode.JMX_REQUEST.op());  // 1
    //		cb.writeBytes(domainInfoData);   // domain data
    //		cb.writeInt(reqId);					// 4
    //		cb.writeByte(methodToKey.get(method)); // 1
    //		cb.writeInt(sargs.length);  			// 4
    //		cb.writeBytes(sargs);		           // sargs.length
    Object result = null;
    MBeanServerConnection server = null;
    buffer.skipBytes(1);
    byte domainIndicator = buffer.readByte();
    if (domainIndicator == 0) {
      server = JMXHelper.getHeliosMBeanServer();
    } else {
      byte[] domainBytes = new byte[domainIndicator];
      buffer.readBytes(domainBytes);
      String domain = new String(domainBytes);
      server = JMXHelper.getLocalMBeanServer(true, domain);
      if (server == null) {
        result = new SmallException("Failed to locate MBeanServer for domain [" + domain + "]");
      }
    }
    int reqId = buffer.readInt();
    byte methodId = buffer.readByte();
    if (result == null) {
      int payloadSize = buffer.readInt();
      byte[] payload = new byte[payloadSize];
      buffer.readBytes(payload);
      Object[] params = getInput(payload);
      Method targetMethod = null;
      try {
        targetMethod = keyToMethod.get(methodId);
        if (targetMethod == null) {
          result =
              new SmallException(
                  "Failed to handle MBeanServerConnection invocation because method Op Code ["
                      + methodId
                      + "] was not recognized");
        } else {
          if ("addNotificationListener".equals(targetMethod.getName())
              && !targetMethod.getParameterTypes()[1].equals(ObjectName.class)) {

          } else if ("removeNotificationListener".equals(targetMethod.getName())
              && !targetMethod.getParameterTypes()[1].equals(ObjectName.class)) {

          } else {
            result = targetMethod.invoke(server, params);
          }
        }
      } catch (Throwable t) {
        SimpleLogger.warn("Failed to invoke [", targetMethod, "]", t);
        result = new SmallException(t.toString());
      }
    }
    writeJMXResponse(reqId, methodId, channel, remoteAddress, result);
  }
Пример #10
0
 @Override
 public void readBody(ChannelBuffer buffer)
     throws UnrecoverablePduException, RecoverablePduException {
   this.messageId = ChannelBufferUtil.readNullTerminatedString(buffer);
   this.finalDate = ChannelBufferUtil.readNullTerminatedString(buffer);
   this.messageState = buffer.readByte();
   this.errorCode = buffer.readByte();
 }
Пример #11
0
  @Override
  public PlayerRotationMessage decode(ChannelBuffer buffer) throws IOException {
    byte playerId = buffer.readByte();
    float yaw = (buffer.readByte() * 360) / 256f;
    float pitch = (buffer.readByte() * 360) / 256f;

    return new PlayerRotationMessage(playerId, yaw, pitch);
  }
Пример #12
0
 @Override
 public RespawnMessage decode(ChannelBuffer buffer) throws IOException {
   int dimension = buffer.readInt();
   byte difficulty = buffer.readByte();
   byte mode = buffer.readByte();
   int worldHeight = ChannelBufferUtils.getExpandedHeight(buffer.readShort());
   String worldType = ChannelBufferUtils.readString(buffer);
   return new RespawnMessage(dimension, difficulty, mode, worldHeight, worldType);
 }
    @Override
    public OFGroupFeaturesStatsReply readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 3
      byte version = bb.readByte();
      if (version != (byte) 0x3)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_12(3), got=" + version);
      // fixed value property type == 19
      byte type = bb.readByte();
      if (type != (byte) 0x13)
        throw new OFParseError("Wrong type: Expected=OFType.STATS_REPLY(19), got=" + type);
      int length = U16.f(bb.readShort());
      if (length != 56) throw new OFParseError("Wrong length: Expected=56(56), got=" + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property statsType == 8
      short statsType = bb.readShort();
      if (statsType != (short) 0x8)
        throw new OFParseError(
            "Wrong statsType: Expected=OFStatsType.GROUP_FEATURES(8), got=" + statsType);
      Set<OFStatsReplyFlags> flags = OFStatsReplyFlagsSerializerVer12.readFrom(bb);
      // pad: 4 bytes
      bb.skipBytes(4);
      long types = U32.f(bb.readInt());
      long capabilities = U32.f(bb.readInt());
      long maxGroupsAll = U32.f(bb.readInt());
      long maxGroupsSelect = U32.f(bb.readInt());
      long maxGroupsIndirect = U32.f(bb.readInt());
      long maxGroupsFf = U32.f(bb.readInt());
      long actionsAll = U32.f(bb.readInt());
      long actionsSelect = U32.f(bb.readInt());
      long actionsIndirect = U32.f(bb.readInt());
      long actionsFf = U32.f(bb.readInt());

      OFGroupFeaturesStatsReplyVer12 groupFeaturesStatsReplyVer12 =
          new OFGroupFeaturesStatsReplyVer12(
              xid,
              flags,
              types,
              capabilities,
              maxGroupsAll,
              maxGroupsSelect,
              maxGroupsIndirect,
              maxGroupsFf,
              actionsAll,
              actionsSelect,
              actionsIndirect,
              actionsFf);
      if (logger.isTraceEnabled()) logger.trace("readFrom - read={}", groupFeaturesStatsReplyVer12);
      return groupFeaturesStatsReplyVer12;
    }
Пример #14
0
 @Override
 public BlockActionMessage decode(ChannelBuffer buffer) throws IOException {
   int x = buffer.readInt();
   int y = buffer.readUnsignedShort();
   int z = buffer.readInt();
   byte firstByte = buffer.readByte();
   byte secondByte = buffer.readByte();
   short blockId = buffer.readShort();
   return new BlockActionMessage(x, y, z, blockId, firstByte, secondByte);
 }
 @Override
 public RelativeEntityPositionRotationMessage decode(ChannelBuffer buffer) throws IOException {
   int id = buffer.readInt();
   int dx = buffer.readByte();
   int dy = buffer.readByte();
   int dz = buffer.readByte();
   int rotation = buffer.readUnsignedByte();
   int pitch = buffer.readUnsignedByte();
   return new RelativeEntityPositionRotationMessage(id, dx, dy, dz, rotation, pitch);
 }
Пример #16
0
 /* This is needed for tests to complete. It is not actually used.
  * See the commented-out code below this function */
 @Override
 public PlayerLoginRequestMessage decodeFromClient(ChannelBuffer buffer) {
   int id = buffer.readInt();
   String worldType = ChannelBufferUtils.readString(buffer);
   byte mode = buffer.readByte();
   byte dimension = buffer.readByte();
   byte difficulty = buffer.readByte();
   buffer.readUnsignedByte(); // not used?
   short maxPlayers = buffer.readUnsignedByte();
   return new PlayerLoginRequestMessage(id, worldType, mode, dimension, difficulty, maxPlayers);
 }
Пример #17
0
  @Override
  public PlayerSpawnMessage decode(ChannelBuffer buffer) throws IOException {
    byte playerId = buffer.readByte();
    String name = ChannelBufferUtils.readString(buffer);
    float x = buffer.readShort() / 32;
    float y = buffer.readShort() / 32;
    float z = buffer.readShort() / 32;
    float yaw = (buffer.readByte() * 360) / 256f;
    float pitch = (buffer.readByte() * 360) / 256f;

    return new PlayerSpawnMessage(playerId, name, x, y, z, yaw, pitch);
  }
Пример #18
0
  protected void handleRequest(ChannelBuffer buffer, final Channel channel) {
    Byte continuation = readContinuationHeader(buffer, channel);
    if (continuation == null) {
      return;
    }
    if (continuation == ChunkingChannelBuffer.CONTINUATION_MORE) {
      PartialRequest partialRequest = partialRequests.get(channel);
      if (partialRequest == null) {
        // This is the first chunk in a multi-chunk request
        RequestType<T> type = getRequestContext(buffer.readByte());
        RequestContext context = readContext(buffer);
        ChannelBuffer targetBuffer = mapSlave(channel, context);
        partialRequest = new PartialRequest(type, context, targetBuffer);
        partialRequests.put(channel, partialRequest);
      }
      partialRequest.add(buffer);
    } else {
      PartialRequest partialRequest = partialRequests.remove(channel);
      RequestType<T> type;
      RequestContext context;
      ChannelBuffer targetBuffer;
      ChannelBuffer bufferToReadFrom;
      ChannelBuffer bufferToWriteTo;
      if (partialRequest == null) {
        // This is the one and single chunk in the request
        type = getRequestContext(buffer.readByte());
        context = readContext(buffer);
        targetBuffer = mapSlave(channel, context);
        bufferToReadFrom = buffer;
        bufferToWriteTo = targetBuffer;
      } else {
        // This is the last chunk in a multi-chunk request
        type = partialRequest.type;
        context = partialRequest.context;
        targetBuffer = partialRequest.buffer;
        partialRequest.add(buffer);
        bufferToReadFrom = targetBuffer;
        bufferToWriteTo = ChannelBuffers.dynamicBuffer();
      }

      bufferToWriteTo.clear();
      final ChunkingChannelBuffer chunkingBuffer =
          new ChunkingChannelBuffer(
              bufferToWriteTo,
              channel,
              chunkSize,
              getInternalProtocolVersion(),
              applicationProtocolVersion);
      submitSilent(
          targetCallExecutor,
          targetCaller(type, channel, context, chunkingBuffer, bufferToReadFrom));
    }
  }
Пример #19
0
  /**
   * Reads from the channel buffer and parses AsPath.
   *
   * @param cb ChannelBuffer
   * @return object of AsPath
   * @throws BgpParseException while parsing AsPath
   */
  public static AsPath read(ChannelBuffer cb) throws BgpParseException {
    List<Short> aspathSet = new ArrayList<>();
    List<Short> aspathSeq = new ArrayList<>();
    ChannelBuffer tempCb = cb.copy();
    Validation validation = Validation.parseAttributeHeader(cb);

    if (cb.readableBytes() < validation.getLength()) {
      Validation.validateLen(
          BgpErrorType.UPDATE_MESSAGE_ERROR,
          BgpErrorType.ATTRIBUTE_LENGTH_ERROR,
          validation.getLength());
    }
    // if fourth bit is set, length is read as short otherwise as byte , len includes type, length
    // and value
    int len =
        validation.isShort()
            ? validation.getLength() + Constants.TYPE_AND_LEN_AS_SHORT
            : validation.getLength() + Constants.TYPE_AND_LEN_AS_BYTE;
    ChannelBuffer data = tempCb.readBytes(len);
    if (validation.getFirstBit() && !validation.getSecondBit() && validation.getThirdBit()) {
      throw new BgpParseException(
          BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_FLAGS_ERROR, data);
    }

    ChannelBuffer tempBuf = cb.readBytes(validation.getLength());
    while (tempBuf.readableBytes() > 0) {
      byte pathSegType = tempBuf.readByte();
      // no of ASes
      byte pathSegLen = tempBuf.readByte();
      int length = pathSegLen * ASNUM_SIZE;
      if (tempBuf.readableBytes() < length) {
        Validation.validateLen(
            BgpErrorType.UPDATE_MESSAGE_ERROR, BgpErrorType.ATTRIBUTE_LENGTH_ERROR, length);
      }
      ChannelBuffer aspathBuf = tempBuf.readBytes(length);
      while (aspathBuf.readableBytes() > 0) {
        short asNum;
        asNum = aspathBuf.readShort();
        switch (pathSegType) {
          case ASPATH_SET_TYPE:
            aspathSet.add(asNum);
            break;
          case ASPATH_SEQ_TYPE:
            aspathSeq.add(asNum);
            break;
          default:
            log.debug("Other type Not Supported:" + pathSegType);
        }
      }
    }
    return new AsPath(aspathSet, aspathSeq);
  }
    @Override
    public OFBsnGentableBucketStatsReply readFrom(ChannelBuffer bb) throws OFParseError {
      int start = bb.readerIndex();
      // fixed value property version == 4
      byte version = bb.readByte();
      if (version != (byte) 0x4)
        throw new OFParseError("Wrong version: Expected=OFVersion.OF_13(4), got=" + version);
      // fixed value property type == 19
      byte type = bb.readByte();
      if (type != (byte) 0x13)
        throw new OFParseError("Wrong type: Expected=OFType.STATS_REPLY(19), got=" + type);
      int length = U16.f(bb.readShort());
      if (length < MINIMUM_LENGTH)
        throw new OFParseError(
            "Wrong length: Expected to be >= " + MINIMUM_LENGTH + ", was: " + length);
      if (bb.readableBytes() + (bb.readerIndex() - start) < length) {
        // Buffer does not have all data yet
        bb.readerIndex(start);
        return null;
      }
      if (logger.isTraceEnabled()) logger.trace("readFrom - length={}", length);
      long xid = U32.f(bb.readInt());
      // fixed value property statsType == 65535
      short statsType = bb.readShort();
      if (statsType != (short) 0xffff)
        throw new OFParseError(
            "Wrong statsType: Expected=OFStatsType.EXPERIMENTER(65535), got=" + statsType);
      Set<OFStatsReplyFlags> flags = OFStatsReplyFlagsSerializerVer13.readFrom(bb);
      // pad: 4 bytes
      bb.skipBytes(4);
      // fixed value property experimenter == 0x5c16c7L
      int experimenter = bb.readInt();
      if (experimenter != 0x5c16c7)
        throw new OFParseError(
            "Wrong experimenter: Expected=0x5c16c7L(0x5c16c7L), got=" + experimenter);
      // fixed value property subtype == 0x5L
      int subtype = bb.readInt();
      if (subtype != 0x5)
        throw new OFParseError("Wrong subtype: Expected=0x5L(0x5L), got=" + subtype);
      List<OFBsnGentableBucketStatsEntry> entries =
          ChannelUtils.readList(
              bb, length - (bb.readerIndex() - start), OFBsnGentableBucketStatsEntryVer13.READER);

      OFBsnGentableBucketStatsReplyVer13 bsnGentableBucketStatsReplyVer13 =
          new OFBsnGentableBucketStatsReplyVer13(xid, flags, entries);
      if (logger.isTraceEnabled())
        logger.trace("readFrom - read={}", bsnGentableBucketStatsReplyVer13);
      return bsnGentableBucketStatsReplyVer13;
    }
Пример #21
0
 /**
  * @param headerLength
  * @param middleLength
  * @param endLength
  * @param buf
  * @return the new AuthentPacket from buffer
  * @throws OpenR66ProtocolPacketException
  */
 public static AuthentPacket createFromBuffer(
     int headerLength, int middleLength, int endLength, ChannelBuffer buf)
     throws OpenR66ProtocolPacketException {
   if (headerLength - 1 <= 0) {
     throw new OpenR66ProtocolPacketException("Not enough data");
   }
   if (middleLength <= 0) {
     throw new OpenR66ProtocolPacketException("Not enough data");
   }
   if (endLength < 5) {
     throw new OpenR66ProtocolPacketException("Not enough data");
   }
   final byte[] bheader = new byte[headerLength - 1];
   final byte[] bmiddle = new byte[middleLength];
   if (headerLength - 1 > 0) {
     buf.readBytes(bheader);
   }
   if (middleLength > 0) {
     buf.readBytes(bmiddle);
   }
   // end part
   Integer newId = buf.readInt();
   byte valid = buf.readByte();
   String version =
       R66Versions.V2_4_12.getVersion(); // first base reference where it is unacceptable
   if (endLength > 5) {
     // version
     byte[] bversion = new byte[endLength - 5];
     buf.readBytes(bversion);
     version = new String(bversion);
   }
   final String sheader = new String(bheader);
   return new AuthentPacket(sheader, bmiddle, newId, valid, version);
 }
Пример #22
0
 private static boolean maybeSsl(final ChannelBuffer buffer) {
   buffer.markReaderIndex();
   final StringBuffer sb = new StringBuffer();
   for (int lineLength = 0; lineLength++ < 3; sb.append((char) buffer.readByte())) ;
   buffer.resetReaderIndex();
   return !httpVerbPrefix.contains(sb.toString());
 }
Пример #23
0
 @Override
 public EntityObjectMessage decode(ChannelBuffer buffer) throws IOException {
   int entityId = buffer.readInt();
   byte type = buffer.readByte();
   int x = buffer.readInt();
   int y = buffer.readInt();
   int z = buffer.readInt();
   int throwerId = buffer.readInt();
   if (throwerId > 0) {
     short speedX = buffer.readShort();
     short speedY = buffer.readShort();
     short speedZ = buffer.readShort();
     return new EntityObjectMessage(
         entityId,
         type,
         x,
         y,
         z,
         throwerId,
         speedX,
         speedY,
         speedZ,
         NullRepositionManager.getInstance());
   }
   return new EntityObjectMessage(
       entityId, type, x, y, z, throwerId, NullRepositionManager.getInstance());
 }
Пример #24
0
 @Override
 public PlayerListMessage decode(ChannelBuffer buffer) throws IOException {
   String name = ChannelBufferUtils.readString(buffer);
   boolean addOrRemove = buffer.readByte() == 1;
   short ping = buffer.readShort();
   return new PlayerListMessage(name, addOrRemove, ping);
 }
Пример #25
0
 @Override
 public LoadChunkMessage decode(ChannelBuffer buffer) {
   int x = buffer.readInt();
   int z = buffer.readInt();
   boolean loaded = buffer.readByte() == 1;
   return new LoadChunkMessage(x, z, loaded);
 }
 private Object processHandshake(Channel channel, ChannelBuffer buf) {
   buf.readByte(); // semicolon symbol
   if (identify(buf.toString(Charset.defaultCharset()), channel)) {
     sendReply(channel, ChannelBuffers.copiedBuffer(ByteOrder.LITTLE_ENDIAN, "*<S", CHARSET));
   }
   return null;
 }
  @Override
  protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buffer)
      throws Exception {
    buffer.markReaderIndex();
    final byte[] buf = new byte[5];
    for (int i = 0; i < buf.length; i++) {
      if (!buffer.readable()) {
        buffer.resetReaderIndex();
        return null;
      }

      buf[i] = buffer.readByte();
      if (buf[i] >= 0) {
        int length = CodedInputStream.newInstance(buf, 0, i + 1).readRawVarint32();
        if (length < 0) {
          throw new CorruptedFrameException("negative length: " + length);
        }

        if (buffer.readableBytes() < length) {
          buffer.resetReaderIndex();
          return null;
        } else {
          return buffer.readBytes(length);
        }
      }
    }

    // Couldn't find the byte whose MSB is off.
    throw new CorruptedFrameException("length wider than 32-bit");
  }
 @Override
 public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
   ChannelBuffer buf = (ChannelBuffer) e.getMessage();
   while (buf.readable()) {
     System.out.println((char) buf.readByte());
     System.out.flush();
   }
 }
Пример #29
0
 /**
  * Read byte from this packet buffer.
  *
  * @return int
  */
 protected final int readC() {
   try {
     return buf.readByte() & 0xFF;
   } catch (Exception e) {
     log.error("Missing C for: " + this);
   }
   return 0;
 }
Пример #30
0
 public static String readRS2String(ChannelBuffer buffer) {
   StringBuilder sb = new StringBuilder();
   byte b;
   while (buffer.readable() && (b = buffer.readByte()) != 0) {
     sb.append((char) b);
   }
   return sb.toString();
 }