diff --git a/f_install/j_setup_db.php b/f_install/j_setup_db.php index 2b830e91..5990f0ae 100644 --- a/f_install/j_setup_db.php +++ b/f_install/j_setup_db.php @@ -15,7 +15,7 @@ $gameImagePath = Util::getPost('game_image_path'); $imageRequestKey = Util::getPost('image_request_key'); $kakaoRESTKey = Util::getPost('kakao_rest_key', 'string', ''); -$kakaoAdminKey = Util::ggetPostetReq('kakao_admin_key', 'string', ''); +$kakaoAdminKey = Util::getPost('kakao_admin_key', 'string', ''); if (!$host || !$port || !$username || !$password || !$dbName || !$servHost || !$sharedIconPath || !$gameImagePath) { diff --git a/hwe/c_vote.php b/hwe/c_vote.php index b8bed2bf..a7d2d77f 100644 --- a/hwe/c_vote.php +++ b/hwe/c_vote.php @@ -38,7 +38,7 @@ if($btn == "투표" && $general->getVar('vote') == 0 && $sel > 0) { } } else if($btn == "댓글" && trim($comment) != "") { - $comment = trim($comment); + $comment = StringUtil::neutralize($comment); $nation = $general->getStaticNation(); diff --git a/hwe/func_command.php b/hwe/func_command.php index b9dec13d..a919fab7 100644 --- a/hwe/func_command.php +++ b/hwe/func_command.php @@ -206,6 +206,26 @@ function _setNationCommand(NationCommand $command, array $turnList):void { ], 'nation_id = %i AND officer_level = %i AND turn_idx IN %li', $nationID, $officerLevel, $turnList); } +function sanitizeArg(?array $args):?array{ + if($args === null){ + return $args; + } + + $result = []; + foreach($args as $key=>$value){ + if(is_array($value)){ + $result[$key] = sanitizeArg($value); + } + else if(is_string($value)){ + $result[$key] = StringUtil::neutralize(StringUtil::removeSpecialCharacter($value)); + } + else{ + $result[$key] = $value; + } + } + return $result; +} + function checkCommandArg(?array $arg):?string{ if($arg === null){ return null; @@ -284,6 +304,7 @@ function setGeneralCommand(int $generalID, array $rawTurnList, string $command, } $turnList = array_keys($turnList); + $arg = sanitizeArg($arg); $argBasicTestResult = checkCommandArg($arg); if($argBasicTestResult !== null){ return [ @@ -357,6 +378,7 @@ function setNationCommand(int $generalID, array $turnList, string $command, ?arr } } + $arg = sanitizeArg($arg); $argBasicTestResult = checkCommandArg($arg); if($argBasicTestResult !== null){ return [ diff --git a/hwe/j_board_article_add.php b/hwe/j_board_article_add.php index 4b4b3a89..6e0c0c7e 100644 --- a/hwe/j_board_article_add.php +++ b/hwe/j_board_article_add.php @@ -34,8 +34,8 @@ if($title === null || $text === null){ ]); } -$title = trim($title); -$text = trim($text); +$title = StringUtil::neutralize($title); +$text = StringUtil::neutralize($text); if(!$title && !$text){ Json::die([ diff --git a/hwe/j_board_comment_add.php b/hwe/j_board_comment_add.php index 12ada898..45820e66 100644 --- a/hwe/j_board_comment_add.php +++ b/hwe/j_board_comment_add.php @@ -33,7 +33,7 @@ if($articleNo === null || $text === null){ ]); } -$text = trim($text); +$text = StringUtil::neutralize($text); if(!$text){ Json::die([ diff --git a/hwe/j_diplomacy_respond_letter.php b/hwe/j_diplomacy_respond_letter.php index 27a11fc4..2784b543 100644 --- a/hwe/j_diplomacy_respond_letter.php +++ b/hwe/j_diplomacy_respond_letter.php @@ -45,7 +45,7 @@ if ($permission < 4) { ]); } -$reason = trim($reason); +$reason = StringUtil::neutralize($reason); $letter = $db->queryFirstRow('SELECT * FROM ng_diplomacy WHERE no=%i AND dest_nation_id = %i AND state = \'proposed\'', $letterNo, $me['nation']); if(!$letter){ diff --git a/hwe/j_diplomacy_send_letter.php b/hwe/j_diplomacy_send_letter.php index ad987993..51ab2af8 100644 --- a/hwe/j_diplomacy_send_letter.php +++ b/hwe/j_diplomacy_send_letter.php @@ -46,8 +46,8 @@ if($textBrief === null || $textDetail === null){ ]); } -$textBrief = trim($textBrief); -$textDetail = trim($textDetail); +$textBrief = StringUtil::neutralize($textBrief); +$textDetail = StringUtil::neutralize($textDetail); if(!$textBrief){ Json::die([ diff --git a/hwe/j_msg_submit.php b/hwe/j_msg_submit.php index 33582367..d180b917 100644 --- a/hwe/j_msg_submit.php +++ b/hwe/j_msg_submit.php @@ -23,7 +23,7 @@ if(!$v->validate()){ } $mailbox = (int)$post['mailbox']; -$text = StringUtil::cutStringForWidth($post['text'], 199, ''); +$text = StringUtil::neutralize(StringUtil::cutStringForWidth($post['text'], 199, '')); $session = Session::requireGameLogin([ 'msgID'=>null diff --git a/hwe/j_troop.php b/hwe/j_troop.php index 868301ab..02caf873 100644 --- a/hwe/j_troop.php +++ b/hwe/j_troop.php @@ -22,7 +22,7 @@ $generalID = $me['no']; $nationID = $me['nation']; if($action == '부대창설'){ - $name = trim($name); + $name = StringUtil::neutralize($name); if(!$name){ Json::die([ 'result'=>false, @@ -52,7 +52,7 @@ if($action == '부대창설'){ } if($action == '부대변경'){ - $name = trim($name); + $name = StringUtil::neutralize($name); if(!$name){ Json::die([ 'result'=>false, diff --git a/hwe/js/chiefCenter.js b/hwe/js/chiefCenter.js index 73d1499b..b80de9a5 100644 --- a/hwe/js/chiefCenter.js +++ b/hwe/js/chiefCenter.js @@ -77,7 +77,7 @@ function reloadTable(){ var turnList = plateObj.turn; $.each(chiefInfo.turn, function(turnIdx, turnText){ turnList[turnIdx].turnTime.text(turnTimeObj.format('hh:mm')); - turnList[turnIdx].turnText.text(turnText).css('font-size', '13px'); + turnList[turnIdx].turnText.html(turnText).css('font-size', '13px'); var oWidth = turnList[turnIdx].turnPad.innerWidth(); var iWidth = turnList[turnIdx].turnText.outerWidth(); if(iWidth > oWidth * 0.95){ diff --git a/hwe/sammo/Command/Nation/che_국기변경.php b/hwe/sammo/Command/Nation/che_국기변경.php new file mode 100644 index 00000000..1d9da47c --- /dev/null +++ b/hwe/sammo/Command/Nation/che_국기변경.php @@ -0,0 +1,182 @@ +arg === null) { + return false; + } + + if (!key_exists('colorType', $this->arg)) { + return false; + } + $colorType = $this->arg['colorType']; + if (!key_exists($colorType, GetNationColors())) { + return false; + } + + $this->arg = [ + 'colorType' => $colorType, + ]; + return true; + } + + protected function init() + { + $general = $this->generalObj; + + $env = $this->env; + + $this->setCity(); + $this->setNation(['can_change_flag']); + + $this->minConditionConstraints = [ + ConstraintHelper::OccupiedCity(), + ConstraintHelper::BeChief(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqNationValue('can_change_flag', '국기색', '>', 0, '더이상 변경이 불가능합니다.') + ]; + } + + protected function initWithArg() + { + $this->fullConditionConstraints = [ + ConstraintHelper::OccupiedCity(), + ConstraintHelper::BeChief(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqNationValue('can_change_flag', '국기색', '>', 0, '더이상 변경이 불가능합니다.') + ]; + } + + public function getCost(): array + { + + return [0, 0]; + } + + public function getPreReqTurn(): int + { + return 0; + } + + public function getPostReqTurn(): int + { + return 0; + } + + public function getBrief(): string + { + $color = GetNationColors()[$this->arg['colorType']]; + return "【국기】를 변경"; + } + + public function run(): bool + { + if (!$this->hasFullConditionMet()) { + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + + $general = $this->generalObj; + $generalID = $general->getID(); + $generalName = $general->getName(); + $date = $general->getTurnTime($general::TURNTIME_HM); + + $colorType = $this->arg['colorType']; + $color = GetNationColors()[$colorType]; + + + $nationID = $general->getNationID(); + $nationName = $this->nation['name']; + + $logger = $general->getLogger(); + + + $general->addExperience(5 * ($this->getPreReqTurn() + 1)); + $general->addDedication(5 * ($this->getPreReqTurn() + 1)); + + $josaYi = JosaUtil::pick($generalName, '이'); + $josaYiNation = JosaUtil::pick($nationName, '이'); + + $db->update('nation', [ + 'color'=>$color, + 'can_change_flag' => $db->sqleval('can_change_flag - 1'), + ], 'nation=%i', $nationID); + + $logger->pushGeneralActionLog("국기를 변경하였습니다 <1>$date"); + $logger->pushGeneralHistoryLog("국기를 변경"); + $logger->pushNationalHistoryLog("{$generalName}{$josaYi} 국기를 변경하였습니다"); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} 국기를 변경하였습니다"); + $logger->pushGlobalHistoryLog("【국기변경】{$nationName}{$josaYiNation} 국기를 변경하였습니다."); + + $general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0)); + $general->applyDB($db); + return true; + } + + public function getJSFiles(): array + { + return [ + 'js/colorSelect.js' + ]; + } + + + public function getForm(): string + { + ob_start(); +?> + 국기를 변경합니다. 단 1회 가능합니다.
+ 색상 :
+
+arg === null) { + return false; + } + + if (!key_exists('nationName', $this->arg)) { + return false; + } + $nationName = $this->arg['nationName']; + if (!is_string($nationName)) { + return false; + } + if (mb_strwidth($nationName) > 18 || $nationName == '') { + return false; + } + + $this->arg = [ + 'nationName' => $nationName, + ]; + return true; + } + + protected function init() + { + $general = $this->generalObj; + + $env = $this->env; + + $this->setCity(); + $this->setNation(['aux']); + $actionName = $this->getName(); + + $this->minConditionConstraints = [ + ConstraintHelper::OccupiedCity(), + ConstraintHelper::BeChief(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqNationAuxValue("can_{$actionName}", 0, '>', 0, '더이상 변경이 불가능합니다.') + ]; + } + + protected function initWithArg() + { + $actionName = $this->getName(); + + $this->fullConditionConstraints = [ + ConstraintHelper::OccupiedCity(), + ConstraintHelper::BeChief(), + ConstraintHelper::SuppliedCity(), + ConstraintHelper::ReqNationAuxValue("can_{$actionName}", 0, '>', 0, '더이상 변경이 불가능합니다.') + ]; + } + + public function getCost(): array + { + + return [0, 0]; + } + + public function getPreReqTurn(): int + { + return 0; + } + + public function getPostReqTurn(): int + { + return 0; + } + + public function getBrief(): string + { + $newNationName = $this->arg['nationName']; + $josaRo = JosaUtil::pick($newNationName, '로'); + return "국호를 【{$newNationName}】{$josaRo} 변경"; + } + + public function run(): bool + { + if (!$this->hasFullConditionMet()) { + throw new \RuntimeException('불가능한 커맨드를 강제로 실행 시도'); + } + + $db = DB::db(); + $actionName = $this->getName(); + + $general = $this->generalObj; + $generalID = $general->getID(); + $generalName = $general->getName(); + $date = $general->getTurnTime($general::TURNTIME_HM); + + $nationID = $general->getNationID(); + $nationName = $this->nation['name']; + + $logger = $general->getLogger(); + + $newNationName = $this->arg['nationName']; + + if($db->queryFirstField('SELECT name FROM nation WHERE name = %s LIMIT 1', $newNationName)){ + $text = "이미 같은 국호를 가진 곳이 있습니다. {$actionName} 실패 <1>{$date}"; + $general->getLogger()->pushGeneralActionLog($text); + return false; + } + + + $josaRo = JosaUtil::pick($newNationName, '로'); + + $general->addExperience(5 * ($this->getPreReqTurn() + 1)); + $general->addDedication(5 * ($this->getPreReqTurn() + 1)); + + $josaYi = JosaUtil::pick($generalName, '이'); + $josaYiNation = JosaUtil::pick($nationName, '이'); + + $aux = Json::decode($this->nation['aux']); + $aux["can_{$actionName}"] = 0; + + $db->update('nation', [ + 'name'=>$newNationName, + 'aux'=>Json::encode($aux) + ], 'nation=%i', $nationID); + + $logger->pushGeneralActionLog("국호를 {$newNationName}{$josaRo} 변경합니다. <1>$date"); + $logger->pushGeneralHistoryLog("국호를 {$newNationName}{$josaRo} 변경"); + $logger->pushNationalHistoryLog("{$generalName}{$josaYi} 국호를 {$newNationName}{$josaRo} 변경"); + $logger->pushGlobalActionLog("{$generalName}{$josaYi} 국호를 {$newNationName}{$josaRo} 변경합니다."); + $logger->pushGlobalHistoryLog("【국호변경】{$nationName}{$josaYiNation} 국호를 {$newNationName}{$josaRo} 변경합니다."); + + $general->setResultTurn(new LastTurn($this->getName(), $this->arg, 0)); + $general->applyDB($db); + return true; + } + + public function getJSFiles(): array + { + return [ + 'js/colorSelect.js' + ]; + } + + + public function getForm(): string + { + ob_start(); +?> + 나라의 이름을 바꿉니다. 황제가 된 후 1회 가능합니다.
+ 국명 :
+
+arg) == 5){ - [$this->key, $this->keyNick, $comp, $this->reqVal, $this->errMsg] = $this->arg; + if (count($this->arg) == 5) { + [$this->key, $this->defaultValue, $comp, $this->reqVal, $this->errMsg] = $this->arg; - if(!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])){ - if(!$throwExeception){return false; } + if (!in_array($comp, ['>', '>=', '==', '<=', '<', '!=', '===', '!=='])) { + if (!$throwExeception) { + return false; + } throw new \InvalidArgumentException("invalid comparator"); } - } - else{ - if(!$throwExeception){return false; } - throw new \InvalidArgumentException("require key, keyNick, comp, reqVal[, errMsg]"); + } else { + if (!$throwExeception) { + return false; + } + throw new \InvalidArgumentException("require key, defaultValue, comp, reqVal, errMsg"); } $this->comp = $comp; - - $this->maxKey = $this->key.'_max'; - if(!key_exists('aux', $this->nation)){ - if(!$throwExeception){return false; } + $this->maxKey = $this->key . '_max'; + + if (!key_exists('aux', $this->nation)) { + if (!$throwExeception) { + return false; + } throw new \InvalidArgumentException("require aux in nation"); } - if($this->nation['aux'] === null){ - if(!$throwExeception){return false; } + if ($this->nation['aux'] === null) { + if (!$throwExeception) { + return false; + } throw new \InvalidArgumentException("invalid aux in nation(null)"); } - if(is_array($this->nation['aux'])){ + if (is_array($this->nation['aux'])) { $this->auxVal = $this->nation['aux']; - } - else if(is_string($this->nation['aux'])){ + } else if (is_string($this->nation['aux'])) { $this->auxVal = Json::decode($this->nation['aux']); - } - else{ - if(!$throwExeception){return false; } + } else { + if (!$throwExeception) { + return false; + } throw new \InvalidArgumentException("inavlid aux in nation(type)"); } - if(!key_exists($this->key, $this->auxVal)){ - if(!$throwExeception){return false; } + if (!key_exists($this->key, $this->auxVal) && $this->defaultValue === null) { + if (!$throwExeception) { + return false; + } throw new \InvalidArgumentException("require {$this->key} in nation['aux']"); } - if(is_numeric($this->reqVal)){ - $this->isPercent = false; - } - else if(is_string($this->reqVal)){ - $this->reqVal = Util::convPercentStrToFloat($this->reqVal); - if($this->reqVal === null){ - if(!$throwExeception){return false; } - throw new \InvalidArgumentException("require valid reqVal(percentStr|numeric) format"); + if (!is_string($this->errMsg)) { + if (!$throwExeception) { + return false; } - - if(!key_exists($this->maxKey, $this->auxVal)){ - if(!$throwExeception){return false; } - throw new \InvalidArgumentException("require {$this->maxKey} in nation['aux']"); - } - $this->isPercent = true; - } - - if($this->errMsg!==null && !is_string($this->errMsg)){ - if(!$throwExeception){return false; } - throw new \InvalidArgumentException("{$this->errMsg} must be string or null"); + throw new \InvalidArgumentException("{$this->errMsg} must be string"); } return true; } - public function test():bool{ + public function test(): bool + { $this->checkInputValues(); $this->tested = true; - $keyNick = $this->keyNick; - - if ($this->isPercent) { - $reqVal = $this->auxVal[$this->maxKey] * $this->reqVal; - } - else{ - $reqVal = $this->reqVal; - } $compList = [ '<'=>function($target, $src){ - return ($target < $src)?true:'너무 많습니다.'; + return ($target < $src); }, '<='=>function($target, $src){ - return ($target <= $src)?true:'너무 많습니다.'; + return ($target <= $src); }, - '=='=>function($target, $src)use($keyNick){ - return ($target == $src)?true:"올바르지 않은 {$keyNick} 입니다."; + '=='=>function($target, $src){ + return ($target == $src); }, - '!='=>function($target, $src)use($keyNick){ - return ($target != $src)?true:"올바르지 않은 {$keyNick} 입니다."; + '!='=>function($target, $src){ + return ($target != $src); }, - '==='=>function($target, $src)use($keyNick){ - return ($target === $src)?true:"올바르지 않은 {$keyNick} 입니다."; + '==='=>function($target, $src){ + return ($target === $src); }, - '!=='=>function($target, $src)use($keyNick){ - return ($target !== $src)?true:"올바르지 않은 {$keyNick} 입니다."; + '!=='=>function($target, $src){ + return ($target !== $src); }, '>='=>function($target, $src){ - if($target >= $src){ - return true; - } - if($src == 1){ - return '없습니다'; - } - return '부족합니다.'; + return ($target >= $src); }, '>'=>function($target, $src){ - if($target > $src){ - return true; - } - if($src == 0){ - return '없습니다'; - } - return '부족합니다.'; + return ($target > $src); }, ]; $comp = $compList[$this->comp]; - $result = ($comp)($this->auxVal[$this->key], $reqVal); + $result = ($comp)($this->auxVal[$this->key]??$this->defaultValue, $this->reqVal); + + if ($result === true) { + return true; + } if($result === true){ return true; } - if($this->errMsg){ - $this->reason = $this->errMsg; - } - else{ - $josaYi = JosaUtil::pick($keyNick, '이'); - $this->reason = "{$keyNick}{$josaYi} {$result}"; - } + $this->reason = $this->errMsg; return false; } -} \ No newline at end of file +} diff --git a/hwe/sammo/GameConstBase.php b/hwe/sammo/GameConstBase.php index bad78527..83992284 100644 --- a/hwe/sammo/GameConstBase.php +++ b/hwe/sammo/GameConstBase.php @@ -329,7 +329,7 @@ class GameConstBase ], '기타'=>[ 'che_국기변경', - //'che_국호변경', + 'che_국호변경', ] ]; public static $retirementYear = 80; diff --git a/src/sammo/StringUtil.php b/src/sammo/StringUtil.php index 376b67a3..746e48ed 100644 --- a/src/sammo/StringUtil.php +++ b/src/sammo/StringUtil.php @@ -161,8 +161,6 @@ class StringUtil $str = StringUtil::subStringForWidth($str, 0, $maxLen); } $str = htmlspecialchars($str); - $str = StringUtil::removeSpecialCharacter($str); - $str = WebUtil::htmlPurify($str); $str = StringUtil::textStrip($str); return $str; }