diff --git a/hwe/b_currentCity.php b/hwe/b_currentCity.php
index 9ca0426b..64079166 100644
--- a/hwe/b_currentCity.php
+++ b/hwe/b_currentCity.php
@@ -21,9 +21,7 @@ $query = "select no,nation,level,city from general where owner='{$userID}'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$me = MYDB_fetch_array($result);
-$query = "select nation,level,spy from nation where nation='{$me['nation']}'";
-$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
-$myNation = MYDB_fetch_array($result);
+$myNation = $db->queryFirstRow('SELECT nation,level,spy FROM nation WHERE nation=%i', $me['nation']);
$templates = new \League\Plates\Engine('templates');
@@ -121,27 +119,34 @@ if($me['level'] == 0) {
if($myNation['level'] > 0) {
// 첩보도시도 목록에 추가
- $where = 'city=0';
- $cities = array_map('intval',explode("|", $myNation['spy']));
- foreach($cities as $citySpy) {
- $city = intdiv($citySpy, 10);
- $where .= " or city='{$city}'";
+
+ $rawSpy = $myNation['spy'];
+
+ if($rawSpy == ''){
+ $spyCities = [];
+ }
+ else if(strpos($rawSpy, '|') !== false || is_integer($rawSpy)){
+ //TODO: 0.8 버전 이후에는 삭제할 것. 이후 버전은 json으로 변경됨.
+ $spyCities = array_map(function($val){
+ $val = intval($val);
+ return intdiv($val, 10);
+ }, 'intval',explode('|', $myNation['spy']));
+ }
+ else{
+ $spyCities = array_keys(Json::decode($rawSpy));
}
- $query = "select city,name,nation from city where {$where}";
- $cityresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
- $citycount = MYDB_num_rows($cityresult);
- for($i=0; $i < $citycount; $i++) {
- $city = MYDB_fetch_array($cityresult);
- echo "
- ";
+ if($spyCities){
+ foreach ($db->query('SELECT city,name,nation FROM city WHERE city in %li', $spyCities) as $city) {
+ echo "";
+ }
}
}
diff --git a/hwe/func.php b/hwe/func.php
index a5d0afb9..6ff68682 100644
--- a/hwe/func.php
+++ b/hwe/func.php
@@ -1128,7 +1128,7 @@ function msgprint($msg, $name, $picture, $imgsvr, $when, $num, $type) {
$db = DB::db();
$connect=$db->get();
- $message = explode("|", $msg);
+ $message = explode('|', $msg);
$count = (count($message) - 2)/2;
$message[0] = Tag2Code($message[0]);
$message[1] = Tag2Code($message[1]);
diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php
index bb9db7ac..4dd8cc77 100644
--- a/hwe/func_gamerule.php
+++ b/hwe/func_gamerule.php
@@ -395,23 +395,33 @@ function preUpdateMonthly() {
}
//첩보-1
- $query = "select nation,spy from nation where spy!=''";
- $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
- $nationCount = MYDB_num_rows($result);
- for($i=0; $i < $nationCount; $i++) {
- $nation = MYDB_fetch_array($result);
- $spy = ""; $k = 0;
- $cities = [];
- if($nation['spy'] != "") { $cities = explode("|", (string)$nation['spy']); }
- while(count($cities)) {
- $cities[$k]--;
- if($cities[$k]%10 != 0) { $spy .= (string)$cities[$k]; }
- $k++;
- if($k >= count($cities)) { break; }
- if($cities[$k-1]%10 != 0) { $spy .= "|"; }
+ foreach($db->queryAllLists("SELECT nation, spy FROM nation WHERE spy!='' AND spy!='{}'") as [$nationNo, $rawSpy]){
+ if (strpos($rawSpy, '|') !== false || is_integer($rawSpy)) {
+ //TODO: 0.8 버전 이후에는 삭제할 것. 이후 버전은 json으로 변경됨.
+ $spyInfo = [];
+ foreach(explode('|', $rawSpy) as $value){
+ $value = intval($value);
+ $cityNo = intdiv($value, 10);
+ $remainMonth = $value % 10;
+ $spyInfo[$cityNo] = $remainMonth;
+ }
}
- $query = "update nation set spy='$spy' where nation='{$nation['nation']}'";
- MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
+ else{
+ $spyInfo = Json::decode($rawSpy);
+ }
+
+ foreach($spyInfo as $cityNo => $remainMonth){
+ if($remainMonth <= 1){
+ unset($spyInfo[$cityNo]);
+ }
+ else{
+ $spyInfo[$cityNo] -= 1;
+ }
+ }
+
+ $db->update('nation', [
+ 'spy'=>Json::encode($spyInfo, Json::EMPTY_ARRAY_IS_DICT)
+ ], 'nation=%i', $nationNo);
}
return true;
diff --git a/hwe/func_map.php b/hwe/func_map.php
index 6fbdc56a..3dd2b6fc 100644
--- a/hwe/func_map.php
+++ b/hwe/func_map.php
@@ -94,19 +94,29 @@ function getWorldMap($req){
$myNation = null;
}
+ $spyInfo = (object)null;
+
if($myNation){
- $spyList = $db->queryFirstField('select `spy` from `nation` where `nation`=%i',
+ $rawSpy = $db->queryFirstField('select `spy` from `nation` where `nation`=%i',
$myNation);
- if($spyList){
- $spyList = array_map('\sammo\Util::toInt', explode("|", $spyList));
+
+ if(strpos($rawSpy, '|') !== false || is_integer($rawSpy)){
+ //NOTE: 0.8 이전 데이터가 남아있으므로, 0.8버전으로 마이그레이션 이후에도 이곳은 삭제하면 안됨
+ $spyInfo = [];
+ foreach(explode('|', $rawSpy) as $value){
+ $value = intval($value);
+ $cityNo = intdiv($value, 10);
+ $remainMonth = $value % 10;
+ $spyInfo[$cityNo] = $remainMonth;
+ }
}
- else{
- $spyList = [];
+ else if($rawSpy != ''){
+ $spyInfo = Json::decode($rawSpy);
}
-
}
- else{
- $spyList = [];
+
+ if(!$spyInfo){
+ $spyInfo = (object)null;
}
$nationList = [];
@@ -142,7 +152,7 @@ function getWorldMap($req){
'month' => $month,
'cityList' => $cityList,
'nationList' => $nationList,
- 'spyList' => $spyList,
+ 'spyList' => $spyInfo,
'shownByGeneralList' => $shownByGeneralList,
'myCity' => $myCity,
'myNation' => $myNation,
diff --git a/hwe/func_npc.php b/hwe/func_npc.php
index c117f548..0a52d7c9 100644
--- a/hwe/func_npc.php
+++ b/hwe/func_npc.php
@@ -361,7 +361,7 @@ function processAI($no) {
}
break;
case 2: //이동 20%
- $paths = explode("|", $city['path']);
+ $paths = explode('|', $city['path']);
$command = EncodeCommand(0, 0, $paths[rand()%count($paths)], 21);
break;
default:
@@ -429,7 +429,7 @@ function processAI($no) {
return;
} elseif(rand()%4 > 0) {
//이동
- $paths = explode("|", $city['path']);
+ $paths = explode('|', $city['path']);
$command = EncodeCommand(0, 0, $paths[rand()%count($paths)], 21);
$query = "update general set turn0='$command' where no='{$general['no']}'";
MYDB_query($query, $connect) or Error("processAI09 ".MYDB_error($connect),"");
@@ -600,7 +600,7 @@ function processAI($no) {
//현도시가 전방이면 공격 가능성 체크
if($city['front'] > 0) {
//주변도시 체크
- $paths = explode("|", $city['path']);
+ $paths = explode('|', $city['path']);
for($i=0; $i < count($paths); $i++) {
$query = "select city,nation from city where city='$paths[$i]'";
$result = MYDB_query($query, $connect) or Error("processAI20 ".MYDB_error($connect),"");
@@ -766,7 +766,7 @@ function processAI($no) {
$command = EncodeCommand(0, 0, 0, (rand()%2)*8 + 1); // 준비는 됐으나 아직 선포중이면 내정, 조달
} else {
//공격 & 내정
- $paths = explode("|", $city['path']);
+ $paths = explode('|', $city['path']);
for($i=0; $i < count($paths); $i++) {
$query = "select city,nation from city where city='$paths[$i]'";
$result = MYDB_query($query, $connect) or Error("processAI21 ".MYDB_error($connect),"");
diff --git a/hwe/func_process.php b/hwe/func_process.php
index 09301876..98a2425a 100644
--- a/hwe/func_process.php
+++ b/hwe/func_process.php
@@ -1743,32 +1743,32 @@ function process_31(&$general) {
$query = "update general set resturn='SUCCESS',gold='{$general['gold']}',rice='{$general['rice']}',leader2='{$general['leader2']}',dedication=dedication+'$ded',experience=experience+'$exp' where no='{$general['no']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
- $query = "select spy from nation where nation='{$general['nation']}'";
- $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
- $nation = MYDB_fetch_array($result);
- if($nation['spy'] != "")
- {
- $cities = array_map('intval', explode("|", $nation['spy']));
+
+
+ $rawSpy = $db->queryFirstField('SELECT spy FROM nation WHERE nation = %i', $general['nation']);
+
+ if($rawSpy == ''){
+ $spyInfo = [];
}
- else{
- $cities = [];
- }
- $exist = 0;
- for($i=0; $i < count($cities); $i++) {
- if(intdiv($cities[$i], 10) == $destination) {
- $exist = 1;
- break;
+ else if(strpos($rawSpy, '|') !== false || is_integer($rawSpy)){
+ //TODO: 0.8 버전 이후에는 삭제할 것. 이후 버전은 json으로 변경됨.
+ $spyInfo = [];
+ foreach(explode('|', $rawSpy) as $value){
+ $value = intval($value);
+ $cityNo = intdiv($value, 10);
+ $remainMonth = $value % 10;
+ $spyInfo[$cityNo] = $remainMonth;
}
}
- // 기존 첩보 목록에 없으면 새로 등록, 있으면 갱신
- if($exist == 0) {
- $cities[] = $destination * 10 + 3;
- } else {
- $cities[$i] = $destination * 10 + 3;
+ else{
+ $spyInfo = Json::decode($rawSpy);
}
- $spy = implode("|", $cities);
- $query = "update nation set spy='$spy' where nation='{$general['nation']}'";
- MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
+
+ $spyInfo[$destination] = 3;
+
+ $db->update('nation', [
+ 'spy'=>Json::encode($spyInfo, Json::EMPTY_ARRAY_IS_DICT)
+ ], 'nation=%i', $general['nation']);
$log = checkAbility($general, $log);
}
diff --git a/hwe/j_map.php b/hwe/j_map.php
index f68a380c..576e78d5 100644
--- a/hwe/j_map.php
+++ b/hwe/j_map.php
@@ -14,6 +14,7 @@ $defaultPost = [
'showMe' => true
];
$post = Json::decode(Util::getReq('data', 'string', '{}'));
+$post += $defaultPost;
if(!$session->isGameLoggedIn()){
$post['neutralView'] = true;
diff --git a/hwe/js/map.js b/hwe/js/map.js
index ec8d4af8..59219ec2 100644
--- a/hwe/js/map.js
+++ b/hwe/js/map.js
@@ -119,23 +119,11 @@ function reloadWorldMap(option){
};
}
- function convertSpyList(arr){
- var result = [];
- arr.forEach(function(v){
- var cityId = (v / 10) | 0;
- var spy = v % 10;
- result[cityId] = spy;
- });
- return result;
- }
-
-
-
var cityList = obj.cityList.map(toCityObj);
var nationList = obj.nationList.map(toNationObj);
nationList = convertDictById(nationList); //array of object -> dict
- var spyList = convertSpyList(obj.spyList);//Array -> Dict
+ var spyList = obj.spyList;
var shownByGeneralList = convertSet(obj.shownByGeneralList);//Array -> Set
var myCity = obj.myCity;
diff --git a/hwe/sql/schema.sql b/hwe/sql/schema.sql
index 1e27f523..1f6b22fd 100644
--- a/hwe/sql/schema.sql
+++ b/hwe/sql/schema.sql
@@ -199,7 +199,7 @@ CREATE TABLE `nation` (
`tech` INT(8) NULL DEFAULT '0',
`totaltech` INT(8) NULL DEFAULT '0',
`power` INT(8) NULL DEFAULT '0',
- `spy` CHAR(255) NULL DEFAULT '',
+ `spy` CHAR(255) NOT NULL DEFAULT '{}',
`level` INT(1) NULL DEFAULT '0',
`type` INT(2) NULL DEFAULT '0',
`rule` TEXT NULL DEFAULT '',
diff --git a/src/sammo/Json.php b/src/sammo/Json.php
index 10fa3fc6..6db51d6f 100644
--- a/src/sammo/Json.php
+++ b/src/sammo/Json.php
@@ -3,10 +3,11 @@ namespace sammo;
class Json
{
- const PRETTY = 1;
- const DELETE_NULL = 2;
- const NO_CACHE = 4;
- const PASS_THROUGH = 8;
+ const PRETTY = 1 << 0;
+ const DELETE_NULL = 1 << 1;
+ const NO_CACHE = 1 << 2;
+ const PASS_THROUGH = 1 << 3;
+ const EMPTY_ARRAY_IS_DICT = 1 << 4;
public static function encode($value, $flag = 0)
{
@@ -17,6 +18,10 @@ class Json
if ($flag & static::DELETE_NULL) {
$value = Util::eraseNullValue($value);
}
+
+ if(($flag & static::EMPTY_ARRAY_IS_DICT) && $value === []){
+ $value = (object)null;
+ }
return json_encode($value, $rawFlag);
}
@@ -25,6 +30,12 @@ class Json
return json_decode($value, true);
}
+ public static function decodeObj($value){
+ //NOTE: 구 코드가 모두 '배열'을 가정하기 때문에 decode는 연관배열로 반환하였으나,
+ //호환을 위해서는object로 반환하는 것이 더 나을것
+ return json_decode($value);
+ }
+
public static function die($value, $flag = self::NO_CACHE)
{
//NOTE: REST 형식에 맞게, ok(), fail()로 쪼개는게 낫지 않을까 생각해봄.
diff --git a/src/sammo/Util.php b/src/sammo/Util.php
index fdce6f0a..804106c0 100644
--- a/src/sammo/Util.php
+++ b/src/sammo/Util.php
@@ -160,6 +160,9 @@ class Util extends \utilphp\util
if ($val == null) {
return null;
}
+ if ($val == ''){
+ return null;
+ }
return intval($val);
}
throw new \InvalidArgumentException('올바르지 않은 타입형 :'.$val);