本文整理汇总了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()));
}
}
}
示例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 );
}
示例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 ) );
}
示例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 );
}
示例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 ) );
}
示例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;
}
示例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 );
}
示例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 );
}
}
示例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 );
}
示例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 );
}
示例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;
}
}
}
示例12: deserialize
import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
this.payload = new byte[buffer.getRemaining()];
buffer.readBytes( this.payload );
}
示例13: deserialize
import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
this.data = new byte[buffer.getRemaining()];
buffer.readBytes( this.data );
}
示例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 );
}
示例15: deserialize
import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
this.payload = new byte[buffer.getRemaining()];
buffer.readBytes( this.payload );
}