diff --git a/hwe/install.php b/hwe/install.php index 0a39ef46..2ec5cf27 100644 --- a/hwe/install.php +++ b/hwe/install.php @@ -196,6 +196,13 @@ if($session->userGrade < 5){ +
+ +
+ +
+
+
diff --git a/hwe/j_autoreset.php b/hwe/j_autoreset.php new file mode 100644 index 00000000..a1711c3c --- /dev/null +++ b/hwe/j_autoreset.php @@ -0,0 +1,43 @@ +queryFirstRow( + 'SELECT * FROM reserved_open WHERE `date` <= %s LIMIT 1', + (new \DateTime())->format('Y-m-d H:i:s') +); + +if(!$reserved){ + Json::die([ + 'result'=>true, + 'affected'=>0 + ]); +} + +$options = Json::decode($reserved['options']); + +$result = ResetHelper::buildScenario( + $options['turnterm'], + $options['sync'], + $options['scenario'], + $options['fiction'], + $options['extend'], + $options['npcmode'], + $options['show_img_level'], + $options['tournament_trig'] +); + +if($result['result']){ + $db->delete('reserved_open', 'id=%i', $reserved['id']); +} + +$result['affected']=1; + +$prefix = DB::prefix(); +AppConf::getList()[$prefix]->openServer(); + +Json::die($result); \ No newline at end of file diff --git a/hwe/j_install.php b/hwe/j_install.php index f2573c24..48a3966a 100644 --- a/hwe/j_install.php +++ b/hwe/j_install.php @@ -47,7 +47,33 @@ $npcmode = (int)$_POST['npcmode']; $show_img_level = (int)$_POST['show_img_level']; $tournament_trig = (int)$_POST['tournament_trig']; -Json::die(ResetHelper::doReset( +$reserve_open = Util::getReq('reserve_open'); +if($reserve_open){ + $reserve_open = new \DateTime($reserve_open); + $db = DB::db(); + + ResetHelper::clearDB(); + + $db->insert('reserved_open', [ + 'options'=>Json::encode([ + 'turnterm'=>$turnterm, + 'sync'=>$sync, + 'scenario'=>$scenario, + 'fiction'=>$fiction, + 'extend'=>$extend, + 'npcmode'=>$npcmode, + 'show_img_level'=>$show_img_level, + 'tournament_trig'=>$tournament_trig + ]), + 'date'=>$reserve_open->format('Y-m-d H:i:s') + ]); + Json::die([ + 'result'=>true, + 'reason'=>'예약' + ]); +} + +Json::die(ResetHelper::buildScenario( $turnterm, $sync, $scenario, diff --git a/hwe/js/install.js b/hwe/js/install.js index 12c19f9e..2e2e2719 100644 --- a/hwe/js/install.js +++ b/hwe/js/install.js @@ -151,7 +151,8 @@ function formSetup(){ extend:$('#extend input:radio:checked').val(), npcmode:$('#npcmode input:radio:checked').val(), show_img_level:$('#show_img_level input:radio:checked').val(), - tournament_trig:$('#tournament_trig input:radio:checked').val() + tournament_trig:$('#tournament_trig input:radio:checked').val(), + reserve_open:$('#reserve_open').val() } }).then(function(result){ var deferred = $.Deferred(); diff --git a/hwe/sammo/ResetHelper.php b/hwe/sammo/ResetHelper.php index 0007c8a5..ee89b953 100644 --- a/hwe/sammo/ResetHelper.php +++ b/hwe/sammo/ResetHelper.php @@ -6,31 +6,7 @@ class ResetHelper{ } - static public function doReset( - int $turnterm, - int $sync, - int $scenario, - int $fiction, - int $extend, - int $npcmode, - int $show_img_level, - int $tournament_trig - ):array{ - //FIXME: 분리할 것 - if(120 % $turnterm != 0){ - return [ - 'result'=>false, - 'reason'=>'turnterm은 120의 약수여야 합니다.' - ]; - } - - if($tournament_trig < 0 || $tournament_trig > 7){ - return [ - 'result'=>false, - 'reason'=>'올바르지 않은 토너먼트 주기입니다.' - ]; - } - + static public function clearDB(){ $servRoot = realpath(__dir__.'/../'); if(!file_exists($servRoot.'/logs') || !file_exists($servRoot.'/data')){ @@ -73,14 +49,12 @@ class ResetHelper{ @file_put_contents($servRoot.'/data/.htaccess', 'Deny from all'); } + $prefix = DB::prefix(); + AppConf::getList()[$prefix]->closeServer(); $db = DB::db(); $mysqli_obj = $db->get(); - - $scenarioObj = new Scenario($scenario, false); - $startyear = $scenarioObj->getYear()??GameConst::$defaultStartYear; - FileUtil::delInDir($servRoot."/logs"); FileUtil::delInDir($servRoot."/data"); @@ -114,7 +88,48 @@ class ResetHelper{ } } + + return [ + 'result'=>true + ]; + } + + static public function buildScenario( + int $turnterm, + int $sync, + int $scenario, + int $fiction, + int $extend, + int $npcmode, + int $show_img_level, + int $tournament_trig + ):array{ + //FIXME: 분리할 것 + if(120 % $turnterm != 0){ + return [ + 'result'=>false, + 'reason'=>'turnterm은 120의 약수여야 합니다.' + ]; + } + + if($tournament_trig < 0 || $tournament_trig > 7){ + return [ + 'result'=>false, + 'reason'=>'올바르지 않은 토너먼트 주기입니다.' + ]; + } + + $clearResult = self::clearDB(); + if(!$clearResult['result']){ + return $clearResult; + } + + $scenarioObj = new Scenario($scenario, false); + $startyear = $scenarioObj->getYear()??GameConst::$defaultStartYear; + + + $db = DB::db(); $db->insert('plock', [ 'plock'=>1 ]);