mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 11:39: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),
|
||||
"auto-save" => true,
|
||||
"enable-mob-ai" => true,
|
||||
"abort-reading-after-N-packets" => PocketMinecraftServer::$PACKET_READING_LIMIT
|
||||
]);
|
||||
|
||||
$this->parseProperties();
|
||||
MobSpawner::$MOB_LIMIT = $this->getProperty("mobs-amount", 50);
|
||||
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
|
||||
define("DEBUG", $this->getProperty("debug", 1));
|
||||
define("ADVANCED_CACHE", false);
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ class PocketMinecraftServer{
|
|||
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 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"){
|
||||
$this->port = (int) $port;
|
||||
$this->doTick = true;
|
||||
|
|
@ -473,19 +473,34 @@ class PocketMinecraftServer{
|
|||
public function process()
|
||||
{
|
||||
$lastLoop = 0;
|
||||
|
||||
if(self::$FORCE_20_TPS){
|
||||
while($this->stop === false){
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet instanceof Packet) $this->packetHandler($packet);
|
||||
$packetcnt = 0;
|
||||
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();
|
||||
}
|
||||
}else{
|
||||
while($this->stop === false){
|
||||
$packetcnt = 0;
|
||||
startReadingAgain:
|
||||
$packet = $this->interface->readPacket();
|
||||
if($packet instanceof Packet){
|
||||
$this->packetHandler($packet);
|
||||
$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){
|
||||
$lastLoop = 0;
|
||||
} else{
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class UDPSocket{
|
|||
if($this->connected === 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){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue