Files
core/twe/func_map.php
T
Hide_D e536e2d4ca 내부 전역 변수값 처리를 위해 함수 정리
conf.php에 getServPrefix 추가. 이후 같은 db에서 다른 서버를 운용할때 사용 가능할 것으로 예상.

$_SESSION 값을 직접 받아서 처리하지 않도록 하기위한 용도로 getUserID(), getGeneralID(), getGeneralName() 을 설정

$_SESSION['p_id']를 p_no로 착각하여 구현한 부분 수정

int|null 변환을 위한 toInt 함수 추가

func_string.php에서 null이 입력될 경우 일부 처리

각 서버에 계정이 생성되었는지 확인하는 isSigned()함수 추가
2018-02-03 03:36:34 +09:00

130 lines
3.4 KiB
PHP

<?php
class MapRequest{
public $year;
public $month;
public $aux;
public $neutralView;
public $showMe;
function __construct($obj){
$this->year = $obj['year'];
$this->month = $obj['month'];
$this->aux = $obj['aux'];
$this->neutralView = $obj['neutralView'];
$this->showMe = $obj['showMe'];
}
}
/**
* @param int $year
* @param int $month
* @return mixed
*/
function getHistoryMap($year, $month){
if(!$year || !$month){
return ['result'=>false, 'reason'=>'연 월이 지정되지 않음'];
}
$map = getDB()->queryFirstField('select map from history where year=%i and month=%i',
$year,
$month);
if(!$map){
return ['result'=>false, 'reason'=>'연감이 저장되지 않음'];
}
return json_decode($map, true);//까짓거 json_decode, json_encode 두번하지 뭐.
}
/**
* @param MapRequest|array $req
* @return mixed
*/
function getWorldMap($req){
if(is_array($req)){
$req = new MapRequest($req);
}
if($req->year && $req->month){
return getHistoryMap($req->year, $req->month);
}
$generalID = getGeneralID(false);
$db = getDB();
$game = $db->queryFirstRow('select `startyear`, `year`, `month` from `game` where `no` = 1');
$startYear = toInt($game['startyear']);
$year = toInt($game['year']);
$month = toInt($game['month']);
if($generalID && ($req->showMe || $req->neutralView)){
$city = $db->queryFirstRow(
'select `city`, `nation` from `general` where `user_id`=%i',
$generalID);
$myCity = toInt($city['city']);
$myNation = toInt($city['nation']);
if(!$req->showMe){
$myCity = null;
}
if(!$req->neutralView){
$myNation = null;
}
}
else{
$myCity = null;
$myNation = null;
}
if($myNation){
$spyList = $db->queryFirstField('select `spy` from `nation` where `nation`=%i',
$myNation);
$spyList = array_map('toInt', explode("|", $spyList));
}
else{
$spyList = [];
}
$nationList = [];
foreach($db->query('select `nation`, `name`, `color`, `capital` from `nation`') as $row){
$nationList[] = [
toInt($row['nation']),
$row['name'],
$row['color'],
toInt($row['capital'])
];
}
if($myNation){
//굳이 타국 도시에 있는 아국 장수 리스트를 뽑을 이유가 없음. 일단 다 뽑자.
$shownByGeneralList =
array_map('toInt',
$db->queryFirstColumn('select distinct `city` from `general` where `nation` = %i',
$myNation));
}
else{
$shownByGeneralList = [];
}
$cityList = [];
foreach($db->query('select `city`, `level`, `state`, `nation`, `region`, `supply` from `city`') as $r){
$cityList[] =
array_map('toInt', [$r['city'], $r['level'], $r['state'], $r['nation'], $r['region'], $r['supply']]);
}
return [
'startYear' => $startYear,
'year' => $year,
'month' => $month,
'cityList' => $cityList,
'nationList' => $nationList,
'spyList' => $spyList,
'shownByGeneralList' => $shownByGeneralList,
'myCity' => $myCity,
'myNation' => $myNation,
'result' => true
];
}