From 953196ec78289d0ede78e95428264f7922388f57 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 29 Apr 2018 12:55:16 +0900 Subject: [PATCH] =?UTF-8?q?=EC=98=88=EC=95=BD=20=EC=98=A4=ED=94=88=20?= =?UTF-8?q?=EC=8B=9C=20=EB=8D=B0=EC=9D=B4=ED=84=B0=EB=A5=BC=20=EB=B0=94?= =?UTF-8?q?=EB=A1=9C=20=EB=82=A0=EB=A6=AC=EC=A7=84=20=EC=95=8A=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/j_autoreset.php | 62 +++++++++++++++++++++++++++++++++++++++++---- hwe/j_install.php | 15 ++++++++--- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/hwe/j_autoreset.php b/hwe/j_autoreset.php index 36e6360f..a18f8588 100644 --- a/hwe/j_autoreset.php +++ b/hwe/j_autoreset.php @@ -6,15 +6,67 @@ 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') -); +$reserved = $db->queryFirstRow('SELECT `date`, options FROM reserved_open ORDER BY `date` ASC LIMIT 1'); if(!$reserved){ Json::die([ 'result'=>true, - 'affected'=>0 + 'affected'=>0, + 'status'=>'no_reserved' + ]); +} + +$reservedDate = new \DateTime($reserved['date']); +$now = new \DateTime(); + + +$status = 'not_yet'; + +if ($db->queryFirstField("SHOW TABLES LIKE 'game'")) { + list($isUnited, $lastTurn) = $db->queryFirstList('SELECT isUnited, turntime FROM game LIMIT 1'); +} +else{ + $isUnited = 2; + $lastTurn = '2000-01-01'; +} + +if($lastTurn !== null){ + $lastTurn = new \DateTime($lastTurn); +} + +if($lastTurn === null){ + //이미 리셋된 상태임 +} +else if(file_exists(__dir__.'/.htaccess')){ + //일단 서버는 닫혀 있음 +} +else if( + $isUnited == 2 && + $now->getTimestamp() - $lastTurn->getTimestamp() > $reservedDate->getTimestamp() - $now->getTimestamp() +){ + //정지 상태 & 중간 넘음 + AppConf::getList()[DB::prefix()]->closeServer(); + $status = 'closed'; +} +else if( + $isUnited > 0 && + $now->getTimestamp() - $lastTurn->getTimestamp() > ($reservedDate->getTimestamp() - $now->getTimestamp()) * 2 +){ + //천통 & 비정지 상태 & 2/3 넘음 + AppConf::getList()[DB::prefix()]->closeServer(); + $status = 'closed'; +} +else if($reservedDate->getTimestamp() - $now->getTimestamp() <= 60*10){ + //어쨌든 간에 10분 남았다면. + AppConf::getList()[DB::prefix()]->closeServer(); + $status = 'closed'; +} + +if($now < $reservedDate){ + Json::die([ + 'result'=>true, + 'affected'=>0, + 'status'=>$status ]); } diff --git a/hwe/j_install.php b/hwe/j_install.php index 4b535e53..f4cc8af0 100644 --- a/hwe/j_install.php +++ b/hwe/j_install.php @@ -52,9 +52,18 @@ if($reserve_open){ $reserve_open = new \DateTime($reserve_open); $db = DB::db(); - $clearResult = ResetHelper::clearDB(); - if(!$clearResult['result']){ - Json::die($clearResult); + if (!$db->queryFirstField("SHOW TABLES LIKE 'game'")) { + $clearResult = ResetHelper::clearDB(); + if(!$clearResult['result']){ + Json::die($clearResult); + } + } + + if (!$db->queryFirstField("SHOW TABLES LIKE 'reserved_open'")) { + Json::die([ + 'result'=>false, + 'reason'=>'예약 테이블이 없음!' + ]); } $scenarioObj = new Scenario($scenario, true);