func_map.php를 통해 현재 지도 값을 받아오는 코드 추가

j_map.php를 통해 지도를 json 형태로 열람하는 코드 추가

연감의 저장코드를 http를 통해 지도를 받아오는 방식에서 func_map.php를 이용하는 방식으로 변경

map.js에서 반환값이 올바른지 확인하는 코드 추가

b_CurrentCity.php의 도시 정보 값을 get으로도 받을 수 있도록 변경

map.js에서 재야 상태일때 올바르게 처리하도록 변경
This commit is contained in:
2018-02-02 09:36:14 +09:00
parent 1a4d82f871
commit 75fb281264
11 changed files with 279 additions and 72 deletions
+8 -8
View File
@@ -36,10 +36,10 @@ if($me['skin'] < 1) {
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 bordercolordark=gray bordercolorlight=black style=font-size:13px;word-break:break-all; id=bg0>
<tr>
<td width=998>
<form name=cityselect method=post>도시선택 :
<form name=cityselect method=get>도시선택 :
<select name=citylist size=1 style=color:white;background-color:black;width:798;>
<?php
if(!array_key_exists('citylist', $_POST) && $_POST['citylist'] == '') { $_POST['citylist'] = $me['city']; }
if(!array_key_exists('citylist', $_REQUEST) || $_REQUEST['citylist'] == '') { $_REQUEST['citylist'] = $me['city']; }
// 재야일때는 현재 도시만
$valid = 0;
@@ -49,7 +49,7 @@ if($me['level'] == 0) {
$city = MYDB_fetch_array($cityresult);
echo "
<option value={$city['city']}";
if($city['city'] == $_POST['citylist']) { echo " selected"; $valid = 1; }
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
echo ">==================================================【"._String::Fill($city['name'], 4, '_')."】";
if($city['nation'] == 0) echo "공백지";
elseif($me['nation'] == $city['nation']) echo "본국==";
@@ -65,7 +65,7 @@ if($me['level'] == 0) {
$city = MYDB_fetch_array($cityresult);
echo "
<option value={$city['city']}";
if($city['city'] == $_POST['citylist']) { echo " selected"; $valid = 1; }
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
echo ">==================================================【"._String::Fill($city['name'], 4, '_')."】";
if($city['nation'] == 0) echo "공백지";
elseif($me['nation'] == $city['nation']) echo "본국==";
@@ -82,7 +82,7 @@ if($me['level'] == 0) {
$city = MYDB_fetch_array($cityresult);
echo "
<option value={$city['city']}";
if($city['city'] == $_POST['citylist']) { echo " selected"; $valid = 1; }
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
echo ">==================================================【"._String::Fill($city['name'], 4, '_')."】";
if($city['nation'] == 0) echo "공백지";
elseif($me['nation'] == $city['nation']) echo "본국==";
@@ -108,7 +108,7 @@ if($myNation['level'] > 0) {
$city = MYDB_fetch_array($cityresult);
echo "
<option value={$city['city']}";
if($city['city'] == $_POST['citylist']) { echo " selected"; $valid = 1; }
if($city['city'] == $_REQUEST['citylist']) { echo " selected"; $valid = 1; }
echo ">==================================================【"._String::Fill($city['name'], 4, '_')."】";
if($city['nation'] == 0) echo "공백지";
elseif($me['nation'] == $city['nation']) echo "본국==";
@@ -130,10 +130,10 @@ echo "
// 첩보된 도시까지만 허용
if($valid == 0 && $me['userlevel'] < 5) {
$_POST['citylist'] = $me['city'];
$_REQUEST['citylist'] = $me['city'];
}
$query = "select * from city where city='{$_POST['citylist']}'"; // 도시 이름 목록
$query = "select * from city where city='{$_REQUEST['citylist']}'"; // 도시 이름 목록
$cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$city = MYDB_fetch_array($cityresult);
+1
View File
@@ -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(){
+2 -2
View File
@@ -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
View File
@@ -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;
+130
View File
@@ -0,0 +1,130 @@
<?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();
$game = $db->queryFirstRow('select `startyear`, `year`, `month` from `game` where `no` = 1');
$startYear = intval($game['startyear']);
$year = intval($game['year']);
$month = intval($game['month']);
if($generalID && ($req->showMe || $req->neutralView)){
$city = $db->queryFirstRow(
'select `city`, `nation` from `general` where `user_id`=%i',
$generalID);
$myCity = intval($city['city']);
$myNation = intval($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('intval', explode("|", $spyList));
}
else{
$spyList = [];
}
$nationList = [];
foreach($db->query('select `nation`, `name`, `color`, `capital` from `nation`') as $row){
$nationList[] = [
intval($row['nation']),
$row['name'],
$row['color'],
intval($row['capital'])
];
}
if($myNation){
//굳이 타국 도시에 있는 아국 장수 리스트를 뽑을 이유가 없음. 일단 다 뽑자.
$shownByGeneralList =
array_map('intval',
$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('intval', [$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
];
}
+1 -1
View File
@@ -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
+34 -3
View File
@@ -1,5 +1,36 @@
<?php
//TODO: json post를 받아온다. 양식은 map.js 참고
include 'lib.php';
include 'func.php';
//TODO: DB를 받아오는 함수를 부른다. 부르는 함수는 func.php 쪽에 있는 것이 좋을 듯. 받아오는 방식은 map.php 참고.
//TODO: 결과값을 반환한다. 반환하는 양식은 tmp_map/result.json 참고
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;
}
returnJson(getWorldMap($post));
+3 -1
View File
@@ -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'])){
+53 -15
View File
@@ -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;
@@ -197,12 +215,15 @@ function reloadWorldMap(option){
if(id in spyList){
clickable |= spyList[id] << 3;
}
if(nationId == myNation){
if(myNation !== null && nationId == myNation){
clickable |= 4;
}
if(shownByGeneralList.hasOwnProperty(id)){
clickable |= 2;
}
if(myCity !== null && id == myCity){
clickable |= 2;
}
if(clickableAll){
clickable |= 1;
}
@@ -373,7 +394,15 @@ function reloadWorldMap(option){
var $this = $(this);
var position = $this.parent().position();
$tooltip_city.html($this.data('text'));
$tooltip_nation.html($this.data('nation'));
var nation_text = $this.data('nation');
if(nation_text){
$tooltip_nation.html(nation_text).show();
}
else{
$tooltip_nation.html('').hide();
}
$tooltip.css({'top': position.top + 25, 'left': position.left + 35}).show();
var touchMode = $this.data('touchMode');
@@ -414,7 +443,13 @@ function reloadWorldMap(option){
$tooltip_city.data('target', $this.data('id'));
$tooltip_city.html($this.data('text'));
$tooltip_nation.html($this.data('nation'));
var nation_text = $this.data('nation');
if(nation_text){
$tooltip_nation.html(nation_text).show();
}
else{
$tooltip_nation.html('').hide();
}
$tooltip.show();
});
@@ -471,24 +506,27 @@ function reloadWorldMap(option){
}
//deferred mode of jQuery. != promise-then.
$.ajax({
deferred = $.ajax({
url: option.targetJson,
type: 'POST',
type: 'post',
dataType:'json',
contentType: 'application/json',
data: {
data: JSON.stringify({
neutralView:option.neutralView,
year:option.year,
month:option.month,
showMe:option.showMe,
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);
}
+1
View File
@@ -89,6 +89,7 @@ session_set_cookie_params(0, '/');
session_cache_expire(60); // 60분
// 세션 변수의 등록
//FIXME:session_start()를 각자 수행하고, ajax등의 경우에는 session_write_close로 빠르게 끝낼 수 있어야한다.
session_start();
//첫 등장
+14 -3
View File
@@ -58,13 +58,22 @@ $scenario = getScenario();
<head>
<title>메인</title>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<script src="../e_lib/jquery-3.2.1.min.js"></script>
<script src="js/main.js"></script>
<script src="js/base_map.js"></script>
<script src="js/map.js"></script>
<script>
$(function(){
reloadWorldMap({
hrefTemplate:'b_currentCity.php?citylist={0}'
});
});
</script>
<link href="css/normalize.css" rel="stylesheet">
<link href="css/common.css" rel="stylesheet">
<link href="css/main.css" rel="stylesheet">
<link rel=stylesheet href=css/common.css type=text/css>
<link href="css/map.css" rel="stylesheet">
<?php require('analytics.php'); ?>
</head>
@@ -178,7 +187,9 @@ if($me['userlevel'] >= 5) {
</table>
<table align=center width=1000 border=1 cellspacing=0 cellpadding=0 style=font-size:13px;word-break:break-all; id=bg0>
<tr>
<td width=698 height=520 colspan=2><iframe src='map.php?type=0&graphic=<?=$me['map'];?>' width=698 height=520 frameborder=0 marginwidth=0 marginheight=0 topmargin=0 scrolling=no></iframe></td>
<td width=698 height=520 colspan=2>
<?=getMapHtml()?>
</td>
<td width=298 rowspan=4><iframe name=commandlist src='commandlist.php' width=298 height=700 frameborder=0 marginwidth=0 marginheight=0 topmargin=0 scrolling=no></iframe></td>
</tr>
<form name=form2 action=preprocessing.php method=post target=commandlist>