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); }
/** * 获得桌子编号 * @return mixed */ public static function getTableId() { $no = RedisUtil::incr(self::TABLE_CNT); if ($no >= 4294967290) { $no = RedisUtil::incr(self::TABLE_CNT, -($no - 1)); RedisUtil::incr(self::TABLE_CLEAR_CNT); } return $no; }
/** * 玩家是否处于游戏中状态 * @param $uid * @return int|mixed */ public static function isInGame($uid) { $uid = (int) $uid; return RedisUtil::lExist(self::GAME_IN_PLAYERS, $uid); }
/** * 移除 * @param $uid * @return mixed */ public static function rmPlayer($uid) { $uid = (int) $uid; return RedisUtil::hDel(self::PLAYER_DATAS, $uid); }