From 86f29f5fced59fb97f63a6b5abc4aab9449471a9 Mon Sep 17 00:00:00 2001 From: Nadyita Date: Sat, 14 Sep 2024 23:36:58 +0200 Subject: [PATCH] Fix onReady detection --- src/Client/SingleClient.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Client/SingleClient.php b/src/Client/SingleClient.php index 2534271..7c49050 100644 --- a/src/Client/SingleClient.php +++ b/src/Client/SingleClient.php @@ -6,6 +6,7 @@ use Amp\DeferredFuture; use AO\Internal\SendQueue; +use AO\Package\Out\Pong; use AO\{ AccountUnfreezer, Connection, @@ -390,6 +391,8 @@ protected function handleIncomingPackage(Package\InPackage $package): void { $this->handleBuddyRemoved($package); } elseif ($package instanceof In\GroupJoined) { $this->handleGroupJoined($package); + } elseif ($package instanceof In\Ping) { + $this->handlePing($package); } elseif ($package instanceof In\GroupLeft) { $this->handleGroupLeft($package); } @@ -433,8 +436,8 @@ protected function handleBuddyRemoved(In\BuddyRemoved $package): void { } protected function handleGroupJoined(In\GroupJoined $package): void { - if (!$this->isReady) { - EventLoop::defer($this->triggerOnReady(...)); + if (!$this->isReady && $this->lastPong < 1) { + $this->write(new Pong('ready')); } $group = new Group( id: $package->groupId, @@ -447,6 +450,12 @@ protected function handleGroupJoined(In\GroupJoined $package): void { $this->publicGroups[$package->groupName] = $group; } + protected function handlePing(In\Ping $package): void { + if (!$this->isReady && $package->extra === 'ready') { + EventLoop::defer($this->triggerOnReady(...)); + } + } + protected function handleGroupLeft(In\GroupLeft $package): void { foreach ($this->publicGroups as $name => $group) { if ($package->groupId->sameAs($group->id)) {