From c3b09096b4498b4f477a90a03ea8fedf8f264dd7 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Sat, 8 Jun 2024 06:35:38 +0300 Subject: [PATCH] AddPlayerPacket is sent directly now --- src/Player.php | 12 +++++++----- src/PocketMinecraftServer.php | 4 +++- src/entity/Entity.php | 2 +- src/math/AxisAlignedBB.php | 2 +- src/math/Vector3.php | 2 +- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Player.php b/src/Player.php index f6a7b5b9..16b1c31a 100755 --- a/src/Player.php +++ b/src/Player.php @@ -1194,8 +1194,9 @@ class Player{ foreach($this->resendQueue as $count => $data){ unset($this->resendQueue[$count]); $this->packetStats[1]++; - $this->lag[] = microtime(true) - $data->sendtime; - $data->sendtime = microtime(true); + $this->lag[] = $time - $data->sendtime; + $data->sendtime = $time; + $cnt = $this->send($data); if(isset($this->chunkCount[$count])){ unset($this->chunkCount[$count]); @@ -2649,13 +2650,14 @@ class Player{ public function handlePacket(RakNetPacket $packet){ if($this->connected === true){ - $this->timeout = microtime(true) + 20; + $time = microtime(true); + $this->timeout = $time + 20; switch($packet->pid()){ case RakNetInfo::NACK: foreach($packet->packets as $count){ if(isset($this->recoveryQueue[$count])){ $this->resendQueue[$count] =& $this->recoveryQueue[$count]; - $this->lag[] = microtime(true) - $this->recoveryQueue[$count]->sendtime; + $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); } ++$this->packetStats[1]; @@ -2665,7 +2667,7 @@ class Player{ case RakNetInfo::ACK: foreach($packet->packets as $count){ if(isset($this->recoveryQueue[$count])){ - $this->lag[] = microtime(true) - $this->recoveryQueue[$count]->sendtime; + $this->lag[] = $time - $this->recoveryQueue[$count]->sendtime; unset($this->recoveryQueue[$count]); unset($this->resendQueue[$count]); } diff --git a/src/PocketMinecraftServer.php b/src/PocketMinecraftServer.php index ae69bd93..6565cf56 100644 --- a/src/PocketMinecraftServer.php +++ b/src/PocketMinecraftServer.php @@ -447,6 +447,7 @@ class PocketMinecraftServer{ if(!is_callable($callback)){ return false; } + $chcnt = $this->scheduleCnt++; $this->schedule[$chcnt] = [$callback, $data, $eventName]; $this->query("INSERT INTO actions (ID, interval, last, repeat) VALUES(" . $chcnt . ", " . ($ticks / 20) . ", " . microtime(true) . ", " . (((bool) $repeat) === true ? 1 : 0) . ");"); @@ -604,7 +605,8 @@ class PocketMinecraftServer{ foreach($this->api->level->levels as $l){ $l->onTick($this, $time); } - return $this->tickerFunction($time); + $r = $this->tickerFunction($time); + return $r; } return 0; } diff --git a/src/entity/Entity.php b/src/entity/Entity.php index 72929db1..8a9edd05 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -1081,7 +1081,7 @@ class Entity extends Position $pk->itemID = 0; $pk->itemAuxValue = 0; $pk->metadata = $this->getMetadata(); - $player->dataPacket($pk); + $player->directDataPacket($pk, 2, true); $pk = new SetEntityMotionPacket(); $pk->eid = $this->eid; diff --git a/src/math/AxisAlignedBB.php b/src/math/AxisAlignedBB.php index 1a65b81e..f98b1db3 100644 --- a/src/math/AxisAlignedBB.php +++ b/src/math/AxisAlignedBB.php @@ -6,7 +6,7 @@ class AxisAlignedBB{ public $maxX; public $maxY; public $maxZ; - + public function __construct($minX, $minY, $minZ, $maxX, $maxY, $maxZ){ $this->minX = $minX; $this->minY = $minY; diff --git a/src/math/Vector3.php b/src/math/Vector3.php index 5f5a03cb..6eac681c 100644 --- a/src/math/Vector3.php +++ b/src/math/Vector3.php @@ -2,7 +2,7 @@ class Vector3{ public $x, $y, $z; - + public function __construct($x = 0, $y = 0, $z = 0){ $this->x = $x; $this->y = $y;