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


Java PacketBuffer.readUnsignedVarInt方法代码示例

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


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

示例1: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
/**
 * Deserialize a transaction action
 *
 * @param buffer Data from the packet
 */
public void deserialize( PacketBuffer buffer ) {
    this.sourceType = buffer.readUnsignedVarInt();

    switch ( this.sourceType ) {
        case SOURCE_CONTAINER:
        case SOURCE_WTF_IS_DIS:
            this.windowId = buffer.readSignedVarInt();
            break;
        case SOURCE_WORLD:
            this.unknown = buffer.readUnsignedVarInt();
            break;
        case SOURCE_CREATIVE:
            break;
        default:
            LOGGER.warn( "Unknown source type: " + this.sourceType );
    }

    this.slot = buffer.readUnsignedVarInt();
    this.oldItem = readItemStack( buffer );
    this.newItem = readItemStack( buffer );
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:27,代码来源:PacketInventoryTransaction.java

示例2: deserialize

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

    this.entityType = buffer.readUnsignedVarInt();
    this.x = buffer.readLFloat();
    this.y = buffer.readLFloat();
    this.z = buffer.readLFloat();
    this.velocityX = buffer.readLFloat();
    this.velocityY = buffer.readLFloat();
    this.velocityZ = buffer.readLFloat();
    this.pitch = buffer.readLFloat();
    this.yaw = buffer.readLFloat();

    int amountOfAttributes = buffer.readUnsignedVarInt();
    for ( int i = 0; i < amountOfAttributes; i++ ) {
        this.attributes.add( new Attribute( buffer.readString(), buffer.readLFloat(), buffer.readLFloat(), buffer.readLFloat() ) );
    }

    this.metadataContainer = new MetadataContainer();
    this.metadataContainer.deserialize( buffer );

    buffer.readUnsignedVarInt();
}
 
开发者ID:GoMint,项目名称:ProxProx,代码行数:26,代码来源:PacketAddEntity.java

示例3: 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

示例4: deserialize

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

    this.slots = new int[buffer.readUnsignedVarInt()];
    for ( int i = 0; i < this.slots.length; i++ ) {
        this.slots[i] = buffer.readUnsignedVarInt();
    }

    this.selectHotbarSlot = buffer.readBoolean();
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:13,代码来源:PacketHotbar.java

示例5: 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

示例6: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.flags = buffer.readUnsignedVarInt();
    this.commandPermission = buffer.readUnsignedVarInt();
    this.flags2 = buffer.readUnsignedVarInt();
    this.playerPermission = buffer.readUnsignedVarInt();
    this.customFlags = buffer.readUnsignedVarInt();
    this.entityId = buffer.readLLong();
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:10,代码来源:PacketAdventureSettings.java

示例7: readItemStacks

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
/**
 * Read in a variable amount of itemstacks
 *
 * @param buffer The buffer to read from
 * @return a list of item stacks
 */
ItemStack[] readItemStacks( PacketBuffer buffer ) {
    int count = buffer.readUnsignedVarInt();
    ItemStack[] itemStacks = new ItemStack[count];

    for ( int i = 0; i < count; i++ ) {
        itemStacks[i] = readItemStack( buffer );
    }

    return itemStacks;
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:17,代码来源:Packet.java

示例8: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.flags = buffer.readUnsignedVarInt();
    this.commandPermission = buffer.readUnsignedVarInt();
    this.flags2 = buffer.readUnsignedVarInt();
    this.playerPermission = buffer.readUnsignedVarInt();
    this.customFlags = buffer.readUnsignedVarInt();
    this.entityId = buffer.readLLong();

    System.out.println( this );
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:12,代码来源:PacketAdventureSettings.java

示例9: readGamerules

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
public Map<Gamerule, Object> readGamerules( PacketBuffer buffer ) {
	int amount = buffer.readUnsignedVarInt();
	if ( amount == 0 ) {
		return null;
	}

	Map<Gamerule, Object> gamerules = new HashMap<>();
	for ( int i = 0; i < amount; i++ ) {
		String name = buffer.readString();
		byte type = buffer.readByte();

		Object val = null;
		switch ( type ) {
			case 1:
				val = buffer.readBoolean();
				break;
			case 2:
				val = buffer.readUnsignedVarInt();
				break;
			case 3:
				val = buffer.readLFloat();
				break;
		}

		System.out.println( name + " -> " + String.valueOf( val ) );
	}

	return gamerules;
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:30,代码来源:Packet.java

示例10: readItemStacks

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
/**
 * Read in a variable amount of itemstacks
 *
 * @param buffer The buffer to read from
 * @return a list of itemstacks
 */
public static ItemStack[] readItemStacks( PacketBuffer buffer ) {
	int count = buffer.readUnsignedVarInt();
	ItemStack[] itemStacks = new ItemStack[count];

	for ( int i = 0; i < count; i++ ) {
		itemStacks[i] = readItemStack( buffer );
	}

	return itemStacks;
}
 
开发者ID:GoMint,项目名称:Proxy,代码行数:17,代码来源:Packet.java

示例11: 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

示例12: 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

示例13: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
/**
 * Deserializes this metadata container from the specified buffer.
 *
 * @param buffer The buffer to deserialize this metadata container from
 * @return Whether or not the metadata container could be deserialized successfully
 */
public boolean deserialize( PacketBuffer buffer ) {
    this.entries.clear();

    int size = buffer.readUnsignedVarInt();
    for ( int i = 0; i < size; i++ ) {
        int index = buffer.readUnsignedVarInt();
        int type = buffer.readUnsignedVarInt();

        MetadataValue value = null;
        switch ( type ) {
            case METADATA_BYTE:
                value = new MetadataByte();
                break;
            case METADATA_SHORT:
                value = new MetadataShort();
                break;
            case METADATA_INT:
                value = new MetadataInt();
                break;
            case METADATA_FLOAT:
                value = new MetadataFloat();
                break;
            case METADATA_STRING:
                value = new MetadataString();
                break;
            case METADATA_ITEM:
                value = new MetadataItem();
                break;
            case METADATA_POSITION:
                value = new MetadataPosition();
                break;
            case METADATA_LONG:
                value = new MetadataLong();
                break;
            case METADATA_VECTOR:
                value = new MetadataVector();
                break;
        }

        if ( value == null ) {
            return false;
        }

        value.deserialize( buffer );
        this.entries.justPut( (byte) index, value );
    }

    return true;
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:56,代码来源:MetadataContainer.java

示例14: 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

示例15: deserialize

import io.gomint.jraknet.PacketBuffer; //导入方法依赖的package包/类
@Override
public void deserialize( PacketBuffer buffer ) {
    this.windowId = buffer.readUnsignedVarInt();
    this.slot = buffer.readUnsignedVarInt();
    this.itemStack = readItemStack( buffer );
}
 
开发者ID:GoMint,项目名称:GoMint,代码行数:7,代码来源:PacketInventorySetSlot.java


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