diff --git a/twe/func.php b/twe/func.php
index be552c66..444085bb 100644
--- a/twe/func.php
+++ b/twe/func.php
@@ -14,6 +14,7 @@ require_once 'func_file.php';
require_once 'func_converter.php';
require_once('func_template.php');
require_once('func_message.php');
+require_once('func_map.php');
/// 0.0~1.0 사이의 랜덤 float
function randF(){
diff --git a/twe/func_gamerule.php b/twe/func_gamerule.php
index 789340b8..8ac5d95b 100644
--- a/twe/func_gamerule.php
+++ b/twe/func_gamerule.php
@@ -366,7 +366,7 @@ function updateQuaterly($connect) {
// 벌점 감소와 건국제한-1 전턴제한-1 외교제한-1, 1달마다 실행, 병사 있는 장수의 군량 감소, 수입비율 조정
function preUpdateMonthly($connect) {
//연감 월결산
- $result = LogHistory($connect);
+ $result = LogHistory();
$history = array();
if($result == false) { return false; }
@@ -1285,7 +1285,7 @@ function checkEmperior($connect) {
pushHistory($connect, $history);
//연감 월결산
- LogHistory($connect);
+ LogHistory();
}
}
}
diff --git a/twe/func_history.php b/twe/func_history.php
index 6f614e5c..d13e39b9 100644
--- a/twe/func_history.php
+++ b/twe/func_history.php
@@ -63,48 +63,37 @@ function getGenHistory($count, $year, $month, $isFirst=0) {
return $str;
}
-function LogHistory($connect, $isFirst=0) {
+function LogHistory($isFirst=0) {
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Start');
-
- $query = "select startyear,year,month from game where no='1'";
- $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
- $admin = MYDB_fetch_array($result);
- if($isFirst == 1) {
- $admin['year'] -= 1;
- $admin['month'] = 12;
- }
//TODO: 새롭게 추가할 지도 값 받아오는 함수를 이용하여 재구성
- $current_url = util::get_current_url();
- $map_path = explode('/',parse_url($current_url, PHP_URL_PASS));
- array_pop($map_path);
- $map_path[] = 'map.php?type=2&graphic=0';
- $map_path = join('/', $map_path);
-
- $client = new GuzzleHttp\Client();
- $response = $client->get($map_path);
-
- $map = (string)$response->getBody();
- $map = str_replace("'", '<_quot_>', $map);
- $map = str_replace('"', '<_dquot_>', $map);
-
- $log = getHistory(20, $admin['year'], $admin['month'], $isFirst);
- $genlog = getGenHistory(50, $admin['year'], $admin['month'], $isFirst);
+ $map = getWorldMap([
+ 'neutralView'=>true,
+ 'showMe'=>false
+ ]);
- $query = "select nation,color,name,power,gennum from nation where level>0 order by power desc";
- $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
- $nationcount = MYDB_num_rows($result);
+ if($isFirst == 1){
+ $map['year'] -= 1;
+ $map['month'] = 12;
+ }
+
+ $startYear = $map['startYear'];
+ $year = $map['year'];
+ $month = $map['month'];
+
+ $map_json = json_encode($map, JSON_UNESCAPED_UNICODE);
+
+ $log = getHistory(20, $year, $month, $isFirst);
+ $genlog = getGenHistory(50, $year, $month, $isFirst);
$nationStr = "";
$powerStr = "";
$genStr = "";
$cityStr = "";
- for($i=0; $i < $nationcount; $i++) {
- $nation = MYDB_fetch_array($result);
- $query = "select city from city where nation='{$nation['nation']}'";
- $cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
- $citycount = MYDB_num_rows($cityresult);
+ $db = getDB();
+ foreach($db->query('select nation,color,name,power,gennum from nation where level>0 order by power desc') as $nation){
+ $cityCount = $db->queryFirstField('select count(*) from city where nation = %i',$nation['nation']);
$nationStr .= "◆ {$nation['name']}
";
$powerStr .= "국력 {$nation['power']}
";
@@ -114,13 +103,17 @@ function LogHistory($connect, $isFirst=0) {
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', contents collected');
- @MYDB_query("
- insert into history (
- year, month, map, log, genlog, nation, power, gen, city
- ) values (
- '{$admin['year']}', '{$admin['month']}', '$map', '$log', '$genlog', '$nationStr', '$powerStr', '$genStr', '$cityStr'
- )",
- $connect) or Error(__LINE__.MYDB_error($connect),"");
+ $db->insert('history', [
+ 'year' => $year,
+ 'month' => $month,
+ 'map' => $map_json,
+ 'log' => $log,
+ 'genlog' => $genlog,
+ 'nation' => $nationStr,
+ 'power' => $powerStr,
+ 'gen' => $genStr,
+ 'city' => $cityStr
+ ]);
if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Finish');
return true;
diff --git a/twe/func_map.php b/twe/func_map.php
new file mode 100644
index 00000000..a5fcc6ff
--- /dev/null
+++ b/twe/func_map.php
@@ -0,0 +1,116 @@
+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();
+
+ $db = getDB();
+
+ list($startYear, $year, $month) = $db->queryFirstRow('select `startyear`, `year`, `month` from `game` where `no`=1');
+
+ if($generalID && ($req->showMe || $req->neutralView)){
+ list($myCity, $myNation)
+ = $db->queryFirstRow(
+ 'select `city`, `nation` from `general` where `user_id`=%i',
+ $generalID);
+ 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('intval', explode("|", $spyList));
+ }
+ else{
+ $spyList = [];
+ }
+
+ $nationList = [];
+ foreach($db->query('select `nation`, `name`, `color`, `capital` from `nation`') as $row){
+ $nationList[] = [$row['nation'], $row['name'], $row['color'], $row['capital']];
+ }
+
+ if($myNation){
+ //굳이 타국 도시에 있는 아국 장수 리스트를 뽑을 이유가 없음. 일단 다 뽑자.
+ $shownByGeneralList =
+ $db->queryFirstRow('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[] = [$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
+ ];
+}
\ No newline at end of file
diff --git a/twe/install3_ok.php b/twe/install3_ok.php
index 92681649..b5d741aa 100644
--- a/twe/install3_ok.php
+++ b/twe/install3_ok.php
@@ -4,7 +4,7 @@ include "func.php";
$connect=dbConn();
-LogHistory($connect, 1);
+LogHistory(1);
//echo "";
echo 'index.php'; //TODO:debug all and replace
diff --git a/twe/j_map.php b/twe/j_map.php
index d1ccc08b..796d7382 100644
--- a/twe/j_map.php
+++ b/twe/j_map.php
@@ -1,5 +1,44 @@
null,
+ 'month' => null,
+ 'aux' => null,
+ 'neutralView' => false,
+ 'showMe' => true
+];
+$post = array_merge($defaultPost, parseJsonPost());
+
+
+if($post['year']){
+ if($post['month'] < 1 || $post['month'] > 12){
+ returnJson([
+ 'result'=>false,
+ 'reason'=>'잘못된 개월 값'
+ ]);
+ }
+
+ $post['year'] = intval($post['year']);
+ $post['month'] = intval($post['month']);
+}
+else{
+ $post['year'] = null;
+ $post['month'] = null;
+}
+
//TODO: DB를 받아오는 함수를 부른다. 부르는 함수는 func.php 쪽에 있는 것이 좋을 듯. 받아오는 방식은 map.php 참고.
-//TODO: 결과값을 반환한다. 반환하는 양식은 tmp_map/result.json 참고
\ No newline at end of file
+//TODO: 결과값을 반환한다. 반환하는 양식은 tmp_map/result.json 참고
+
+$request = new MapRequest($post);
+
+
+
+returnJson(getWorldMap($request));
\ No newline at end of file
diff --git a/twe/j_msgsubmit.php b/twe/j_msgsubmit.php
index 7de86b96..9ef9fb6e 100644
--- a/twe/j_msgsubmit.php
+++ b/twe/j_msgsubmit.php
@@ -1,10 +1,12 @@