mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-22 20:49:43 +00:00
server will try reading packets until none left(or limit is reached)
This commit is contained in:
parent
fcff48b5b8
commit
d5a38220bf
3 changed files with 22 additions and 5 deletions
|
|
@ -136,11 +136,13 @@ class ServerAPI{
|
||||||
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
|
"rcon.password" => substr(base64_encode(Utils::getRandomBytes(20, false)), 3, 10),
|
||||||
"auto-save" => true,
|
"auto-save" => true,
|
||||||
"enable-mob-ai" => true,
|
"enable-mob-ai" => true,
|
||||||
|
"abort-reading-after-N-packets" => PocketMinecraftServer::$PACKET_READING_LIMIT
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->parseProperties();
|
$this->parseProperties();
|
||||||
MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50);
|
MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50);
|
||||||
Entity::$allowedAI = $this->getProperty("enable-mob-ai", true);
|
Entity::$allowedAI = $this->getProperty("enable-mob-ai", true);
|
||||||
|
PocketMinecraftServer::$PACKET_READING_LIMIT = $this->getProperty("abort-reading-after-N-packets", PocketMinecraftServer::$PACKET_READING_LIMIT);
|
||||||
//Load advanced properties
|
//Load advanced properties
|
||||||
define("DEBUG", $this->getProperty("debug", 1));
|
define("DEBUG", $this->getProperty("debug", 1));
|
||||||
define("ADVANCED_CACHE", false);
|
define("ADVANCED_CACHE", false);
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,7 @@ class PocketMinecraftServer{
|
||||||
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
|
private $serverip, $evCnt, $handCnt, $events, $eventsID, $handlers, $serverType, $lastTick, $memoryStats, $async = [], $asyncID = 0;
|
||||||
|
|
||||||
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
|
public $doTick, $levelData, $tiles, $entities, $schedule, $scheduleCnt, $whitelist, $spawn, $difficulty, $stop, $asyncThread;
|
||||||
public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true;
|
public static $FORCE_20_TPS = false, $KEEP_CHUNKS_LOADED = true, $PACKET_READING_LIMIT = 100;
|
||||||
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
function __construct($name, $gamemode = SURVIVAL, $seed = false, $port = 19132, $serverip = "0.0.0.0"){
|
||||||
$this->port = (int) $port;
|
$this->port = (int) $port;
|
||||||
$this->doTick = true;
|
$this->doTick = true;
|
||||||
|
|
@ -473,19 +473,34 @@ class PocketMinecraftServer{
|
||||||
public function process()
|
public function process()
|
||||||
{
|
{
|
||||||
$lastLoop = 0;
|
$lastLoop = 0;
|
||||||
|
|
||||||
if(self::$FORCE_20_TPS){
|
if(self::$FORCE_20_TPS){
|
||||||
while($this->stop === false){
|
while($this->stop === false){
|
||||||
$packet = $this->interface->readPacket();
|
$packetcnt = 0;
|
||||||
if($packet instanceof Packet) $this->packetHandler($packet);
|
while($packet = $this->interface->readPacket()){
|
||||||
|
if($packet instanceof Packet) {
|
||||||
|
$this->packetHandler($packet);
|
||||||
|
if(++$packetcnt > self::$PACKET_READING_LIMIT){
|
||||||
|
ConsoleAPI::warn("Reading more than ".self::$PACKET_READING_LIMIT." packets per tick! Forcing ticking!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->tick();
|
$this->tick();
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
while($this->stop === false){
|
while($this->stop === false){
|
||||||
|
$packetcnt = 0;
|
||||||
|
startReadingAgain:
|
||||||
$packet = $this->interface->readPacket();
|
$packet = $this->interface->readPacket();
|
||||||
if($packet instanceof Packet){
|
if($packet instanceof Packet){
|
||||||
$this->packetHandler($packet);
|
$this->packetHandler($packet);
|
||||||
$lastLoop = 0;
|
$lastLoop = 0;
|
||||||
|
if(++$packetcnt > self::$PACKET_READING_LIMIT){
|
||||||
|
ConsoleAPI::warn("Reading more than ".self::$PACKET_READING_LIMIT." packets per tick! Forcing ticking!");
|
||||||
|
}else{
|
||||||
|
goto startReadingAgain;
|
||||||
|
}
|
||||||
} elseif($this->tick() > 0){
|
} elseif($this->tick() > 0){
|
||||||
$lastLoop = 0;
|
$lastLoop = 0;
|
||||||
} else{
|
} else{
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ class UDPSocket{
|
||||||
if($this->connected === false){
|
if($this->connected === false){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return @socket_recvfrom($this->sock, $buf, 65535, 0, $source, $port);;
|
return @socket_recvfrom($this->sock, $buf, 65535, 0, $source, $port);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function write($data, $dest, $port){
|
public function write($data, $dest, $port){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue