예제 #1
0
 public static function doApi($data)
 {
     // 获取客户端请求
     if (!$data || !isset($re['type'])) {
         \Utils\RedisUtil::set('msg', 'error');
         $v = \Utils\RedisUtil::get('msg');
         return array('s' => Constants::RESPONSE_ERROR, 'v' => $v);
     }
     $re = array();
     $re['type'] = $data['type'];
     if ($data['type'] == 'login') {
         //            Login::doApi($data,$re);
     } else {
         $uid = $data['uid'];
         $player = PlayerDao::getPlayer($uid);
         //            RedisUtil::lock($uid);
         if (!$data['uid'] || !$player) {
             $re['s'] = Constants::RESPONSE_NO_PLAYER;
             //                RedisUtil::unlock($uid);
             return $re;
         }
         $re['s'] = Constants::RESPONSE_SUCCESS;
         switch ($data['type']) {
             case 'test':
                 //                    Progress::doApi($player,$data,$re);
                 break;
             default:
                 $re['s'] = Constants::RESPONSE_FAIL;
                 break;
         }
     }
     return $re;
     //        RedisUtil::unlock($uid);
 }
예제 #2
0
 public static function getPlayerInfos($uids, $selfPlayer)
 {
     $playerInfos = array();
     foreach ($uids as $uid) {
         if ($selfPlayer->uid == $uid) {
             $playerInfos[$uid] = $selfPlayer->getPlayerInfo();
             continue;
         }
         $player = PlayerDao::getPlayer($uid);
         $playerInfos[$uid] = $player->getPlayerInfo();
     }
     return $playerInfos;
 }
예제 #3
0
 public static function doApi($client_id, $message)
 {
     // 获取客户端请求
     $data = json_decode($message, true);
     if (!$data) {
         return;
     }
     $re = array();
     $re['type'] = $data['type'];
     $st = 0;
     if ($data['type'] == 'login') {
         Login::doApi($data, $re);
         isset($re['uid']) && Gateway::bindUid($client_id, $re['uid']);
     } else {
         $uid = $data['uid'];
         $player = PlayerDao::getPlayer($uid);
         //            RedisUtil::lock($uid);
         if (!$data['uid'] || !$player) {
             $re['s'] = Constants::RESPONSE_NO_PLAYER;
             Gateway::sendToClient($client_id, json_encode($re));
             //                RedisUtil::unlock($uid);
             return;
         }
         $re['s'] = Constants::RESPONSE_SUCCESS;
         switch ($data['type']) {
             case 'test':
                 $st = Progress::doApi($player, $data, $re, $client_id);
                 break;
             case 'jt':
                 JoinTable::doApi($player, $data, $re);
                 break;
             case 'll':
                 Landlord::doApi($player, $data, $re);
                 break;
             case 'play':
                 $st = Play::doApi($player, $data, $re);
                 break;
             case 'chgSt':
                 ChgPlaySt::doApi($player, $data, $re);
                 break;
             default:
                 $re['s'] = Constants::RESPONSE_FAIL;
                 break;
         }
     }
     if ($st != 1) {
         Gateway::sendToClient($client_id, json_encode($re));
     }
     //        RedisUtil::unlock($uid);
 }
예제 #4
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;
     }
 }
예제 #5
0
 /**
  * 废弃桌子
  */
 public function rmTable()
 {
     if ($this->blinkTimeOut) {
         Timer::del($this->blinkTimeOut);
     }
     $this->blinkTimeOut = 0;
     foreach ($this->uids as $uid) {
         $player = PlayerDao::getPlayer($uid);
         if ($player && $player->tableId == $this->tableId) {
             PlayerDao::rmPlayer($uid);
         }
     }
     TableDao::rmTable($this->tableId);
 }