1
This commit is contained in:
parent
279dbe96fc
commit
01d4af797d
@ -4,7 +4,6 @@ require_once('models/User.php');
|
||||
|
||||
use phpcommon\SqlHelper;
|
||||
use models\User;
|
||||
use models\Hero;
|
||||
|
||||
class TeamController extends BaseAuthedController {
|
||||
|
||||
@ -14,343 +13,116 @@ class TeamController extends BaseAuthedController {
|
||||
$teamUuid = $nodeId . '_' . md5($this->_getAccountId()) . $this->_getNowTime();
|
||||
|
||||
$userDb = User::find($this->_getAccountId());
|
||||
$userDto = User::info($userDb);
|
||||
$userDto['createtime'] = $userDb['createtime'];
|
||||
$teamDb = array(
|
||||
'team_uuid' => $teamUuid,
|
||||
'state' => 0,
|
||||
'member_list' => array($userDb));
|
||||
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
$r->set(TEAMID_KEY . $teamUuid, json_encode($teamDb));
|
||||
$r->pexpire(TEAMID_KEY . $teamUuid, 1000*600);
|
||||
|
||||
echo json_encode (array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
$this->saveTeamDb($r, $teamUuid, $teamDb);
|
||||
$this->_rspData(array(
|
||||
'team_uuid' => $teamUuid
|
||||
));
|
||||
}
|
||||
|
||||
public function teamInfo()
|
||||
{
|
||||
if (!isset($_REQUEST['team_uuid'])) {
|
||||
return;
|
||||
}
|
||||
$teamUuid = $_REQUEST['team_uuid'];
|
||||
$teamUuid = getReqVal('team_uuid', '');
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
|
||||
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$sessionid = $_REQUEST['session_id'];
|
||||
$user_db_str = $r->get(TEAMID_KEY . $teamUuid);
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
|
||||
$teamDb = $this->readTeamDb($r, $teamUuid);
|
||||
if (empty($teamDb)) {
|
||||
$this->_rspErr(1, '队伍已经解散');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效2');
|
||||
return;
|
||||
}
|
||||
$member_list = array();
|
||||
foreach ($user_db['member_list'] as $member) {
|
||||
array_push($member_list, array(
|
||||
'idx' => $member['idx'],
|
||||
'account_id' => $member['account_id'],
|
||||
'name' => $member['name'],
|
||||
'rank' => $member['rank'],
|
||||
'game_times' => $member['game_times'],
|
||||
'win_times' => $member['win_times'],
|
||||
'kills' => $member['kills'],
|
||||
'create_time' => $member['create_time'],
|
||||
'hiID' => $member['hiID'],
|
||||
'readyState' =>$member['readyState'],
|
||||
'hiFrameID' => $member['hiFrameID'],
|
||||
'roomManager' => $member['roomManager'],
|
||||
'sex' => $member['sex'],
|
||||
));
|
||||
}
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg'=> '',
|
||||
'team_uuid' => $teamUuid,
|
||||
'state' => $user_db['state'],
|
||||
'member_list' => $member_list,
|
||||
'model' => $user_db['model'],
|
||||
'map_id' => $user_db['map_id'],
|
||||
$r->pexpire(TEAMID_KEY . $teamUuid, 1000*600);
|
||||
$this->_rspData(array(
|
||||
'team_info' => $teamDb
|
||||
));
|
||||
}
|
||||
|
||||
public function joinTeam()
|
||||
{
|
||||
if (!isset($_REQUEST['team_uuid'])) {
|
||||
return;
|
||||
}
|
||||
$teamUuid = $_REQUEST['team_uuid'];
|
||||
|
||||
$teamUuid = getReqVal('team_uuid', '');
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
|
||||
$user_db_str = $r->get(TEAMID_KEY.$teamUuid);
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
|
||||
$teamDb = $this->readTeamDb($r, $teamUuid);
|
||||
if (empty($teamDb)) {
|
||||
$this->_rspErr(1, '队伍已经解散');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1, 'session失效2');
|
||||
if (count($teamDb['member_list']) >= 4) {
|
||||
$this->_rspErr(2, '队伍已满');
|
||||
return;
|
||||
}
|
||||
$member_num = count($user_db['member_list']);
|
||||
|
||||
if ($member_num >= 4) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 2,'队伍人数已满');
|
||||
return;
|
||||
}
|
||||
$flag = 0;
|
||||
foreach ($user_db['member_list'] as $member) {
|
||||
if ($member['account_id'] == $_REQUEST['account_id']) {
|
||||
$flag = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($flag == 1) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 3,'已在队伍中');
|
||||
return;
|
||||
}
|
||||
$rank = 1;
|
||||
$kuang = 0;
|
||||
$sex = 2;
|
||||
$hiID = 0;
|
||||
$hiFrameID = 0;
|
||||
$roomManger = 0;
|
||||
$readyState = 1;
|
||||
$selectHeroID = 0;
|
||||
$selectHeroSkinID = 0;
|
||||
if (isset($_REQUEST['rank'])) {
|
||||
$rank = $_REQUEST['rank'];
|
||||
}
|
||||
if (isset($_REQUEST['sex'])) {
|
||||
$sex = $_REQUEST['sex'];
|
||||
}
|
||||
if (isset($_REQUEST['hiID'])) {
|
||||
$hiID = $_REQUEST['hiID'];
|
||||
}
|
||||
if (isset($_REQUEST['hiFrameID'])) {
|
||||
$hiFrameID = $_REQUEST['hiFrameID'];
|
||||
}
|
||||
$account_id = $_REQUEST['account_id'];
|
||||
$conn = $this->_getMysql($account_id);
|
||||
$row = $conn->execQueryOne('SELECT game_times, win_times, kills, create_time FROM user WHERE account_id=:account_id;',
|
||||
array(
|
||||
'account_id' => $account_id,
|
||||
));
|
||||
array_push ($user_db['member_list'], array(
|
||||
'idx' => $member_num + 1,
|
||||
'account_id' => $_REQUEST['account_id'],
|
||||
'name' => $_REQUEST['name'],
|
||||
'rank' => $rank,
|
||||
'game_times' => $row['game_times'],
|
||||
'win_times' => $row['win_times'],
|
||||
'kills' => $row['kills'],
|
||||
'cre3ate_time' => $row['create_time'],
|
||||
'hiID' => $hiID,
|
||||
'hiFrameID' => $hiFrameID,
|
||||
'readyState' => $readyState,
|
||||
'roomManager' => $roomManger,
|
||||
'sex' => $sex,
|
||||
'selectHeroID' => $selectHeroID,
|
||||
"selectHeroSkinID" => $selectHeroSkinID
|
||||
));
|
||||
$r->set(TEAMID_KEY . $teamUuid, json_encode($user_db));
|
||||
$r -> pexpire(TEAMID_KEY . $teamUuid, 1000 * 600);
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
'roomID' =>$teamUuid,
|
||||
'data' =>$user_db
|
||||
));
|
||||
}
|
||||
|
||||
public function kickoutMember()
|
||||
{
|
||||
if (!isset($_REQUEST['team_uuid'])) {
|
||||
return;
|
||||
}
|
||||
$teamUuid = $_REQUEST['team_uuid'];
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
if (!$r) {
|
||||
echo 'is null';
|
||||
} else {
|
||||
$user_db_str = $r->get(TEAMID_KEY . $teamUuid);
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
|
||||
foreach ($teamDb['member_list'] as $member) {
|
||||
if ($member['account_id'] == $this->_getAccountId()) {
|
||||
$this->_rspData(array(
|
||||
'team_uuid' => $teamUuid
|
||||
));
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效2');
|
||||
return;
|
||||
}
|
||||
$flag = 0;
|
||||
foreach ($user_db['member_list'] as $member) {
|
||||
if ($member['account_id'] == $_REQUEST['member_id']) {
|
||||
$flag = $member['idx'] - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($user_db['member_list'][$flag]);
|
||||
$user_db['member_list'] = array_values($user_db['member_list']);
|
||||
|
||||
$i = 1;
|
||||
foreach ($user_db['member_list'] as &$memberlist) {
|
||||
$memberlist['idx'] = $i;
|
||||
$i++;
|
||||
}
|
||||
|
||||
$r->set(TEAMID_KEY . $teamUuid, json_encode($user_db));
|
||||
$r -> pexpire(TEAMID_KEY . $teamUuid, 1000 * 600);
|
||||
}
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
$userDb = User::find($this->_getAccountId());
|
||||
$userDto = User::info($userDb);
|
||||
$userDto['createtime'] = $userDb['createtime'];
|
||||
array_push($teamDb['member_list'], $userDto);
|
||||
$this->saveTeamDb($r, $teamUuid, $teamDb);
|
||||
$this->_rspData(array(
|
||||
'team_uuid' => $teamUuid
|
||||
));
|
||||
}
|
||||
|
||||
public function leaveTeam()
|
||||
{
|
||||
if (!isset($_REQUEST['team_uuid'])) {
|
||||
$teamUuid = getReqVal('team_uuid', '');
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
$teamDb = $this->readTeamDb($r, $teamUuid);
|
||||
if (empty($teamDb)) {
|
||||
$this->_rspOk();
|
||||
return;
|
||||
}
|
||||
$teamUuid = $_REQUEST['team_uuid'];
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
$roomManager = $_REQUEST['roomManager'];
|
||||
|
||||
if (!$r) {
|
||||
echo 'is null';
|
||||
} else {
|
||||
$user_db_str = $r->get(TEAMID_KEY . $teamUuid);
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效2');
|
||||
return;
|
||||
}
|
||||
$flag = 0;
|
||||
foreach ($user_db['member_list'] as $member) {
|
||||
if ($member['account_id'] == $_REQUEST['account_id']) {
|
||||
$flag = $member['idx'] - 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
unset($user_db['member_list'][$flag]);
|
||||
$user_db['member_list'] = array_values($user_db['member_list']);
|
||||
|
||||
$i = 1;
|
||||
foreach ($user_db['member_list'] as &$memberlist) {
|
||||
$memberlist['idx'] = $i;
|
||||
if($roomManager == 1)
|
||||
{
|
||||
if($i == 1)
|
||||
{
|
||||
$memberlist['roomManager'] = 1;
|
||||
$memberlist['readyState'] = 1;
|
||||
}
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
$r->set(TEAMID_KEY . $teamUuid, json_encode($user_db));
|
||||
$r -> pexpire(TEAMID_KEY . $teamUuid, 1000 * 600);
|
||||
if (count($user_db['member_list']) == 0) {
|
||||
$r->del(TEAMID_KEY . $teamUuid, json_encode($user_db));
|
||||
$newMemberList = array();
|
||||
foreach ($teamDb['member_list'] as $member) {
|
||||
if ($member['account_id'] != $this->_getAccountId()) {
|
||||
array_push($newMemberList, $member);
|
||||
}
|
||||
}
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
));
|
||||
}
|
||||
|
||||
public function updateTeam()
|
||||
{
|
||||
if (!isset($_REQUEST['team_uuid'])) {
|
||||
return;
|
||||
}
|
||||
$teamUuid = $_REQUEST['team_uuid'];
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
|
||||
if (!$r){
|
||||
echo 'is null';
|
||||
} else {
|
||||
$user_db_str = $r->get(TEAMID_KEY . $teamUuid);
|
||||
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效2');
|
||||
return;
|
||||
}
|
||||
foreach ($user_db['member_list'] as $member) {
|
||||
if ($member['account_id'] == $_REQUEST['account_id']) {
|
||||
if($member['idx'] != 1){
|
||||
phpcommon\sendError(ERR_USER_BASE + 4,'你不是队长');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$user_db['auto_fill'] = $_REQUEST['auto_fill'];
|
||||
$user_db['map_id'] = $_REQUEST['map_id'];
|
||||
$r->set(TEAMID_KEY . $teamUuid, json_encode($user_db));
|
||||
$r -> pexpire(TEAMID_KEY . $teamUuid, 1000 * 600);
|
||||
}
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
));
|
||||
$teamDb['member_list'] = $newMemberList;
|
||||
$this->saveTeamDb($r, $teamUuid, $teamDb);
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
public function startGame()
|
||||
{
|
||||
if (!isset($_REQUEST['team_uuid'])) {
|
||||
return;
|
||||
}
|
||||
$teamUuid = $_REQUEST['team_uuid'];
|
||||
//error_log("剔除玩家===");
|
||||
$teamUuid = getReqVal('team_uuid', '');
|
||||
$r = $this->_getRedis($teamUuid);
|
||||
|
||||
if (!$r) {
|
||||
echo 'is null';
|
||||
} else {
|
||||
$user_db_str = $r->get(TEAMID_KEY . $teamUuid);
|
||||
|
||||
if (empty($user_db_str)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
|
||||
return;
|
||||
}
|
||||
$user_db = json_decode($user_db_str, true);
|
||||
if (empty($user_db)) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 1,'session失效2');
|
||||
return;
|
||||
}
|
||||
foreach ($user_db['member_list'] as $member) {
|
||||
if ($member['account_id'] == $_REQUEST['account_id']) {
|
||||
if($member['idx'] != 1) {
|
||||
phpcommon\sendError(ERR_USER_BASE + 4,'你不是队长');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
$user_db['state'] = $_REQUEST['state'];
|
||||
$r->set(TEAMID_KEY . $teamUuid, json_encode($user_db));
|
||||
$r->pexpire(TEAMID_KEY . $teamUuid, 10 * 1000);
|
||||
$teamDb = $this->readTeamDb($r, $teamUuid);
|
||||
if (empty($teamDb)) {
|
||||
$this->_rspErr(1, '队伍已经解散');
|
||||
return;
|
||||
}
|
||||
echo json_encode(array(
|
||||
'errcode' => 0,
|
||||
'errmsg' => '',
|
||||
));
|
||||
$teamDb['state'] = 1;
|
||||
$this->saveTeamDb($r, $teamUuid, $teamDb);
|
||||
$this->_rspOk();
|
||||
}
|
||||
|
||||
private function readTeamDb($r, $teamUuid)
|
||||
{
|
||||
$teamDbStr = $r->get(TEAMID_KEY . $teamUuid);
|
||||
if (empty($teamDbStr)) {
|
||||
return null;
|
||||
}
|
||||
$teamDb = json_decode($teamDbStr, true);
|
||||
return $teamDb;
|
||||
}
|
||||
|
||||
private function saveTeamDb($r, $teamUuid, $teamDb)
|
||||
{
|
||||
$r->set(TEAMID_KEY . $teamUuid, json_encode($teamDb));
|
||||
$r->pexpire(TEAMID_KEY . $teamUuid, 1000*600);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user