Fix Packet Logging

This commit is contained in:
Kam committed 2025-01-29 15:08:24 -05:00
1 parent f573259fd1
commit dcf3a0d8b0
4 files changed
+12 -31

No files matched your search

@@ -21,8 +21,6 @@ public abstract class LargeAbstractPacket extends AbstractPacket {
int totalSize = data.length;
UUID packetId = UUID.randomUUID();
System.out.println("Sending data with packetId: " + packetId + ", totalSize: " + totalSize);
// Break the data into chunks of CHUNK_SIZE bytes each
for (int offset = 0; offset < totalSize; offset += CHUNK_SIZE) {
int chunkSize = Math.min(CHUNK_SIZE, totalSize - offset);
@@ -36,8 +34,6 @@ public abstract class LargeAbstractPacket extends AbstractPacket {
// Write the chunk bytes
out.writeBytes(data, offset, chunkSize);
System.out.println("Sent chunk with offset: " + offset + ", size: " + chunkSize);
}
}
@@ -61,11 +57,6 @@ public abstract class LargeAbstractPacket extends AbstractPacket {
// Read the exact chunk data
ByteBuf chunk = in.readBytes(chunkSize);
System.out.println("Receiving data: packetId=" + packetId
+ ", totalSize=" + totalSize
+ ", offset=" + offset
+ ", chunkSize=" + chunkSize);
// Store the received chunk in a PacketStorage
PacketStorage storage = packetChunks.computeIfAbsent(packetId,
k -> new PacketStorage(Unpooled.buffer(totalSize), 0, totalSize));
@@ -83,8 +74,6 @@ public abstract class LargeAbstractPacket extends AbstractPacket {
// Copy (or slice) the exact bytes, then handle them
ByteBuf completeData = storage.data.copy(0, totalSize);
System.out.println("Received complete data for packetId: " + packetId);
// Clean up and handle
storage.data.release();
handleCompleteData(completeData, player);
@@ -14,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.NetHandlerPlayServer;
import noppes.npcs.CustomNpcs;
import noppes.npcs.LogWriter;
import java.util.*;
import java.util.function.Consumer;
@@ -28,7 +29,7 @@ public final class PacketHandler {
public final static PacketChannel CLIENT_PACKET = new PacketChannel("CNPC+|Client", EnumPacketType.CLIENT);
public final static PacketChannel LARGE_PACKET = new PacketChannel("CNPC+|Large", EnumPacketType.LARGE);
public final static List<PacketChannel> packetChannels = new ArrayList<>();
private final static List<PacketChannel> packetChannels = new ArrayList<>();
public PacketHandler() {
// Register Channels
@@ -89,22 +90,20 @@ public final class PacketHandler {
EnumPacketType packetType = EnumPacketType.values()[packetTypeOrdinal];
PacketChannel packetChannel = getPacketChannel(packetType);
if (packetChannel == null) {
System.err.println("Error: Packet channel is null for packet type: " + packetType);
LogWriter.error("Error: Packet channel is null for packet type: " + packetType);
return;
}
int packetId = buf.readInt();
AbstractPacket abstractPacket = packetChannel.packets.get(packetId);
if (abstractPacket == null) {
System.err.println("Error: Abstract packet is null for packet ID: " + packetId);
LogWriter.error("Error: Abstract packet is null for packet ID: " + packetId);
return;
}
abstractPacket.receiveData(buf, player);
} catch (IndexOutOfBoundsException e) {
System.err.println("Error: IndexOutOfBoundsException in handlePacket: " + e.getMessage());
e.printStackTrace();
LogWriter.error("Error: IndexOutOfBoundsException in handlePacket: " + e.getMessage());
} catch (Exception e) {
System.err.println("Error: Exception in handlePacket: " + e.getMessage());
e.printStackTrace();
LogWriter.error("Error: Exception in handlePacket: " + e.getMessage());
}
}
@@ -118,7 +117,7 @@ public final class PacketHandler {
public void sendToPlayer(AbstractPacket packet, EntityPlayerMP player) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
System.err.println("Error: Event channel is null for packet: " + packet.getClass().getName());
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendPacket(packet, proxyPacket -> eventChannel.sendTo(proxyPacket, player));
@@ -127,7 +126,7 @@ public final class PacketHandler {
public void sendToServer(AbstractPacket packet) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
System.err.println("Error: Event channel is null for packet: " + packet.getClass().getName());
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendPacket(packet, eventChannel::sendToServer);
@@ -136,7 +135,7 @@ public final class PacketHandler {
public void sendToAll(AbstractPacket packet) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
System.err.println("Error: Event channel is null for packet: " + packet.getClass().getName());
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendPacket(packet, eventChannel::sendToAll);
@@ -145,7 +144,7 @@ public final class PacketHandler {
public void sendToAllAround(AbstractPacket packet, NetworkRegistry.TargetPoint point) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
System.err.println("Error: Event channel is null for packet: " + packet.getClass().getName());
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendPacket(packet, proxyPacket -> eventChannel.sendToAllAround(proxyPacket, point));
@@ -154,7 +153,7 @@ public final class PacketHandler {
public void sendToDimension(AbstractPacket packet, int dimensionId) {
FMLEventChannel eventChannel = getEventChannel(packet);
if (eventChannel == null) {
System.err.println("Error: Event channel is null for packet: " + packet.getClass().getName());
LogWriter.error("Error: Event channel is null for packet: " + packet.getClass().getName());
return;
}
sendPacket(packet, proxyPacket -> eventChannel.sendToDimension(proxyPacket, dimensionId));
@@ -45,18 +45,11 @@ public final class LargeScrollDataPacket extends LargeAbstractPacket {
}
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);
System.out.println("getData: Written data to buffer: " + buffer.toString());
return bytes;
}
@Override
protected void handleCompleteData(ByteBuf data, EntityPlayer player) throws IOException {
if (data == null || data.readableBytes() <= 0) {
System.err.println("LargeScrollDataPacket: ByteBuf is empty or already read.");
return;
}
data.readerIndex(0);
System.out.println("handleCompleteData: Reading data from buffer: " + data.toString());
NoppesUtil.setScrollData(data);
}
}
@@ -39,8 +39,8 @@ public final class LargeScrollGroupPacket extends LargeAbstractPacket {
ByteBuf buffer = Unpooled.buffer();
buffer.writeInt(data.size());
for (Map.Entry<String, Integer> entry : data.entrySet()) {
ByteBufUtils.writeString(buffer, entry.getKey());
buffer.writeInt(entry.getValue());
ByteBufUtils.writeString(buffer, entry.getKey());
}
byte[] bytes = new byte[buffer.readableBytes()];
buffer.readBytes(bytes);