diff --git a/f_install/j_create_admin.php b/f_install/j_create_admin.php index c40b3f28..18ed9f08 100644 --- a/f_install/j_create_admin.php +++ b/f_install/j_create_admin.php @@ -6,9 +6,9 @@ require(__dir__.'/../vendor/autoload.php'); session_start(); session_destroy(); -$username = mb_strtolower(Util::array_get($_POST['username']), 'utf-8'); -$password = Util::array_get($_POST['password']); -$nickname = Util::array_get($_POST['nickname']); +$username = mb_strtolower(Util::getReq('username'), 'utf-8'); +$password = Util::getReq('password'); +$nickname = Util::getReq('nickname'); if(!$username || !$password || !$nickname){ Json::die([ diff --git a/f_install/j_setup_db.php b/f_install/j_setup_db.php index 24629212..29499efb 100644 --- a/f_install/j_setup_db.php +++ b/f_install/j_setup_db.php @@ -3,12 +3,12 @@ namespace sammo; require(__dir__.'/../vendor/autoload.php'); -$host = Util::array_get($_POST['db_host']); -$port = Util::array_get($_POST['db_port']); -$username = Util::array_get($_POST['db_id']); -$password = Util::array_get($_POST['db_pw']); -$dbName = Util::array_get($_POST['db_name']); -$servHost = Util::array_get($_POST['serv_host']); +$host = Util::getReq('db_host'); +$port = Util::getReq('db_port', 'int'); +$username = Util::getReq('db_id'); +$password = Util::getReq('db_pw'); +$dbName = Util::getReq('db_name'); +$servHost = Util::getReq('serv_host'); if(!$host || !$port || !$username || !$password || !$dbName || !$servHost){ Json::die([ diff --git a/hwe/_119_b.php b/hwe/_119_b.php index 7e739339..65abc72e 100644 --- a/hwe/_119_b.php +++ b/hwe/_119_b.php @@ -20,8 +20,8 @@ if(!$v->validate()){ Error($v->errorStr()); } -$minute = Util::toInt(Util::array_get($_POST['minute'])); -$minute2 = Util::toInt(Util::array_get($_POST['minute2'])); +$minute = Util::getReq('minute', 'int'); +$minute2 = Util::getReq('minute2', 'int'); $db = DB::db(); $connect=$db->get(); diff --git a/hwe/_admin1_submit.php b/hwe/_admin1_submit.php index f5022c66..0f33955c 100644 --- a/hwe/_admin1_submit.php +++ b/hwe/_admin1_submit.php @@ -22,6 +22,8 @@ if(!$v->validate()){ Error($v->errorStr()); } + + $db = DB::db(); $connect=$db->get(); diff --git a/hwe/_simul.php b/hwe/_simul.php index befadaa9..a0085736 100644 --- a/hwe/_simul.php +++ b/hwe/_simul.php @@ -9,14 +9,14 @@ $userID = Session::getUserID(); //로그인 검사 -$isgen = Util::array_get($_POST['isgen'], ''); -$tech1 = Util::array_get($_POST['tech1'], 0); -$tech2 =Util::array_get($_POST['tech2'], 0); -$dex10 = Util::array_get($_POST['dex10'], 0); -$dex110 = Util::array_get($_POST['dex110'], 0); -$dex120 = Util::array_get($_POST['dex120'], 0); -$dex130 = Util::array_get($_POST['dex130'], 0); -$dex140 = Util::array_get($_POST['dex140'], 0); +$isgen = Util::getReq('isgen'); +$tech1 = Util::getReq('tech1', 'int', 0); +$tech2 = Util::getReq('tech2', 'int', 0); +$dex10 = Util::getReq('dex10', 'int', 0); +$dex110 = Util::getReq('dex110', 'int', 0); +$dex120 = Util::getReq('dex120', 'int', 0); +$dex130 = Util::getReq('dex130', 'int', 0); +$dex140 = Util::getReq('dex140', 'int', 0); $dx10 = array_fill(0, 20, ''); $dx110 = array_fill(0, 20, ''); @@ -24,11 +24,11 @@ $dx120 = array_fill(0, 20, ''); $dx130 = array_fill(0, 20, ''); $dx140 = array_fill(0, 20, ''); -$dex20 = Util::array_get($_POST['dex20'], 0); -$dex210 = Util::array_get($_POST['dex210'], 0); -$dex220 = Util::array_get($_POST['dex220'], 0); -$dex230 = Util::array_get($_POST['dex230'], 0); -$dex240 = Util::array_get($_POST['dex240'], 0); +$dex20 = Util::getReq('dex20', 'int', 0); +$dex210 = Util::getReq('dex210', 'int', 0); +$dex220 = Util::getReq('dex220', 'int', 0); +$dex230 = Util::getReq('dex230', 'int', 0); +$dex240 = Util::getReq('dex240', 'int', 0); $dx20 = array_fill(0, 20, ''); $dx210 = array_fill(0, 20, ''); diff --git a/hwe/a_history.php b/hwe/a_history.php index 1be14045..dbe5c1ca 100644 --- a/hwe/a_history.php +++ b/hwe/a_history.php @@ -3,7 +3,7 @@ namespace sammo; include "lib.php"; include "func.php"; -$btn = Util::array_get($_POST['btn']); +$btn = Util::getReq('btn'); $yearmonth = $_POST['yearmonth']; //로그인 검사 $session = Session::requireGameLogin()->setReadOnly(); diff --git a/hwe/c_chiefboard.php b/hwe/c_chiefboard.php index 96344515..a86cb557 100644 --- a/hwe/c_chiefboard.php +++ b/hwe/c_chiefboard.php @@ -4,9 +4,9 @@ namespace sammo; include "lib.php"; include "func.php"; -$title = Util::array_get($_POST['title']); -$msg = Util::array_get($_POST['msg']); -$num = Util::toInt(Util::array_get($_POST['num'])); +$title = Util::getReq('title'); +$msg = Util::getReq('msg'); +$num = Util::getReq('num'); // $title, $msg, $num //로그인 검사 diff --git a/hwe/c_myBossInfo.php b/hwe/c_myBossInfo.php index 8305b970..e2658c0d 100644 --- a/hwe/c_myBossInfo.php +++ b/hwe/c_myBossInfo.php @@ -5,10 +5,11 @@ include "lib.php"; include "func.php"; // $btn, $level, $genlist, $outlist -$btn = Util::array_get($_POST['btn']); -$level = Util::toInt(Util::array_get($_POST['level'])); -$genlist = Util::toInt(Util::array_get($_POST['genlist'])); -$outlist = Util::toInt(Util::array_get($_POST['outlist'])); +$btn = Util::getReq('btn'); +$level = Util::getReq('level', 'int'); +$genlist = Util::getReq('genlist', 'int'); +$outlist = Util::getReq('outlist', 'int'); +$citylist = Util::getReq('citylist', 'int'); //로그인 검사 $session = Session::requireGameLogin()->setReadOnly(); diff --git a/hwe/c_nationboard.php b/hwe/c_nationboard.php index 7bafd78f..2d269803 100644 --- a/hwe/c_nationboard.php +++ b/hwe/c_nationboard.php @@ -4,9 +4,9 @@ namespace sammo; include "lib.php"; include "func.php"; // $title, $msg, $num -$title = Util::array_get($_POST['title']); -$msg = Util::array_get($_POST['msg']); -$num = Util::toInt(Util::array_get($_POST['num'])); +$title = Util::getReq('title'); +$msg = Util::getReq('msg'); +$num = Util::getReq('num', 'int'); //로그인 검사 $session = Session::requireGameLogin()->setReadOnly(); diff --git a/hwe/c_tournament.php b/hwe/c_tournament.php index e3d48954..3fa6f992 100644 --- a/hwe/c_tournament.php +++ b/hwe/c_tournament.php @@ -5,8 +5,8 @@ include "lib.php"; include "func.php"; // $btn, $msg -$gen = Util::toInt(Util::array_get($_POST['gen'])); -$sel = Util::toInt(Util::array_get($_POST['sel'])); +$gen = Util::getReq('gen', 'int'); +$sel = Util::getReq('sel', 'int'); //로그인 검사 $session = Session::requireGameLogin()->setReadOnly(); diff --git a/hwe/c_vote.php b/hwe/c_vote.php index a89cbecf..1657f2c7 100644 --- a/hwe/c_vote.php +++ b/hwe/c_vote.php @@ -4,7 +4,7 @@ namespace sammo; include "lib.php"; include "func.php"; -$sel = Util::toInt(Util::array_get($_POST['sel'])); +$sel = Util::getReq('sel', 'int'); //로그인 검사 $session = Session::requireGameLogin()->setReadOnly(); diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index ecf8e872..08e081eb 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -217,13 +217,17 @@ function SetNationFront($nationNo) { ); if($enemyCities) { foreach($enemyCities as $city){ - $adj = array_merge($adj, CityConst::byID($city)->path); + foreach(CityConst::byID($city)->path as $adjKey=>$adjVal){ + $adj[$adjKey] = $adjVal; + } } } else { //평시이면 공백지 //NOTE: if, else일 경우 NPC는 전쟁시에는 공백지로 출병하지 않는다는 뜻이 된다. foreach ($db->queryFirstColumn('SELECT city,path from city where nation=0') as $city) { - $adj = array_merge($adj, CityConst::byID($city)->path); + foreach(CityConst::byID($city)->path as $adjKey=>$adjVal){ + $adj[$adjKey] = $adjVal; + } } } diff --git a/hwe/j_install_db.php b/hwe/j_install_db.php index 140a008c..ee7ee67b 100644 --- a/hwe/j_install_db.php +++ b/hwe/j_install_db.php @@ -12,12 +12,12 @@ if($session->userGrade < 6){ ]); } -$fullReset = Util::array_get($_POST['full_reset'], false); -$host = Util::array_get($_POST['db_host']); -$port = Util::array_get($_POST['db_port']); -$username = Util::array_get($_POST['db_id']); -$password = Util::array_get($_POST['db_pw']); -$dbName = Util::array_get($_POST['db_name']); +$fullReset = Util::getReq('full_reset', 'bool', false); +$host = Util::getReq('db_host'); +$port = Util::getReq('db_port', 'int'); +$username = Util::getReq('db_id'); +$password = Util::getReq('db_pw'); +$dbName = Util::getReq('db_name'); if(!$host || !$port || !$username || !$password || !$dbName){ Json::die([ diff --git a/hwe/join_post.php b/hwe/join_post.php index 6bf37201..ff8d6007 100644 --- a/hwe/join_post.php +++ b/hwe/join_post.php @@ -4,7 +4,7 @@ namespace sammo; include "lib.php"; include "func.php"; -$v = new Validator($_POST); +$v = new Validator(array_merge($_POST, $_GET)); $v ->rule('required', [ 'name', @@ -44,14 +44,14 @@ $session = Session::requireLogin()->setReadOnly(); $userID = Session::getUserID(); //NOTE: 이 페이지에서는 세션에 데이터를 등록하지 않음. 로그인은 이후에. -$name = $_POST['name']; +$name = Util::getReq('name'); $name = StringUtil::removeSpecialCharacter($name); -$pic = (int)Util::array_get($_POST['pic'], 0); -$character = (int)Util::array_get($_POST['character'], 0); +$pic = Util::getReq('pic', 'int', 0); +$character = Util::getReq('character', 'int', 0); -$leader = (int)$_POST['leader']; -$power = (int)$_POST['power']; -$intel = (int)$_POST['intel']; +$leader = Util::getReq('leader', 'int', 50); +$power = Util::getReq('power', 'int', 50); +$intel = Util::getReq('intel', 'int', 50); $mylog = []; diff --git a/i_entrance/j_server_change_status.php b/i_entrance/j_server_change_status.php index ca9b1dec..67798c47 100644 --- a/i_entrance/j_server_change_status.php +++ b/i_entrance/j_server_change_status.php @@ -12,9 +12,9 @@ $session = Session::requireLogin(null); // $_POST['notice'] : 공지 // $_POST['server'] : 서버 인덱스 -$action = Util::array_get($_POST['action'], ''); -$notice = Util::array_get($_POST['notice'], ''); -$server = Util::array_get($_POST['server'], ''); +$action = Util::getReq('action', 'string', ''); +$notice = Util::getReq('notice', 'string', ''); +$server = Util::getReq('server', 'string', ''); $db = RootDB::db(); $userGrade = $session->userGrade; diff --git a/i_entrance/j_set_userlist.php b/i_entrance/j_set_userlist.php index 13e22ebb..dc652709 100644 --- a/i_entrance/j_set_userlist.php +++ b/i_entrance/j_set_userlist.php @@ -17,9 +17,9 @@ if($session->userGrade < 6){ // $_POST['user_id'] : 유저 이름 // $_POST['param'] : 추가 파라미터 -$action = Util::array_get($_POST['action']); -$userID = Util::array_get($_POST['user_id']); -$param = Util::array_get($_POST['param']); +$action = Util::getReq('action'); +$userID = Util::getReq('user_id'); +$param = Util::getReq('param'); if(!$action){ Json::die([ diff --git a/j_login.php b/j_login.php index 4565cdf5..169b60b7 100644 --- a/j_login.php +++ b/j_login.php @@ -10,8 +10,8 @@ if($session->isLoggedIn()){ $session->logout(); } -$username = mb_strtolower(Util::array_get($_POST['username']), 'utf-8'); -$password = Util::array_get($_POST['password']); +$username = mb_strtolower(Util::getReq('username'), 'utf-8'); +$password = Util::getReq('password'); if(!$username || !$password){ Json::die([ diff --git a/oauth_kakao/j_check_dup.php b/oauth_kakao/j_check_dup.php index e76e0b90..da30ab44 100644 --- a/oauth_kakao/j_check_dup.php +++ b/oauth_kakao/j_check_dup.php @@ -13,8 +13,8 @@ if(!$access_token){ } -$value = Util::array_get($_POST['value']); -switch(Util::array_get($_POST['type'])){ +$value = Util::getReq('value'); +switch(Util::getReq('type')){ case 'nickname': Json::die(checkNicknameDup($value)); case 'username': diff --git a/oauth_kakao/j_join_process.php b/oauth_kakao/j_join_process.php index 6c43f866..33179091 100644 --- a/oauth_kakao/j_join_process.php +++ b/oauth_kakao/j_join_process.php @@ -35,10 +35,10 @@ if($expires < $nowDate && (!$refresh_token || ($refresh_token_expires < $nowDate 'reason'=>'로그인 토큰 만료.'.$refresh_token_expires.' 다시 카카오로그인을 수행해주세요.' ]); } -$secret_agree =Util::array_get($_POST['secret_agree']); -$username = mb_strtolower(Util::array_get($_POST['username']), 'utf-8'); -$password = Util::array_get($_POST['password']); -$nickname = Util::array_get($_POST['nickname']); +$secret_agree = Util::getReq('secret_agree', 'bool'); +$username = mb_strtolower(Util::getReq('username'), 'utf-8'); +$password = Util::getReq('password'); +$nickname = Util::getReq('nickname'); if(!$username || !$password || !$nickname){ Json::die([ diff --git a/src/sammo/Session.php b/src/sammo/Session.php index 0215eb60..d82ee4de 100644 --- a/src/sammo/Session.php +++ b/src/sammo/Session.php @@ -65,7 +65,7 @@ class Session ]; if (is_array($result)) { - $jsonResult = array_merge($result, $jsonResult); + $jsonResult = array_merge($jsonResult, $result); } Json::die($jsonResult); diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 0492a436..692172c4 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -3,27 +3,8 @@ namespace sammo; class Util extends \utilphp\util { - /** - * $_GET, $_POST에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능. - * 타입이 복잡해질 경우 이 함수를 통하지 않고 json으로 요청할 것을 권장. - * - * @param string $name 가져오고자 하는 key 이름. - * @param string $type 가져오고자 하는 type. [string, int, float, bool, array, array_string, array_int] - * @param mixed $ifNull 만약 $_GET과 $_POST에 값이 없을 경우 반환하는 변수. 이 값은 $type을 검사하지 않음. - * @return int|float|string|array|null - * @throws \InvalidArgumentException - */ - public static function getReq(string $name, string $type = 'string', $ifNull = null){ - if(isset($_GET[$name])){ - $value = $_GET[$name]; - } - else if(isset($_POST[$name])){ - $value = $_POST[$name]; - } - else{ - return $ifNull; - } + private static function _parseReq($value, string $type){ if(is_array($value)){ if($type === 'array_int'){ return array_map('intval', $value); @@ -43,6 +24,10 @@ class Util extends \utilphp\util } if($type === 'bool'){ + $value = strtolower($value); + if($value === 'false' || $value === 'no' || $value === 'n' || $value === 'x' || $value === 'null'){ + return false; + } return !!$value; } if($type === 'int'){ @@ -58,6 +43,51 @@ class Util extends \utilphp\util throw new \InvalidArgumentException('올바르지 않은 type 지정'); } + /** + * $_GET, $_POST에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능. + * 타입이 복잡해질 경우 이 함수를 통하지 않고 json으로 요청할 것을 권장. + * + * @param string $name 가져오고자 하는 key 이름. + * @param string $type 가져오고자 하는 type. [string, int, float, bool, array, array_string, array_int] + * @param mixed $ifNotExists 만약 $_GET과 $_POST에 값이 없을 경우 반환하는 변수. 이 값은 $type을 검사하지 않음. + * @return int|float|string|array|null + * @throws \InvalidArgumentException + */ + public static function getReq(string $name, string $type = 'string', $ifNotExists = null){ + if(isset($_GET[$name])){ + $value = $_GET[$name]; + } + else if(isset($_POST[$name])){ + $value = $_POST[$name]; + } + else{ + return $ifNotExists; + } + + return static::_parseReq($value, $type); + } + + /** + * $_POST에서 값을 가져오는 함수. Util::array_get($_POST[$name])을 축약 가능. $_GET에서도 가져올 수 있다면 getReq 사용. + * 타입이 복잡해질 경우 이 함수를 통하지 않고 json으로 요청할 것을 권장. + * + * @param string $name 가져오고자 하는 key 이름. + * @param string $type 가져오고자 하는 type. [string, int, float, bool, array, array_string, array_int] + * @param mixed $ifNotExists 만약 $_GET과 $_POST에 값이 없을 경우 반환하는 변수. 이 값은 $type을 검사하지 않음. + * @return int|float|string|array|null + * @throws \InvalidArgumentException + */ + public static function getPost(string $name, string $type = 'string', $ifNotExists = null){ + if(isset($_POST[$name])){ + $value = $_POST[$name]; + } + else{ + return $ifNotExists; + } + + return static::_parseReq($value, $type); + } + public static function hashPassword($salt, $password) { return hash('sha512', $salt.$password.$salt);