当前位置: 首页>>代码示例>>Java>>正文


Java PacketBuffer.readBytes方法代码示例

本文整理汇总了Java中io.gomint.jraknet.PacketBuffer.readBytes方法的典型用法代码示例。如果您正苦于以下问题:Java PacketBuffer.readBytes方法的具体用法?Java PacketBuffer.readBytes怎么用?Java PacketBuffer.readBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.gomint.jraknet.PacketBuffer的用法示例。


在下文中一共展示了PacketBuffer.readBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleBatchPacket

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
private void handleBatchPacket(Client client, ByteBuf buf) {
    // Encrypted?
    byte[] input = new byte[buf.readableBytes()];
    buf.readBytes(input);

    if (client.getProtocolEncryption() != null) {
        input = client.getProtocolEncryption().decryptInputFromClient(input);
        if (input == null) {
            disconnectClient(client, "Invalid checksum");
            return;
        }
    }

    byte[] payload = ByteBufUtils.inflate(input);

    PacketBuffer buffer = new PacketBuffer(payload, 0);
    while (buffer.getRemaining() > 0) {
        int packetLength = buffer.readUnsignedVarInt();

        byte[] payloadData = new byte[packetLength];
        buffer.readBytes(payloadData);

        ByteBuf pktBuffer = ByteBufAllocator.DEFAULT.buffer(payloadData.length);
        pktBuffer.writeBytes(payloadData);

        pktBuffer.markReaderIndex();

        handleSocketData(client, pktBuffer);

        if (pktBuffer.readableBytes() > 0) {
            pktBuffer.resetReaderIndex();
            log.warn("Did not read packet ID 0x{} to completion", Integer.toHexString(pktBuffer.readByte()));
        }
    }
}
 
开发者ID:JungleTree,项目名称:JungleTree,代码行数:36,代码来源:JungleConnectivityManager.java

示例2: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.protocol = buffer.readInt();

    // Decompress inner data (i don't know why you compress inside of a Batched Packet but hey)
    this.payload = new byte[buffer.readUnsignedVarInt()];
    buffer.readBytes( this.payload );
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:9,代码来源:PacketLogin.java

示例3: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.data = new byte[buffer.getRemaining()];
    buffer.readBytes( this.data );

    System.out.println( Util.toHexString( this.data ) );
    System.out.println( new String( this.data ) );
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:9,代码来源:PacketDump.java

示例4: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
	this.protocol = buffer.readInt();

	this.payload = new byte[buffer.readUnsignedVarInt()];
	buffer.readBytes( this.payload );
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:8,代码来源:PacketClientHandshake.java

示例5: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.commandName = buffer.readString();
    this.overloadName = buffer.readString();

    this.unknown1 = buffer.readUnsignedVarInt();
    this.unknown2 = buffer.readUnsignedVarInt();

    this.hasOutput = buffer.readBoolean();

    System.out.println( this.unknown1 );
    System.out.println( this.unknown2 );
    System.out.println( this.hasOutput );

    this.clientGuid = buffer.readUnsignedVarLong();

    this.input = buffer.readString();
    this.output = buffer.readString();

    System.out.println( "GUID: " + this.clientGuid );
    System.out.println( "Commandname: " + this.commandName );
    System.out.println( "Overloadname: " + this.overloadName );
    System.out.println( "Input: " + this.input );
    System.out.println( "Output: " + this.output );

    // String next?

    this.data = new byte[buffer.getRemaining()];
    buffer.readBytes( this.data );

    System.out.println( Util.toHexString( this.data ) );
    System.out.println( new String( this.data ) );
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:34,代码来源:PacketCommandStep.java

示例6: handleBatchPacket

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
public static List<PacketBuffer> handleBatchPacket( PacketBuffer buffer, boolean batch ) {
    if ( batch ) {
        return new ArrayList<>();
    }

    int compressedSize = buffer.readInt();              // Compressed payload length (not of interest; only uncompressed size matters)

    InflaterInputStream inflaterInputStream = new InflaterInputStream( new ByteArrayInputStream( buffer.getBuffer(), buffer.getPosition(), compressedSize ) );

    ByteArrayOutputStream bout = new ByteArrayOutputStream( compressedSize );
    byte[] batchIntermediate = new byte[256];

    try {
        int read;
        while ( ( read = inflaterInputStream.read( batchIntermediate ) ) > -1 ) {
            bout.write( batchIntermediate, 0, read );
        }
    } catch ( IOException e ) {
        // Check if we have a debugger attached
        e.printStackTrace();
    }

    List<PacketBuffer> buffers = new ArrayList<>();
    PacketBuffer payloadBuffer = new PacketBuffer( bout.toByteArray(), 0 );
    while ( payloadBuffer.getRemaining() > 0 ) {
        int packetLength = payloadBuffer.readInt();

        byte[] pktData = new byte[packetLength];
        payloadBuffer.readBytes( pktData );

        buffers.add( new PacketBuffer( pktData, 0 ) );
    }

    return buffers;
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:36,代码来源:Util.java

示例7: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.entityId = buffer.readSignedVarLong().longValue();
    buffer.readUnsignedVarLong();

    this.data = new byte[buffer.getRemaining()];
    buffer.readBytes( this.data );
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:9,代码来源:PacketAddItem.java

示例8: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.mode = buffer.readByte();
    this.channel = buffer.readByte();

    // Data mode
    if ( this.mode == 2 ) {
        int dataLength = buffer.readShort();
        this.data = new byte[dataLength];
        buffer.readBytes( this.data );
    }
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:13,代码来源:PacketCustomProtocol.java

示例9: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    // I only care for the entity id long
    this.uuid = buffer.readUUID();
    this.name = buffer.readString();
    this.entityId = buffer.readSignedVarLong().longValue();
    buffer.readUnsignedVarLong();

    this.data = new byte[buffer.getRemaining()];
    buffer.readBytes( this.data );
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:12,代码来源:PacketAddPlayer.java

示例10: send

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
public void send( byte packetId, PacketBuffer buffer ) {
    this.debugger.addPacket( "UpStream", "Client", packetId, buffer );

    byte[] data = new byte[buffer.getRemaining()];
    buffer.readBytes( data );

    PacketBuffer packetBuffer = new PacketBuffer( 64 );
    packetBuffer.writeByte( packetId );
    packetBuffer.writeShort( (short) 0 );
    packetBuffer.writeBytes( data );

    this.packetQueue.add( packetBuffer );
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:14,代码来源:UpstreamConnection.java

示例11: handleBatchPacket

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
/**
 * Handles compressed batch packets directly by decoding their payload.
 *
 * @param buffer The buffer containing the batch packet's data (except packet ID)
 */
private void handleBatchPacket( long currentTimeMillis, PacketBuffer buffer, boolean batch ) {
    if ( batch ) {
        LOGGER.error( "Malformed batch packet payload: Batch packets are not allowed to contain further batch packets" );
        return;
    }

    // Encrypted?
    byte[] input = new byte[buffer.getRemaining()];
    System.arraycopy( buffer.getBuffer(), buffer.getPosition(), input, 0, input.length );
    if ( this.encryptionHandler != null ) {
        input = this.encryptionHandler.decryptInputFromClient( input );
        if ( input == null ) {
            // Decryption error
            disconnect( "Checksum of encrypted packet was wrong" );
            return;
        }
    }

    InflaterInputStream inflaterInputStream = new InflaterInputStream( new ByteArrayInputStream( input ) );

    ByteArrayOutputStream bout = new ByteArrayOutputStream( buffer.getRemaining() );
    byte[] batchIntermediate = new byte[256];

    try {
        int read;
        while ( ( read = inflaterInputStream.read( batchIntermediate ) ) > -1 ) {
            bout.write( batchIntermediate, 0, read );
        }
    } catch ( IOException e ) {
        LOGGER.error( "Failed to decompress batch packet", e );
        return;
    }

    byte[] payload = bout.toByteArray();

    PacketBuffer payloadBuffer = new PacketBuffer( payload, 0 );
    while ( payloadBuffer.getRemaining() > 0 ) {
        int packetLength = payloadBuffer.readUnsignedVarInt();

        byte[] payData = new byte[packetLength];
        payloadBuffer.readBytes( payData );
        PacketBuffer pktBuf = new PacketBuffer( payData, 0 );
        this.handleSocketData( currentTimeMillis, pktBuf, true );

        if ( pktBuf.getRemaining() > 0 ) {
            LOGGER.error( "Malformed batch packet payload: Could not read enclosed packet data correctly: 0x" +
                Integer.toHexString( payData[0] ) + " reamining " + pktBuf.getRemaining() + " bytes" );
            return;
        }
    }
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:57,代码来源:PlayerConnection.java

示例12: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.payload = new byte[buffer.getRemaining()];
    buffer.readBytes( this.payload );
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:6,代码来源:PacketBatch.java

示例13: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.data = new byte[buffer.getRemaining()];
    buffer.readBytes( this.data );
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:6,代码来源:PacketPassthrough.java

示例14: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.protocol = buffer.readInt();
    this.payload = new byte[buffer.readUnsignedVarInt()];
    buffer.readBytes( this.payload );
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:7,代码来源:PacketLogin.java

示例15: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
	this.payload = new byte[buffer.getRemaining()];
	buffer.readBytes( this.payload );
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:6,代码来源:PacketBatch.java


注:本文中的io.gomint.jraknet.PacketBuffer.readBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。