Skip to content

Commit

Permalink
Better buddy-interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Nadyita committed Mar 4, 2024
1 parent f3e794b commit e01d078
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Client/Multi.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,13 @@ public function lookupCharacter(int $uid, bool $cacheOnly=false, ?string $worker
return $character ?? $this->getBestWorker($worker)?->lookupCharacter($uid, $cacheOnly);
}

/** Get the character of the worker with the least buddies on its list */
public function getMostEmptyWorker(): string {
$fill = $this->getBuddylistSize();
asort($fill);
return array_keys($fill)[0];
}

/**
* Get the current amount of used up buddylist slots per worker
*
Expand All @@ -223,6 +230,24 @@ public function getBuddylistSize(): array {
return $result;
}

/** Add a buddy to the most empty worker */
public function buddyAdd(int $uid): void {
$this->write(
package: new Package\Out\BuddyAdd(charId: $uid),
worker: $this->getMostEmptyWorker(),
);
}

/** Remove a buddy from all workers */
public function buddyRemove(int $uid): void {
foreach ($this->connections as $id => $connection) {
$buddies = $connection->getBuddylist();
if (isset($buddies[$uid])) {
$connection->write(new Package\Out\BuddyRemove($uid));
}
}
}

/**
* Get the buddylist as uid => online
*
Expand Down

0 comments on commit e01d078

Please sign in to comment.