diff --git a/f_func/class._Session.php b/f_func/class._Session.php
index 0d13340e..0fdcd1b7 100644
--- a/f_func/class._Session.php
+++ b/f_func/class._Session.php
@@ -3,11 +3,7 @@ require(__dir__.'/../vendor/autoload.php');
class _Session {
public function __construct() {
- $sessionPath = ROOT.W.D_SESSION;
- session_save_path($sessionPath);
session_cache_limiter('nocache, must_revalidate');
- session_cache_expire(10080); // 60*24*7분
- session_set_cookie_params(604800, '/');
// 세션 변수의 등록
session_start();
@@ -20,21 +16,6 @@ class _Session {
}
}
- public static function TrashSession() {
- $sessionPath = ROOT.W.D_SESSION;
- if($dir = @opendir($sessionPath)) {
- while($file = @readdir($dir)) {
- if(!strstr($file, 'sess_')) continue;
- if(strpos($file, 'sess_') != 0) continue;
- if(!$atime = @fileatime("{$sessionPath}/{$file}")) continue;
- if(time() > $atime+604800) { // 3600*24*7초
- @unlink("{$sessionPath}/{$file}");
- }
- }
- closedir($dir);
- }
- }
-
public function Set($key, $val) {
$_SESSION[$key] = $val;
}
@@ -50,8 +31,7 @@ class _Session {
}
public function Logout() {
- $_SESSION['noMember'] = 0;
- session_destroy();
+ unset($_SESSION['noMember']);
}
public function IsLoggedIn() {
diff --git a/i_entrance/adminAction.js b/i_entrance/adminAction.js
index 75db42f8..251606b4 100644
--- a/i_entrance/adminAction.js
+++ b/i_entrance/adminAction.js
@@ -84,5 +84,5 @@ function Entrance_AdminClosedLogin(serverDir) {
}
function Entrance_AdminOpen119(serverDir) {
- Open(serverDir+W+'119'+PHP);
+ Open(serverDir+W+'_119'+PHP);
}
diff --git a/i_entrance/serverListPost.php b/i_entrance/serverListPost.php
index 0be8af4d..5f8e2822 100644
--- a/i_entrance/serverListPost.php
+++ b/i_entrance/serverListPost.php
@@ -43,7 +43,7 @@ for($i=0; $i < $_serverCount; $i++) {
else { $state = "<{$nation['CNT']}국 경쟁중>"; }
$state = "{$state}";
- if($me) { $site = "login_process.php"; }
+ if($me) { $site = "index.php"; }
elseif($game['NPCMODE'] == 1) { $site = "selection.php"; }
else { $site = "join.php"; }
@@ -76,7 +76,7 @@ for($i=0; $i < $_serverCount; $i++) {
$character = "
{$picture}
{$me['NAME']}
-
+
";
} elseif($gen['CNT'] >= $game['MAXGENERAL']) {
$character = "- 장수 등록 마감 -
";
diff --git a/i_login/Post.php b/i_login/Post.php
index 4e1eeadc..c98fdd86 100644
--- a/i_login/Post.php
+++ b/i_login/Post.php
@@ -13,13 +13,13 @@ $id = $_POST['id'];
$pw = $_POST['pw'];
$conmsg = $_POST['conmsg'];
+$_SESSION['conmsg'] = $conmsg;//XXX: conmsg를 처리할 더 적절한 장소는?
+
$id = _String::NoSpecialCharacter($id);
$pw = substr($pw, 0, 32);
$response['result'] = 'FAIL';
-_Session::TrashSession();
-
$SESSION = new _Session();
$rs = $DB->Select('NO, GRADE, QUIT', 'MEMBER', "ID='{$id}' AND PW='{$pw}'");
diff --git a/twe/func.php b/twe/func.php
index 9f0d8264..83deba6b 100644
--- a/twe/func.php
+++ b/twe/func.php
@@ -46,27 +46,37 @@ function getUserID($forceExit=false){
* @return int|null
*/
function getGeneralID($forceExit=false){
- $username = getUserID();
- if(!$username){ //유저명 없으면 어차피 의미 없음.
+ $userID = getUserID();
+ if(!$userID){ //유저명 없으면 어차피 의미 없음.
return null;
}
- $id_key = getServPrefix().'p_no';
- $generalID = util::array_get($_SESSION[$id_key], null);
+ $idKey = getServPrefix().'p_no';
+ $generalID = util::array_get($_SESSION[$idKey], null);
if($generalID){
return $generalID;
}
+ $db = getDB();
//흠?
- $generalID = getDB()->queryFirstField('select no from general where user_id = %s', $username);
+ $generalID = $db->queryFirstField('select no from general where user_id = %s', $userID);
if(!$generalID && $forceExit){
header('Location:..');
die();
}
- if($generalIDid){
- $_SESSION[$id_key] = $generalID;
+ if($generalID){
+ //로그인으로 처리
+ //XXX: 'get' 함수인데 update가 들어가있다.
+ //TODO: 조금더 적절한 형태의 로그인 카운트를 생각해볼 것
+ $query=$db->query("update general set logcnt=logcnt+1 ,ip = %s_ip,lastconnect=%s_lastConnect,conmsg=%s_conmsg where user_id= %s_userID",[
+ 'ip' => getenv("REMOTE_ADDR"),
+ 'lastConnect' => date('Y-m-d H:i:s'),
+ 'conmsg' => util::array_get($_SESSION['conmsg'], ''),
+ 'userID' => $userID
+ ]);
+ $_SESSION[$idKey] = $generalID;
}
return $generalID;
@@ -89,8 +99,8 @@ function getGeneralName($forceExit=false)
return null;
}
- $id_key = getServPrefix().'p_name';
- $generalName = util::array_get($_SESSION[$id_key], null);
+ $nameKey = getServPrefix().'p_name';
+ $generalName = util::array_get($_SESSION[$nameKey], null);
if($generalName){
return $generalName;
@@ -98,6 +108,32 @@ function getGeneralName($forceExit=false)
//흠?
$generalName = getDB()->queryFirstField('select name from general where no = %i', $generalID);
+ if(!$generalName){
+ //이게 말이 돼?
+ resetSessionGeneralValues();
+ if($forceExit){
+ header('Location:..');
+ die();
+ }
+ }
+
+ if($generalName){
+ $_SESSION[$nameKey] = $generalName;
+ }
+
+ return $generalName;
+}
+
+/**
+ * Session에 보관된 장수 정보를 제거함.
+ * _prefix_p_no, _prefix_p_name 두 값임
+ */
+function resetSessionGeneralValues(){
+ $idKey = getServPrefix().'p_no';
+ $nameKey = getServPrefix().'p_name';
+
+ unset($_SESSION[$idKey]);
+ unset($_SESSION[$nameKey]);
}
function GetImageURL($imgsvr) {
@@ -112,16 +148,23 @@ function GetImageURL($imgsvr) {
/**
* generalID를 이용해 각 서버 등록 여부를 확인함
*
+ * FIXME: 현재의 구현으로는 session에 p_no가 남아있지만 general 테이블에서는 삭제되어있는 진풍경(!)이 펼쳐질 수도 있음.
+ * 장수가 사망했을 때에 바로 테이블에서 삭제하는 것이 아니라 삭제 플래그를 설정하는 것이 나을 것임.
+ * (퀘 섭등 NPC가 빙의할 경우에도 마찬가지!)
+ *
+ * 세팅된 플래그는 새롭게 장수를 생성하거나, 새로 빙의할 때 초기화하는 것이 적절한 해결책일 것.
+ *
* @return bool
*/
function isSigned(){
- $p_id = getGeneralID();
- if(!$_pid){
+ $generalID = getGeneralID();
+ if(!$generalID){
return false;
}
return true;
}
+
function checkLimit($userlevel, $con, $conlimit) {
//TODO: 접속 제한의 기준을 새로 세울 것.
//운영자
diff --git a/twe/func_legacy.php b/twe/func_legacy.php
index cbf1abb5..0dc499eb 100644
--- a/twe/func_legacy.php
+++ b/twe/func_legacy.php
@@ -3,14 +3,10 @@
function CheckLogin($type=0) {
if(!isset($_SESSION['p_id'])) {
if($type == 0) {
- header('Location: start.php');
- //echo "";
- //echo 'start.php';//TODO:debug all and replace
+ header('Location: ../');
}
else {
header('Location: main.php');
- //echo 'main.php';//TODO:debug all and replace
- //echo "";
}
exit();
}
diff --git a/twe/install2_ok.php b/twe/install2_ok.php
index 719cce98..9731b9a4 100644
--- a/twe/install2_ok.php
+++ b/twe/install2_ok.php
@@ -65,18 +65,17 @@ if($img < 1) { $picture = 'default.jpg'; };
$connect
) or Error(__LINE__.MYDB_error($connect),"");
-$pw = md5('12qw!@QW12qw!@QW');
-
$picture = 'pic_2.jpg';
if($img < 1) { $picture = 'default.jpg'; };
+//부운영자는 비밀번호를 지정하지 않아 로그인할수 없도록 처리한다.
@MYDB_query("
insert into general (
user_id, password, connect, name, picture, nation, city, troop, makelimit,
leader, power, intel, experience, dedication, gold, rice, crew, train, atmos,
weap, book, level, turntime, killturn, lastconnect, userlevel
) values (
- 'viceadmin', '$pw', '0', '부운영자', '$picture', '0', '3', '0', '0',
+ 'viceadmin', 'a', '0', '부운영자', '$picture', '0', '3', '0', '0',
'50', '50', '50', '0', '0', '10000', '10000', '0', '0', '0',
'0', '0', '0', '$turntime', '80', '$lastconnect', '5'
)",
diff --git a/twe/install_ok.php b/twe/install_ok.php
index 3c4d68bd..fbfbe85e 100644
--- a/twe/install_ok.php
+++ b/twe/install_ok.php
@@ -24,7 +24,6 @@ if(MYDB_error($connect)) Error(__LINE__.MYDB_error($connect),"");
MYDB_select_db($dbname, $connect) or Error("MySQL-DB Select
Error!!!","");
delInDir("logs");
-delInDir("data/session");
@unlink("data/connected.php");
// 관리자 테이블 삭제
diff --git a/twe/j_msgsubmit.php b/twe/j_msgsubmit.php
index c64b97ee..03e43b19 100644
--- a/twe/j_msgsubmit.php
+++ b/twe/j_msgsubmit.php
@@ -51,6 +51,15 @@ $conlimit = $db->queryFirstField('select conlimit from game where no=1');
$me = $db->queryFirstRow('select `no`,`name`,`nation`,`level`,`msgindex`,`userlevel`,`con`,`picture`,`imgsvr` from `general` where `user_id` = %s_p_id',
array('p_id'=>$_SESSION['p_id']));
+if(!$me){
+ resetSessionGeneralValues();
+ returnJson([
+ 'result' => false,
+ 'reason' => '로그인되지 않았습니다.',
+ 'redirect' => NULL
+ ]);
+}
+
$con = checkLimit($me['userlevel'], $me['con'], $conlimit);
if($con >= 2) {
returnJson([
diff --git a/twe/lib.php b/twe/lib.php
index 9f46b24a..29e556db 100644
--- a/twe/lib.php
+++ b/twe/lib.php
@@ -14,7 +14,6 @@ use utilphp\util as util;
define('__OLINE__',__LINE__);
define('__LINE__',__FILE__." ".__FUNCTION__." ".__LINE__." : ");
ini_set("session.cache_expire", 10080); // minutes
-ini_set("session.gc_maxlifetime", 604800); // seconds
ob_start();
@@ -73,22 +72,11 @@ unset($setup);
// data폴더가 없으면 data/session까지 생성
if(is_dir("data")){
if(!is_writable("data")) Error("Data 디렉토리의 쓰기 권한이 없습니다!");
- if(is_dir("data/session")){
- if(!is_writable("data/session")) Error("세션 디렉토리 data/session의 쓰기 권한이 없습니다!");
- }else{
- mkdir("data/session");
- }
}else{
mkdir("data");
- mkdir("data/session");
}
-
-
-session_save_path('data/session');
-session_cache_limiter('nocache, must_revalidate');//NOTE: 캐시가 가능할 수도 있음. 주의!
-session_set_cookie_params(0, '/');
-session_cache_expire(60); // 60분
+session_cache_limiter('nocache, must_revalidate');//NOTE: 캐시가 가능하도록 설정해야 할 수도 있음. 주의!
// 세션 변수의 등록
//NOTE: ajax등의 경우에는 session_write_close로 빠르게 끝낼 수 있어야한다.
@@ -106,7 +94,6 @@ if($_SESSION['p_time']+3600 < time()) {
unset($_SESSION['p_id']);
unset($_SESSION[getServPrefix().'p_name']);
$_SESSION['p_time'] = time();
- session_destroy();
} else {
$_SESSION['p_time'] = time();
}
diff --git a/twe/login_process.php b/twe/login_process.php
index 795e7642..f9840b1b 100644
--- a/twe/login_process.php
+++ b/twe/login_process.php
@@ -62,6 +62,7 @@ $_SESSION['p_time'] = time();
$date = date('Y-m-d H:i:s');
+//
$query="update general set logcnt=logcnt+1,ip='{$_SESSION['p_ip']}',lastconnect='$date',conmsg='$conmsg' where user_id='{$_SESSION['p_id']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
diff --git a/twe/logout_process.php b/twe/logout_process.php
index 04c9c04e..93645dd4 100644
--- a/twe/logout_process.php
+++ b/twe/logout_process.php
@@ -8,6 +8,4 @@ unset($_SESSION['p_ip']);
unset($_SESSION[getServPrefix().'p_no']);
unset($_SESSION[getServPrefix().'p_name']);
-session_destroy();
-
-header('Location:start.php');
\ No newline at end of file
+header('Location:../');
\ No newline at end of file
diff --git a/twe/main.php b/twe/main.php
index 732d3757..9095b7b6 100644
--- a/twe/main.php
+++ b/twe/main.php
@@ -1,27 +1,33 @@
location.replace('start.php');";
- exit(0);
+$db = getDB();
+
+//로그인 검사
+if(!isSigned()){
+ header('Location:../');
+ die();
}
-$query = "select no,skin,userlevel,con,turntime,newmsg,newvote,map from general where user_id='{$_SESSION['p_id']}'";
-$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
-$me = MYDB_fetch_array($result);
+$userID = getUserID();
+if(!$userID){
+ header('Location:../');
+ die();
+}
+
+$me = $db->queryFirstRow('select no,skin,userlevel,con,turntime,newmsg,newvote,map from general where user_id = %s', $userID);
//그새 사망이면
-if($me['no'] == 0) {
- //echo "a";
- header('Location: start.php');
- //echo "";
- exit(0);
+if($me === null) {
+ resetSessionGeneralValues();
+ header('Location: ../');
+ die();
}
if($me['newmsg'] == 1 && $me['newvote'] == 1) {
diff --git a/twe/npc_login.php b/twe/npc_login.php
index 5f5d4f9f..72e5bddc 100644
--- a/twe/npc_login.php
+++ b/twe/npc_login.php
@@ -2,6 +2,8 @@
include "lib.php";
include "func.php";
+//NOTE:관리자의 경우 NPC로그인을 user_id는 유지하되 no값만 바꾸는 식으로 가능하지 않을까?
+
$connect=dbConn();
?>
diff --git a/twe/npc_login_process.php b/twe/npc_login_process.php
index c6421961..52942569 100644
--- a/twe/npc_login_process.php
+++ b/twe/npc_login_process.php
@@ -7,8 +7,6 @@ $id = $_POST['id'];
$pw = $_POST['pw'];
$pw = md5($pw.$pw);
-DeleteSession();
-
//회원 테이블에서 정보확인
$query="select no from general where user_id='$id'";
$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");