func_map.php를 통해 현재 지도 값을 받아오는 코드 추가
j_map.php를 통해 지도를 json 형태로 열람하는 코드 추가 연감의 저장코드를 http를 통해 지도를 받아오는 방식에서 func_map.php를 이용하는 방식으로 변경 map.js에서 반환값이 올바른지 확인하는 코드 추가
This commit is contained in:
@@ -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(){
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+32
-39
@@ -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 .= "<font color=cyan>◆</font> <font style=color:".newColor($nation['color']).";background-color:{$nation['color']};>{$nation['name']}</font><br>";
|
||||
$powerStr .= "국력 {$nation['power']}<br>";
|
||||
@@ -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;
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
<?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();
|
||||
|
||||
$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
|
||||
];
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ include "func.php";
|
||||
|
||||
$connect=dbConn();
|
||||
|
||||
LogHistory($connect, 1);
|
||||
LogHistory(1);
|
||||
|
||||
//echo "<script>location.replace('index.php');</script>";
|
||||
echo 'index.php'; //TODO:debug all and replace
|
||||
|
||||
+41
-2
@@ -1,5 +1,44 @@
|
||||
<?php
|
||||
//TODO: json post를 받아온다. 양식은 map.js 참고
|
||||
include 'lib.php';
|
||||
include 'func.php';
|
||||
|
||||
use utilphp\util as util;
|
||||
|
||||
//읽기 전용이다. 빠르게 세션 끝내자
|
||||
session_write_close();
|
||||
|
||||
$defaultPost = [
|
||||
'year' => 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 참고
|
||||
//TODO: 결과값을 반환한다. 반환하는 양식은 tmp_map/result.json 참고
|
||||
|
||||
$request = new MapRequest($post);
|
||||
|
||||
|
||||
|
||||
returnJson(getWorldMap($request));
|
||||
+3
-1
@@ -1,10 +1,12 @@
|
||||
<?php
|
||||
include 'lib.php';
|
||||
include 'func.php';
|
||||
require_once('func_message.php');
|
||||
|
||||
use utilphp\util as util;
|
||||
|
||||
//읽기 전용이다. 빠르게 세션 끝내자
|
||||
session_write_close();
|
||||
|
||||
$post = parseJsonPost();
|
||||
|
||||
if(!isset($post['genlist']) || !isset($post['msg'])){
|
||||
|
||||
+29
-8
@@ -37,6 +37,24 @@ function reloadWorldMap(option){
|
||||
//OBJ : startYear, year, month, cityList, nationList, spyList, shownByGeneralList, myCity
|
||||
var $world_map = $('.world_map');
|
||||
|
||||
var deferred;
|
||||
|
||||
function checkReturnObject(obj){
|
||||
if(!obj.result){
|
||||
deferred.reject();
|
||||
return;
|
||||
}
|
||||
|
||||
if(!$.isNumeric(obj.startYear)
|
||||
||!$.isNumeric(obj.year)
|
||||
||!$.isNumeric(obj.month)){
|
||||
deferred.reject();
|
||||
return;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
function setMapBackground(obj){
|
||||
var startYear = obj.startYear;
|
||||
var year = obj.year;
|
||||
@@ -471,7 +489,7 @@ function reloadWorldMap(option){
|
||||
}
|
||||
|
||||
//deferred mode of jQuery. != promise-then.
|
||||
$.ajax({
|
||||
deferred = $.ajax({
|
||||
url: option.targetJson,
|
||||
type: 'POST',
|
||||
contentType: 'application/json',
|
||||
@@ -483,12 +501,15 @@ function reloadWorldMap(option){
|
||||
aux:option.aux
|
||||
},
|
||||
dataType:'json'
|
||||
})
|
||||
.then(setMapBackground)
|
||||
.then(convertCityObjs)
|
||||
.then(isDetailMap?drawDetailWorldMap:drawBasicWorldMap)
|
||||
.then(setMouseWork)
|
||||
.then(setCityClickable)
|
||||
.then(saveCityInfo);
|
||||
});
|
||||
|
||||
deferred
|
||||
.then(checkReturnObject)
|
||||
.then(setMapBackground)
|
||||
.then(convertCityObjs)
|
||||
.then(isDetailMap?drawDetailWorldMap:drawBasicWorldMap)
|
||||
.then(setMouseWork)
|
||||
.then(setCityClickable)
|
||||
.then(saveCityInfo);
|
||||
}
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ session_set_cookie_params(0, '/');
|
||||
session_cache_expire(60); // 60분
|
||||
|
||||
// 세션 변수의 등록
|
||||
//FIXME:session_start()를 각자 수행하고, ajax등의 경우에는 session_write_close로 빠르게 끝낼 수 있어야한다.
|
||||
session_start();
|
||||
|
||||
//첫 등장
|
||||
|
||||
Reference in New Issue
Block a user