This commit is contained in:
2026-04-04 10:29:39 +08:00
parent 4e999574a9
commit b77321ff4b
6 changed files with 232 additions and 213 deletions
+34 -4
View File
@@ -50,18 +50,48 @@ class Transport
/**
* @param int $fd
* @param int $fd
* @return void
*/
public function remove(int $fd): void
{
if ($this->clients[$fd]) {
$this->clients[$fd]->ws->close();
if ($this->has($fd)) {
$this->clients[$fd]?->ws->close();
}
unset($this->clients[$fd]);
}
/**
* @param int $fd
* @return Struct|null
*/
public function getClientId(int $fd): ?Struct
{
return array_find($this->clients, fn($client) => $client->fd == $fd);
}
/**
* @param int $fd
* @return Struct|null
*/
public function getUserId(int $fd): ?Struct
{
return $this->clients[$fd] ?? null;
}
/**
* @param int $fd
* @return bool
*/
public function has(int $fd): bool
{
return isset($this->clients[$fd]);
}
/**
* @return array
*/
@@ -71,7 +101,7 @@ class Transport
foreach ($this->clients as $fd => $client) {
$array[] = [
'userId' => $fd,
'nickname' => $client->user['nickname'],
'nickname' => $client->user->getNickname(),
];
}
return $array;