Rate Limiting fixes

This commit is contained in:
Eoghanmc22 2020-08-13 14:51:01 -04:00
parent 8ecb90f359
commit d66d87ed97
3 changed files with 19 additions and 14 deletions

View File

@ -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) {

View File

@ -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();

View File

@ -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);
}
}
}