From 2220920afe423e49b60702acbe55f14f75ba811e Mon Sep 17 00:00:00 2001 From: hide_d Date: Fri, 1 May 2020 18:24:05 +0900 Subject: [PATCH] =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .phan/config.php | 7 ++- f_config/config.php | 4 +- hwe/MYDB.php | 2 +- hwe/a_emperior_detail.php | 15 +++-- hwe/b_tournament.php | 34 +---------- hwe/c_tournament.php | 115 +++++------------------------------- hwe/func_tournament.php | 2 +- hwe/sammo/WarUnit.php | 4 -- hwe/templates/oldNation.php | 2 +- src/sammo/StringUtil.php | 12 ++-- src/sammo/Util.php | 23 +++++++- 11 files changed, 63 insertions(+), 157 deletions(-) diff --git a/.phan/config.php b/.phan/config.php index 7f07e7f3..68f08443 100644 --- a/.phan/config.php +++ b/.phan/config.php @@ -17,8 +17,7 @@ return [ // (See `backward_compatibility_checks` for additional options) "target_php_version" => '8.0', 'backward_compatibility_checks ' => false, - 'ignore_undeclared_variables_in_global_scope' => false, - 'minimum_severity'=>\Phan\Issue::SEVERITY_CRITICAL, + 'minimum_severity'=>\Phan\Issue::SEVERITY_NORMAL, 'file_list' => [ 'f_config/config.php', @@ -170,6 +169,10 @@ return [ 'vendor/' ], + 'suppress_issue_types' => [ + 'PhanUnreferencedUseNormal', + ], + // A list of plugin files to execute. // See https://github.com/phan/phan/tree/master/.phan/plugins for even more. // (Pass these in as relative paths. diff --git a/f_config/config.php b/f_config/config.php index 9f23b279..ebcf9521 100644 --- a/f_config/config.php +++ b/f_config/config.php @@ -8,8 +8,8 @@ mb_internal_encoding("UTF-8"); mb_http_output('UTF-8'); mb_regex_encoding('UTF-8'); -ini_set("session.cache_expire", 10080); // minutes -ini_set("session.gc_maxlifetime", 604800); // seconds +ini_set("session.cache_expire", '10080'); // minutes +ini_set("session.gc_maxlifetime", '604800'); // seconds function getFriendlyErrorType($type) { diff --git a/hwe/MYDB.php b/hwe/MYDB.php index 5098ef86..cfbd49b5 100644 --- a/hwe/MYDB.php +++ b/hwe/MYDB.php @@ -12,7 +12,7 @@ function MYDB_num_rows(\mysqli_result $result) : int } /** - * @return mixed[] + * @return mixed[]|null */ function MYDB_fetch_array(\mysqli_result $result) { diff --git a/hwe/a_emperior_detail.php b/hwe/a_emperior_detail.php index 69d4a050..527da7de 100644 --- a/hwe/a_emperior_detail.php +++ b/hwe/a_emperior_detail.php @@ -176,14 +176,17 @@ if($showServers){ $nation['typeName'] = getNationType($nation['type']); $nation['levelName'] = getNationLevel($nation['level']); - if($nation['generals']){ - $generals = $db->query('SELECT `general_no`, `name`, `last_yearmonth` FROM ng_old_generals WHERE server_id=%s AND general_no IN %li', $serverID, $nation['generals']); + /** @var int[]|null $nationGenerals */ + $nationGenerals = $nation['generals']; + + if($nationGenerals){ + $generals = $db->query('SELECT `general_no`, `name`, `last_yearmonth` FROM ng_old_generals WHERE server_id=%s AND general_no IN %li', $serverID, $nationGenerals); - if(count($generals) != count($nation['generals']) && $serverID == UniqueConst::$serverID){ - $liveGenerals = $nation['generals']; + if(count($generals) != count($nationGenerals) && $serverID == UniqueConst::$serverID){ + $liveGenerals = $nationGenerals; foreach($generals as $general){ - if(in_array($general['general_no'], $nation['generals'])){ - unset($nation['generals'][$general['general_no']]); + if(in_array($general['general_no'], $nationGenerals)){ + unset($nationGenerals[$general['general_no']]); } } $liveGenerals = $db->query('SELECT `no`as`general_no`, `name` FROM general WHERE no IN %li', $liveGenerals); diff --git a/hwe/b_tournament.php b/hwe/b_tournament.php index e36d68ee..e194aecb 100644 --- a/hwe/b_tournament.php +++ b/hwe/b_tournament.php @@ -113,38 +113,8 @@ if ($session->userGrade >= 5) { switch ($admin['tournament']) { case 1: - echo " - - - - - - - - - - - "; + echo ""; + echo ""; break; case 2: echo ""; break; case 3: echo ""; break; diff --git a/hwe/c_tournament.php b/hwe/c_tournament.php index c30fbcc5..eec353f5 100644 --- a/hwe/c_tournament.php +++ b/hwe/c_tournament.php @@ -20,13 +20,10 @@ $userID = Session::getUserID(); $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); -$connect=$db->get(); $admin = $gameStor->getValues(['tournament','phase','tnmt_type','develcost']); -$query = "select no,name,tournament from general where owner='{$userID}'"; -$result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); -$me = MYDB_fetch_array($result); +$me = $db->queryFirstList('SELECT no,name,tournament from general where owner=%i',$userID); switch($admin['tnmt_type']) { case 0: $tp = "total"; $tp2 = "전력전"; $tp3 = "leadership+strength+intel"; break; @@ -102,57 +99,8 @@ if($btn == "자동개최설정") { $gameStor->tnmt_auto = 0; $gameStor->tournament = 0; $gameStor->phase = 0; -} elseif($btn == "투입" || $btn == "무명투입" || $btn == "쪼렙투입" || $btn == "일반투입" || $btn == "굇수투입" || $btn == "랜덤투입") { - if($btn == "투입") { - $query = "select no,name,npc,leadership,strength,intel,explevel,gold,horse,weapon,book from general where no='$gen'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); - $general['gold'] -= $admin['develcost']; - } elseif($btn == "무명투입") { - $general['no'] = 0; - $general['name'] = "무명장수"; - $general['npc'] = 2; - $general['leadership'] = 10; - $general['strength'] = 10; - $general['intel'] = 10; - $general['explevel'] = 10; - $general['gold'] = 0; - } elseif($btn == "쪼렙투입") { - $sel = rand() % 32; - $query = "select no,name,npc,leadership,strength,intel,explevel,gold,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by {$tp} limit {$sel},1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); - $general['gold'] -= $admin['develcost']; - } elseif($btn == "일반투입") { - //참가한 사람 평균치 - $query = "select AVG({$tp3}) as av from general where tournament=1"; - $genResult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $avgGen = MYDB_fetch_array($genResult); - - //그 장수보다 높은장수 수 - $query = "select no from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 and {$tp3}>{$avgGen['av']}"; - $genResult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $genCount = MYDB_num_rows($genResult); - - $sel = rand() % 32 + $genCount - 8; - - $query = "select no,name,npc,leadership,strength,intel,explevel,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by {$tp} desc limit {$sel},1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); - $general['gold'] -= $admin['develcost']; - } elseif($btn == "굇수투입") { - $sel = rand() % 32; - $query = "select no,name,npc,leadership,strength,intel,explevel,gold,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by {$tp} desc limit {$sel},1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); - $general['gold'] -= $admin['develcost']; - } elseif($btn == "랜덤투입") { - $query = "select no,name,npc,leadership,strength,intel,explevel,gold,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by rand() limit 0,1"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); - $general['gold'] -= $admin['develcost']; - //참가 - } +} elseif($btn == "랜덤투입") { + $general = $db->queryFirstRow('SELECT no,name,npc,leadership,strength,intel,explevel,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 order by rand() limit 1'); $occupied = []; foreach($db->queryFirstColumn('SELECT grp FROM tournament WHERE grp < 10 GROUP BY grp HAVING count(*)=8') as $grp){ @@ -179,7 +127,6 @@ if($btn == "자동개최설정") { ]); $db->update('general', [ 'tournament'=>1, - 'gold'=>$general['gold'] ], 'no=%i', $general['no']); } @@ -189,50 +136,21 @@ if($btn == "자동개최설정") { $gameStor->phase = 0; } -} elseif($btn == "쪼렙전부투입" || $btn == "일반전부투입" || $btn == "굇수전부투입" || $btn == "랜덤전부투입") { - $z = 0; +} elseif($btn == "랜덤전부투입") { $code = []; - for($i=0; $i < 8; $i++) { - $query = "select grp from tournament where grp='$i'"; - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $grpCount = MYDB_num_rows($result); - for($k=$grpCount; $k < 8; $k++) { - $code[$z++] = $i * 10 + $k; + foreach($db->queryAllLists('SELECT grp, count(*) FROM tournament WHERE 0 <= grp AND grp < 8 GROUP BY grp') as [$grpIdx, $cnt]){ + foreach(Util::range($cnt, 8) as $grpNo){ + $code[] = $grpIdx * 10 + $grpNo; } } - //섞기 - for($i=0; $i < $z; $i++) { - $index = rand() % $z; - $temp = $code[$i]; - $code[$i] = $code[$index]; - $code[$index] = $temp; - } + $z = count($code); - for($i=0; $i < $z; $i++) { + + $generals = $db->query('SELECT no,name,npc,leadership,strength,intel,explevel,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 order by rand() limit %i', $z); + + foreach(Util::range($z) as $i){ $sel = rand() % 32; - if($btn == "쪼렙전부투입") { - $query = "select no,name,npc,leadership,strength,intel,explevel,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by {$tp} limit {$sel},1"; - } elseif($btn == "일반전부투입") { - //참가한 사람 평균치 - $query = "select AVG({$tp3}) as av from general where tournament=1"; - $genResult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $avgGen = MYDB_fetch_array($genResult); - - //그 장수보다 높은장수 수 - $query = "select no from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 and {$tp3}>{$avgGen['av']}"; - $genResult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $genCount = MYDB_num_rows($genResult); - - $sel += $genCount - 8; - - $query = "select no,name,npc,leadership,strength,intel,explevel,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by {$tp} desc limit {$sel},1"; - } elseif($btn == "굇수전부투입") { - $query = "select no,name,npc,leadership,strength,intel,explevel,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by {$tp} desc limit {$sel},1"; - } else { - $query = "select no,name,npc,leadership,strength,intel,explevel,leadership+strength+intel as total,horse,weapon,book from general where tournament=0 and gold>='{$admin['develcost']}' and npc>=2 order by rand() limit 0,1"; - } - $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); - $general = MYDB_fetch_array($result); + $general = $generals[$i]; $grp = intdiv($code[$i], 10); $grp_no = $code[$i] % 10; @@ -250,11 +168,10 @@ if($btn == "자동개최설정") { 'w'=>$general['weapon'], 'b'=>$general['book'] ]); - $db->update('general', [ - 'tournament'=>1, - 'gold'=>$db->sqleval('gold - %i', $admin['develcost']) - ], 'no=%i', $general['no']); } + $db->update('general', [ + 'tournament'=>1, + ], 'no=%li', array_column($generals, 'no')); $gameStor->tournament = 2; $gameStor->phase = 0; diff --git a/hwe/func_tournament.php b/hwe/func_tournament.php index 7540bf8e..7f4cf9b9 100644 --- a/hwe/func_tournament.php +++ b/hwe/func_tournament.php @@ -167,7 +167,7 @@ function getTournament(int $tnmt) { ][$tnmt]??"TOURNAMENT_TYPE_ERR_{$tnmt}"; } -function printRow($k, $npc, $name, $abil, $tgame, $win, $draw, $lose, $gd, $gl, $prmt) { +function printRow(int $k, int $npc, string $name, int $abil, int $tgame, int $win, int $draw, int $lose, int $gd, int $gl, int $prmt) { if($prmt > 0) { $name = "".$name.""; } elseif($npc >= 2) { $name = "".$name.""; } elseif($npc == 1) { $name = "".$name.""; } diff --git a/hwe/sammo/WarUnit.php b/hwe/sammo/WarUnit.php index b701a5b9..b49fcb41 100644 --- a/hwe/sammo/WarUnit.php +++ b/hwe/sammo/WarUnit.php @@ -334,19 +334,16 @@ class WarUnit{ function getHP():int{ throw new NotInheritedMethodException(); - return 0; } function decreaseHP(int $damage):int{ $this->dead += $damage; throw new NotInheritedMethodException(); - return 0; } function increaseKilled(int $damage):int{ $this->killed += $damage; throw new NotInheritedMethodException(); - return 0; } function calcDamage():int{ @@ -376,6 +373,5 @@ class WarUnit{ function applyDB(\MeekroDB $db):bool{ throw new MustNotBeReachedException('Must be WarUnitCity or WarUnitGeneral'); - return false; } } \ No newline at end of file diff --git a/hwe/templates/oldNation.php b/hwe/templates/oldNation.php index 1f8ae712..415950da 100644 --- a/hwe/templates/oldNation.php +++ b/hwe/templates/oldNation.php @@ -52,7 +52,7 @@ 국가열전 - ConvertLog($history)?> + ConvertLog, $history)?> diff --git a/src/sammo/StringUtil.php b/src/sammo/StringUtil.php index ff1cf284..376b67a3 100644 --- a/src/sammo/StringUtil.php +++ b/src/sammo/StringUtil.php @@ -183,19 +183,19 @@ class StringUtil } public static function uniord(string $c) { - $c0 = ord($c{0}); + $c0 = ord($c[0]); if ($c0 >=0 && $c0 <= 127) return $c0; if ($c0 >= 192 && $c0 <= 223) - return ($c0-192)*64 + (ord($c{1})-128); + return ($c0-192)*64 + (ord($c[1])-128); if ($c0 >= 224 && $c0 <= 239) - return ($c0-224)*4096 + (ord($c{1})-128)*64 + (ord($c{2})-128); + return ($c0-224)*4096 + (ord($c[1])-128)*64 + (ord($c[2])-128); if ($c0 >= 240 && $c0 <= 247) - return ($c0-240)*262144 + (ord($c{1})-128)*4096 + (ord($c{2})-128)*64 + (ord($c{3})-128); + return ($c0-240)*262144 + (ord($c[1])-128)*4096 + (ord($c[2])-128)*64 + (ord($c[3])-128); if ($c0 >= 248 && $c0 <= 251) - return ($c0-248)*16777216 + (ord($c{1})-128)*262144 + (ord($c{2})-128)*4096 + (ord($c{3})-128)*64 + (ord($c{4})-128); + return ($c0-248)*16777216 + (ord($c[1])-128)*262144 + (ord($c[2])-128)*4096 + (ord($c[3])-128)*64 + (ord($c[4])-128); if ($c0 >= 252 && $c0 <= 253) - return ($c0-252)*1073741824 + (ord($c{1})-128)*16777216 + (ord($c{2})-128)*262144 + (ord($c{3})-128)*4096 + (ord($c{4})-128)*64 + (ord($c{5})-128); + return ($c0-252)*1073741824 + (ord($c[1])-128)*16777216 + (ord($c[2])-128)*262144 + (ord($c[3])-128)*4096 + (ord($c[4])-128)*64 + (ord($c[5])-128); if ($c0 >= 254 && $c0 <= 255) // error return FALSE; return 0; diff --git a/src/sammo/Util.php b/src/sammo/Util.php index 004cd918..83e8d64c 100644 --- a/src/sammo/Util.php +++ b/src/sammo/Util.php @@ -685,8 +685,25 @@ class Util extends \utilphp\util * 길이가 다른 경우, 앞의 결과를 먼저 비교한 뒤, 짧은쪽의 값을 null으로 가정하여 길이 처리 */ public static function arrayCompare(iterable $lhs, iterable $rhs, ?callable $comp=null){ - $lhsIter = new \Iterator($lhs); - $rhsIter = new \Iterator($rhs); + if($lhs instanceof \Traversable){ + $lhsIter = new \IteratorIterator($lhs); + } + else if(is_array($lhs)){ + $lhsIter = new \ArrayIterator($lhs); + } + else{ + throw new \InvalidArgumentException('$lhs is not Traversable'); + } + + if($rhs instanceof \Traversable){ + $rhsIter = new \IteratorIterator($rhs); + } + else if(is_array($rhs)){ + $rhsIter = new \ArrayIterator($rhs); + } + else{ + throw new \InvalidArgumentException('$rhs is not Traversable'); + } while($lhsIter->valid() && $rhsIter->valid()){ $lhsVal = $lhsIter->current(); @@ -759,7 +776,7 @@ class Util extends \utilphp\util * @param null|int $to * @param null|int $step * @return \Traversable - * @throws InvalidArgumentException + * @throws \InvalidArgumentException */ public static function range(int $from, ?int $to=null, ?int $step=null):\Traversable{ if($to === null){