From db0c5eac48dd63aa3c244452d823dcdfa876a5b8 Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Thu, 21 Sep 2023 16:27:29 +0800 Subject: [PATCH] 1 --- doc/Battle.py | 3 + .../controller/BaseAuthedController.class.php | 8 + webapp/controller/BattleController.class.php | 153 +++++++++--------- 3 files changed, 88 insertions(+), 76 deletions(-) diff --git a/doc/Battle.py b/doc/Battle.py index 52e22caf..2e1ccbca 100644 --- a/doc/Battle.py +++ b/doc/Battle.py @@ -137,6 +137,9 @@ class Battle(object): 'response': [ _common.RspHead(), ['sign', '', '签名'], + ['zone_id', '', 'zone_id'], + ['node_id', '', 'node_id'], + ['start_time', '', 'start_time'], ['room_uuid', '', '房间id'], ['!team_list', [_common.BattleTeam()], '队伍数据'], ] diff --git a/webapp/controller/BaseAuthedController.class.php b/webapp/controller/BaseAuthedController.class.php index ffbd6efe..cd071dc1 100644 --- a/webapp/controller/BaseAuthedController.class.php +++ b/webapp/controller/BaseAuthedController.class.php @@ -65,6 +65,14 @@ class BaseAuthedController extends BaseController { $this->mysqlConn = null; } + public function switchOnlineAccount($accountId){ + $this->accountId = $accountId; + $this->mysqlConn = null; + $r = $this->_getRedis($this->_getAccountId()); + $myself->sessionId = $r->get(LAST_SESSION_KEY . $this->_getAccountId()); + return !empty($myself->sessionId); + } + public function _handlePre() { // if (SERVER_ENV == _ONLINE) { diff --git a/webapp/controller/BattleController.class.php b/webapp/controller/BattleController.class.php index 2189676c..f617b08b 100644 --- a/webapp/controller/BattleController.class.php +++ b/webapp/controller/BattleController.class.php @@ -341,48 +341,31 @@ class BattleController extends BaseAuthedController { } } + $zoneId = $customData['zone_id']; + $nodeId = $customData['node_id']; + $roomUuid = $customData['room_uuid']; + $startTime = $customData['start_time']; + $data = array( + 'sign' => $sign, + 'zone_id' => $zoneId, + 'node_id' => $nodeId, + 'room_uuid' => $roomUuid, 'members' => array() ); - $currSeason = mt\RankSeason::getCurrentSeason(); - $account_id = getReqVal('account_id', ''); - $session_id = getReqVal('session_id', ''); - $battle_uuid = getReqVal('battle_uuid', ''); - $current_get_star = myself()->_getDailyV(TN_DAILY_GET_STAR_NUM, 0); - $info = array( - 'account_id' => $account_id, - 'session_id' => $session_id, - 'battle_uuid' => $battle_uuid, - 'current_get_star' => $current_get_star, - 'elo' => 0, - 'rank' => 0, - 'name' => '', - 'level' =>'', - 'hero_uniid' => '', - 'hero_id' => '', - 'weapon_uuid1' => '', - 'weapon_uuid2' => '', - 'parachute' => '', - 'hero_skin' => '', - 'skill_id' => '', - 'chip_page' => array(), - 'battle_times' => '', - 'hero_dto' => '', - 'weapon_dto1' => '', - 'weapon_dto2' => '', - 'is_valid_battle' => 0, - //'payload' => json_encode($member['cmjoin']), - 'errcode' => 0, - 'errmsg' => '', - ); - if (!phpcommon\isValidSessionId($account_id, $session_id)) { - $info['errcode'] = 50; - $info['errmsg'] = 'invalid session_id'; - }else{ - { - $userDb = User::find($account_id); - if ($userDb){ + $currSeason = mt\RankSeason::getCurrentSeason(); + foreach ($customData['members'] as $team) { + foreach ($team['members'] as $member) { + $accountId = $member['account_id']; + $switchOk = $this->switchOnlineAccount($accountId); + if (!$switchOk) { + myself()->_rspErr(1, 'data error'); + return; + } + $info = $this->genInitBattleData(); + $userDb = User::find($accountId); + if ($userDb) { $userPresetInfo = User::toPreset($userDb); $info['elo'] = $userDb['elo']; $info['rank'] = $userDb['rank']; @@ -405,50 +388,68 @@ class BattleController extends BaseAuthedController { $info['battle_times'] = getXVal($seasonBattleData, 'total_battle_times', 0); } - }else{ - $info['errcode'] = 51; - $info['errmsg'] = 'paramater error'; - } - } - - { - $heroDb = Hero::findByAccountId($account_id,$info['hero_uniid']); - if ($heroDb) { - $info['is_valid_battle'] = 1; - $info['hero_dto'] = Hero::toDto($heroDb); - } else { - $info['errcode'] = 51; - $info['errmsg'] = 'paramater error'; - } - } - -// { -// for ($i = 1; $i <= 2; ++$i) { -// if (isset($info['weapon_uuid' . $i])) { -// $gunDb = Gun::findByAccountId($account_id, $info['weapon_uuid' . $i]); -// if ($gunDb) { -// $info['weapon_dto' . $i] = Gun::toDto($gunDb); -// } -// } -// } -// } - - { - $itemDb = Bag::findEx($account_id, V_ITEM_REVIVE_COIN); - $info['revive_coin'] = $itemDb && $itemDb['item_num'] > 0 ? $itemDb['item_num'] : 0; - } - - { - $info['match_mode'] = 0; - if ($currSeason){ - $info['match_mode'] = 1; + $heroDb = Hero::findByAccountId($account_id,$info['hero_uniid']); + if ($heroDb) { + $info['is_valid_battle'] = 1; + $info['hero_dto'] = Hero::toDto($heroDb); + } else { + $info['errcode'] = 51; + $info['errmsg'] = 'paramater error'; + } + + { + $itemDb = Bag::findEx($account_id, V_ITEM_REVIVE_COIN); + $info['revive_coin'] = $itemDb && $itemDb['item_num'] > 0 ? $itemDb['item_num'] : 0; + } + + { + $info['match_mode'] = 0; + if ($currSeason){ + $info['match_mode'] = 1; + } + } } + array_push($data['members'], $info); } } - array_push($data['members'], $info); myself()->_rspData($data); } + private function genInitBattleData() + { + $accountId = myself()->_getAccountId(); + $sessionId = myself()->_getSessionId(); + $battleUuuid = ''; + $currentGetStar = myself()->_getDailyV(TN_DAILY_GET_STAR_NUM, 0); + $info = array( + 'account_id' => $accountId, + 'session_id' => $sessionIid, + 'battle_uuid' => $battleUuid, + 'current_get_star' => $currentGetStar, + 'elo' => 0, + 'rank' => 0, + 'name' => '', + 'level' =>'', + 'hero_uniid' => '', + 'hero_id' => '', + 'weapon_uuid1' => '', + 'weapon_uuid2' => '', + 'parachute' => '', + 'hero_skin' => '', + 'skill_id' => '', + 'chip_page' => array(), + 'battle_times' => '', + + 'hero_dto' => '', + 'weapon_dto1' => '', + 'weapon_dto2' => '', + 'is_valid_battle' => 0, + //'payload' => json_encode($member['cmjoin']), + 'errcode' => 0, + 'errmsg' => '', + ); + } + public function getBattleDataNew() { error_log(json_encode($_REQUEST));