Skip to content

Commit

Permalink
Abnormal connection blocked for 60 seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
lt-name committed Aug 28, 2024
1 parent 3576fe6 commit 475efd1
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/cn/nukkit/network/session/RakNetPlayerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import cn.nukkit.network.protocol.DataPacket;
import cn.nukkit.network.protocol.DisconnectPacket;
import cn.nukkit.network.protocol.ProtocolInfo;
import cn.nukkit.plugin.InternalPlugin;
import cn.nukkit.utils.Binary;
import cn.nukkit.utils.BinaryStream;
import com.google.common.base.Preconditions;
Expand All @@ -29,6 +30,7 @@

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import java.net.InetAddress;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.Collection;
Expand Down Expand Up @@ -148,11 +150,22 @@ protected void channelRead0(ChannelHandlerContext channelHandlerContext, RakMess
try {
this.server.getNetwork().processBatch(packetBuffer, this.inbound, compressionIn, this.channel.config().getProtocolVersion(), this.player);
} catch (Exception e) {
Server.getInstance().getScheduler().scheduleDelayedTask(InternalPlugin.INSTANCE, () -> {
try {
InetAddress address = this.channel.remoteAddress().getAddress();
this.channel.unsafe().close(this.channel.voidPromise());
this.server.blockAddress(address, 60);
} catch (Throwable throwable) {
if (Nukkit.DEBUG > 1) {
log.info("Error while closing channel", throwable);
}
}
}, 10);
this.disconnect("Sent malformed packet");
log.error("[{}] Unable to process batch packet", (this.player == null ? this.channel.remoteAddress() : this.player.getName()), e);
}
} else if (Nukkit.DEBUG > 1) {
log.debug("Unknown EncapsulatedPacket: " + packetId);
log.info("Unknown EncapsulatedPacket: {}", packetId);
}
}

Expand Down

0 comments on commit 475efd1

Please sign in to comment.