예제 #1
0
 /**
  * 牌局玩家进度广播
  */
 public static function doApi($player, $data, &$re, $client_id)
 {
     $uid = $player->uid;
     $table = TableDao::getTable($player->tableId);
     if (!$table) {
         return 1;
     }
     if (!Timer::isExistTimer($table->blinkTimeOut)) {
         Gateway::bindUid($client_id, $uid);
         $table->blinkTimeOut = Timer::add(Constants::TABLE_INIT_CHECK_TIME, array($table, 'checkTime'));
         TableDao::addTable($table->tableId, $table);
     }
     if (!isset($table->playerStatus[$uid])) {
         $table->addUid($uid);
         GameDao::addInGamePlayer($uid);
         TableDao::addTable($table->tableId, $table);
     }
     if ($data['st'] == 1) {
         if (!in_array($uid, $table->readyUids)) {
             $table->readyUids[] = $uid;
             TableDao::addTable($table->tableId, $table);
         }
         if (count($table->readyUids) >= 3) {
             $table->recordTime = time();
             TableDao::addTable($table->tableId, $table);
             $re['uid'] = -1;
             Gateway::sendToUid($table->uids, json_encode($re));
         }
     }
     if ($data['addVal'] != -1) {
         $uids = $table->uids;
         $re['uid'] = $uid;
         foreach ($uids as $_uid) {
             if ($_uid == $uid) {
                 continue;
             }
             $re['addVal'] = $data['addVal'];
             $re['oldVal'] = $data['oldVal'];
             Gateway::sendToUid($_uid, json_encode($re));
         }
     }
     return 1;
 }
예제 #2
0
 /**
  * 玩家账号注册,确定牌局
  * @param $data
  * @param $re
  * @return int
  */
 public static function doApi($data, &$re)
 {
     if (!isset($data['uid'])) {
         $re['s'] = Constants::RESPONSE_FAIL;
         return 0;
     }
     $uid = $data['uid'];
     $re['uid'] = $uid;
     $player = PlayerDao::getPlayer($uid);
     if (!$player) {
         $ip = $_SERVER['REMOTE_ADDR'];
         $player = new Player($data, $ip);
         PlayerDao::addPlayer($player->uid, $player);
     } else {
         $player->lastLoginIp = $player->loginIp;
         $player->loginIp = $_SERVER['REMOTE_ADDR'];
         $player->loginTime = time();
         $player->tableId = $data['tid'];
         PlayerDao::addPlayer($player->uid, $player);
     }
     $table = TableDao::getTable($player->tableId);
     $nowTime = time();
     if ($table && isset($table->playerStatus[$uid]) && $nowTime - $table->recordTime <= 60 && $table->tableStatus != Constants::TABLE_INIT && $table->tableStatus != Constants::TABLE_END && $table->playerStatus[$uid] != Constants::PLAYER_LEAVE) {
         GameDao::addInGamePlayer($uid);
         $re['s'] = Constants::RESPONSE_RECONN_SUCCESS;
         $tableInfo = $table->getTableInfo($player);
         if ($tableInfo) {
             $re['tableInfo'] = $tableInfo;
             Gateway::sendToUid($uid, json_encode($re));
             return 1;
         }
     }
     if (!$table || $nowTime - $table->initTime >= 120) {
         $table = new Table($data['tid'], $data['uids']);
         TableDao::addTable($table->tableId, $table);
     }
     if ($table && in_array($uid, $table->uids)) {
         $re['s'] = Constants::RESPONSE_SUCCESS;
     } else {
         $re['s'] = Constants::RESPONSE_FAIL;
     }
 }
예제 #3
0
 public static function doApi($player, $data, &$re)
 {
     $uid = $player->uid;
     if ($player->tableId > 0) {
         $table = TableDao::getTable($player->tableId);
         if ($table && $table->tableStatus == Constants::TABLE_IN_GAME) {
             $op = $data['op'];
             if ($op == 1) {
                 $table->playerStatus[$uid] = Constants::PLAYER_DEPOSIT;
                 $table->noPlayNums[$uid] = 0;
             } else {
                 $table->playerStatus[$uid] = Constants::PLAYER_UN_DEPOSIT;
             }
             TableDao::addTable($table->tableId, $table);
             $re['s'] = Constants::RESPONSE_SUCCESS;
             $re['st'] = $table->playerStatus[$uid];
             $re['uid'] = $uid;
             Gateway::sendToUid($table->uids, json_encode($re));
             return 1;
         }
     }
     $re['s'] = Constants::RESPONSE_FAIL;
     return 0;
 }
예제 #4
0
파일: Event.php 프로젝트: 871263000/zdl
 /**
  * 当客户端断开连接时
  * @param integer $client_id 客户端id
  */
 public static function onClose($client_id)
 {
     // debug
     // echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']}  client_id:$client_id onClose:''\n";
     // 从房间的客户端列表中删除
     $adminUid = 1;
     if (isset($_SESSION['room_id'])) {
         $room_id = $_SESSION['room_id'];
         $uid = $_SESSION['uid'];
         $logined = Gateway::getClientIdByUid($uid);
         //uid 还在线
         if (empty($logined)) {
             $new_message = array('type' => 'logout', 'from_uid_id' => $uid, 'from_client_name' => $_SESSION['client_name'], 'time' => date('Y-m-d H:i:s'));
             Gateway::sendToGroup($room_id, json_encode($new_message));
             //发给管理员,要看所有的在线人数
             $new_logout = ['type' => 'loggoutTwo'];
             Gateway::sendToUid($adminUid, json_encode($new_logout));
         }
     }
 }
예제 #5
0
 /**
  * 地主确认信息
  * @param $table
  * @param $re
  * @return mixed
  */
 public static function sendInfo($table, $re, $uid = 0)
 {
     $re['s'] = Constants::RESPONSE_SUCCESS;
     $re['st'] = Constants::LANDLORD_ENSURE;
     $re['lUid'] = $table->landlordUid;
     $re['tableSt'] = $table->tableStatus;
     $re['rTime'] = $table->recordTime;
     $re['multiple'] = $table->multiple;
     foreach ($table->uids as $_uid) {
         if ($_uid != $uid) {
             Gateway::sendToUid($_uid, json_encode($re));
         }
     }
     return $re;
 }
예제 #6
0
   /**
    * 有消息时
    * @param int $client_id
    * @param string $message
    */
   public static function onMessage($client_id, $message)
   {
        // debug
        // echo "client:{$_SERVER['REMOTE_ADDR']}:{$_SERVER['REMOTE_PORT']} gateway:{$_SERVER['GATEWAY_ADDR']}:{$_SERVER['GATEWAY_PORT']}  client_id:$client_id session:".json_encode($_SESSION)." onMessage:".$message."\n";

        // 客户端传递的是json数据
        $message = str_replace("script", "'script'" , $message);
        $message_data = json_decode($message, true);
        if(!$message_data)
        {
            return ;
        }
        // echo $message_data['type'];
        // 根据类型执行不同的业务
        switch($message_data['type'])
        {
            // 客户端回应服务端的心跳
            case 'pong':
                return;
            // 客户端登录 message格式: {type:login, name:xx, room_id:1} ,添加到客户端,广播给所有客户端xx进入聊天室
            case 'login':
                //是否已登录
                // $exist = (bool)false;
                //client_id 和 uid 绑定
                $logined = Gateway::getClientIdByUid($message_data['uid']);
                //绑定uid
                Gateway::bindUid($client_id, $message_data['uid']);
                // 把房间号昵称放到session中
                $room_id = $message_data['room_id'];
                $uid = $message_data['uid'];
                // 判断是否有房间号
                if(!isset($message_data['room_id']))
                {
                    throw new \Exception("\$message_data['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']} \$message:$message");
                }
                $client_name = htmlspecialchars($message_data['client_name']);
                $_SESSION['room_id'] = $room_id;
                $_SESSION['client_name'] = $client_name;
                $_SESSION['uid'] = $uid;
                $_SESSION['header_img_url'] = $message_data['header_img_url'];
                // 获取房间内所有用户列表 
                $clients_list = Gateway::getClientInfoByGroup($room_id);
                foreach($clients_list as $tmp_client_id=>$item)
                {
                    $clients_list[$tmp_client_id]['client_name'] = $item['client_name'];
                    $clients_list[$tmp_client_id]['uid'] = $item['uid'];
                }
                //判断是否已登陆
                if (empty($logined)) {
                    $clients_list[$client_id]['client_name'] = htmlspecialchars($client_name);
                    $clients_list[$client_id]['uid'] = $uid;
                    $new_message = array('type'=>$message_data['type'], 'client_list'=>$clients_list, 'time'=>date('Y-m-d H:i:s'));
                    Gateway::sendToGroup($room_id, json_encode($new_message));
                     // 给当前用户发送用户列表 
                    $new_message['client_list'] = $clients_list;
                    Gateway::sendToCurrentClient(json_encode($new_message));   
                } else {
                    print_r($clients_list);
                    // 给当前用户发送用户列表 
                    $new_message['client_list'] = $clients_list;
                    Gateway::sendToCurrentClient(json_encode($new_message));  
                }
                Gateway::joinGroup($client_id, $room_id);
                return;
            // 客户端发言 message: {type:say, to_client_id:xx, content:xx}
            case 'say':
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $client_name = $_SESSION['client_name'];
                
                // 私聊
                if($message_data['to_client_id'] != 'all')
                {
                    $new_message = array(
                        'type'=>'say',
                        'from_client_id'=>$client_id, 
                        'from_client_name' =>$client_name,
                        'to_client_id'=>$message_data['to_client_id'],
                        'content'=>"<b>对你说: </b>".nl2br(htmlspecialchars($message_data['content'])),
                        'time'=>date('Y-m-d H:i:s'),
                    );
                    Gateway::sendToClient($message_data['to_client_id'], json_encode($new_message));
                    $new_message['content'] = "<b>你对".htmlspecialchars($message_data['to_client_name'])."说: </b>".nl2br(htmlspecialchars($message_data['content']));
                    return Gateway::sendToCurrentClient(json_encode($new_message));
                }
                
                $new_message = array(
                    'type'=>'say', 
                    'from_client_id'=>$client_id,
                    'from_client_name' =>$client_name,
                    'to_client_id'=>'all',
                    'content'=>nl2br(htmlspecialchars($message_data['content'])),
                    'time'=>date('Y-m-d H:i:s'),
                );
                return Gateway::sendToGroup($room_id ,json_encode($new_message));
            case 'say_uid':
                $db1 = Db::instance('oms');
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $client_name = $_SESSION['client_name'];
                $uid = $_SESSION['uid'];
                // 私聊
                $message_content = $message_data['content'];
                if($message_data['to_uid_id'] !== 'all')
                {
                    $new_message = array(
                        'type'=>'say_uid',
                        'from_client_id'=>$client_id, 
                        'from_client_name' =>$client_name,
                        'from_uid_id'=>$uid,
                        'groupId'=>$message_data['groupId'],
                        'mestype'=>$message_data['message_type'],
                        'content'=>$message_content,
                        'time'=>date('Y-m-d H:i:s'),
                    );
                    if ($message_data['message_type'] == "message") {
                        $session_no = $uid > $message_data['to_uid_id'] ? $message_data['to_uid_id']."-".$uid : $uid."-".$message_data['to_uid_id'];
                        $new_message['mestype'] = "message";
                        $to_uid = $message_data['to_uid_id'];
                    } else {
                        //验证是否在群聊
                        $va = $db1->query("SELECT `group_participants`, `group_name` FROM `oms_group_chat` WHERE `id`=".$message_data['session_no']);
                        $arrVa = explode(',', $va[0]['group_participants']);
                        if (!in_array($uid, $arrVa)) {
                            return ;
                        }
                        $session_no = $message_data['session_no'];
                        $new_message['mestype'] = "groupMessage";
                        $new_message['group_name'] = $va[0]['group_name'];
                        $message_data['to_uid_id'] = $va[0]['group_participants'];
                        $new_message['to_uid_id'] = $va[0]['group_participants'];
                        foreach ($arrVa as $key => $value) {
                            if ($value == $uid) {
                                unset($arrVa[$key]);
                            }
                        }
                        $to_uid = $arrVa;
                    }
                    $insert_id = $db1->insert('oms_string_message')->cols(array('room_id'=>$room_id, 'sender_id'=>$uid,'accept_id'=>$message_data['to_uid_id'], 'sender_name'=>$client_name, 'accept_name'=>$message_data['accept_name'],'message_type'=>$message_data['message_type'], 'groupId'=>$message_data['groupId'], 'message_content'=>$message_content, 'session_no'=>$session_no, 'create_time'=>time(), 'update_time'=>time()))->query();
                    $new_message['insert_id'] = $insert_id;
                    $new_message['session_no'] = $session_no;
                    if ($message_data['message_type'] == "groupMessage") {
                        $db1->query("UPDATE `oms_groups_people` SET `mes_state`=1, `mes_id`=".$insert_id." WHERE `staffid` != $uid AND `pid`=".$message_data['session_no']);
                    } 
                    Gateway::sendToUid($to_uid, json_encode($new_message));
                    return ;
                }
                // 组聊
                $new_message = array(
                    'type'=>'say_uid', 
                    'from_client_id'=>$client_id,
                    'from_client_name' =>$client_name,
                    'to_client_id'=>'all',
                    'content'=>"{$client_name}说: ".nl2br(htmlspecialchars($message_data['content'])),
                    'time'=>date('Y-m-d H:i:s'),
                );
                $insert_id = $db1->insert('oms_string_message')->cols(array('room_id'=>$room_id, 'sender_id'=>$message_data['senderid'],'accept_id'=>0,'accept_name'=>$client_name ,'message_type'=>$message_data['message_type'], 'message_content'=>nl2br(htmlspecialchars($message_data['content'])), 'create_time'=>time(), 'update_time'=>time()))->query();
                return Gateway::sendToGroup($room_id ,json_encode($new_message));

            //审核消息
            case 'audit':
                 $db1 = Db::instance('oms');
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $client_name = $_SESSION['client_name'];
                $uid = $_SESSION['uid'];
                // 私聊
                if($message_data['to_uid_id'] != 'all')
                {
                    $new_message = array(
                        'message_url'=>$message_data['message_url'],
                        'type'=>'audit',
                        'from_client_id'=>$client_id, 
                        'from_client_name' =>$client_name,
                        'content'=>nl2br(htmlspecialchars($message_data['content'])),
                        'time'=>date('Y-m-d H:i:s'),
                    );

                    // Gateway::sendToClient($message_data['to_client_id'], json_encode($new_message));
                    $newTime = time();
                    $session_no = $newTime.$client_id;
                    if (!empty($message_data['to_uid_id'])) {
                        foreach ($message_data['to_uid_id'] as $key => $value) {
                            $arrValue[] = "($value, '".$message_data['senderid']."', '".$message_data['message_type']."', '".$message_data['content']."', '1', '".$message_data['message_url']."', '".$session_no."', ".$newTime.", ".$newTime.")";
                        }
                    }
                    $value = implode(',', $arrValue);
                    //插入数据
                    $insert_id = $db1->query("INSERT INTO `oms_string_message` (`accept_id`, `sender_id`, `message_type`, `message_content`, `oms_id`, `message_url`, `session_no`,  `create_time`, `update_time`) VALUE".$value);
                    $new_message['session_no'] = $session_no;
                    Gateway::sendToUid($message_data['to_uid_id'], json_encode($new_message));
                    return ;
                }
                // 组聊
                $new_message = array(
                    'type'=>'say_uid', 
                    'from_client_id'=>$client_id,
                    'from_client_name' =>$client_name,
                    'to_client_id'=>'all',
                    'content'=>"{$client_name}说: ".nl2br(htmlspecialchars($message_data['content'])),
                    'time'=>date('Y-m-d H:i:s'),
                );
                $insert_id = $db1->insert('oms_string_message')->cols(array('room_id'=>$room_id, 'sender_id'=>$message_data['senderid'],'accept_id'=>0,'accept_name'=>$client_name ,'message_type'=>$message_data['message_type'], 'message_content'=>nl2br(htmlspecialchars($message_data['content'])), 'create_time'=>time(), 'update_time'=>time()))->query();
                return Gateway::sendToGroup($room_id ,json_encode($new_message));

            return;
            //数据操作消息的关闭
            case 'mes_close':
                $db1 = Db::instance('oms');
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $mesid = $message_data['mesid'];
                $session_no = $message_data['session_no'];
                $uid = $_SESSION['uid'];
                if ($message_data['mestype'] == 'message') {
                    $db1->query("UPDATE `oms_string_message` SET `state`=1 WHERE `id`= "."'{$mesid}'");
                } else {
                    $db1->query("UPDATE `oms_groups_people` SET `mes_state`=0 WHERE `staffid`=$uid AND `pid`=".$session_no);
                }
                return ;
            // 选择人后聊天信息
            case 'mes_chat':
                $db1 = Db::instance('oms');
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $uid = $_SESSION['uid'];
                $session_no = $uid < $message_data['mes_para'] ? $uid."-".$message_data['mes_para'] : $message_data['mes_para']."-".$uid;
                $mes_list = $db1->query("SELECT `id`, `message_content`, `create_time`, `sender_name`, `sender_id` FROM `oms_string_message` WHERE `delState` = 0 AND `session_no`= "."'{$session_no}' ORDER BY create_time desc limit 0, 10");
                if (!empty($mes_list)) {
                    foreach ($mes_list as $key => $value) {
                            $mes_list[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
                    }
                }
                $mes_list['type'] = 'mes_chat';
                Gateway::sendToClient($client_id, json_encode($mes_list));
                return;
            //滚动消息的分页
            case 'mes_load':
                $db1 = Db::instance('oms');
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $uid = $_SESSION['uid'];
                if ($message_data['message_type'] == "message") {
                    //会话id
                    $session_no = $uid > $message_data['to_uid'] ? $message_data['to_uid']."-".$uid : $uid."-".$message_data['to_uid'];
                } else {
                    //验证是否在群聊
                    $va = $db1->query("SELECT `group_participants` FROM `oms_group_chat` WHERE `id`=".$message_data['session_no']);
                    $arrVa = explode(',', $va[0]['group_participants']);
                    if (!in_array($uid, $arrVa)) {
                        return ;
                    }
                    //会话id
                    $session_no = $message_data['session_no'];
                }
                if (!empty($message_data['mes_loadnum'])) {
                    $onlode = $db1->query("SELECT `id`, `message_content`, `create_time`, `accept_name`, `sender_id`, `sender_name` FROM `oms_string_message` WHERE `delState` = 0 AND `session_no`= "."'{$session_no}' ORDER BY create_time desc limit ".$message_data['mes_loadnum'].", 10");
                    if (!empty($onlode)) {
                        foreach ($onlode as $key => $value) {
                                $onlode[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
                        }
                        $onlode['type'] = 'onlode';
                        $onlode['save'] = 1;
                    } else {
                        $onlode['type'] = 'onlode';
                        $onlode['save'] = 0;
                    }
                    Gateway::sendToClient($client_id, json_encode($onlode));
                }
                
            return ;
            //群聊
            case 'mes_groupChat':
                $db1 = Db::instance('oms');
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $uid = $_SESSION['uid'];
                $arrYanzhng = explode(',', $message_data['groupvalue']);
                if (!in_array($uid, $arrYanzhng)) {
                    return ;
                }
                $group_mes_list = $db1->query("SELECT `id`, `message_content`, `create_time`, `sender_name`, `sender_id` FROM `oms_string_message` WHERE `delState` = 0 AND `session_no`= '".$message_data['session_no']."' ORDER BY create_time desc limit 0, 10");
                if (!empty($group_mes_list)) {
                    foreach ($group_mes_list as $key => $value) {
                            $group_mes_list[$key]['create_time'] = date('Y-m-d H:i:s', $value['create_time']);
                    }
                }
                $group_mes_list['type'] = 'mes_chat';
                Gateway::sendToClient($client_id, json_encode($group_mes_list));
                return;
            case 'recentcClose':
                $db1 = Db::instance('oms');
                $uid = $_SESSION['uid'];
                $db1->query("UPDATE `oms_string_message` SET `delState` = 1 WHERE `session_no` = '".$message_data['session']."'");
                return;
            case 'addGroupMan':
                $db1 = Db::instance('oms');
                $uid = $_SESSION['uid'];
                $arrAddGroupMan = $db1->query("SELECT `group_participants`,`group_name` FROM `oms_group_chat` WHERE id=".$message_data['session_no']);
                $arr = explode(",", $arrAddGroupMan[0]['group_participants']);
                if (!in_array($uid, $arr)) {
                    return;
                }
                foreach ($message_data['sidList'] as $key => $value) {
                    if (!in_array($value, $arr)) {
                        $arr[] = $value;
                        $addMan[] = $value;
                    }
                }
                $sAddGroupMan = implode(",", $arr);
                foreach ($addMan as $k => $val) {
                    $arrvalue[] = "('".$message_data['session_no']."', '".$val."', '".$arrAddGroupMan[0]['group_name']."', ".time()." ,".time().")";
                }
                $strvalue = implode(",", $arrvalue);
                $db1->query("INSERT INTO `oms_groups_people` (`pid`, `staffid`, `group_name`, `create_time`, `update_time`) value".$strvalue);
                $db1->query("UPDATE `oms_group_chat` SET `group_participants`='".$sAddGroupMan."' WHERE id=".$message_data['session_no']);
                $db1->query("UPDATE `oms_groups_people` SET `all_staffid`='".$sAddGroupMan."' WHERE `pid`=".$message_data['session_no']);
                return;
            case 'delgroupman':
                $uid =  $_SESSION['uid'];
                $id = $message_data['id'];
                $db1 = Db::instance('oms');
                $arrgrouppeople = $db1->query("SELECT * FROM `oms_groups_people` WHERE `id`=".$message_data['groupid']);
                $arrjoinGroup = explode(',', $arrgrouppeople[0]['all_staffid']);
                foreach ($arrjoinGroup as $key => $value) {
                    if ($value == $id) {
                        unset($arrjoinGroup[$key]);
                    }
                }
                $unarrjoinGroup = $arrjoinGroup;
                $unstrgroupman = implode(",", $unarrjoinGroup);
                if (in_array($uid, explode(',', $arrgrouppeople[0]['all_staffid']))) {
                    echo "UPDATE `oms_groups_people` SET `all_staffid`= '".$unstrgroupman."' WHERE `pid`=".$arrgrouppeople[0]['pid'];
                    $db1->query("UPDATE `oms_groups_people` SET `all_staffid`= '".$unstrgroupman."' WHERE `pid`=".$arrgrouppeople[0]['pid']);
                    $db1->query("UPDATE `oms_groups_people` SET `state`= 1 WHERE `id`=".$message_data['groupid']);
                    $db1->query("UPDATE `oms_group_chat` SET `group_participants`= '".$unstrgroupman."' WHERE `id`=".$arrgrouppeople[0]['pid']);
                }
                return ;
            case 'active':
                // 非法请求
                if(!isset($_SESSION['room_id']))
                {
                    throw new \Exception("\$_SESSION['room_id'] not set. client_ip:{$_SERVER['REMOTE_ADDR']}");
                }
                $room_id = $_SESSION['room_id'];
                $client_name = $_SESSION['client_name'];
                
                // 私聊
                if($message_data['to_uid_id'] != 'all')
                {
                    $new_message = array(
                        'type'=>'say',
                        'from_client_id'=>$client_id, 
                        'from_client_name' =>$client_name,
                        'to_client_id'=>$message_data['to_client_id'],
                        'content'=>"<b>对你说: </b>".nl2br(htmlspecialchars($message_data['content'])),
                        'time'=>date('Y-m-d H:i:s'),
                    );
                    Gateway::sendToClient($message_data['to_client_id'], json_encode($new_message));
                    $new_message['content'] = "<b>你对".htmlspecialchars($message_data['to_client_name'])."说: </b>".nl2br(htmlspecialchars($message_data['content']));
                    return Gateway::sendToCurrentClient(json_encode($new_message));
                }
                
                $new_message = array(
                    'type'=>'say', 
                    'from_client_id'=>$client_id,
                    'from_client_name' =>$client_name,
                    'to_client_id'=>'all',
                    'content'=>nl2br(htmlspecialchars($message_data['content'])),
                    'time'=>date('Y-m-d H:i:s'),
                );
                return Gateway::sendToGroup($room_id ,json_encode($new_message));

        }
   }
예제 #7
0
 public function reply()
 {
     CustomLogger::getLogger()->info("LKCmdParser reply the cmd");
     Gateway::sendToUid($this->_protocol_data->getDeviceSn(), $this->format_reply_string());
 }
예제 #8
0
 /**
  *  检查操作超时
  */
 public function checkTime($table = '')
 {
     $table || ($table = TableDao::getTable($this->tableId));
     if (!$table || !is_object($table)) {
         //            echo "checkTime:table is not table!! table:".$table."\n";
         //            echo 'flag:'.$table->blinkTimeOut."====checkTime:table is not table!! table:".$table."\n";
         return;
     }
     $nowTime = time();
     if ($table->tableStatus == Constants::TABLE_INIT) {
         //            echo "tid:".$this->tableId." checkTime:table init playerStatus:".count($table->playerStatus)." time:".time()."\n";
         if ($nowTime - $table->recordTime >= 120 && count($table->playerStatus) < 3) {
             //牌局结束-人数不足 2.初始化失败
             Table::exceptionOver($table, 203, 'initFail');
             $table->rmTable();
         }
         if (count($table->playerStatus) == 3) {
             //                echo "tid:".$this->tableId." sendTableInfo\n";
             $uids = $table->uids;
             $table->tableStatus = Constants::TABLE_LANDLORD;
             $re = array();
             $re['type'] = 'jt';
             $re['s'] = Constants::RESPONSE_SUCCESS;
             foreach ($uids as $_uid) {
                 $_player = PlayerDao::getPlayer($_uid);
                 $re['tableInfo'] = $table->getTableInfo($_player);
                 if (!$re['tableInfo']) {
                     return;
                 }
                 Gateway::sendToUid($_uid, json_encode($re));
             }
             $table->recordTime = time();
             Timer::del($table->blinkTimeOut);
             $table->blinkTimeOut = Timer::add(Constants::TABLE_GAME_CHECK_TIME, array($table, 'checkTime'));
             TableDao::addTable($table->tableId, $table);
         }
     } elseif ($table->tableStatus == Constants::TABLE_LANDLORD) {
         //            echo "tid:".$this->tableId." checkTime:table landlord readyUids:".count($table->readyUids)." time:".time()."\n";
         if (count($table->readyUids) >= 3 && $nowTime - $table->recordTime >= Constants::LANDLORD_TIME + 1 + $table->initPlayAddCd) {
             $table->initPlayAddCd = 0;
             $table->landlordOverTime();
         }
     } elseif ($table->tableStatus == Constants::TABLE_IN_GAME && $nowTime - $table->recordTime >= 2) {
         $status = $table->playerStatus[$table->currOpUid];
         if ($status == Constants::PLAYER_UN_DEPOSIT && $nowTime - $table->recordTime < Constants::PLAY_TIME) {
             return;
         }
         if ($status != Constants::PLAYER_LEAVE && !GameDao::isInGame($table->currOpUid)) {
             //玩家掉线超时或逃跑
             $table->playerStatus[$table->currOpUid] = Constants::PLAYER_LEAVE;
             LeaveGame::sendMsg($table->currOpUid, $table->tableId);
         }
         $table->nextPlay();
     }
 }