Skip to content

Commit

Permalink
Merge pull request #36 from xuanyanwow/added-group-batch
Browse files Browse the repository at this point in the history
批量获取群组ID内客户端个数
walkor authored Mar 7, 2024

Verified

This commit was signed with the committer’s verified signature. The key has expired.
dduportal Damien Duportal
2 parents 0f67651 + 13b2da1 commit a001220
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Gateway.php
Original file line number Diff line number Diff line change
@@ -323,6 +323,30 @@ public static function getClientCountByGroup($group = '')
return static::getClientIdCountByGroup($group);
}

/**
* 批量获取群组ID内客户端个数.
*/
public static function batchGetClientIdCountByGroup(array $groups): array
{
$gateway_data = GatewayProtocol::$empty;
$gateway_data['cmd'] = GatewayProtocol::CMD_BATCH_GET_CLIENT_COUNT_BY_GROUP;
$gateway_data['ext_data'] = json_encode($groups);
$all_buffer_array = static::getBufferFromAllGateway($gateway_data);

$return = [];
foreach ($all_buffer_array as $local_ip => $buffer_array) {
foreach ($buffer_array as $local_port => $data) {
foreach ($data as $group => $count) {
if (! isset($return[$group])) {
$return[$group] = 0;
}
$return[$group] += $count;
}
}
}
return $return;
}

/**
* 获取某个群组在线client_id列表
*
2 changes: 2 additions & 0 deletions GatewayProtocol.php
Original file line number Diff line number Diff line change
@@ -85,6 +85,8 @@ class GatewayProtocol
const CMD_GET_GROUP_ID_LIST = 26;
// 取消分组
const CMD_UNGROUP = 27;
// 批量获取群组ID内客户端个数
const CMD_BATCH_GET_CLIENT_COUNT_BY_GROUP = 28;
// worker连接gateway事件
const CMD_WORKER_CONNECT = 200;
// 心跳

0 comments on commit a001220

Please sign in to comment.