diff --git a/hwe/commandlist.php b/hwe/commandlist.php index 233b32f0..9662029b 100644 --- a/hwe/commandlist.php +++ b/hwe/commandlist.php @@ -78,7 +78,7 @@ function myCommandList() { $date = date('Y-m-d H:i:s'); // 명령 목록 - $admin = $gameStor->getValues(['year','month','turnterm']); + $admin = $gameStor->getValues(['year','month','turnterm','turntime']); $me = $db->queryFirstRow("SELECT `no`,turntime,term,turn0,turn1,turn2,turn3,turn4,turn5,turn6,turn7,turn8,turn9,turn10,turn11,turn12,turn13,turn14,turn15,turn16,turn17,turn18,turn19,turn20,turn21,turn22,turn23 FROM general WHERE `owner`=%s", $userID); if(!$me){ @@ -97,7 +97,7 @@ function myCommandList() { $month = $admin['month']; // 실행된 턴시간이면 +1 $cutTurn = cutTurn($me['turntime'], $admin['turnterm']); - if($date <= $cutTurn) { $month++; } + if($date <= $cutTurn && $date < $admin['tuntime']) { $month++; } $totaldate = $me['turntime']; diff --git a/hwe/func.php b/hwe/func.php index b8c74338..37eb5792 100644 --- a/hwe/func.php +++ b/hwe/func.php @@ -1523,6 +1523,11 @@ function checkTurn() { $alllog = []; + if(date('Y-m-d H:i:s') < $gameStor->turntime){ + //턴 시각 이전이면 아무것도 하지 않음 + return true; + } + // 잦은 갱신 금지 현재 5초당 1회 if(!timeover()) { return; } // 현재 처리중이면 접근 불가 @@ -1557,7 +1562,12 @@ function checkTurn() { $db->update('plock', ['plock'=>1], true); return; } + + $date = date('Y-m-d H:i:s'); + $gameStor->cacheAll(); + + // 1턴이상 갱신 없었으면 서버 지연 //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', checkDelay'); checkDelay(); @@ -1569,10 +1579,11 @@ function checkTurn() { CheckOverhead(); //서버정보 - $date = date('Y-m-d H:i:s'); + // 최종 처리 월턴의 다음 월턴시간 구함 $prevTurn = cutTurn($gameStor->turntime, $gameStor->turnterm); $nextTurn = addTurn($prevTurn, $gameStor->turnterm); + $computedPrevTurn = false; // 현재 턴 이전 월턴까지 모두처리. //최종 처리 이후 다음 월턴이 현재 시간보다 전이라면 while($nextTurn <= $date) { @@ -1678,12 +1689,16 @@ function checkTurn() { // 다음달로 넘김 $prevTurn = $nextTurn; $nextTurn = addTurn($prevTurn, $gameStor->turnterm); + $computedPrevTurn = true; } //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', '.__LINE__); // 이시각 정각 시까지 업데이트 완료했음 - $gameStor->turntime = $prevTurn; + if($computedPrevTurn){ + $gameStor->turntime = $prevTurn; + } + // 그 시각 년도,월 저장 list($gameStor->year, $gameStor->month) = turnDate($prevTurn); @@ -2915,16 +2930,24 @@ function SabotageInjury($city, $type=0) { return $injuryCount; } -function getRandTurn($term) { +function getRandTurn($term, ?\DateTimeInterface $baseDateTime = null) { + if($baseDateTime === null){ + $baseDateTime = new \DateTimeImmutable(); + } + else if($baseDateTime instanceof \DateTime){ + $baseDateTime = DateTimeImmutable::createFromMutable($baseDateTime); + } $randtime = rand(0, 60 * $term - 1); - $turntime = date('Y-m-d H:i:s', strtotime('now') + $randtime); - - return $turntime; + return $baseDateTime->add(new \DateInterval('PT'.$randtime.'S'))->format('Y-m-d H:i:s'); } -function getRandTurn2($term) { +function getRandTurn2($term, ?\DateTimeInterface $baseDateTime = null) { + if($baseDateTime === null){ + $baseDateTime = new \DateTimeImmutable(); + } + else if($baseDateTime instanceof \DateTime){ + $baseDateTime = DateTimeImmutable::createFromMutable($baseDateTime); + } $randtime = rand(0, 60 * $term - 1); - $turntime = date('Y-m-d H:i:s', strtotime('now') - $randtime); - - return $turntime; + return $baseDateTime->sub(new \DateInterval('PT'.$randtime.'S'))->format('Y-m-d H:i:s'); } diff --git a/hwe/func_gamerule.php b/hwe/func_gamerule.php index 03132efc..ba16fdec 100644 --- a/hwe/func_gamerule.php +++ b/hwe/func_gamerule.php @@ -973,7 +973,7 @@ function updateNationState() { $connect=$db->get(); $history = array(); - $admin = $gameStor->getValues(['year', 'month', 'fiction', 'startyear', 'show_img_level', 'turnterm']); + $admin = $gameStor->getValues(['year', 'month', 'fiction', 'startyear', 'show_img_level', 'turnterm', 'turntime']); $query = "select nation,name,level,gennum,tech from nation"; $nationresult = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); diff --git a/hwe/func_process_chief.php b/hwe/func_process_chief.php index 3e9a9bc8..04125696 100644 --- a/hwe/func_process_chief.php +++ b/hwe/func_process_chief.php @@ -1894,7 +1894,7 @@ function process_76(&$general) { $date = substr($general['turntime'],11,5); - $admin = $gameStor->getValues(['startyear','year','month','develcost','npccount','turnterm']); + $admin = $gameStor->getValues(['startyear','year','month','develcost','npccount','turnterm','turntime']); $query = "select nation,supply from city where city='{$general['city']}'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); @@ -2070,7 +2070,7 @@ function process_76(&$general) { $affinity = rand() % 150 + 1; $name = "ⓖ의병장{$npcid}"; $picture = 'default.jpg'; - $turntime = getRandTurn($admin['turnterm']); + $turntime = getRandTurn($admin['turnterm'], new \DateTimeImmutable($admin['turntime'])); $personal = rand() % 10; $bornyear = $admin['year']; $deadyear = $admin['year'] + 3; diff --git a/hwe/func_process_personnel.php b/hwe/func_process_personnel.php index 10c6e192..0eade9c9 100644 --- a/hwe/func_process_personnel.php +++ b/hwe/func_process_personnel.php @@ -290,7 +290,7 @@ function process_29(&$general) { $history = []; $date = substr($general['turntime'],11,5); - $admin = $gameStor->getValues(['startyear','year','month','develcost','npccount','turnterm','scenario','maxgeneral']); + $admin = $gameStor->getValues(['startyear','year','month','develcost','npccount','turnterm','scenario','maxgeneral', 'turntime']); $query = "select nation,name,level,gennum,scout from nation where nation='{$general['nation']}'"; $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),""); @@ -490,7 +490,7 @@ function process_29(&$general) { $npccount = 10000 + $npcid; $affinity = rand() % 150 + 1; $picture = 'default.jpg'; - $turntime = getRandTurn($admin['turnterm']); + $turntime = getRandTurn($admin['turnterm'], new \DateTimeImmutable($admin['turntime'])); $personal = rand() % 10; $bornyear = $admin['year']; $deadyear = $admin['year'] + 3; diff --git a/hwe/install.php b/hwe/install.php index 4fcc5d39..b4edf004 100644 --- a/hwe/install.php +++ b/hwe/install.php @@ -225,6 +225,13 @@ if($session->userGrade < 5 && !$allowReset){ +