[teamController]

This commit is contained in:
aozhiwei 2021-07-12 10:23:54 +08:00
parent 5035566f3f
commit 98f60973aa

View File

@ -12,51 +12,39 @@ class TeamController extends BaseAuthedController {
$node_id = (int)$_REQUEST['node_id']; $node_id = (int)$_REQUEST['node_id'];
} }
$team_uuid = $node_id . '_' . md5($_REQUEST['account_id']) . phpcommon\getNowTime(); $team_uuid = $node_id . '_' . md5($_REQUEST['account_id']) . phpcommon\getNowTime();
$cloth_id = 0;
$hair_id = 0;
$color_id = 0;
$hat_id = 0;
$rank = 1; $rank = 1;
$equip_id = 0; $equip_id = 0;
$model = false; $model = 0;
$vip_level = 0; error_log("创建房间===".$team_uuid);
$kuang = 0;
$hiID = 0;
$hiFrameID = 0;
$sex = 2; $sex = 2;
$map_id = 0; $map_id = 0;
$roomManager = 1;
$readyState = 1;
$selectHeroID = 0;
$selectHeroSkinID = 0;
if (isset($_REQUEST['map_id'])) { if (isset($_REQUEST['map_id'])) {
$map_id = $_REQUEST['map_id']; $map_id = $_REQUEST['map_id'];
} }
if (isset($_REQUEST['cloth_id'])) {
$cloth_id = $_REQUEST['cloth_id'];
}
if (isset($_REQUEST['hair_id'])) {
$hair_id = $_REQUEST['hair_id'];
}
if (isset($_REQUEST['color_id'])) {
$color_id = $_REQUEST['color_id'];
}
if (isset($_REQUEST['hat_id'])) {
$hat_id = $_REQUEST['hat_id'];
}
if (isset($_REQUEST['rank'])) { if (isset($_REQUEST['rank'])) {
$rank = $_REQUEST['rank']; $rank = $_REQUEST['rank'];
} }
if (isset($_REQUEST['equip_id'])) {
$equip_id = $_REQUEST['equip_id'];
}
if (isset($_REQUEST['model'])) { if (isset($_REQUEST['model'])) {
$model = $_REQUEST['model']; $model = $_REQUEST['model'];
} }
if (isset($_REQUEST['vip_level'])) { if (isset($_REQUEST['hiID'])) {
$vip_level = $_REQUEST['vip_level']; $hiID = $_REQUEST['hiID'];
}
if (isset($_REQUEST['kuang'])) {
$kuang = $_REQUEST['kuang'];
} }
if (isset($_REQUEST['sex'])) { if (isset($_REQUEST['sex'])) {
$sex = $_REQUEST['sex']; $sex = $_REQUEST['sex'];
} }
if (isset($_REQUEST['hiFrameID'])) {
$hiFrameID = $_REQUEST['hiFrameID'];
}
$account_id = $_REQUEST['account_id']; $account_id = $_REQUEST['account_id'];
$conn = $this->getMysql($account_id); $conn = $this->getMysql($account_id);
$row = $conn->execQueryOne('SELECT game_times, win_times, kills, create_time FROM user WHERE accountid=:accountid;', $row = $conn->execQueryOne('SELECT game_times, win_times, kills, create_time FROM user WHERE accountid=:accountid;',
@ -66,7 +54,6 @@ class TeamController extends BaseAuthedController {
$team_db = array( $team_db = array(
'team_uuid' => $team_uuid, 'team_uuid' => $team_uuid,
'auto_fill' => $_REQUEST['auto_fill'],
'state' => 0, 'state' => 0,
'model' => $model, 'model' => $model,
'map_id' => $map_id, 'map_id' => $map_id,
@ -75,26 +62,24 @@ class TeamController extends BaseAuthedController {
'idx' => 1, 'idx' => 1,
'account_id' => $_REQUEST['account_id'], 'account_id' => $_REQUEST['account_id'],
'name' => $_REQUEST['name'], 'name' => $_REQUEST['name'],
'avatar_url' => $_REQUEST['avatar_url'],
'cloth_id' => $cloth_id,
'hair_id' => $hair_id,
'color_id' => $color_id,
'hat_id' => $hat_id,
'rank' => $rank, 'rank' => $rank,
'equip_id' => $equip_id,
'game_times' => $row['game_times'], 'game_times' => $row['game_times'],
'win_times' => $row['win_times'], 'win_times' => $row['win_times'],
'kills' => $row['kills'], 'kills' => $row['kills'],
'create_time' => $row['create_time'], 'create_time' => $row['create_time'],
'vip_level' => $vip_level, 'roomManager' => $roomManager,
'kuang' => $kuang, 'readyState' => $readyState,
'hiID' => $hiID,
'hiFrameID' => $hiFrameID,
'sex' => $sex, 'sex' => $sex,
'selectHeroID' => $selectHeroID,
"selectHeroSkinID" => $selectHeroSkinID
) )
)); ));
$r = $this->getRedis($team_uuid); $r = $this->getRedis($team_uuid);
$r -> set(TEAMID_KEY . $team_uuid, json_encode($team_db)); $r -> set(TEAMID_KEY . $team_uuid, json_encode($team_db));
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600); $r -> pexpire(TEAMID_KEY . $team_uuid, 1000*600);
echo json_encode (array( echo json_encode (array(
'errcode' => 0, 'errcode' => 0,
@ -130,19 +115,15 @@ class TeamController extends BaseAuthedController {
'idx' => $member['idx'], 'idx' => $member['idx'],
'account_id' => $member['account_id'], 'account_id' => $member['account_id'],
'name' => $member['name'], 'name' => $member['name'],
'avatar_url' => $member['avatar_url'],
'cloth_id' => $member['cloth_id'],
'hair_id' => $member['hair_id'],
'color_id' => $member['color_id'],
'hat_id' => $member['hat_id'],
'rank' => $member['rank'], 'rank' => $member['rank'],
'equip_id' => $member['equip_id'],
'game_times' => $member['game_times'], 'game_times' => $member['game_times'],
'win_times' => $member['win_times'], 'win_times' => $member['win_times'],
'kills' => $member['kills'], 'kills' => $member['kills'],
'create_time' => $member['create_time'], 'create_time' => $member['create_time'],
'vip_level' => $member['vip_level'], 'hiID' => $member['hiID'],
'kuang' => $member['kuang'], 'readyState' =>$member['readyState'],
'hiFrameID' => $member['hiFrameID'],
'roomManager' => $member['roomManager'],
'sex' => $member['sex'], 'sex' => $member['sex'],
)); ));
} }
@ -150,15 +131,145 @@ class TeamController extends BaseAuthedController {
'errcode' => 0, 'errcode' => 0,
'errmsg'=> '', 'errmsg'=> '',
'team_uuid' => $team_uuid, 'team_uuid' => $team_uuid,
'auto_fill' => $user_db['auto_fill'],
'state' => $user_db['state'], 'state' => $user_db['state'],
'member_list' => $member_list, 'member_list' => $member_list,
'model' => $user_db['model'], 'model' => $user_db['model'],
'map_id' => $user_db['map_id'], 'map_id' => $user_db['map_id'],
)); ));
} }
public function getSelectHeroTeamInfo()
{
if (!isset($_REQUEST['team_uuid'])) {
return;
}
$team_uuid = $_REQUEST['team_uuid'];
$r = $this->getRedis($team_uuid);
$accountid = $_REQUEST['account_id'];
$sessionid = $_REQUEST['session_id'];
$user_db_str = $r->get(TEAMID_KEY . $team_uuid);
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;
}
$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'],
'hiID' => $member['hiID'],
'readyState' => $member['readyState'],
'hiFrameID' => $member['hiFrameID'],
'roomManager' => $member['roomManager'],
'sex' => $member['sex'],
'selectHeroID' => $member['selectHeroID'],
'selectHeroSkinID' => $member['selectHeroSkinID']
));
}
echo json_encode(array(
'errcode' => 0,
'errmsg'=> '',
'team_uuid' => $team_uuid,
'state' => $user_db['state'],
'member_list' => $member_list,
'model' => $user_db['model'],
'map_id' => $user_db['map_id'],
));
}
public function selectHero()
{
if (!isset($_REQUEST['team_uuid'])) {
return;
}
$team_uuid = $_REQUEST['team_uuid'];
$r = $this->getRedis($team_uuid);
$user_db_str = $r->get(TEAMID_KEY.$team_uuid);
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;
}
$type = $_REQUEST['type'];
$acctID = $_REQUEST['account_id'];
error_log("SelectHero".$type."==".$acctID);
foreach ($user_db['member_list'] as &$memberlist)
{
if($memberlist['account_id'] == $acctID)
{
if($type == 1)
{
$heroID = $_REQUEST['heroID'];
$heroSkinID = $_REQUEST['heroSkinID'];
$memberlist['selectHeroID'] = $heroID;
$memberlist['selectHeroSkinID'] = $heroSkinID;
}
else if($type == 2)
{
$readyState = $_REQUEST['readyState'];
$memberlist['readyState'] = $readyState;
}
break;
}
}
$r->set(TEAMID_KEY . $team_uuid, json_encode($user_db));
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
echo json_encode(array(
'errcode' => 0,
'errmsg' => ''
));
}
public function readyGame()
{
if (!isset($_REQUEST['team_uuid'])) {
return;
}
$team_uuid = $_REQUEST['team_uuid'];
$r = $this->getRedis($team_uuid);
$user_db_str = $r->get(TEAMID_KEY.$team_uuid);
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;
}
$readyState = $_REQUEST['readyState'];
error_log("readyState=====".$readyState);
// $user_db['member_list'] = array_values($user_db['member_list']);
$acctID = $_REQUEST['account_id'];
foreach ($user_db['member_list'] as &$memberlist)
{
if($memberlist['account_id'] == $acctID)
{
$memberlist['readyState'] = $readyState;
break;
}
}
error_log("Data===".json_encode($user_db));
$r->set(TEAMID_KEY . $team_uuid, json_encode($user_db));
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
echo json_encode(array(
'errcode' => 0,
'errmsg' => ''
));
}
public function joinTeam() public function joinTeam()
{ {
if (!isset($_REQUEST['team_uuid'])) { if (!isset($_REQUEST['team_uuid'])) {
@ -168,7 +279,6 @@ class TeamController extends BaseAuthedController {
$r = $this->getRedis($team_uuid); $r = $this->getRedis($team_uuid);
$user_db_str = $r->get(TEAMID_KEY.$team_uuid); $user_db_str = $r->get(TEAMID_KEY.$team_uuid);
if (empty($user_db_str)) { if (empty($user_db_str)) {
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
@ -193,45 +303,29 @@ class TeamController extends BaseAuthedController {
} }
} }
if ($flag == 1) { if ($flag == 1) {
phpcommon\sendError(ERR_USER_BASE + 3,'已在队伍中'); phpcommon\sendError(ERR_USER_BASE + 3,'已在队伍中');
return; return;
} }
$cloth_id = 0;
$hair_id = 0;
$color_id = 0;
$hat_id = 0;
$rank = 1; $rank = 1;
$equip_id = 0;
$vip_level = 0;
$kuang = 0; $kuang = 0;
$sex = 2; $sex = 2;
if (isset($_REQUEST['cloth_id'])) { $hiID = 0;
$cloth_id = $_REQUEST['cloth_id']; $hiFrameID = 0;
} $roomManger = 0;
if (isset($_REQUEST['hair_id'])) { $readyState = 1;
$hair_id = $_REQUEST['hair_id']; $selectHeroID = 0;
} $selectHeroSkinID = 0;
if (isset($_REQUEST['color_id'])) {
$color_id = $_REQUEST['color_id'];
}
if (isset($_REQUEST['hat_id'])) {
$hat_id = $_REQUEST['hat_id'];
}
if (isset($_REQUEST['rank'])) { if (isset($_REQUEST['rank'])) {
$rank = $_REQUEST['rank']; $rank = $_REQUEST['rank'];
} }
if (isset($_REQUEST['equip_id'])) {
$equip_id = $_REQUEST['equip_id'];
}
if (isset($_REQUEST['vip_level'])) {
$vip_level = $_REQUEST['vip_level'];
}
if (isset($_REQUEST['kuang'])) {
$kuang = $_REQUEST['kuang'];
}
if (isset($_REQUEST['sex'])) { if (isset($_REQUEST['sex'])) {
$sex = $_REQUEST['sex']; $sex = $_REQUEST['sex'];
}
if (isset($_REQUEST['hiID'])) {
$hiID = $_REQUEST['hiID'];
}
if (isset($_REQUEST['hiFrameID'])) {
$hiFrameID = $_REQUEST['hiFrameID'];
} }
$accountid = $_REQUEST['account_id']; $accountid = $_REQUEST['account_id'];
$conn = $this->getMysql($accountid); $conn = $this->getMysql($accountid);
@ -243,66 +337,60 @@ class TeamController extends BaseAuthedController {
'idx' => $member_num + 1, 'idx' => $member_num + 1,
'account_id' => $_REQUEST['account_id'], 'account_id' => $_REQUEST['account_id'],
'name' => $_REQUEST['name'], 'name' => $_REQUEST['name'],
'avatar_url' => $_REQUEST['avatar_url'],
'cloth_id' => $cloth_id,
'hair_id' => $hair_id,
'color_id' => $color_id,
'hat_id' => $hat_id,
'rank' => $rank, 'rank' => $rank,
'equip_id' => $equip_id,
'game_times' => $row['game_times'], 'game_times' => $row['game_times'],
'win_times' => $row['win_times'], 'win_times' => $row['win_times'],
'kills' => $row['kills'], 'kills' => $row['kills'],
'create_time' => $row['create_time'], 'create_time' => $row['create_time'],
'vip_level' => $vip_level, 'hiID' => $hiID,
'kuang' => $kuang, 'hiFrameID' => $hiFrameID,
'readyState' => $readyState,
'roomManager' => $roomManger,
'sex' => $sex, 'sex' => $sex,
'selectHeroID' => $selectHeroID,
"selectHeroSkinID" => $selectHeroSkinID
)); ));
$r->set(TEAMID_KEY . $team_uuid, json_encode($user_db)); $r->set(TEAMID_KEY . $team_uuid, json_encode($user_db));
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600); $r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
echo json_encode(array( echo json_encode(array(
'errcode' => 0, 'errcode' => 0,
'errmsg' => '', 'errmsg' => '',
'roomID' =>$team_uuid,
'data' =>$user_db
)); ));
} }
public function kickoutMember() public function kickoutMember()
{ {
error_log("剔除玩家==06=");
if (!isset($_REQUEST['team_uuid'])) { if (!isset($_REQUEST['team_uuid'])) {
return; return;
} }
$team_uuid = $_REQUEST['team_uuid']; $team_uuid = $_REQUEST['team_uuid'];
error_log("剔除玩家===");
$r = $this->getRedis($team_uuid); $r = $this->getRedis($team_uuid);
if (!$r) { if (!$r) {
echo 'is null'; echo 'is null';
} else { } else {
$user_db_str = $r->get(TEAMID_KEY . $team_uuid); $user_db_str = $r->get(TEAMID_KEY . $team_uuid);
if (empty($user_db_str)) { if (empty($user_db_str)) {
error_log("剔除玩家==3=");
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
return; return;
} }
$user_db = json_decode($user_db_str, true); $user_db = json_decode($user_db_str, true);
if (empty($user_db)) { if (empty($user_db)) {
error_log("剔除玩家==5=");
phpcommon\sendError(ERR_USER_BASE + 1,'session失效2'); phpcommon\sendError(ERR_USER_BASE + 1,'session失效2');
return; return;
} }
$flag = 0; $flag = 0;
foreach ($user_db['member_list'] as $member) { foreach ($user_db['member_list'] as $member) {
if ($member['account_id'] == $_REQUEST['account_id']) { if ($member['account_id'] == $_REQUEST['member_id']) {
if ($member['idx'] != 1) { $flag = $member['idx'] - 1;
phpcommon\sendError(ERR_USER_BASE + 4,'你不是队长');
return;
}
foreach ($user_db['member_list'] as $member) {
if ($member['account_id'] == $_REQUEST['member_id']) {
$flag = $member['idx'] - 1;
break;
}
}
break; break;
} }
} }
unset($user_db['member_list'][$flag]); unset($user_db['member_list'][$flag]);
$user_db['member_list'] = array_values($user_db['member_list']); $user_db['member_list'] = array_values($user_db['member_list']);
@ -328,12 +416,15 @@ class TeamController extends BaseAuthedController {
} }
$team_uuid = $_REQUEST['team_uuid']; $team_uuid = $_REQUEST['team_uuid'];
$r = $this->getRedis($team_uuid); $r = $this->getRedis($team_uuid);
$roomManager = $_REQUEST['roomManager'];
error_log("是否是队长===".$roomManager);
if (!$r) { if (!$r) {
echo 'is null'; echo 'is null';
} else { } else {
$user_db_str = $r->get(TEAMID_KEY . $team_uuid); $user_db_str = $r->get(TEAMID_KEY . $team_uuid);
if (empty($user_db_str)) { if (empty($user_db_str)) {
error_log("剔除玩家===1");
phpcommon\sendError(ERR_USER_BASE + 1,'session失效1'); phpcommon\sendError(ERR_USER_BASE + 1,'session失效1');
return; return;
} }
@ -355,9 +446,16 @@ class TeamController extends BaseAuthedController {
$i = 1; $i = 1;
foreach ($user_db['member_list'] as &$memberlist) { foreach ($user_db['member_list'] as &$memberlist) {
$memberlist['idx'] = $i; $memberlist['idx'] = $i;
if($roomManager == 1)
{
if($i == 1)
{
$memberlist['roomManager'] = 1;
$memberlist['readyState'] = 1;
}
}
$i++; $i++;
} }
$r->set(TEAMID_KEY . $team_uuid, json_encode($user_db)); $r->set(TEAMID_KEY . $team_uuid, json_encode($user_db));
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600); $r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
if (count($user_db['member_list']) == 0) { if (count($user_db['member_list']) == 0) {
@ -417,6 +515,7 @@ class TeamController extends BaseAuthedController {
return; return;
} }
$team_uuid = $_REQUEST['team_uuid']; $team_uuid = $_REQUEST['team_uuid'];
error_log("剔除玩家===");
$r = $this->getRedis($team_uuid); $r = $this->getRedis($team_uuid);
if (!$r) { if (!$r) {