568 lines
19 KiB
PHP
568 lines
19 KiB
PHP
<?php
|
|
|
|
|
|
class TeamController extends BaseAuthedController {
|
|
|
|
public function createTeam()
|
|
{
|
|
$node_id = 1;
|
|
if (isset($_REQUEST['node_id'])) {
|
|
$node_id = (int)$_REQUEST['node_id'];
|
|
}
|
|
$team_uuid = $node_id . '_' . md5($_REQUEST['account_id']) . phpcommon\getNowTime();
|
|
$rank = 1;
|
|
$equip_id = 0;
|
|
$model = 0;
|
|
|
|
$hiID = 0;
|
|
$hiFrameID = 0;
|
|
$sex = 2;
|
|
$map_id = 0;
|
|
$roomManager = 1;
|
|
$readyState = 1;
|
|
$selectHeroID = 0;
|
|
$selectHeroSkinID = 0;
|
|
if (isset($_REQUEST['map_id'])) {
|
|
$map_id = $_REQUEST['map_id'];
|
|
}
|
|
|
|
if (isset($_REQUEST['rank'])) {
|
|
$rank = $_REQUEST['rank'];
|
|
}
|
|
|
|
if (isset($_REQUEST['model'])) {
|
|
$model = $_REQUEST['model'];
|
|
}
|
|
if (isset($_REQUEST['hiID'])) {
|
|
$hiID = $_REQUEST['hiID'];
|
|
}
|
|
if (isset($_REQUEST['sex'])) {
|
|
$sex = $_REQUEST['sex'];
|
|
}
|
|
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,
|
|
));
|
|
|
|
$team_db = array(
|
|
'team_uuid' => $team_uuid,
|
|
'state' => 0,
|
|
'model' => $model,
|
|
'map_id' => $map_id,
|
|
'member_list' => array(
|
|
array(
|
|
'idx' => 1,
|
|
'account_id' => $_REQUEST['account_id'],
|
|
'name' => $_REQUEST['name'],
|
|
'rank' => $rank,
|
|
'game_times' => $row['game_times'],
|
|
'win_times' => $row['win_times'],
|
|
'kills' => $row['kills'],
|
|
'create_time' => $row['create_time'],
|
|
'roomManager' => $roomManager,
|
|
'readyState' => $readyState,
|
|
'hiID' => $hiID,
|
|
'hiFrameID' => $hiFrameID,
|
|
'sex' => $sex,
|
|
'selectHeroID' => $selectHeroID,
|
|
"selectHeroSkinID" => $selectHeroSkinID
|
|
)
|
|
));
|
|
|
|
$r = $this->_getRedis($team_uuid);
|
|
$r -> set(TEAMID_KEY . $team_uuid, json_encode($team_db));
|
|
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000*600);
|
|
|
|
echo json_encode (array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
'team_uuid' => $team_uuid
|
|
));
|
|
}
|
|
public function resetRoom()//解散房间
|
|
{
|
|
if (!isset($_REQUEST['team_uuid'])) {
|
|
return;
|
|
}
|
|
$team_uuid = $_REQUEST['team_uuid'];
|
|
$r = $this->_getRedis($team_uuid);
|
|
|
|
|
|
$account_id = $_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;
|
|
}
|
|
$user_db['state'] = 3;
|
|
$r->set(TEAMID_KEY . $team_uuid, json_encode($user_db));
|
|
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
|
|
$this->leaveTeam();
|
|
|
|
}
|
|
public function teamInfo()
|
|
{
|
|
if (!isset($_REQUEST['team_uuid'])) {
|
|
return;
|
|
}
|
|
$team_uuid = $_REQUEST['team_uuid'];
|
|
$r = $this->_getRedis($team_uuid);
|
|
|
|
|
|
$account_id = $_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'],
|
|
'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' => $team_uuid,
|
|
'state' => $user_db['state'],
|
|
'member_list' => $member_list,
|
|
'model' => $user_db['model'],
|
|
'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);
|
|
|
|
|
|
$account_id = $_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'];
|
|
// $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;
|
|
}
|
|
}
|
|
$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()
|
|
{
|
|
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;
|
|
}
|
|
$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'],
|
|
'create_time' => $row['create_time'],
|
|
'hiID' => $hiID,
|
|
'hiFrameID' => $hiFrameID,
|
|
'readyState' => $readyState,
|
|
'roomManager' => $roomManger,
|
|
'sex' => $sex,
|
|
'selectHeroID' => $selectHeroID,
|
|
"selectHeroSkinID" => $selectHeroSkinID
|
|
));
|
|
$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' => '',
|
|
'roomID' =>$team_uuid,
|
|
'data' =>$user_db
|
|
));
|
|
}
|
|
|
|
public function kickoutMember()
|
|
{
|
|
if (!isset($_REQUEST['team_uuid'])) {
|
|
return;
|
|
}
|
|
$team_uuid = $_REQUEST['team_uuid'];
|
|
$r = $this->_getRedis($team_uuid);
|
|
if (!$r) {
|
|
echo 'is null';
|
|
} else {
|
|
$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;
|
|
}
|
|
$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 . $team_uuid, json_encode($user_db));
|
|
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
public function leaveTeam()
|
|
{
|
|
if (!isset($_REQUEST['team_uuid'])) {
|
|
return;
|
|
}
|
|
$team_uuid = $_REQUEST['team_uuid'];
|
|
$r = $this->_getRedis($team_uuid);
|
|
$roomManager = $_REQUEST['roomManager'];
|
|
|
|
if (!$r) {
|
|
echo 'is null';
|
|
} else {
|
|
$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;
|
|
}
|
|
$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 . $team_uuid, json_encode($user_db));
|
|
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
|
|
if (count($user_db['member_list']) == 0) {
|
|
$r->del(TEAMID_KEY . $team_uuid, json_encode($user_db));
|
|
}
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
public function updateTeam()
|
|
{
|
|
if (!isset($_REQUEST['team_uuid'])) {
|
|
return;
|
|
}
|
|
$team_uuid = $_REQUEST['team_uuid'];
|
|
$r = $this->_getRedis($team_uuid);
|
|
|
|
if (!$r){
|
|
echo 'is null';
|
|
} else {
|
|
$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;
|
|
}
|
|
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 . $team_uuid, json_encode($user_db));
|
|
$r -> pexpire(TEAMID_KEY . $team_uuid, 1000 * 600);
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
|
|
public function startGame()
|
|
{
|
|
if (!isset($_REQUEST['team_uuid'])) {
|
|
return;
|
|
}
|
|
$team_uuid = $_REQUEST['team_uuid'];
|
|
//error_log("剔除玩家===");
|
|
$r = $this->_getRedis($team_uuid);
|
|
|
|
if (!$r) {
|
|
echo 'is null';
|
|
} else {
|
|
$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;
|
|
}
|
|
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 . $team_uuid, json_encode($user_db));
|
|
$r->pexpire(TEAMID_KEY . $team_uuid, 10 * 1000);
|
|
}
|
|
echo json_encode(array(
|
|
'errcode' => 0,
|
|
'errmsg' => '',
|
|
));
|
|
}
|
|
}
|