Skip to content

Commit

Permalink
Revive TickSyncPacket
Browse files Browse the repository at this point in the history
  • Loading branch information
dries-c committed Jun 14, 2024
1 parent 2d2bdc6 commit da7564a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ProxyThread.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
namespace libproxy;


use libproxy\data\TickSyncPacket;
use NetherGames\Quiche\SocketAddress;
use pmmp\thread\ThreadSafeArray;
use pocketmine\network\mcpe\protocol\PacketPool;
use pocketmine\Server;
use pocketmine\snooze\SleeperHandlerEntry;
use pocketmine\thread\log\AttachableThreadSafeLogger;
Expand Down Expand Up @@ -54,6 +56,8 @@ protected function onRun(): void
ini_set('display_startup_errors', '1');
ini_set('memory_limit', '512M');

PacketPool::getInstance()->registerPacket(new TickSyncPacket());

if ($this->autoloaderPath !== null) {
require $this->autoloaderPath;
}
Expand Down
54 changes: 53 additions & 1 deletion data/TickSyncPacket.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,62 @@
use libproxy\ProxyNetworkInterface;
use pocketmine\network\mcpe\handler\InGamePacketHandler;
use pocketmine\network\mcpe\NetworkSession;
use pocketmine\network\mcpe\protocol\ClientboundPacket;
use pocketmine\network\mcpe\protocol\DataPacket;
use pocketmine\network\mcpe\protocol\PacketHandlerInterface;
use pocketmine\network\mcpe\protocol\serializer\PacketSerializer;
use pocketmine\network\mcpe\protocol\ServerboundPacket;

class TickSyncPacket extends \pocketmine\network\mcpe\protocol\TickSyncPacket
class TickSyncPacket extends DataPacket implements ClientboundPacket, ServerboundPacket
{
public const NETWORK_ID = 0x17;

private int $clientSendTime;
private int $serverReceiveTime;

/**
* @generate-create-func
*/
private static function create(int $clientSendTime, int $serverReceiveTime): self
{
$result = new self;
$result->clientSendTime = $clientSendTime;
$result->serverReceiveTime = $serverReceiveTime;
return $result;
}

public static function request(int $clientTime): self
{
return self::create($clientTime, 0 /* useless, but always written anyway */);
}

public static function response(int $clientSendTime, int $serverReceiveTime): self
{
return self::create($clientSendTime, $serverReceiveTime);
}

public function getClientSendTime(): int
{
return $this->clientSendTime;
}

public function getServerReceiveTime(): int
{
return $this->serverReceiveTime;
}

protected function decodePayload(PacketSerializer $in): void
{
$this->clientSendTime = $in->getLLong();
$this->serverReceiveTime = $in->getLLong();
}

protected function encodePayload(PacketSerializer $out): void
{
$out->putLLong($this->clientSendTime);
$out->putLLong($this->serverReceiveTime);
}

public function handle(PacketHandlerInterface $handler): bool
{
if (!($handler instanceof InGamePacketHandler)) {
Expand Down

0 comments on commit da7564a

Please sign in to comment.