Example #1
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();
     }
 }