Search in sources :

Example 1 with DataType

use of com.github.dirtpowered.dirtmv.data.protocol.DataType in project DirtMultiversion by DirtPowered.

the class PacketUtil method readModernPacket.

public static PacketData readModernPacket(MinecraftVersion ver, ProtocolState state, PacketInput buf, PacketDirection dir, int id) throws IOException {
    BaseProtocol protocol = ProtocolRegistry.getProtocolFromVersion(ver);
    DataType[] parts = protocol.getStateDependedProtocol().getInstruction(id, state, dir);
    if (parts == null) {
        Logger.warn("Unknown packet id {} ({}), state: {}, direction: {}", StringUtils.intToHexStr(id), id, state, dir);
        return new PacketData(0);
    }
    TypeHolder[] typeHolders = new TypeHolder[parts.length];
    int i = 0;
    while (i < parts.length) {
        DataType dataType = parts[i];
        typeHolders[i] = new TypeHolder(dataType.getType(), dataType.read(buf));
        i++;
    }
    return new PacketData(id, typeHolders);
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) DataType(com.github.dirtpowered.dirtmv.data.protocol.DataType) BaseProtocol(com.github.dirtpowered.dirtmv.data.protocol.BaseProtocol) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Example 2 with DataType

use of com.github.dirtpowered.dirtmv.data.protocol.DataType in project DirtMultiversion by DirtPowered.

the class PacketUtil method readPacket.

public static PacketData readPacket(MinecraftVersion version, PacketInput buffer) throws IOException {
    Preconditions.checkNotNull(version, "Version not provided");
    short packetId = buffer.readUnsignedByte();
    BaseProtocol protocol = ProtocolRegistry.getProtocolFromVersion(version);
    Preconditions.checkNotNull(protocol, "Protocol %s is not registered", version);
    DataType[] parts = protocol.dataTypes[packetId];
    String packetMapping = PreNettyPacketNames.getPacketName(packetId);
    String protocolName = protocol.getClass().getSimpleName();
    Preconditions.checkNotNull(parts, "Unknown packet id %s (%s) in protocol %s", packetId, packetMapping, protocolName);
    TypeHolder[] typeHolders = new TypeHolder[parts.length];
    int i = 0;
    while (i < parts.length) {
        DataType dataType = parts[i];
        typeHolders[i] = new TypeHolder(dataType.getType(), dataType.read(buffer));
        i++;
    }
    return new PacketData(packetId, typeHolders);
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) DataType(com.github.dirtpowered.dirtmv.data.protocol.DataType) BaseProtocol(com.github.dirtpowered.dirtmv.data.protocol.BaseProtocol) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Aggregations

BaseProtocol (com.github.dirtpowered.dirtmv.data.protocol.BaseProtocol)2 DataType (com.github.dirtpowered.dirtmv.data.protocol.DataType)2 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)2 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)2