private String translateToString(Packet packet, int pos) { String ptr = " "; if (pos == currentIndex) ptr = " \2474"; if (packet == null) return (count + pos) + "null:[]"; String trans = ptr + (count + pos) + "\247r: " + packet.getClass().getSimpleName() + ": ["; int vars = 0; for (Field f : packet.getClass().getDeclaredFields()) { if (!Modifier.isStatic(f.getModifiers())) { if (!f.isAccessible()) f.setAccessible(true); try { Object obj = f.get(packet); String value = "null"; if (obj != null) value = obj.toString(); trans += " f" + vars + "=" + value + ","; } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } } if (trans.endsWith(",")) { trans = trans.substring(0, trans.length() - 1); } trans += "]"; return trans; }
@EventTarget public synchronized void onPacketSend(PacketSendEvent event) { if (currentIndex >= packets.length) { renderer.count += currentIndex; currentIndex = 0; } Packet packet = event.getPacket(); if (!blacklist.contains(packet.getClass().getSimpleName())) { synchronized (packets) { packets[currentIndex++] = packet; } } }
protected void decode(ChannelHandlerContext p_decode_1_, ByteBuf p_decode_2_, List p_decode_3_) throws IOException, InstantiationException, IllegalAccessException { if (p_decode_2_.readableBytes() != 0) { PacketBuffer var4 = new PacketBuffer(p_decode_2_); int var5 = var4.readVarIntFromBuffer(); Packet var6 = ((EnumConnectionState) p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()) .getPacket(this.direction, var5); if (var6 == null) { throw new IOException("Bad packet id " + var5); } else { var6.readPacketData(var4); if (var4.readableBytes() > 0) { throw new IOException( "Packet " + ((EnumConnectionState) p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get()) .getId() + "/" + var5 + " (" + var6.getClass().getSimpleName() + ") was larger than I expected, found " + var4.readableBytes() + " bytes extra whilst reading packet " + var5); } else { p_decode_3_.add(var6); if (logger.isDebugEnabled()) { logger.debug( RECEIVED_PACKET_MARKER, " IN: [{}:{}] {}", new Object[] { p_decode_1_.channel().attr(NetworkManager.attrKeyConnectionState).get(), Integer.valueOf(var5), var6.getClass().getName() }); } } } } }
private boolean handleVanilla(Packet msg) { if (state == ConnectionState.AWAITING_HANDSHAKE && msg instanceof S01PacketJoinGame) { handshakeChannel.pipeline().fireUserEventTriggered(msg); } else { FMLLog.info( "Unexpected packet during modded negotiation - assuming vanilla or keepalives : %s", msg.getClass().getName()); } return false; }
@Override public void toBytes(ByteBuf buf) { buf.writeInt(((ISegment) world).getIDNumber()); buf.writeInt((EnumConnectionState.PLAY.getPacketId(EnumPacketDirection.SERVERBOUND, packet))); try { packet.writePacketData(new PacketBuffer(buf)); } catch (IOException e) { throw new RuntimeException("Error in encoding packet: " + e); } }
@Override public void fromBytes(ByteBuf buf) { world = DimensionManager.getWorld(buf.readInt()); try { packet = EnumConnectionState.PLAY.getPacket(EnumPacketDirection.SERVERBOUND, buf.readInt()); packet.readPacketData(new PacketBuffer(buf)); } catch (InstantiationException | IllegalAccessException | IOException e) { throw new DecoderException(e); } }