コード例 #1
0
ファイル: Play.php プロジェクト: songsihan/doudizhu
 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) {
             if (time() - $table->recordTime >= Constants::PLAY_TIME + 2) {
                 $re['s'] = Constants::RESPONSE_FAIL;
                 return 0;
             }
             if ($uid == $table->currOpUid) {
                 $table->recordTime = time();
                 TableDao::addTable($table->tableId, $table);
                 $playCardNos = $data['playCardNos'];
                 $table->nextPlay($playCardNos, $data['op']);
                 return 1;
                 //协议已发送
             }
         } else {
             $player->tableId = 0;
             PlayerDao::addPlayer($player->uid, $player);
         }
     }
     $re['s'] = Constants::RESPONSE_FAIL;
     return 0;
 }
コード例 #2
0
ファイル: Landlord.php プロジェクト: songsihan/doudizhu
 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_LANDLORD) {
             //                echo "=======time:".(time()-$table->recordTime)." bool:".((time()-$table->recordTime) >= (Constants::LANDLORD_TIME + 1)).' ==========';
             if (time() - $table->recordTime >= Constants::LANDLORD_TIME + 1) {
                 $re['s'] = Constants::RESPONSE_FAIL;
                 return 0;
             }
             if ($uid == $table->currOpUid) {
                 $table->recordTime = time();
                 TableDao::addTable($table->tableId, $table);
                 $op = $data['op'];
                 if ($op == 0 || $op > $table->multiple || $op == $table->multiple && $op == 1) {
                     $status = $table->nextLandlord($uid, $op);
                     if ($status == -3) {
                         $re['s'] = Constants::RESPONSE_FAIL;
                         return 0;
                     }
                     $table->recordTime = time();
                     TableDao::addTable($table->tableId, $table);
                     $tableInfo = array();
                     if (is_array($status)) {
                         $tableInfo = $status['tableInfo'];
                         $status = $status['st'];
                     }
                     switch ($status) {
                         case Constants::LANDLORD_ENSURE:
                             $re = self::sendInfo($table, $re, $uid);
                             break;
                         case Constants::LANDLORD_RESET_TABLE:
                             $re['s'] = Constants::RESPONSE_RE_TABLE;
                             $re['tableInfo'] = $tableInfo;
                             break;
                         case Constants::LANDLORD_NEXT_CHOOSE:
                             $re = self::sendNextInfo($table, $re, $uid);
                             break;
                         case Constants::LANDLORD_RE_JOIN:
                             $re['s'] = Constants::RESPONSE_RE_JOIN;
                             break;
                     }
                     return 0;
                 }
             }
         } else {
             $player->tableId = 0;
             PlayerDao::addPlayer($player->uid, $player);
         }
     }
     $re['s'] = Constants::RESPONSE_FAIL;
     return 0;
 }
コード例 #3
0
ファイル: JoinTable.php プロジェクト: songsihan/doudizhu
 /**
  * 玩家加入牌局,进入准备。
  * 1.牌局人数满足则开启牌局
  * 2.牌局人数不足且超时,牌局解散
  * @param $player
  * @param $data
  * @param $re
  * @return int
  */
 public static function doApi($player, $data, &$re)
 {
     $uid = $player->uid;
     $table = TableDao::getTable($player->tableId);
     if ($table) {
         $table->addUid($uid);
         GameDao::addInGamePlayer($uid);
         if (count($table->playerStatus) == 3) {
             //                echo "JoinTable:\n";
             $table->checkTime($table);
         }
         TableDao::addTable($table->tableId, $table);
         $re['s'] = Constants::RESPONSE_FAIL;
         return 0;
     }
     $re['s'] = Constants::RESPONSE_MATCHING;
     return 0;
 }
コード例 #4
0
ファイル: Progress.php プロジェクト: songsihan/doudizhu
 /**
  * 牌局玩家进度广播
  */
 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;
 }
コード例 #5
0
ファイル: Login.php プロジェクト: songsihan/doudizhu
 /**
  * 玩家账号注册,确定牌局
  * @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;
     }
 }
コード例 #6
0
ファイル: ChgPlaySt.php プロジェクト: songsihan/doudizhu
 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;
 }
コード例 #7
0
ファイル: Table.php プロジェクト: songsihan/doudizhu
 /**
  *  检查操作超时
  */
 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();
     }
 }