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){ +
+ +
+ +
+
+
diff --git a/hwe/j_autoreset.php b/hwe/j_autoreset.php index 33b4f9c0..d1f3b872 100644 --- a/hwe/j_autoreset.php +++ b/hwe/j_autoreset.php @@ -88,7 +88,8 @@ $result = ResetHelper::buildScenario( $options['npcmode'], $options['show_img_level'], $options['tournament_trig'], - $options['join_mode'] + $options['join_mode'], + $options['starttime'] ); $result['affected']=1; diff --git a/hwe/j_install.php b/hwe/j_install.php index c4a753d5..08e5901b 100644 --- a/hwe/j_install.php +++ b/hwe/j_install.php @@ -27,6 +27,20 @@ if($reserve_open && $reserve_open < date('Y-m-d H:i')){ ]); } +$pre_reserve_open = Util::getReq('pre_reserve_open'); +if($pre_reserve_open && !$reserve_open){ + Json::die([ + 'result'=>false, + 'reason'=>'가오픈 예약을 위해선 오픈 예약을 지정해야합니다.' + ]); +} +if($pre_reserve_open && $pre_reserve_open >= $reserve_open){ + Json::die([ + 'result'=>false, + 'reason'=>'가오픈 시간이 오픈 예약 시점보다 이전이어야 합니다.' + ]); +} + if($session->userGrade < 5 && !$allowReset){ Json::die([ 'result'=>false, @@ -114,22 +128,35 @@ if($reserve_open){ } $scenarioObj = new Scenario($scenario, true); + $open_date = $reserve_open->format('Y-m-d H:i:s'); + + $reserveInfo = [ + 'turnterm'=>$turnterm, + 'sync'=>$sync, + 'scenario'=>$scenario, + 'scenarioName'=>$scenarioObj->getTitle(), + 'fiction'=>$fiction, + 'extend'=>$extend, + 'npcmode'=>$npcmode, + 'show_img_level'=>$show_img_level, + 'tournament_trig'=>$tournament_trig, + 'gameConf'=>$scenarioObj->getGameConf(), + 'join_mode'=>$join_mode, + 'starttime'=>$open_date, + ]; + + + if($pre_reserve_open){ + $pre_reserve_open = new \DateTime($pre_reserve_open); + $open_date = $pre_reserve_open->format('Y-m-d H:i:s'); + } + + + $db->delete('reserved_open', true); $db->insert('reserved_open', [ - 'options'=>Json::encode([ - 'turnterm'=>$turnterm, - 'sync'=>$sync, - 'scenario'=>$scenario, - 'scenarioName'=>$scenarioObj->getTitle(), - 'fiction'=>$fiction, - 'extend'=>$extend, - 'npcmode'=>$npcmode, - 'show_img_level'=>$show_img_level, - 'tournament_trig'=>$tournament_trig, - 'gameConf'=>$scenarioObj->getGameConf(), - 'join_mode'=>$join_mode, - ]), - 'date'=>$reserve_open->format('Y-m-d H:i:s') + 'options'=>Json::encode($reserveInfo), + 'date'=>$open_date ]); AppConf::getList()[DB::prefix()]->closeServer(); Json::die([ @@ -147,5 +174,6 @@ Json::die(ResetHelper::buildScenario( $npcmode, $show_img_level, $tournament_trig, - $join_mode + $join_mode, + TimeUtil::DatetimeNow() )); \ No newline at end of file diff --git a/hwe/join_post.php b/hwe/join_post.php index 2452534c..89bd02cc 100644 --- a/hwe/join_post.php +++ b/hwe/join_post.php @@ -68,7 +68,7 @@ if (!$member) { $db = DB::db(); $gameStor = KVStorage::getStorage($db, 'game_env'); -$gameStor->cacheValues(['year','month','maxgeneral','scenario','show_img_level','turnterm','genius','npcmode']); +$gameStor->cacheValues(['year','month','maxgeneral','scenario','show_img_level','turnterm','turntime','genius','npcmode']); ########## 동일 정보 존재여부 확인. ########## $gencount = $db->queryFirstField('SELECT count(`no`) FROM general WHERE npc<2'); @@ -153,7 +153,7 @@ $leader = $leader + $pleader; $power = $power + $ppower; $intel = $intel + $pintel; -$admin = $gameStor->getValues(['scenario', 'turnterm', 'show_img_level', 'startyear', 'year']); +$admin = $gameStor->getValues(['scenario', 'turnterm', 'turntime', 'show_img_level', 'startyear', 'year']); $relYear = Util::valueFit($admin['year'] - $admin['startyear'], 0); $age = 20 + ($pleader + $ppower + $pintel) * 2 - (mt_rand(0, 1)); @@ -187,7 +187,7 @@ else{ $experience *= 0.8; } -$turntime = getRandTurn($admin['turnterm']); +$turntime = getRandTurn($admin['turnterm'], new \DateTimeImmutable($admin['turntime'])); $lastconnect = date('Y-m-d H:i:s'); if ($lastconnect >= $turntime) { diff --git a/hwe/js/install.js b/hwe/js/install.js index 893ff3fc..10034b89 100644 --- a/hwe/js/install.js +++ b/hwe/js/install.js @@ -155,6 +155,7 @@ function formSetup(){ show_img_level:$('#show_img_level input:radio:checked').val(), tournament_trig:$('#tournament_trig input:radio:checked').val(), reserve_open:$('#reserve_open').val(), + pre_reserve_open:$('#pre_reserve_open').val(), join_mode:$('#join_mode input:radio:checked').val(), } }).then(function(result){ diff --git a/hwe/sammo/ResetHelper.php b/hwe/sammo/ResetHelper.php index fd1582bc..e5e6d057 100644 --- a/hwe/sammo/ResetHelper.php +++ b/hwe/sammo/ResetHelper.php @@ -129,7 +129,8 @@ class ResetHelper{ int $npcmode, int $show_img_level, int $tournament_trig, - string $join_mode + string $join_mode, + string $turntime ):array{ //FIXME: 분리할 것 if(120 % $turnterm != 0){ @@ -186,8 +187,6 @@ class ResetHelper{ true ); - - $turntime = date('Y-m-d H:i:s'); $time = substr($turntime, 11, 2); if($sync == 0) { // 현재 시간을 1월로 맞춤 diff --git a/hwe/sammo/Scenario/NPC.php b/hwe/sammo/Scenario/NPC.php index c336bfd8..05f387d6 100644 --- a/hwe/sammo/Scenario/NPC.php +++ b/hwe/sammo/Scenario/NPC.php @@ -227,7 +227,7 @@ class NPC{ $level = $nationID?1:0; } - $turntime = \sammo\getRandTurn($env['turnterm']); + $turntime = \sammo\getRandTurn($env['turnterm'], new \DateTimeImmutable($env['turntime'])); $killturn = ($this->death - $year) * 12 + mt_rand(0, 11);