mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-11 19:00:52 +01:00
Fix packet parsing for disconnected clients
This commit is contained in:
parent
f2fec73202
commit
b304e1328a
@ -1307,11 +1307,10 @@ public class Player extends LivingEntity implements CommandSender, Localizable,
|
||||
}
|
||||
if (playerConnection instanceof PlayerSocketConnection) {
|
||||
((PlayerSocketConnection) playerConnection).writeAndFlush(disconnectPacket);
|
||||
playerConnection.disconnect();
|
||||
} else {
|
||||
playerConnection.sendPacket(disconnectPacket);
|
||||
playerConnection.refreshOnline(false);
|
||||
}
|
||||
playerConnection.disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -29,6 +29,7 @@ public class FakePlayerConnection extends PlayerConnection {
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
super.disconnect();
|
||||
if (getFakePlayer().getOption().isRegistered())
|
||||
MinecraftServer.getConnectionManager().removePlayer(this);
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public abstract class PlayerConnection {
|
||||
|
||||
private Player player;
|
||||
private volatile ConnectionState connectionState;
|
||||
private boolean online;
|
||||
volatile boolean online;
|
||||
|
||||
// Text used to kick client sending too many packets
|
||||
private static final Component rateLimitKickMessage = Component.text("Too Many Packets", NamedTextColor.RED);
|
||||
@ -146,7 +146,9 @@ public abstract class PlayerConnection {
|
||||
/**
|
||||
* Forcing the player to disconnect.
|
||||
*/
|
||||
public abstract void disconnect();
|
||||
public void disconnect() {
|
||||
this.online = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the player linked to this connection.
|
||||
@ -177,10 +179,6 @@ public abstract class PlayerConnection {
|
||||
return online;
|
||||
}
|
||||
|
||||
public void refreshOnline(boolean online) {
|
||||
this.online = online;
|
||||
}
|
||||
|
||||
public void setConnectionState(@NotNull ConnectionState connectionState) {
|
||||
this.connectionState = connectionState;
|
||||
}
|
||||
|
@ -106,6 +106,8 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
try {
|
||||
this.cacheBuffer = PacketUtils.readPackets(readBuffer, compressed,
|
||||
(id, payload) -> {
|
||||
if (!isOnline())
|
||||
return; // Prevent packet corruption
|
||||
try {
|
||||
packetProcessor.process(this, id, payload);
|
||||
} catch (Exception e) {
|
||||
@ -212,6 +214,7 @@ public class PlayerSocketConnection extends PlayerConnection {
|
||||
|
||||
@Override
|
||||
public void disconnect() {
|
||||
super.disconnect();
|
||||
this.workerQueue.relaxedOffer(() -> this.worker.disconnect(this, channel));
|
||||
}
|
||||
|
||||
|
@ -82,11 +82,11 @@ public final class Worker extends MinestomThread {
|
||||
}
|
||||
|
||||
public void disconnect(PlayerSocketConnection connection, SocketChannel channel) {
|
||||
assert !connection.isOnline();
|
||||
try {
|
||||
channel.close();
|
||||
this.connectionMap.remove(channel);
|
||||
MinecraftServer.getConnectionManager().removePlayer(connection);
|
||||
connection.refreshOnline(false);
|
||||
Player player = connection.getPlayer();
|
||||
if (player != null && !player.isRemoved()) {
|
||||
player.scheduleNextTick(Entity::remove);
|
||||
|
Loading…
Reference in New Issue
Block a user