You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
672 lines
19 KiB
672 lines
19 KiB
<?php
|
|
namespace Application;
|
|
|
|
use \Workerman\Autoloader;
|
|
use \GatewayWorker\Lib\Mem;
|
|
use \GatewayWorker\Lib\Db;
|
|
use \Application\Asset\AI;
|
|
|
|
require_once __DIR__ . '/GatewayClient/Gateway.php';
|
|
\Gateway::$registerAddress = \Config\Site::$registerAddress;
|
|
|
|
|
|
class Crontab {
|
|
// 在线房间人数
|
|
const ROOM_ONLINE_NUM_PREFIX = "ROOM_ONLINE_NUM_";
|
|
// 上次在线房间人数
|
|
const ROOM_ONLINE_PEPOLE_REBOT = "ROOM_ONLINE_PEPOLE_REBOT";
|
|
// 房间在线用户等级排序列表
|
|
const ROOM_SORTED_CLIENTS_PREFIX = "ROOM_SORTED_CLIENTS_";
|
|
// 热门主播列表
|
|
const ROOM_SORTED_HOT_LIST = "ROOM_SORTED_HOT_LIST";
|
|
// 当前房间数量
|
|
const ROOM_COUNT_ALL = "ROOM_COUNT_ALL";
|
|
// 主播在线标识位
|
|
const ROOM_ANCHOR_ONLIE_PREFIX = "ROOM_ANCHOR_ONLIE_PREFIX_";
|
|
|
|
// 缓存热门主播列表标志位
|
|
public static $cacheHotRoomFlag = false;
|
|
|
|
public static $RobotChangeMin = 0;
|
|
public static $RobotChangeMax = 0;
|
|
public static $RobotOpen = 1;
|
|
|
|
// 当前在线房间列表
|
|
public static $currentRoomList = array();
|
|
|
|
// 所有当前在线房间 Timer
|
|
public static $allRoomTimer = array();
|
|
|
|
// AI用户列表
|
|
public static $AIList = array();
|
|
|
|
// AI 所在房间map
|
|
public static $AIMap = array();
|
|
|
|
public static $RobotMin = 0;
|
|
|
|
public static $RobotMax = 0;
|
|
|
|
public static function setAnchorOnline($room_id, $user_id) {
|
|
if (!Mem::get(self::ROOM_ANCHOR_ONLIE_PREFIX . $room_id)) {
|
|
RoomStatus::updateAnchorOnLineToDb($user_id);
|
|
}
|
|
Mem::set(self::ROOM_ANCHOR_ONLIE_PREFIX . $room_id, 'online', 0, 30);
|
|
}
|
|
public static function delAnchorOnline($room_id) {
|
|
Mem::delete(self::ROOM_ANCHOR_ONLIE_PREFIX . $room_id);
|
|
}
|
|
|
|
/**
|
|
* 初始化AI 用户
|
|
*/
|
|
|
|
public static function initAI()
|
|
{
|
|
//对机器人赋值
|
|
// //static::$AIList = AI::$AIUser;
|
|
// $AIArray = Db::instance('dbDefault')->query("select * from ss_member where is_robot=1");
|
|
// //array('user_id'=>900, 'username'=>'AI_1','nickname'=>'机器人1号', 'ucuid'=>843, 'levelid'=>3,'vip'=>0,'AI'=>true),
|
|
// $AIUser = array();
|
|
// $num = 0;
|
|
// foreach($AIArray as $key => $value)
|
|
// {
|
|
// $AIUser[$num]['user_id']=$value['id'];
|
|
// $AIUser[$num]['username']=$value['username'];
|
|
// $AIUser[$num]['nickname']=$value['nickname'];
|
|
// $AIUser[$num]['ucuid']=$value['ucuid'];
|
|
// $spendcoin=$value['spendcoin'];
|
|
// $levelid = Db::instance('dbDefault')->query("select levelid from ss_emceelevel where earnbean_low <=".$spendcoin." and earnbean_up >=".$spendcoin);
|
|
// $AIUser[$num]['levelid']=$levelid[0]['levelid'];
|
|
// $AIUser[$num]['vip']=$value['vip'];
|
|
// $AIUser[$num]['AI']=true;
|
|
// $num++;
|
|
// }
|
|
$UserSet = Db::instance('dbDefault')->query("select robot_max, robot_switch, robot_min,robot_change_min,robot_change_max from ss_siteconfig");
|
|
static::$RobotMax = $UserSet[0]['robot_max'];
|
|
static::$RobotMin = $UserSet[0]['robot_min'];
|
|
static::$RobotChangeMin = $UserSet[0]['robot_change_min'];
|
|
static::$RobotChangeMax = $UserSet[0]['robot_change_max'];
|
|
static::$RobotOpen = $UserSet[0]['robot_switch'];
|
|
//static::$AIList = $AIUser;
|
|
|
|
|
|
if(count(static::$AIList) < static::$RobotMax)
|
|
{
|
|
static::$RobotMax = count(static::$AIList);
|
|
}
|
|
|
|
if(count(static::$AIList) <= 0)
|
|
{
|
|
static::$RobotOpen = 0;
|
|
}
|
|
|
|
if(static::$RobotMax <= 0)
|
|
{
|
|
static::$RobotOpen = 0;
|
|
}
|
|
|
|
if(static::$RobotMin <= 0)
|
|
{
|
|
static::$RobotMin = 0;
|
|
}
|
|
}
|
|
|
|
public static function getRandomAIFromDb($num)
|
|
{
|
|
//对机器人赋值
|
|
//static::$AIList = AI::$AIUser;
|
|
$AIArray = Db::instance('dbDefault')->query("select * from ss_member where is_robot=1 and limit ".$num.",1");
|
|
//array('user_id'=>900, 'username'=>'AI_1','nickname'=>'机器人1号', 'ucuid'=>843, 'levelid'=>3,'vip'=>0,'AI'=>true),
|
|
$AIUser = array();
|
|
foreach($AIArray as $key => $value)
|
|
{
|
|
$AIUser['user_id']=$value['id'];
|
|
$AIUser['username']=$value['username'];
|
|
$AIUser['nickname']=$value['nickname'];
|
|
$AIUser['ucuid']=$value['ucuid'];
|
|
$spendcoin=$value['spendcoin'];
|
|
$levelid = Db::instance('dbDefault')->query("select levelid from ss_emceelevel where earnbean_low <=".$spendcoin." and earnbean_up >=".$spendcoin);
|
|
$AIUser['levelid']=$levelid[0]['levelid'];
|
|
$AIUser['vip']=$value['vip'];
|
|
$AIUser['AI']=true;
|
|
}
|
|
var_dump($AIUser);
|
|
return $AIUser;
|
|
}
|
|
|
|
/**
|
|
* 获取随机AI用户
|
|
*
|
|
* @return array
|
|
*/
|
|
public static function getRandomAI($room_id, $roomAI)
|
|
{
|
|
// 不要机器人
|
|
if($roomAI == -1)
|
|
return array();
|
|
|
|
if (isset(static::$AIMap[$room_id]) && (time() - static::$AIMap[$room_id]['time']) < 8) {
|
|
return static::$AIMap[$room_id]['list'];
|
|
}
|
|
$AIUser = self::getRandomAIFromDb(0);
|
|
$tmpAI = array();
|
|
$num = 1;
|
|
while(!empty($AIUser))
|
|
{
|
|
if (isset($tmpAI[$AIUser['username']])) {
|
|
continue ;
|
|
}
|
|
|
|
$tmpAI[$AIUser['username']] = $AIUser;
|
|
if(count($tmpAI) >= $roomAI)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if(count($tmpAI) >= static::$RobotMax)
|
|
{
|
|
break;
|
|
}
|
|
|
|
$AIUser = self::getRandomAIFromDb($num);
|
|
$num++;
|
|
}
|
|
|
|
// foreach(static::$AIList as $k=>$v)
|
|
// {
|
|
// if(count(static::$AIList) <= 0)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// if(!$k) {
|
|
// continue;
|
|
// }
|
|
// $ai = $v;
|
|
// if (isset($tmpAI[$ai['username']])) {
|
|
// continue ;
|
|
// }
|
|
|
|
// $tmpAI[$ai['username']] = $ai;
|
|
// if(count($tmpAI) >= $roomAI)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// if(count($tmpAI) >= static::$RobotMax)
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
//echo '1:';
|
|
//var_dump(count($tmpAI));
|
|
static::$AIMap[$room_id] = array('time'=>time(), 'list'=>$tmpAI);
|
|
return $tmpAI;
|
|
}
|
|
|
|
public static function initAllRoom()
|
|
{
|
|
if (static::$cacheHotRoomFlag) {
|
|
arsort(static::$currentRoomList);
|
|
$tmp = count(static::$currentRoomList) <= 300 ? static::$currentRoomList : array_slice(static::$currentRoomList,0,300,true);
|
|
Mem::set(static::ROOM_SORTED_HOT_LIST, json_encode($tmp));
|
|
}
|
|
Mem::set(static::ROOM_COUNT_ALL, count(static::$currentRoomList));
|
|
|
|
$onlineRooms = static::getAllOnLineRoom();
|
|
/*
|
|
$allGroupInfo = \Gateway::getAllClientInfo();
|
|
$tmp = array();
|
|
foreach($allGroupInfo as $client_id => $status) {
|
|
if (empty($status)) {
|
|
continue ;
|
|
}
|
|
if (!isset($tmp[$status['room_id']])) {
|
|
$tmp[$status['room_id']] = array();
|
|
}
|
|
$tmp[$status['room_id']][] = $status;
|
|
}
|
|
unset($allGroupInfo);
|
|
*/
|
|
// 删除不在直播房间的Timer
|
|
foreach (static::$allRoomTimer as $room_id => $timer) {
|
|
if (in_array($room_id,$onlineRooms)) {
|
|
continue ;
|
|
}
|
|
static::removeRoomTimer($room_id);
|
|
}
|
|
|
|
$tmp = array();
|
|
foreach ($onlineRooms as $room_id) {
|
|
$tmp[$room_id] = \Gateway::getClientInfoByGroup($room_id);
|
|
}
|
|
static::$currentRoomList = $group_info = array();
|
|
foreach($tmp as $room_id => $group_client) {
|
|
static::$currentRoomList[$room_id] = 0;
|
|
if (count($group_client) == 0) {
|
|
self::removeRoomTimer($room_id);
|
|
continue;
|
|
}
|
|
if (isset(static::$allRoomTimer[$room_id])) {
|
|
$group_info[$room_id] = static::$allRoomTimer[$room_id];
|
|
continue;
|
|
}
|
|
$group_info[$room_id] = \Workerman\Lib\Timer::add(2,array("\Application\Crontab","getClientList"),array($room_id),true);
|
|
}
|
|
|
|
// if (!empty(static::$allRoomTimer)) {
|
|
// $roomOrignal = array_keys(static::$allRoomTimer);
|
|
// $roomNew = array_keys($group_info);
|
|
// $arrayDiff = array_diff($roomOrignal, $roomNew);
|
|
// foreach($arrayDiff as $room_id => $timer) {
|
|
// self::removeRoomTimer($room_id);
|
|
// }
|
|
// }
|
|
// unset($tmp);
|
|
static::$allRoomTimer = $group_info;
|
|
}
|
|
|
|
public static function getAllOnLineRoom()
|
|
{
|
|
$group = RoomStatus::getOnlineRoom();
|
|
$tmp = array();
|
|
if ( !is_array($group) || empty($group)) {
|
|
return $tmp;
|
|
}
|
|
|
|
foreach ($group as $room) {
|
|
if ($room['curroomnum'] <= 0) {
|
|
continue;
|
|
}
|
|
$tmp[] = $room['curroomnum'];
|
|
}
|
|
return $tmp;
|
|
}
|
|
|
|
public static function removeRoomTimer($room_id)
|
|
{
|
|
if (!isset(static::$allRoomTimer[$room_id])) {
|
|
return ;
|
|
}
|
|
$Rebot_List = array();
|
|
$list = json_decode(Mem::get(static::ROOM_ONLINE_PEPOLE_REBOT.$room_id),true);
|
|
$list_array = (array)$list;
|
|
$Rebot_List = $list_array['Rebot_List'];
|
|
Mem::set(static::ROOM_ONLINE_PEPOLE_REBOT.$room_id, json_encode(array('is_over'=>-1,'Rebot_List'=>$Rebot_List)));
|
|
\Workerman\Lib\Timer::del(static::$allRoomTimer[$room_id]);
|
|
//var_dump('exit');
|
|
self::getClientList($room_id);
|
|
unset(static::$allRoomTimer[$room_id]);
|
|
//Mem::delete(self::ROOM_ONLINE_NUM_PREFIX.$room_id);
|
|
}
|
|
|
|
public static function get_rand_ai($room_id, $roomAI,$Rebot_List)
|
|
{
|
|
// 不要机器人
|
|
if($roomAI == -1)
|
|
return array();
|
|
|
|
if (isset(static::$AIMap[$room_id]) && (time() - static::$AIMap[$room_id]['time']) < 8) {
|
|
return static::$AIMap[$room_id]['list'];
|
|
}
|
|
|
|
$AIUser = self::getRandomAIFromDb(0);
|
|
$tmpAI = array();
|
|
$num = 1;
|
|
while(!empty($AIUser))
|
|
{
|
|
$ai = $AIUser;
|
|
if (isset($tmpAI[$ai['username']])) {
|
|
continue ;
|
|
}
|
|
if (isset($Rebot_List[$ai['username']])) {
|
|
continue ;
|
|
}
|
|
$tmpAI[$ai['username']] = $ai;
|
|
if(count($tmpAI) >= $roomAI)
|
|
{
|
|
break;
|
|
}
|
|
|
|
if(count($tmpAI) >= static::$RobotMax)
|
|
{
|
|
break;
|
|
}
|
|
$AIUser = self::getRandomAIFromDb($num);
|
|
$num++;
|
|
}
|
|
|
|
// $tmpAI = array();
|
|
// foreach(static::$AIList as $k=>$v)
|
|
// {
|
|
// if(count(static::$AIList) <= 0)
|
|
// {
|
|
// break;
|
|
// }
|
|
// if(!$k) {
|
|
// continue;
|
|
// }
|
|
// $ai = $v;
|
|
// if (isset($tmpAI[$ai['username']])) {
|
|
// continue ;
|
|
// }
|
|
// if (isset($Rebot_List[$ai['username']])) {
|
|
// continue ;
|
|
// }
|
|
// $tmpAI[$ai['username']] = $ai;
|
|
// if(count($tmpAI) >= $roomAI)
|
|
// {
|
|
// break;
|
|
// }
|
|
|
|
// if(count($tmpAI) >= static::$RobotMax)
|
|
// {
|
|
// break;
|
|
// }
|
|
// }
|
|
|
|
//echo '2:';
|
|
//var_dump(count($tmpAI));
|
|
static::$AIMap[$room_id] = array('time'=>time(), 'list'=>$tmpAI);
|
|
return $tmpAI;
|
|
}
|
|
|
|
public static function get_ai_list($room_id,$room_info)
|
|
{
|
|
|
|
var_dump('get_ai_list');
|
|
self::initAI();
|
|
if(!static::$RobotOpen)
|
|
{
|
|
var_dump('RobotOpen');
|
|
Mem::set(static::ROOM_ONLINE_PEPOLE_REBOT.$room_id, json_encode(array('is_over'=>1,'Rebot_List'=>array())));
|
|
return array();
|
|
}
|
|
//默认配置 现在设置第一次初始化添加2个机器人
|
|
$InitRebot = mt_rand(static::$RobotMin-1,static::$RobotMax-1);
|
|
var_dump($InitRebot);
|
|
//默认1:10
|
|
if(static::$RobotChangeMax <= 0)
|
|
{
|
|
$Ratio = -1;
|
|
}
|
|
else{
|
|
$Ratio = mt_rand(static::$RobotChangeMin-1,static::$RobotChangeMax-1);
|
|
|
|
}
|
|
|
|
// var_dump($Ratio);
|
|
//此处添加
|
|
//将上次人数保存
|
|
$room_people_num = count((array)$room_info);
|
|
$roomAI_list=array();
|
|
if(!Mem::get(static::ROOM_ONLINE_PEPOLE_REBOT.$room_id))
|
|
{
|
|
$roomAI = $InitRebot;
|
|
$roomAI_list = self::getRandomAI($room_id,$roomAI);
|
|
}
|
|
else
|
|
{
|
|
$list = json_decode(Mem::get(static::ROOM_ONLINE_PEPOLE_REBOT.$room_id),true);
|
|
$list_array = (array)$list;
|
|
if(empty($list_array))
|
|
{
|
|
$roomAI = $InitRebot;
|
|
$roomAI_list = self::getRandomAI($room_id,$roomAI);
|
|
}
|
|
else
|
|
{
|
|
$is_over = $list_array['is_over'];
|
|
$Rebot_List = $list_array['Rebot_List'];
|
|
if($is_over == -1)
|
|
{
|
|
echo " is_over";
|
|
$roomAI = $InitRebot;
|
|
$roomAI_list = self::getRandomAI($room_id,$roomAI);
|
|
}
|
|
else
|
|
{
|
|
echo " Ratio";
|
|
$roomAI = $Ratio;
|
|
$roomAI_list_new = self::get_rand_ai($room_id,$roomAI,$Rebot_List);
|
|
|
|
foreach($roomAI_list_new as $k=>$v)
|
|
{
|
|
$Rebot_List[$k] = $v;
|
|
}
|
|
$roomAI_list = $Rebot_List;
|
|
$room_people_num =$room_people_num + $roomAI;
|
|
}
|
|
|
|
}
|
|
}
|
|
//var_dump(count($roomAI_list));
|
|
Mem::set(static::ROOM_ONLINE_PEPOLE_REBOT.$room_id, json_encode(array('is_over'=>1,'Rebot_List'=>$roomAI_list)));
|
|
//echo "roomAI_list";
|
|
//此处结束
|
|
return $roomAI_list;
|
|
}
|
|
|
|
public static function getClientList($room_id)
|
|
{
|
|
$room_info = \Gateway::getClientInfoByGroup($room_id);
|
|
//var_dump($room_info);
|
|
//$roomAI = self::get_ai_list($room_id,$room_info);
|
|
$list = json_decode(Mem::get(static::ROOM_ONLINE_PEPOLE_REBOT.$room_id),true);
|
|
//var_dump($list);
|
|
$list_array = (array)$list;
|
|
$Rebot_List=array();
|
|
$is_over = -1;
|
|
$is_over = $list_array['is_over'];
|
|
$Rebot_List = $list_array['Rebot_List'];
|
|
if($is_over == -1)
|
|
{
|
|
//$roomAI = $Rebot_List;
|
|
if(count($room_info)!=0)
|
|
{
|
|
//$room_info = array_diff($room_info, $Rebot_List);
|
|
$room_info = array();
|
|
}
|
|
//$room_info = array_diff($room_info, $Rebot_List);
|
|
}else
|
|
{
|
|
$roomAI = $Rebot_List;
|
|
$room_info = array_merge($room_info, $roomAI);
|
|
}
|
|
|
|
//var_dump(count($room_info));
|
|
// TODO 按规则排序,vip/等级 同时保留用户状态信息,便于前端显示
|
|
$adminer_list = array();
|
|
$client_list = array();
|
|
foreach ($room_info as $client_id => $session) {
|
|
if (empty($session)) {
|
|
continue;
|
|
}
|
|
$session['avatar'] = AdminClient::getAvatar($session['user_id']);
|
|
if (isset($session['role'])) {
|
|
if (strcmp($session['role'], 'owner') === 0) {
|
|
continue;
|
|
}
|
|
$adminer_list[] = $session;
|
|
} else {
|
|
$client_list[] = $session;
|
|
}
|
|
}
|
|
|
|
$viewer_num = 0;
|
|
$adminer_list = self::sortClient($adminer_list, true, $viewer_num);
|
|
$client_list = self::sortClient($client_list, false, $viewer_num);
|
|
$all_num = count($adminer_list) + count($client_list) + $viewer_num;
|
|
|
|
$all_num = 50 + $all_num;
|
|
// if (Mem::get(self::ROOM_ANCHOR_ONLIE_PREFIX . $room_id) == 'online') {
|
|
static::$currentRoomList[$room_id] = $all_num;
|
|
// }
|
|
#$all_num = $all_num + 100;
|
|
RoomStatus::updateOnlineNumToDb($room_id, $all_num);
|
|
// $status_num_json = json_encode(array('all_num'=>$all_num, 'viewer_num'=>$viewer_num));
|
|
// $status_client_list_json = json_encode(array('adminer_list'=>$adminer_list, 'client_list'=>$client_list));
|
|
|
|
// if ($status_num != Mem::get(static::ROOM_ONLINE_NUM_PREFIX . $room_id) && $status_client_list != Mem::get(static::ROOM_SORTED_CLIENTS_PREFIX . $room_id)) {
|
|
// 在线用户已改变,广播至客户端,并写入缓存
|
|
self::BroadCast($room_id, $all_num, $viewer_num, $adminer_list, $client_list);
|
|
// }
|
|
return ;
|
|
}
|
|
|
|
public static function sendOnLineList($room_id, $session)
|
|
{
|
|
//$num = json_decode(Mem::get(static::ROOM_ONLINE_NUM_PREFIX . $room_id), true);
|
|
// if (isset($session['role']) && strcmp($session['role'], 'owner') === 0) {
|
|
// Crontab::initAI();
|
|
// Crontab::getClientList($room_id);
|
|
// return ;
|
|
// }
|
|
//echo 'sendOnLineList ';
|
|
$list = json_decode(Mem::get(static::ROOM_SORTED_CLIENTS_PREFIX . $room_id), true);
|
|
|
|
//$list=NULL;
|
|
//var_dump($list);
|
|
unset($session['msged']);
|
|
unset($session['time']);
|
|
$session['avatar'] = AdminClient::getAvatar($session['user_id']);
|
|
|
|
$viewer_num = 0;
|
|
$adminer_list = !$list ? array() : $list['adminer_list'];
|
|
$client_list = !$list ? array() : $list['client_list'];
|
|
|
|
$AIList = self::get_ai_list($room_id, array_merge($adminer_list, $client_list));
|
|
|
|
$client_list = array_merge($client_list, $AIList);
|
|
if (isset($session['role'])) {
|
|
if ( strcmp($session['role'], 'owner') !== 0 && !self::inOnLineList($session['user_id'], $adminer_list)) {
|
|
$adminer_list[] = $session;
|
|
$useless = 0;
|
|
$adminer_list = self::sortClient($adminer_list, true, $useless);
|
|
}
|
|
} else if (!self::inOnLineList($session['user_id'], $client_list)) {
|
|
$client_list[] = $session;
|
|
$client_list = self::sortClient($client_list, false, $viewer_num);
|
|
}
|
|
|
|
$message = array(
|
|
'type' => 'onLineClient',
|
|
'all_num' => count($adminer_list) + count($client_list) + $viewer_num,
|
|
'viewer_num' => $viewer_num,
|
|
'adminer_list' => $adminer_list,
|
|
'client_list' => $client_list,
|
|
);
|
|
$message['all_num'] =50 + $message['all_num'];
|
|
echo "room_id:".$room_id." client_list:";
|
|
var_dump(count($client_list));
|
|
\Gateway::sendToClient($session['client_id'],json_encode($message));
|
|
return ;
|
|
/*
|
|
if (!$num || !$list || $num['all_num'] == 0) {
|
|
if (isset($session['role'])) {
|
|
if (strcmp($session['role'],'owner') !== 0) {
|
|
$message['all_num'] = 1;
|
|
$message['adminer_list'][0] = $session;
|
|
}
|
|
} else {
|
|
$message['all_num'] = 1;
|
|
$message['viewer_num'] = $session['user_id'] == -1 ? 1 : 0;
|
|
$message['client_list'][0] = $session;
|
|
}
|
|
\Gateway::sendToGroup($room_id, json_encode($message));
|
|
return ;
|
|
}
|
|
$message['all_num'] = $num['all_num'];
|
|
$message['viewer_num'] = $num['viewer_num'];
|
|
$message['adminer_list'] = $list['adminer_list'];
|
|
$message['client_list'] = $list['client_list'];
|
|
*/
|
|
}
|
|
|
|
public static function inOnLineList($user_id, $user_info)
|
|
{
|
|
foreach ($user_info as $key => $session) {
|
|
if ($session['user_id'] == $user_id) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public static function BroadCast($room_id, $all_num, $viewer_num,$adminer_list, $client_list)
|
|
{
|
|
$message = array(
|
|
'type'=>'onLineClient',
|
|
'all_num'=>$all_num,
|
|
'viewer_num'=>$viewer_num,
|
|
'adminer_list'=>$adminer_list,
|
|
'client_list'=>$client_list,
|
|
);
|
|
\Gateway::sendToGroup($room_id, json_encode($message));
|
|
Mem::set(static::ROOM_ONLINE_NUM_PREFIX . $room_id, json_encode(array('all_num'=>$all_num,'viewer_num'=>$viewer_num)));
|
|
Mem::set(static::ROOM_SORTED_CLIENTS_PREFIX . $room_id, json_encode(array('adminer_list'=>$adminer_list,'client_list'=>$client_list)));
|
|
}
|
|
public static function sortClient($user_info, $adminer = false , &$viewer_num)
|
|
{
|
|
$room_owner = null;
|
|
$vip1_tmp = $vip2_tmp = $vip0_tmp = array();
|
|
$hasLoginUser = array();
|
|
foreach($user_info as $index => $session) {
|
|
if ($adminer && strcmp($session['role'],'owner') == 0) {
|
|
// $room_owner = $session;
|
|
continue ;
|
|
}
|
|
if (!$adminer && $session['user_id'] == -1 && (!isset($session['AI']) || !$session['AI'])) {
|
|
$viewer_num++;
|
|
continue ;
|
|
}
|
|
if (in_array($session['user_id'],$hasLoginUser)) {
|
|
// 在线列表踢出重复登录用户
|
|
continue;
|
|
}
|
|
unset($session['time']);
|
|
unset($session['msged']);
|
|
switch ((int)$session['vip']) {
|
|
case 1:
|
|
if (!isset($vip1_tmp[$session['levelid']])) {
|
|
$vip1_tmp[$session['levelid']] = array();
|
|
}
|
|
$vip1_tmp[$session['levelid']][] = $session;
|
|
break;
|
|
case 2:
|
|
if (!isset($vip2_tmp[$session['levelid']])) {
|
|
$vip2_tmp[$session['levelid']] = array();
|
|
}
|
|
$vip2_tmp[$session['levelid']][] = $session;
|
|
break;
|
|
case 0:
|
|
if (!isset($vip0_tmp[$session['levelid']])) {
|
|
$vip0_tmp[$session['levelid']] = array();
|
|
}
|
|
$vip0_tmp[$session['levelid']][] = $session;
|
|
default:
|
|
// do nothing
|
|
}
|
|
$hasLoginUser[] = $session['user_id'];
|
|
}
|
|
|
|
unset($hasLoginUser);
|
|
krsort($vip1_tmp);
|
|
krsort($vip2_tmp);
|
|
krsort($vip0_tmp);
|
|
$vip1_list = $vip2_list = $vip0_list = array();
|
|
foreach($vip1_tmp as $levelid => $list) {
|
|
$vip1_list = array_merge($vip1_list, $list);
|
|
}
|
|
foreach ($vip2_tmp as $levelid => $list) {
|
|
$vip2_list = array_merge($vip2_list, $list);
|
|
}
|
|
foreach($vip0_tmp as $levelid => $list) {
|
|
$vip0_list = array_merge($vip0_list, $list);
|
|
}
|
|
|
|
$all_client_list = $room_owner != null ? array_merge(array($room_owner), array_merge($vip1_list, array_merge($vip2_list, $vip0_list))) : array_merge($vip1_list, array_merge($vip2_list, $vip0_list));
|
|
return count($all_client_list) <= 200 ? $all_client_list : array_slice($all_client_list, 0, 200, true);
|
|
}
|
|
}
|
|
|