mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-03 23:17:48 +01:00
Rate Limiting fixes
This commit is contained in:
parent
8ecb90f359
commit
d66d87ed97
@ -290,6 +290,8 @@ public class Player extends LivingEntity implements CommandSender {
|
||||
// Flush all pending packets
|
||||
playerConnection.flush();
|
||||
|
||||
playerConnection.updateStats();
|
||||
|
||||
// Process received packets
|
||||
ClientPlayPacket packet;
|
||||
while ((packet = packets.poll()) != null) {
|
||||
|
@ -59,6 +59,7 @@ public class NettyPlayerConnection extends PlayerConnection {
|
||||
|
||||
@Override
|
||||
public void writePacket(ByteBuf buffer, boolean copy) {
|
||||
//System.out.println(getConnectionState() + " out");
|
||||
if ((encrypted || compressed) && copy) {
|
||||
buffer = buffer.copy();
|
||||
buffer.retain();
|
||||
|
@ -45,21 +45,23 @@ public abstract class PlayerConnection {
|
||||
}
|
||||
|
||||
public void updateStats() {
|
||||
tickCounter++;
|
||||
if (tickCounter % 20 == 0 && tickCounter > 0) {
|
||||
tickCounter = 0;
|
||||
int i = packetCounter.get();
|
||||
packetCounter.set(0);
|
||||
if (i > MinecraftServer.getRateLimit()) {
|
||||
if (connectionState == ConnectionState.LOGIN) {
|
||||
sendPacket(new LoginDisconnect("Too Many Packets"));
|
||||
} else {
|
||||
DisconnectPacket disconnectPacket = new DisconnectPacket();
|
||||
disconnectPacket.message = rateLimitKickMessage;
|
||||
sendPacket(disconnectPacket);
|
||||
if (MinecraftServer.getRateLimit() > 0) {
|
||||
tickCounter++;
|
||||
if (tickCounter % 20 == 0 && tickCounter > 0) {
|
||||
tickCounter = 0;
|
||||
int i = packetCounter.get();
|
||||
packetCounter.set(0);
|
||||
if (i > MinecraftServer.getRateLimit()) {
|
||||
if (connectionState == ConnectionState.LOGIN) {
|
||||
sendPacket(new LoginDisconnect("Too Many Packets"));
|
||||
} else {
|
||||
DisconnectPacket disconnectPacket = new DisconnectPacket();
|
||||
disconnectPacket.message = rateLimitKickMessage;
|
||||
sendPacket(disconnectPacket);
|
||||
}
|
||||
disconnect();
|
||||
refreshOnline(false);
|
||||
}
|
||||
disconnect();
|
||||
refreshOnline(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user