Ejemplo n.º 1
0
 /**
  * 玩家加入牌局,进入准备。
  * 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;
 }
Ejemplo n.º 2
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;
 }
Ejemplo n.º 3
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;
     }
 }