eee
This commit is contained in:
+44
-33
@@ -12,16 +12,28 @@ class Transport
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @param int $userId
|
||||
* @param Struct $data
|
||||
* @return void
|
||||
*/
|
||||
public function add(int $fd, Struct $data): void
|
||||
public function add(int $userId, Struct $data): void
|
||||
{
|
||||
if (isset($this->clients[$fd])) {
|
||||
$this->clients[$fd]->ws->close();
|
||||
if (isset($this->clients[$userId])) {
|
||||
$this->clients[$userId]->ws->close();
|
||||
}
|
||||
$this->clients[$userId] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function sendUserId(int $userId, mixed $data): void
|
||||
{
|
||||
if (isset($this->clients[$userId])) {
|
||||
$this->clients[$userId]->ws->push($data);
|
||||
}
|
||||
$this->clients[$fd] = $data;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,36 +41,35 @@ class Transport
|
||||
* @param mixed $data
|
||||
* @return void
|
||||
*/
|
||||
public function send(int $fd, mixed $data): void
|
||||
public function sendFd(int $fd, mixed $data): void
|
||||
{
|
||||
if (isset($this->clients[$fd])) {
|
||||
$this->clients[$fd]->ws->push($data);
|
||||
$struct = $this->getClientId($fd);
|
||||
$struct?->ws->push($data);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @return void
|
||||
*/
|
||||
public function close(int $userId): void
|
||||
{
|
||||
if (isset($this->clients[$userId])) {
|
||||
$this->clients[$userId]->ws->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @param int $userId
|
||||
* @return void
|
||||
*/
|
||||
public function close(int $fd): void
|
||||
public function remove(int $userId): void
|
||||
{
|
||||
if (isset($this->clients[$fd])) {
|
||||
$this->clients[$fd]->ws->close();
|
||||
if ($this->has($userId)) {
|
||||
$this->clients[$userId]?->ws->close();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @return void
|
||||
*/
|
||||
public function remove(int $fd): void
|
||||
{
|
||||
if ($this->has($fd)) {
|
||||
$this->clients[$fd]?->ws->close();
|
||||
}
|
||||
unset($this->clients[$fd]);
|
||||
unset($this->clients[$userId]);
|
||||
}
|
||||
|
||||
|
||||
@@ -73,22 +84,22 @@ class Transport
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @param int $userId
|
||||
* @return Struct|null
|
||||
*/
|
||||
public function getUserId(int $fd): ?Struct
|
||||
public function getUserId(int $userId): ?Struct
|
||||
{
|
||||
return $this->clients[$fd] ?? null;
|
||||
return $this->clients[$userId] ?? null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $fd
|
||||
* @param int $userId
|
||||
* @return bool
|
||||
*/
|
||||
public function has(int $fd): bool
|
||||
public function has(int $userId): bool
|
||||
{
|
||||
return isset($this->clients[$fd]);
|
||||
return isset($this->clients[$userId]);
|
||||
}
|
||||
|
||||
|
||||
@@ -98,9 +109,9 @@ class Transport
|
||||
public function getLists(): array
|
||||
{
|
||||
$array = [];
|
||||
foreach ($this->clients as $fd => $client) {
|
||||
foreach ($this->clients as $userId => $client) {
|
||||
$array[] = [
|
||||
'userId' => $fd,
|
||||
'userId' => $userId,
|
||||
'nickname' => $client->user->getNickname(),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user