added limit-ack-packets into extra.properties(enabled by default)

This commit is contained in:
GameHerobrine 2026-11-09 07:55:33 +03:00
parent 8208e4119c
commit dbaa8a659f
2 changed files with 14 additions and 4 deletions

View file

@ -109,6 +109,7 @@ class PocketMinecraftServer{
"allow-dropping-single-items" => Player::$allowDroppingSingleItems, "allow-dropping-single-items" => Player::$allowDroppingSingleItems,
"enable-light-updates" => self::$ENABLE_LIGHT_UPDATES, "enable-light-updates" => self::$ENABLE_LIGHT_UPDATES,
"min-block-breaking-progress" => self::$BLOCK_BREAKING_PROGRESS, "min-block-breaking-progress" => self::$BLOCK_BREAKING_PROGRESS,
"limit-ack-packets" => MinecraftInterface::$LIMIT_ACKS,
], comments: [ ], comments: [
"min-block-breaking-progress" => [ "min-block-breaking-progress" => [
"Affects how strict block breaking speed check is.", "Affects how strict block breaking speed check is.",
@ -141,6 +142,10 @@ class PocketMinecraftServer{
], ],
"keep-chunks-loaded" => [ "keep-chunks-loaded" => [
"If disabled chunks won't be loaded into memory until the player(or something else) loads them" "If disabled chunks won't be loaded into memory until the player(or something else) loads them"
],
"limit-ack-packets" => [
"Prevents players from sending too many ACK/NACK packets if enabled",
"Disabling this settings may result in server getting crashed/frozen if someone sends ack packet with a lot of sequences"
] ]
]); ]);
self::$BLOCK_BREAKING_PROGRESS = $this->extraprops->get("min-block-breaking-progress"); self::$BLOCK_BREAKING_PROGRESS = $this->extraprops->get("min-block-breaking-progress");
@ -152,12 +157,13 @@ class PocketMinecraftServer{
Living::$despawnMobs = $this->extraprops->get("despawn-mobs"); Living::$despawnMobs = $this->extraprops->get("despawn-mobs");
Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks"); Living::$despawnTimer = $this->extraprops->get("mob-despawn-ticks");
Living::$entityPushing = $this->extraprops->get("enable-mob-pushing"); Living::$entityPushing = $this->extraprops->get("enable-mob-pushing");
self::$KEEP_CHUNKS_LOADED = $this->extraprops->get("keep-chunks-loaded"); self::$KEEP_CHUNKS_LOADED = $this->extraprops->get("keep-chunks-loaded");
self::$ENABLE_LIGHT_UPDATES = $this->extraprops->get("enable-light-updates"); self::$ENABLE_LIGHT_UPDATES = $this->extraprops->get("enable-light-updates");
PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data"); PocketMinecraftServer::$SAVE_PLAYER_DATA = $this->extraprops->get("save-player-data");
Explosion::$enableExplosions = $this->extraprops->get("enable-explosions"); Explosion::$enableExplosions = $this->extraprops->get("enable-explosions");
NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor"); NetherReactorBlock::$enableReactor = $this->extraprops->get("enable-nether-reactor");
MinecraftInterface::$LIMIT_ACKS = $this->extraprops->get("limit-ack-packets");
if(self::$TICKING_MODE == self::TICK_F20TPS){ if(self::$TICKING_MODE == self::TICK_F20TPS){
ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!"); ConsoleAPI::warn("Forcing 20 tps. This may result in higher CPU usage!");
} }
@ -167,6 +173,9 @@ class PocketMinecraftServer{
if(!self::$ENABLE_LIGHT_UPDATES){ if(!self::$ENABLE_LIGHT_UPDATES){
ConsoleAPI::warn("Light updates are disabled: this should decrease memory consumption and increase performance, but will prevent all existing light from updating and disable some light-dependant features."); ConsoleAPI::warn("Light updates are disabled: this should decrease memory consumption and increase performance, but will prevent all existing light from updating and disable some light-dependant features.");
} }
if(!MinecraftInterface::$LIMIT_ACKS){
ConsoleAPI::warn("ACK packet limit is disabled: server can be frozen or crashed using bad ACK packets!");
}
if($this->extraprops->get("discord-msg")){ if($this->extraprops->get("discord-msg")){
if($this->extraprops->get("discord-webhook-url") !== "none"){ if($this->extraprops->get("discord-webhook-url") !== "none"){
console("[INFO] Discord Logger is enabled."); console("[INFO] Discord Logger is enabled.");

View file

@ -1,7 +1,7 @@
<?php <?php
class MinecraftInterface{ class MinecraftInterface{
public static $LIMIT_ACKS = true;
public $bandwidth; public $bandwidth;
private $socket; private $socket;
private $packets; private $packets;
@ -78,9 +78,10 @@ class MinecraftInterface{
$nackCnt = 0; $nackCnt = 0;
$acks = $this->maxACKsAllowed[$id] ?? 0; $acks = $this->maxACKsAllowed[$id] ?? 0;
$nacks = $this->maxNACKsAllowed[$id] ?? 0; $nacks = $this->maxNACKsAllowed[$id] ?? 0;
if(!static::$LIMIT_ACKS) $acks = $nacks = -1;
$packet = RakNetParser::parse($buffer, $acks, $nacks, $ackCnt, $nackCnt); //TODO rewrite this mess later (hai "this code is still horribly ugly, messy, and unmaintainable") $packet = RakNetParser::parse($buffer, $acks, $nacks, $ackCnt, $nackCnt); //TODO rewrite this mess later (hai "this code is still horribly ugly, messy, and unmaintainable")
if($packet !== false){ if($packet !== false){
if($ackCnt != 0){ if(static::$LIMIT_ACKS && $ackCnt != 0){
$pid = $packet->pid(); $pid = $packet->pid();
if($pid == RakNetInfo::ACK && isset($this->maxACKsAllowed[$id])){ if($pid == RakNetInfo::ACK && isset($this->maxACKsAllowed[$id])){
$this->maxACKsAllowed[$id] = $acks - $ackCnt; $this->maxACKsAllowed[$id] = $acks - $ackCnt;
@ -94,7 +95,7 @@ class MinecraftInterface{
return false; return false;
} }
return $packet; return $packet;
}else if($ackCnt > 0){ }else if(static::$LIMIT_ACKS && $ackCnt > 0){
$CID = PocketMinecraftServer::clientID($source, $port); $CID = PocketMinecraftServer::clientID($source, $port);
$server = ServerAPI::request(); $server = ServerAPI::request();
$c = $server->clients[$CID] ?? false; $c = $server->clients[$CID] ?? false;