Skip to content

Commit

Permalink
Merge pull request #121 from xuanyanwow/added-batch-group-count
Browse files Browse the repository at this point in the history
批量获取群组ID内客户端个数
  • Loading branch information
walkor authored Mar 7, 2024
2 parents 21d8216 + 32d7374 commit 89478a1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,21 @@ public function onWorkerMessage($connection, $data)
}
$buffer = serialize($return);

$connection->send(pack('N', strlen($buffer)) . $buffer, true);
return;
// 批量获取群组ID内客户端个数
case GatewayProtocol::CMD_BATCH_GET_CLIENT_COUNT_BY_GROUP:
$groups = json_decode($data['ext_data'], true);
$return = [];
foreach ($groups as $group) {
if (isset($this->_groupConnections[$group])) {
$return[$group] = count($this->_groupConnections[$group]);
} else {
$return[$group] = 0;
}
}

$buffer = serialize($return);
$connection->send(pack('N', strlen($buffer)) . $buffer, true);
return;
default :
Expand Down
3 changes: 3 additions & 0 deletions src/Protocols/GatewayProtocol.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ class GatewayProtocol
// 取消分组
const CMD_UNGROUP = 27;

// 批量获取群组ID内客户端个数
const CMD_BATCH_GET_CLIENT_COUNT_BY_GROUP = 28;

// worker连接gateway事件
const CMD_WORKER_CONNECT = 200;

Expand Down

0 comments on commit 89478a1

Please sign in to comment.