game2006api/webapp/controller/MatchController.class.php
aozhiwei 91a6b5c15d 1
2023-12-26 15:55:46 +08:00

168 lines
5.0 KiB
PHP

<?php
require_once('models/User.php');
require_once('models/Hero.php');
require_once('models/Gun.php');
require_once('models/ChipPage.php');
require_once('models/HeroPreset.php');
require_once('models/HeroSkin.php');
require_once('mt/PveGemini.php');
require_once('mt/Skill.php');
require_once('mt/StarLevel.php');
require_once('services/PropertyChgService.php');
use phpcommon\SqlHelper;
use models\User;
use models\Hero;
use models\Gun;
use models\ChipPage;
use models\HeroPreset;
use models\HeroSkin;
class MatchController extends BaseAuthedController {
public function getMatchInfo()
{
$teamUuid = getReqVal('team_uuid', '');
$r = $this->_getRedis($teamUuid);
$teamDb = $this->readTeamDb($r, $teamUuid);
if (empty($teamDb)) {
$this->_rspErr(1, 'The team has been disbanded');
return;
}
$matchInfo = array(
'state' => 0,
'team_list' => array()
);
$matchOkDb = $this->readMatchOk($r, $teamUuid);
if ($matchOkDb) {
$this->refreshKeyExpire($r, MATCH_OK_KEY . $teamUuid, 1000*600);
$this->refreshKeyExpire($r, MATCH_OK_KEY . $matchOkDb['target_team'], 1000*600);
$this->refreshKeyExpire($r, TEAMID_KEY . $matchOkDb['target_team'], 1000*600);
$this->fillMatchInfo($r, $teamUuid, $matchInfo, $matchOkDb);
} else {
$currMatchDb = $this->readCurrMatchTeam($r);
if (empty($currMatchDb)) {
$currMatchDb = array(
'current_team' => $teamUuid,
'match_time' => $this->_getNowTime()
);
$r->set(MATCH_CURRENT_TEAM_KEY, json_encode($currMatchDb));
$this->refreshKeyExpire($r, MATCH_CURRENT_TEAM_KEY, 1000*600);
} else {
if ($currMatchDb['current_team'] != $teamUuid) {
$this->matchOk($r, $teamUuid, $currMatchDb);
$this->fillMatchInfo($r, $teamUuid, $matchInfo, $this->readMatchOk($r, $teamUuid));
}
}
}
$this->_rspData($matchInfo);
}
public function cancel()
{
$teamUuid = getReqVal('team_uuid', '');
$r = $this->_getRedis($teamUuid);
$teamDb = $this->readTeamDb($r, $teamUuid);
if (!empty($teamDb)) {
$r->del(MATCH_OK_KEY . $teamUuid);
$matchOkDb = $this->readMatchOk($r, $teamUuid);
if ($matchOkDb) {
$r->del(MATCH_OK_KEY . $matchOkDb['target_team']);
}
}
$this->_rspOk();
}
private function readTeamDb($r, $teamUuid)
{
$teamDbStr = $r->get(TEAMID_KEY . $teamUuid);
if (empty($teamDbStr)) {
return null;
}
$this->refreshKeyExpire($r, TEAMID_KEY . $teamUuid, 1000*600);
$teamDb = json_decode($teamDbStr, true);
return $teamDb;
}
/*
{
"current_team": "dafsdf"
"match_time": 231434
}
*/
private function readCurrMatchTeam($r)
{
$teamDbStr = $r->get(MATCH_CURRENT_TEAM_KEY);
if (empty($teamDbStr)) {
return null;
}
$teamDb = json_decode($teamDbStr, true);
return $teamDb;
}
/*
{
"target_team": "dafsdf"
"match_time": 231434
}
*/
private function readMatchOk($r, $teamUuid)
{
$teamDbStr = $r->get(MATCH_OK_KEY . $teamUuid);
if (empty($teamDbStr)) {
return null;
}
$this->refreshKeyExpire($r, MATCH_OK_KEY . $teamUuid, 1000*600);
$teamDb = json_decode($teamDbStr, true);
return $teamDb;
}
private function refreshKeyExpire($r, $key, $time)
{
$r->pexpire($key, $time);
}
private function matchOk($r, $teamUuid, $currMatchDb)
{
{
$r->del(MATCH_CURRENT_TEAM_KEY);
}
{
$matchOkDb = array(
'target_team' => $currMatchDb['current_team'],
'match_time' => $this->_getNowTime()
);
$r->set(MATCH_OK_KEY . $teamUuid, json_encode($currMatchDb));
$this->refreshKeyExpire($r, MATCH_OK_KEY . $teamUuid, 1000*600);
}
{
$matchOkDb = array(
'target_team' => $teamUuid,
'match_time' => $this->_getNowTime()
);
$r->set(MATCH_OK_KEY . $currMatchDb['current_team'], json_encode($currMatchDb));
$this->refreshKeyExpire($r, MATCH_OK_KEY . $currMatchDb['current_team'], 1000*600);
}
}
private function fillMatchInfo($r, $teamUuid, &$matchInfo, $matchOkDb)
{
if (empty($matchOkDb)) {
return;
}
$matchInfo['state'] = 1;
{
$teamDb = $this->readTeamDb($r, $teamUuid);
array_push($matchInfo['team_list'], $teamDb);
}
{
$teamDb = $this->readTeamDb($r, $matchOkDb['target_team']);
array_push($matchInfo['team_list'], $teamDb);
}
}
}