diff --git a/i_banner/banner.php b/i_banner/banner.php
index 5f8da1ca..b3d9bbc7 100644
--- a/i_banner/banner.php
+++ b/i_banner/banner.php
@@ -1,56 +1 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-queryFirstField('select no from general where user_id = %s', $username);
+ if(!$generalID && $forceExit){
+ header('Location:..');
+ die();
+ }
+
+ if($generalIDid){
+ $_SESSION[$id_key] = $generalID;
+ }
+
+ return $generalID;
+}
+
+/**
+ * 로그인한 유저의 장수명을 받아옴
+ *
+ * @return string|null
+ */
+function getGeneralName($forceExit=false)
+{
+ $generalID = getGeneralID();
+ if(!$generalID){
+ if($forceExit){
+ header('Location:..');
+ die();
+ }
+
+ return null;
+ }
+
+ $id_key = getServPrefix().'p_name';
+ $generalName = util::array_get($_SESSION[$id_key], null);
+
+ if($generalName){
+ return $generalName;
+ }
+
+ //흠?
+ $generalName = getDB()->queryFirstField('select name from general where no = %i', $generalID);
+}
function GetImageURL($imgsvr) {
global $image, $image1;
@@ -44,9 +109,14 @@ function GetImageURL($imgsvr) {
}
}
-function CheckLoginEx(){
- //TODO: 서버 별로 p_id를 다르게 설정할 수 있어야함.
- if(!isset($_SESSION['p_id'])) {
+/**
+ * generalID를 이용해 각 서버 등록 여부를 확인함
+ *
+ * @return bool
+ */
+function isSigned(){
+ $p_id = getGeneralID();
+ if(!$_pid){
return false;
}
return true;
@@ -70,7 +140,7 @@ function checkLimit($userlevel, $con, $conlimit) {
}
function getBlockLevel() {
- return getDB()->queryFirstField('select block from general where user_id= %i', getGeneralID());
+ return getDB()->queryFirstField('select block from general where no = %i', getGeneralID());
}
function getRandGenName() {
@@ -1801,7 +1871,9 @@ function getOnlineNum() {
function onlinegen($connect) {
$onlinegen = "";
- if($_SESSION['p_nation'] == 0) {
+ $generalID = getGeneralID();
+ $nationID = getDB()->queryFirstField('select `nation` from `general` where `no` = %i', $generalID);
+ if($nationID !== null || toInt($nationID) === 0) {
$query = "select onlinegen from game where no='1'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$game = MYDB_fetch_array($result);
@@ -2140,14 +2212,14 @@ function increateRefreshEx($type, $cnt=1){
));
$date = date('Y-m-d H:i:s');
- $p_id = getGeneralID();
+ $generalID = getGeneralID();
if($p_id !== NULL){
$db->query("update `general` set `lastrefresh`= %s_date, `con` = `con`+%d_cnt, `connect`= `connect`+ %d_cnt, '\
- '`refcnt` = `refcnt` + %d_cnt, `refresh` = `refresh` + %d_cnt where `user_id` =%s_p_id",array(
+ '`refcnt` = `refcnt` + %d_cnt, `refresh` = `refresh` + %d_cnt where `no` =%i_generalID",array(
'date'=>$date,
'cnt'=>$cnt,
- 'p_id'=>$p_id
+ 'p_id'=>$generalID
));
}
@@ -2155,7 +2227,7 @@ function increateRefreshEx($type, $cnt=1){
$date2 = substr($date, 0, 10);
$online = getOnlineNum();
$fp = fopen("logs/_{$date2}_refresh.txt", "a");
- $msg = _String::Fill2($date,20," ")._String::Fill2($_SESSION['p_id'],13," ")._String::Fill2($_SESSION['p_name'],13," ")._String::Fill2($_SESSION['p_ip'],16," ")._String::Fill2($type, 10, " ")." 동접자: {$online}";
+ $msg = _String::Fill2($date,20," ")._String::Fill2(getUserID(),13," ")._String::Fill2(getGeneralName(),13," ")._String::Fill2($_SESSION['p_ip'],16," ")._String::Fill2($type, 10, " ")." 동접자: {$online}";
fwrite($fp, $msg."\n");
fclose($fp);
@@ -2184,7 +2256,7 @@ function increateRefreshEx($type, $cnt=1){
if($str != "") {
file_put_contents("logs/_{$date2}_ipcheck.txt",
sprintf("ID:%s//name:%s//REMOTE_ADDR:%s%s\n",
- $_SESSION['p_id'],$_SESSION['p_name'],$_SERVER['REMOTE_ADDR'],$str), FILE_APPEND);
+ getUserID(), getGeneralName(),$_SERVER['REMOTE_ADDR'],$str), FILE_APPEND);
}
diff --git a/twe/func_converter.php b/twe/func_converter.php
index d0c37e05..c801fbf5 100644
--- a/twe/func_converter.php
+++ b/twe/func_converter.php
@@ -629,7 +629,7 @@ function getBill($dedication) {
function getCost($armtype) {
//FIXME: 정말로 side effect가 없으려면 query는 밖으로 이동해야함.
//TODO: 병종 값이 column으로 들어있는건 전혀 옳지 않음. key->value 형태로 바꿔야함
- return getDB()->queryFirstColumn('select cst%l from game where no=1', intval($armtype));
+ return getDB()->queryFirstColumn('select %b from game where no=1', sprintf('cst%d', $armtype));
}
function TechLimit($startyear, $year, $tech) {
diff --git a/twe/func_map.php b/twe/func_map.php
index b14f1ac3..2aa49146 100644
--- a/twe/func_map.php
+++ b/twe/func_map.php
@@ -50,22 +50,22 @@ function getWorldMap($req){
return getHistoryMap($req->year, $req->month);
}
- $generalID = getGeneralID();
+ $generalID = getGeneralID(false);
$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']);
+ $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 = intval($city['city']);
- $myNation = intval($city['nation']);
+ $myCity = toInt($city['city']);
+ $myNation = toInt($city['nation']);
if(!$req->showMe){
$myCity = null;
@@ -82,7 +82,7 @@ function getWorldMap($req){
if($myNation){
$spyList = $db->queryFirstField('select `spy` from `nation` where `nation`=%i',
$myNation);
- $spyList = array_map('intval', explode("|", $spyList));
+ $spyList = array_map('toInt', explode("|", $spyList));
}
else{
$spyList = [];
@@ -91,17 +91,17 @@ function getWorldMap($req){
$nationList = [];
foreach($db->query('select `nation`, `name`, `color`, `capital` from `nation`') as $row){
$nationList[] = [
- intval($row['nation']),
+ toInt($row['nation']),
$row['name'],
$row['color'],
- intval($row['capital'])
+ toInt($row['capital'])
];
}
if($myNation){
//굳이 타국 도시에 있는 아국 장수 리스트를 뽑을 이유가 없음. 일단 다 뽑자.
$shownByGeneralList =
- array_map('intval',
+ array_map('toInt',
$db->queryFirstColumn('select distinct `city` from `general` where `nation` = %i',
$myNation));
}
@@ -112,7 +112,7 @@ function getWorldMap($req){
$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']]);
+ array_map('toInt', [$r['city'], $r['level'], $r['state'], $r['nation'], $r['region'], $r['supply']]);
}
return [
diff --git a/twe/func_message.php b/twe/func_message.php
index 303b8a71..271dc7e9 100644
--- a/twe/func_message.php
+++ b/twe/func_message.php
@@ -82,7 +82,7 @@ function getRawMessage($mailbox, $limit=30, $fromTime=NULL){
}
function getMessage($msgType, $limit=30, $fromTime=NULL){
- $generalID = getGeneralID();
+ $generalID = getGeneralID(false);
if($generalID === NULL){
return [];
}
@@ -91,12 +91,12 @@ function getMessage($msgType, $limit=30, $fromTime=NULL){
return getRawMessage(9999, $limit, $fromTime);
}
else if($msgType === 'private'){
- return getRawMessage($genID, $limit, $fromTime);
+ return getRawMessage($generalID, $limit, $fromTime);
}
else if($msgType === 'national'){
$nationID = getDB()->queryFirstField(
- 'select `nation` from `general` where user_id = %i',
- $genID
+ 'select `nation` from `general` where no = %i',
+ $generalID
);
return getRawMessage(9000 + $nationID, $limit, $fromTime);
}
@@ -164,9 +164,14 @@ function sendMessage($msgType, $src, $dest, $msg, $date = null){
function getMailboxList(){
$result = [];
- $generalID = getGeneralID();
+ $generalID = getGeneralID(false);
+
+ if(!$generalID){
+
+ }
+
$db = getDB();
- $me = $db->queryFirstRow('select no,nation,level from general where user_id=%i', $generalID);
+ $me = $db->queryFirstRow('select no,nation,level from general where no=%i', $generalID);
//가장 최근에 주고 받은 사람.
$latestMessage = util::array_get(getMessage('private', 1)[0], null);
diff --git a/twe/func_string.php b/twe/func_string.php
index e804e52b..5543bfe5 100644
--- a/twe/func_string.php
+++ b/twe/func_string.php
@@ -224,6 +224,9 @@ class _String {
//중간정렬
public static function staticFill($str, $maxsize, $ch) {
+ if(!$str){
+ $str = '';
+ }
$size = strlen($str);
$count = ($maxsize - $size) / 2;
@@ -239,6 +242,9 @@ class _String {
}
public static function Fill($str, $maxsize, $ch) {
+ if(!$str){
+ $str = '';
+ }
$size = strlen($str);
$count = ($maxsize - $size) / 2;
@@ -256,6 +262,9 @@ class _String {
//우측정렬
public static function Fill2($str, $maxsize, $ch='0') {
+ if(!$str){
+ $str = '';
+ }
$size = strlen($str);
$count = ($maxsize - $size);
diff --git a/twe/j_map.php b/twe/j_map.php
index 7f9c8496..7bcf8f53 100644
--- a/twe/j_map.php
+++ b/twe/j_map.php
@@ -25,8 +25,8 @@ if($post['year']){
]);
}
- $post['year'] = intval($post['year']);
- $post['month'] = intval($post['month']);
+ $post['year'] = toInt($post['year']);
+ $post['month'] = toInt($post['month']);
}
else{
$post['year'] = null;
diff --git a/twe/j_msgsubmit.php b/twe/j_msgsubmit.php
index 9ef9fb6e..c64b97ee 100644
--- a/twe/j_msgsubmit.php
+++ b/twe/j_msgsubmit.php
@@ -24,7 +24,7 @@ $datetime = new DateTime();
$date = $datetime->format('Y-m-d H:i:s');
//로그인 검사
-if(!CheckLoginEx($db)){
+if(!isSigned()){
returnJson([
'result' => false,
'reason' => '로그인되지 않았습니다.',
diff --git a/twe/j_turn.php b/twe/j_turn.php
new file mode 100644
index 00000000..8ddfb695
--- /dev/null
+++ b/twe/j_turn.php
@@ -0,0 +1,9 @@
+