Search in sources :

Example 66 with ByteBufInputStream

use of io.netty.buffer.ByteBufInputStream in project Glowstone by GlowstoneMC.

the class GlowBufUtils method readCompound.

private static CompoundTag readCompound(ByteBuf buf, boolean network) {
    int idx = buf.readerIndex();
    if (buf.readByte() == 0) {
        return null;
    }
    buf.readerIndex(idx);
    try (NbtInputStream str = new NbtInputStream(new ByteBufInputStream(buf), false)) {
        return str.readCompound(network ? new NbtReadLimiter(2097152L) : NbtReadLimiter.UNLIMITED);
    } catch (IOException e) {
        return null;
    }
}
Also used : NbtReadLimiter(net.glowstone.util.nbt.NbtReadLimiter) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) NbtInputStream(net.glowstone.util.nbt.NbtInputStream)

Example 67 with ByteBufInputStream

use of io.netty.buffer.ByteBufInputStream in project minecolonies by Minecolonies.

the class SaveScanMessage method fromBytes.

@Override
public void fromBytes(@NotNull final ByteBuf buf) {
    final PacketBuffer buffer = new PacketBuffer(buf);
    try (ByteBufInputStream stream = new ByteBufInputStream(buffer)) {
        final NBTTagCompound wrapperCompound = CompressedStreamTools.readCompressed(stream);
        nbttagcompound = wrapperCompound.getCompoundTag(TAG_SCHEMATIC);
        fileName = wrapperCompound.getString(TAG_MILLIS);
    } catch (final RuntimeException e) {
        Log.getLogger().info("Structure too big to be processed", e);
    } catch (final IOException e) {
        Log.getLogger().info("Problem at retrieving structure on server.", e);
    }
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) PacketBuffer(net.minecraft.network.PacketBuffer)

Example 68 with ByteBufInputStream

use of io.netty.buffer.ByteBufInputStream in project Fracture by HellFirePvP.

the class PktSyncData method fromBytes.

@Override
public void fromBytes(ByteBuf buf) {
    int size = buf.readInt();
    for (int i = 0; i < size; i++) {
        String key = ByteBufUtils.readString(buf);
        byte providerId = buf.readByte();
        AbstractData.AbstractDataProvider<? extends AbstractData> provider = AbstractData.Registry.getProvider(providerId);
        if (provider == null) {
            Fracture.log.warn("[Fracture] Provider for ID " + providerId + " doesn't exist! Skipping...");
            continue;
        }
        NBTTagCompound cmp;
        try {
            cmp = CompressedStreamTools.read(new ByteBufInputStream(buf), NBTSizeTracker.INFINITE);
        } catch (IOException e) {
            Fracture.log.warn("[Fracture] Provider Compound of " + providerId + " threw an IOException! Skipping...");
            Fracture.log.warn("[Fracture] Exception message: " + e.getMessage());
            continue;
        }
        AbstractData dat = provider.provideNewInstance();
        dat.readRawFromPacket(cmp);
        data.put(key, dat);
    }
}
Also used : AbstractData(hellfirepvp.fracture.common.data.AbstractData) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException)

Example 69 with ByteBufInputStream

use of io.netty.buffer.ByteBufInputStream in project LanternServer by LanternPowered.

the class LanternByteBuffer method readLimitedDataView.

@Nullable
@Override
public DataView readLimitedDataView(int maximumDepth, int maxBytes) {
    final int index = this.buf.readerIndex();
    if (this.buf.readByte() == 0) {
        return null;
    }
    this.buf.readerIndex(index);
    try {
        try (NbtDataContainerInputStream input = new NbtDataContainerInputStream(new LimitInputStream(new ByteBufInputStream(this.buf), maxBytes), false, maximumDepth)) {
            return input.read();
        }
    } catch (IOException e) {
        throw new CodecException(e);
    }
}
Also used : NbtDataContainerInputStream(org.lanternpowered.server.data.persistence.nbt.NbtDataContainerInputStream) CodecException(io.netty.handler.codec.CodecException) LimitInputStream(org.lanternpowered.server.util.io.LimitInputStream) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) IOException(java.io.IOException) Nullable(javax.annotation.Nullable)

Example 70 with ByteBufInputStream

use of io.netty.buffer.ByteBufInputStream in project ArsMagica2 by Mithion.

the class AMPacketProcessorServer method onServerPacketData.

@SubscribeEvent
public void onServerPacketData(ServerCustomPacketEvent event) {
    ByteBufInputStream bbis = new ByteBufInputStream(event.packet.payload());
    byte packetID = -1;
    try {
        if (event.packet.getTarget() != Side.SERVER) {
            return;
        }
        // constant details all packets share:  ID, player, and remaining data
        packetID = bbis.readByte();
        NetHandlerPlayServer srv = (NetHandlerPlayServer) event.packet.handler();
        EntityPlayerMP player = srv.playerEntity;
        byte[] remaining = new byte[bbis.available()];
        bbis.readFully(remaining);
        switch(packetID) {
            case AMPacketIDs.SPELL_SHAPE_GROUP_CHANGE:
                handleCastingModeChange(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.MAGIC_LEVEL_UP:
                handleMagicLevelUp(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SYNC_BETA_PARTICLES:
                handleSyncBetaParticles(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.POSSIBLE_CLIENT_EXPROP_DESYNC:
                handlePossibleClientExpropDesync(remaining);
                break;
            case AMPacketIDs.REQUEST_BETA_PARTICLES:
                handleRequestBetaParticles(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SPELL_CUSTOMIZE:
                handleSpellCustomize(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SPELLBOOK_CHANGE_ACTIVE_SLOT:
                handleSpellBookChangeActiveSlot(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SYNC_SPELL_KNOWLEDGE:
                handleSyncSpellKnowledge(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.DECO_BLOCK_UPDATE:
                handleDecoBlockUpdate(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.INSCRIPTION_TABLE_UPDATE:
                handleInscriptionTableUpdate(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.TK_DISTANCE_SYNC:
                ExtendedProperties.For((EntityPlayerMP) player).TK_Distance = new AMDataReader(remaining).getFloat();
                break;
            case AMPacketIDs.SAVE_KEYSTONE_COMBO:
                handleSaveKeystoneCombo(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SET_KEYSTONE_COMBO:
                handleSetKeystoneCombo(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SET_MAG_WORK_REC:
                handleSetMagiciansWorkbenchRecipe(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.RUNE_BAG_GUI_OPEN:
                handleRuneBagGUIOpen(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.M_BENCH_LOCK_RECIPE:
                handleMBenchLockRecipe(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.IMBUE_ARMOR:
                handleImbueArmor(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.REQUEST_PWR_PATHS:
                handlePowerPathSync(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.SYNC_EXTENDED_PROPS:
                handleExpropOperation(remaining, (EntityPlayerMP) player);
                break;
            case AMPacketIDs.AFFINITY_ACTIVATE:
                handleAffinityActivate(remaining, player);
                break;
        }
    } catch (Throwable t) {
        LogHelper.error("Server Packet Failed to Handle!");
        LogHelper.error("Packet Type: " + packetID);
        t.printStackTrace();
    } finally {
        try {
            if (bbis != null)
                bbis.close();
        } catch (Throwable t) {
            t.printStackTrace();
        }
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ByteBufInputStream(io.netty.buffer.ByteBufInputStream) NetHandlerPlayServer(net.minecraft.network.NetHandlerPlayServer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

ByteBufInputStream (io.netty.buffer.ByteBufInputStream)78 IOException (java.io.IOException)28 ByteBuf (io.netty.buffer.ByteBuf)27 InputStreamReader (java.io.InputStreamReader)18 BadRequestException (co.cask.cdap.common.BadRequestException)16 Reader (java.io.Reader)16 InputStream (java.io.InputStream)15 JsonSyntaxException (com.google.gson.JsonSyntaxException)11 Path (javax.ws.rs.Path)9 ObjectInputStream (java.io.ObjectInputStream)8 DataInputStream (java.io.DataInputStream)7 POST (javax.ws.rs.POST)6 NamespaceId (co.cask.cdap.proto.id.NamespaceId)5 ByteBuffer (java.nio.ByteBuffer)5 Test (org.junit.jupiter.api.Test)5 AuditPolicy (co.cask.cdap.common.security.AuditPolicy)4 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 ByteBufOutputStream (io.netty.buffer.ByteBufOutputStream)4 RpcException (org.apache.drill.exec.rpc.RpcException)4 UnsupportedTypeException (co.cask.cdap.api.data.schema.UnsupportedTypeException)3