mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-30 20:11:26 +01:00
Better warning message when a packet is not fully read
This commit is contained in:
parent
facc43e550
commit
868f921b94
@ -16,6 +16,9 @@ public final class OptifineSupport {
|
|||||||
|
|
||||||
private static volatile boolean enabled;
|
private static volatile boolean enabled;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enables optifine support by registering the required biomes.
|
||||||
|
*/
|
||||||
public static void enable() {
|
public static void enable() {
|
||||||
Check.stateCondition(enabled, "Optifine support is already enabled!");
|
Check.stateCondition(enabled, "Optifine support is already enabled!");
|
||||||
OptifineSupport.enabled = true;
|
OptifineSupport.enabled = true;
|
||||||
|
@ -10,10 +10,14 @@ import net.minestom.server.network.PacketProcessor;
|
|||||||
import net.minestom.server.network.netty.packet.InboundPacket;
|
import net.minestom.server.network.netty.packet.InboundPacket;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
|
public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
|
||||||
|
|
||||||
|
public final static Logger LOGGER = LoggerFactory.getLogger(ClientChannel.class);
|
||||||
|
|
||||||
private final ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
|
private final ConnectionManager connectionManager = MinecraftServer.getConnectionManager();
|
||||||
private final PacketProcessor packetProcessor;
|
private final PacketProcessor packetProcessor;
|
||||||
|
|
||||||
@ -34,9 +38,10 @@ public class ClientChannel extends SimpleChannelInboundHandler<InboundPacket> {
|
|||||||
final int availableBytes = packet.body.readableBytes();
|
final int availableBytes = packet.body.readableBytes();
|
||||||
|
|
||||||
if (availableBytes > 0) {
|
if (availableBytes > 0) {
|
||||||
// TODO log4j2
|
final PlayerConnection playerConnection = packetProcessor.getPlayerConnection(ctx);
|
||||||
System.err.println("WARNING: Packet 0x" + Integer.toHexString(packet.packetId)
|
|
||||||
+ " not fully read (" + availableBytes + " bytes left)");
|
LOGGER.warn("WARNING: Packet 0x" + Integer.toHexString(packet.packetId)
|
||||||
|
+ " not fully read (" + availableBytes + " bytes left), " + playerConnection);
|
||||||
|
|
||||||
packet.body.skipBytes(availableBytes);
|
packet.body.skipBytes(availableBytes);
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import io.netty.channel.ChannelHandlerContext;
|
|||||||
import io.netty.handler.codec.ByteToMessageCodec;
|
import io.netty.handler.codec.ByteToMessageCodec;
|
||||||
import io.netty.handler.codec.CorruptedFrameException;
|
import io.netty.handler.codec.CorruptedFrameException;
|
||||||
import net.minestom.server.MinecraftServer;
|
import net.minestom.server.MinecraftServer;
|
||||||
import net.minestom.server.entity.Player;
|
|
||||||
import net.minestom.server.network.PacketProcessor;
|
import net.minestom.server.network.PacketProcessor;
|
||||||
import net.minestom.server.network.player.PlayerConnection;
|
import net.minestom.server.network.player.PlayerConnection;
|
||||||
import net.minestom.server.utils.Utils;
|
import net.minestom.server.utils.Utils;
|
||||||
@ -60,10 +59,7 @@ public class PacketFramer extends ByteToMessageCodec<ByteBuf> {
|
|||||||
if (packetSize >= MinecraftServer.getMaxPacketSize()) {
|
if (packetSize >= MinecraftServer.getMaxPacketSize()) {
|
||||||
final PlayerConnection playerConnection = packetProcessor.getPlayerConnection(ctx);
|
final PlayerConnection playerConnection = packetProcessor.getPlayerConnection(ctx);
|
||||||
if (playerConnection != null) {
|
if (playerConnection != null) {
|
||||||
final Player player = playerConnection.getPlayer();
|
final String identifier = playerConnection.getIdentifier();
|
||||||
final String identifier = player != null ?
|
|
||||||
player.getUsername() :
|
|
||||||
playerConnection.getRemoteAddress().toString();
|
|
||||||
LOGGER.warn("An user (" + identifier + ") sent a packet over the maximum size (" + packetSize + ")");
|
LOGGER.warn("An user (" + identifier + ") sent a packet over the maximum size (" + packetSize + ")");
|
||||||
} else {
|
} else {
|
||||||
LOGGER.warn("An unregistered user sent a packet over the maximum size (" + packetSize + ")");
|
LOGGER.warn("An unregistered user sent a packet over the maximum size (" + packetSize + ")");
|
||||||
|
@ -73,6 +73,20 @@ public abstract class PlayerConnection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a printable identifier for this connection, will be the player username
|
||||||
|
* or the connection remote address.
|
||||||
|
*
|
||||||
|
* @return this connection identifier
|
||||||
|
*/
|
||||||
|
@NotNull
|
||||||
|
public String getIdentifier() {
|
||||||
|
final Player player = getPlayer();
|
||||||
|
return player != null ?
|
||||||
|
player.getUsername() :
|
||||||
|
getRemoteAddress().toString();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serializes the packet and send it to the client.
|
* Serializes the packet and send it to the client.
|
||||||
* <p>
|
* <p>
|
||||||
@ -156,4 +170,12 @@ public abstract class PlayerConnection {
|
|||||||
public int getLastPacketCounter() {
|
public int getLastPacketCounter() {
|
||||||
return lastPacketCounter.get();
|
return lastPacketCounter.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "PlayerConnection{" +
|
||||||
|
"connectionState=" + connectionState +
|
||||||
|
", identifier=" + getIdentifier() +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user