기본 예약 리셋 동작

This commit is contained in:
2018-04-25 02:13:40 +09:00
parent 9122342fb9
commit 6253b757ec
5 changed files with 123 additions and 31 deletions
+7
View File
@@ -196,6 +196,13 @@ if($session->userGrade < 5){
</div>
</div>
<div class="form-group row">
<label for="reserve_open" class="col-sm-3 col-form-label">오픈 예약</label>
<div class="col-sm-9">
<input type="text" class="form-control" name="reserve_open" id="reserve_open" placeholder="YYYY-MM-DD hh:mm" value="" />
</div>
</div>
<div class="form-group row">
<div class="col-sm-3"></div>
<div class="col-sm-9">
+43
View File
@@ -0,0 +1,43 @@
<?php
namespace sammo;
include 'lib.php';
include "func.php";
$db = DB::db();
$reserved = $db->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);
+27 -1
View File
@@ -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,
+2 -1
View File
@@ -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();
+44 -29
View File
@@ -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
]);