From 36dd7fef1961dfc59f32cf54db0b7e4a78957a2b Mon Sep 17 00:00:00 2001 From: hide_d Date: Wed, 4 Apr 2018 03:02:35 +0900 Subject: [PATCH] =?UTF-8?q?Session::requireGameLogin()=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80.=20=EC=95=9E=EC=9C=BC=EB=A1=9C=20=EB=8B=A4=EC=96=91?= =?UTF-8?q?=ED=9E=88=20=ED=99=9C=EC=9A=A9=20=EA=B0=80=EB=8A=A5.=20getGener?= =?UTF-8?q?alID(),=20getGeneralName(),=20isSigned()=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/func.php | 107 ------------------------------------------ hwe/j_msgsubmit.php | 14 ++---- hwe/j_turn.php | 4 +- src/sammo/Session.php | 36 ++++++++++---- 4 files changed, 31 insertions(+), 130 deletions(-) diff --git a/hwe/func.php b/hwe/func.php index 92447a50..e3bb9953 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -21,93 +21,6 @@ require_once('func_map.php'); require_once('func_diplomacy.php'); require_once('func_command.php'); - - - - -/** - * 로그인한 유저의 장수 id를 받아옴 - * - * @return int|null - */ -function getGeneralID($forceExit=false, $countLogin=true){ - $userID = Session::getUserID(); - if(!$userID){ //유저id 없으면 어차피 의미 없음. - return null; - } - - $idKey = DB::prefix().'p_no'; - $generalID = Util::array_get($_SESSION[$idKey], null); - - if($generalID){ - return $generalID; - } - - $db = DB::db(); - //흠? - $generalID = $db->queryFirstField('select no from general where owner = %i', $userID); - if(!$generalID && $forceExit){ - header('Location:..'); - die(); - } - - if($generalID && $countLogin){ - //로그인으로 처리 - //XXX: 'get' 함수인데 update가 들어가있다. - //TODO: 조금더 적절한 형태의 로그인 카운트를 생각해볼 것 - $query=$db->query("update general set logcnt=logcnt+1 ,ip = %s_ip,lastconnect=%s_lastConnect where owner= %s_userID",[ - 'ip' => getenv("REMOTE_ADDR"), - 'lastConnect' => date('Y-m-d H:i:s'), - 'userID' => $userID - ]); - $_SESSION[$idKey] = $generalID; - } - - return $generalID; -} - -/** - * 로그인한 유저의 장수명을 받아옴 - * - * @return string|null - */ -function getGeneralName($forceExit=false) -{ - $generalID = Session::Instance()->generalID; - if(!$generalID){ - if($forceExit){ - header('Location:..'); - die(); - } - - return null; - } - - $nameKey = DB::prefix().'p_name'; - $generalName = Util::array_get($_SESSION[$nameKey], null); - - if($generalName){ - return $generalName; - } - - //흠? - $generalName = DB::db()->queryFirstField('select name from general where no = %i', $generalID); - if(!$generalName){ - //이게 말이 돼? - resetSessionGeneralValues(); - if($forceExit){ - header('Location:..'); - die(); - } - } - - if($generalName){ - $_SESSION[$nameKey] = $generalName; - } - - return $generalName; -} - /** * nationID를 이용하여 국가의 '어지간해선' 변경되지 않는 정보(이름, 색, 성향, 규모, 수도)를 반환해줌 * @@ -163,26 +76,6 @@ function GetImageURL($imgsvr) { } } -/** - * generalID를 이용해 각 서버 등록 여부를 확인함 - * - * FIXME: 현재의 구현으로는 session에 p_no가 남아있지만 general 테이블에서는 삭제되어있는 진풍경(!)이 펼쳐질 수도 있음. - * 장수가 사망했을 때에 바로 테이블에서 삭제하는 것이 아니라 삭제 플래그를 설정하는 것이 나을 것임. - * (퀘 섭등 NPC가 빙의할 경우에도 마찬가지!) - * - * 세팅된 플래그는 새롭게 장수를 생성하거나, 새로 빙의할 때 초기화하는 것이 적절한 해결책일 것. - * - * @return bool - */ -function isSigned(){ - $generalID = Session::Instance()->generalID; - if(!$generalID){ - return false; - } - return true; -} - - function checkLimit($con, $conlimit) { if(Session::getUserGrade()>=4){ return 0; diff --git a/hwe/j_msgsubmit.php b/hwe/j_msgsubmit.php index 981b1256..28a5b8c1 100644 --- a/hwe/j_msgsubmit.php +++ b/hwe/j_msgsubmit.php @@ -5,6 +5,9 @@ include 'lib.php'; include 'func.php'; +$session = Session::requireGameLogin([ + 'newSeq' => false +])->setReadOnly(); /** * 메시지 전송 코드. @@ -13,7 +16,6 @@ include 'func.php'; */ //읽기 전용이다. 빠르게 세션 끝내자 -session_write_close(); $post = WebUtil::parseJsonPost(); @@ -31,16 +33,6 @@ $msg = $post['msg']; $datetime = new \DateTime(); $date = $datetime->format('Y-m-d H:i:s'); -//로그인 검사 -if(!isSigned()){ - Json::die([ - 'result' => false, - 'reason' => '로그인되지 않았습니다.', - 'newSeq' => false - ]); -} - - $db = DB::db(); $connect = dbConn(); diff --git a/hwe/j_turn.php b/hwe/j_turn.php index 4eaa3497..5f5e5788 100644 --- a/hwe/j_turn.php +++ b/hwe/j_turn.php @@ -6,6 +6,4 @@ include "func.php"; -if(!isSigned()){ - -} \ No newline at end of file +$session = Session::requireGameLogin(null)->setReadOnly(); \ No newline at end of file diff --git a/src/sammo/Session.php b/src/sammo/Session.php index a590b15f..f65794e1 100644 --- a/src/sammo/Session.php +++ b/src/sammo/Session.php @@ -50,23 +50,41 @@ class Session { return $this; } - public static function requireLogin($movePath = ROOT): Session{ + private static function die($result){ + if(is_string($result)){ + header('Location:'.$result); + die(); + } + + $jsonResult = [ + 'result'=>false, + 'reason'=>'로그인이 필요합니다.' + ]; + + if(is_array($result)){ + $jsonResult = array_merge($result, $jsonResult); + } + + Json::die($jsonResult); + } + + public static function requireLogin($result = ROOT): Session{ $session = Session::Instance(); if($session->isLoggedIn()){ return $session; } - $session->setReadOnly(); + static::die($result); + } - if(is_string($path)){ - header('Location:'.$path); - die(); + public static function requireGameLogin($movePath = ROOT): Session{ + $session = Session::requireLogin()->loginGame(); + + if($session->generalID){ + return $session; } - Json::die([ - 'result'=>false, - 'reason'=>'로그인이 필요합니다.' - ]); + static::die($result); } public function __construct() {