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;
}
}
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);
}
}
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);
}
}
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);
}
}
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();
}
}
}
Aggregations