서버 커스터마이징 가능
This commit is contained in:
+100
-100
@@ -1,101 +1,101 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
include 'lib.php';
|
||||
include "func.php";
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
if (!$db->queryFirstField("SHOW TABLES LIKE 'reserved_open'")) {
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'affected'=>0,
|
||||
'status'=>'no_reserved_table'
|
||||
]);
|
||||
}
|
||||
|
||||
$reserved = $db->queryFirstRow('SELECT `date`, options FROM reserved_open ORDER BY `date` ASC LIMIT 1');
|
||||
|
||||
if(!$reserved){
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'affected'=>0,
|
||||
'status'=>'no_reserved'
|
||||
]);
|
||||
}
|
||||
|
||||
$reservedDate = new \DateTime($reserved['date']);
|
||||
$now = new \DateTime();
|
||||
|
||||
|
||||
$status = 'not_yet';
|
||||
|
||||
list($isUnited, $lastTurn) = $gameStor->getValuesAsArray(['isunited', 'turntime']);
|
||||
if($isUnited === null || $lastTurn === null){
|
||||
$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
|
||||
]);
|
||||
}
|
||||
|
||||
$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'],
|
||||
$options['join_mode'],
|
||||
$options['starttime'],
|
||||
$options['autorun_user']?:null
|
||||
);
|
||||
|
||||
$result['affected']=1;
|
||||
|
||||
$prefix = DB::prefix();
|
||||
AppConf::getList()[$prefix]->openServer();
|
||||
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
include 'lib.php';
|
||||
include "func.php";
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
|
||||
if (!$db->queryFirstField("SHOW TABLES LIKE 'reserved_open'")) {
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'affected'=>0,
|
||||
'status'=>'no_reserved_table'
|
||||
]);
|
||||
}
|
||||
|
||||
$reserved = $db->queryFirstRow('SELECT `date`, options FROM reserved_open ORDER BY `date` ASC LIMIT 1');
|
||||
|
||||
if(!$reserved){
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'affected'=>0,
|
||||
'status'=>'no_reserved'
|
||||
]);
|
||||
}
|
||||
|
||||
$reservedDate = new \DateTime($reserved['date']);
|
||||
$now = new \DateTime();
|
||||
|
||||
|
||||
$status = 'not_yet';
|
||||
|
||||
list($isUnited, $lastTurn) = $gameStor->getValuesAsArray(['isunited', 'turntime']);
|
||||
if($isUnited === null || $lastTurn === null){
|
||||
$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()
|
||||
){
|
||||
//정지 상태 & 중간 넘음
|
||||
ServConfig::getServerList()[DB::prefix()]->closeServer();
|
||||
$status = 'closed';
|
||||
}
|
||||
else if(
|
||||
$isUnited > 0 &&
|
||||
$now->getTimestamp() - $lastTurn->getTimestamp() > ($reservedDate->getTimestamp() - $now->getTimestamp()) * 2
|
||||
){
|
||||
//천통 & 비정지 상태 & 2/3 넘음
|
||||
ServConfig::getServerList()[DB::prefix()]->closeServer();
|
||||
$status = 'closed';
|
||||
}
|
||||
else if($reservedDate->getTimestamp() - $now->getTimestamp() <= 60*10){
|
||||
//어쨌든 간에 10분 남았다면.
|
||||
ServConfig::getServerList()[DB::prefix()]->closeServer();
|
||||
$status = 'closed';
|
||||
}
|
||||
|
||||
if($now < $reservedDate){
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'affected'=>0,
|
||||
'status'=>$status
|
||||
]);
|
||||
}
|
||||
|
||||
$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'],
|
||||
$options['join_mode'],
|
||||
$options['starttime'],
|
||||
$options['autorun_user']?:null
|
||||
);
|
||||
|
||||
$result['affected']=1;
|
||||
|
||||
$prefix = DB::prefix();
|
||||
ServConfig::getServerList()[$prefix]->openServer();
|
||||
|
||||
Json::die($result);
|
||||
+208
-208
@@ -1,209 +1,209 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
include "lib.php";
|
||||
include "func.php";
|
||||
|
||||
WebUtil::requireAJAX();
|
||||
|
||||
$session = Session::requireLogin([])->setReadOnly();
|
||||
|
||||
if(!class_exists('\\sammo\\DB')){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'DB리셋 필요'
|
||||
]);
|
||||
}
|
||||
|
||||
$serverName = DB::prefix();
|
||||
$serverAcl = $session->acl[$serverName]??[];
|
||||
$allowReset = in_array('reset', $serverAcl);
|
||||
$allowFullReset = in_array('fullReset',$serverAcl);
|
||||
$allowReset |= $allowFullReset;
|
||||
|
||||
$reserve_open = Util::getPost('reserve_open');
|
||||
if($reserve_open && $reserve_open < date('Y-m-d H:i')){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'현재 시간보다 이전 시간대를 예약 시간으로 지정했습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
$pre_reserve_open = Util::getPost('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,
|
||||
'reason'=>'관리자 아님'
|
||||
]);
|
||||
}
|
||||
|
||||
$v = new Validator($_POST);
|
||||
$v->rule('required', [
|
||||
'turnterm',
|
||||
'sync',
|
||||
'scenario',
|
||||
'fiction',
|
||||
'extend',
|
||||
'join_mode',
|
||||
'npcmode',
|
||||
'show_img_level',
|
||||
'autorun_user_minutes'
|
||||
])->rule('integer', [
|
||||
'turnterm',
|
||||
'sync',
|
||||
'scenario',
|
||||
'fiction',
|
||||
'extend',
|
||||
'npcmode',
|
||||
'show_img_level',
|
||||
'tournament_trig',
|
||||
'autorun_user_minutes'
|
||||
])->rule('in', 'join_mode', ['onlyRandom', 'full']);
|
||||
if(!$v->validate()){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$v->errorStr()
|
||||
]);
|
||||
}
|
||||
|
||||
$allowReset = true;
|
||||
if($session->userGrade < 5 && !$allowFullReset){
|
||||
//리셋 가능한 조건인지 테스트
|
||||
$allowReset = false;
|
||||
|
||||
if(file_exists(__DIR__.'/.htaccess')){
|
||||
$allowReset = true;
|
||||
}
|
||||
else{
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
if($gameStor->isunited){
|
||||
$allowReset = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$allowReset){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'부족한 권한: 서버가 닫혀있거나, 천통되어 있을 경우에만 리셋 가능합니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
$turnterm = (int)$_POST['turnterm'];
|
||||
$sync = (int)$_POST['sync'];
|
||||
$scenario = (int)$_POST['scenario'];
|
||||
$fiction = (int)$_POST['fiction'];
|
||||
$extend = (int)$_POST['extend'];
|
||||
$npcmode = (int)$_POST['npcmode'];
|
||||
$show_img_level = (int)$_POST['show_img_level'];
|
||||
$tournament_trig = (int)$_POST['tournament_trig'];
|
||||
$join_mode = $_POST['join_mode'];
|
||||
$autorun_user_minutes = (int)$_POST['autorun_user_minutes'];
|
||||
$autorun_user_options = [];
|
||||
foreach(Util::getPost('autorun_user', 'array_string', []) as $autorun_option){
|
||||
$autorun_user_options[$autorun_option] = 1;
|
||||
}
|
||||
|
||||
if($autorun_user_minutes > 0 && !$autorun_user_options){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'적어도 자동 행동 중 하나는 선택을 해야합니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
if($autorun_user_minutes < 0){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'자동 행동 기한이 0보다 작을 수 없습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
$autorun_user = $autorun_user_minutes?[
|
||||
'limit_minutes'=>$autorun_user_minutes,
|
||||
'options'=>$autorun_user_options
|
||||
]:null;
|
||||
|
||||
if($reserve_open){
|
||||
$reserve_open = new \DateTime($reserve_open);
|
||||
$db = DB::db();
|
||||
|
||||
if (!$db->queryFirstField("SHOW TABLES LIKE 'storage'")) {
|
||||
$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);
|
||||
$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,
|
||||
'autorun_user'=>$autorun_user
|
||||
];
|
||||
|
||||
|
||||
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($reserveInfo),
|
||||
'date'=>$open_date
|
||||
]);
|
||||
AppConf::getList()[DB::prefix()]->closeServer();
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'reason'=>'예약'
|
||||
]);
|
||||
}
|
||||
|
||||
Json::die(ResetHelper::buildScenario(
|
||||
$turnterm,
|
||||
$sync,
|
||||
$scenario,
|
||||
$fiction,
|
||||
$extend,
|
||||
$npcmode,
|
||||
$show_img_level,
|
||||
$tournament_trig,
|
||||
$join_mode,
|
||||
TimeUtil::now(),
|
||||
$autorun_user
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
include "lib.php";
|
||||
include "func.php";
|
||||
|
||||
WebUtil::requireAJAX();
|
||||
|
||||
$session = Session::requireLogin([])->setReadOnly();
|
||||
|
||||
if(!class_exists('\\sammo\\DB')){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'DB리셋 필요'
|
||||
]);
|
||||
}
|
||||
|
||||
$serverName = DB::prefix();
|
||||
$serverAcl = $session->acl[$serverName]??[];
|
||||
$allowReset = in_array('reset', $serverAcl);
|
||||
$allowFullReset = in_array('fullReset',$serverAcl);
|
||||
$allowReset |= $allowFullReset;
|
||||
|
||||
$reserve_open = Util::getPost('reserve_open');
|
||||
if($reserve_open && $reserve_open < date('Y-m-d H:i')){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'현재 시간보다 이전 시간대를 예약 시간으로 지정했습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
$pre_reserve_open = Util::getPost('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,
|
||||
'reason'=>'관리자 아님'
|
||||
]);
|
||||
}
|
||||
|
||||
$v = new Validator($_POST);
|
||||
$v->rule('required', [
|
||||
'turnterm',
|
||||
'sync',
|
||||
'scenario',
|
||||
'fiction',
|
||||
'extend',
|
||||
'join_mode',
|
||||
'npcmode',
|
||||
'show_img_level',
|
||||
'autorun_user_minutes'
|
||||
])->rule('integer', [
|
||||
'turnterm',
|
||||
'sync',
|
||||
'scenario',
|
||||
'fiction',
|
||||
'extend',
|
||||
'npcmode',
|
||||
'show_img_level',
|
||||
'tournament_trig',
|
||||
'autorun_user_minutes'
|
||||
])->rule('in', 'join_mode', ['onlyRandom', 'full']);
|
||||
if(!$v->validate()){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$v->errorStr()
|
||||
]);
|
||||
}
|
||||
|
||||
$allowReset = true;
|
||||
if($session->userGrade < 5 && !$allowFullReset){
|
||||
//리셋 가능한 조건인지 테스트
|
||||
$allowReset = false;
|
||||
|
||||
if(file_exists(__DIR__.'/.htaccess')){
|
||||
$allowReset = true;
|
||||
}
|
||||
else{
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
if($gameStor->isunited){
|
||||
$allowReset = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!$allowReset){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'부족한 권한: 서버가 닫혀있거나, 천통되어 있을 경우에만 리셋 가능합니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
$turnterm = (int)$_POST['turnterm'];
|
||||
$sync = (int)$_POST['sync'];
|
||||
$scenario = (int)$_POST['scenario'];
|
||||
$fiction = (int)$_POST['fiction'];
|
||||
$extend = (int)$_POST['extend'];
|
||||
$npcmode = (int)$_POST['npcmode'];
|
||||
$show_img_level = (int)$_POST['show_img_level'];
|
||||
$tournament_trig = (int)$_POST['tournament_trig'];
|
||||
$join_mode = $_POST['join_mode'];
|
||||
$autorun_user_minutes = (int)$_POST['autorun_user_minutes'];
|
||||
$autorun_user_options = [];
|
||||
foreach(Util::getPost('autorun_user', 'array_string', []) as $autorun_option){
|
||||
$autorun_user_options[$autorun_option] = 1;
|
||||
}
|
||||
|
||||
if($autorun_user_minutes > 0 && !$autorun_user_options){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'적어도 자동 행동 중 하나는 선택을 해야합니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
if($autorun_user_minutes < 0){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'자동 행동 기한이 0보다 작을 수 없습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
$autorun_user = $autorun_user_minutes?[
|
||||
'limit_minutes'=>$autorun_user_minutes,
|
||||
'options'=>$autorun_user_options
|
||||
]:null;
|
||||
|
||||
if($reserve_open){
|
||||
$reserve_open = new \DateTime($reserve_open);
|
||||
$db = DB::db();
|
||||
|
||||
if (!$db->queryFirstField("SHOW TABLES LIKE 'storage'")) {
|
||||
$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);
|
||||
$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,
|
||||
'autorun_user'=>$autorun_user
|
||||
];
|
||||
|
||||
|
||||
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($reserveInfo),
|
||||
'date'=>$open_date
|
||||
]);
|
||||
ServConfig::getServerList()[DB::prefix()]->closeServer();
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'reason'=>'예약'
|
||||
]);
|
||||
}
|
||||
|
||||
Json::die(ResetHelper::buildScenario(
|
||||
$turnterm,
|
||||
$sync,
|
||||
$scenario,
|
||||
$fiction,
|
||||
$extend,
|
||||
$npcmode,
|
||||
$show_img_level,
|
||||
$tournament_trig,
|
||||
$join_mode,
|
||||
TimeUtil::now(),
|
||||
$autorun_user
|
||||
));
|
||||
+102
-102
@@ -1,103 +1,103 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
include "lib.php";
|
||||
include "func.php";
|
||||
|
||||
WebUtil::requireAJAX();
|
||||
|
||||
$session = Session::requireLogin([])->setReadOnly();
|
||||
if($session->userGrade < 6){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'관리자 아님'
|
||||
]);
|
||||
}
|
||||
|
||||
$fullReset = Util::getPost('full_reset', 'bool', false);
|
||||
$host = Util::getPost('db_host');
|
||||
$port = Util::getPost('db_port', 'int');
|
||||
$username = Util::getPost('db_id');
|
||||
$password = Util::getPost('db_pw');
|
||||
$dbName = Util::getPost('db_name');
|
||||
|
||||
if(!$host || !$port || !$username || !$password || !$dbName){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'입력 값이 올바르지 않습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if($fullReset && class_exists('\\sammo\\DB')){
|
||||
$mysqli_obj = DB::db()->get();
|
||||
|
||||
if($mysqli_obj->multi_query(file_get_contents(__DIR__.'/sql/reset.sql'))){
|
||||
while(true){
|
||||
if (!$mysqli_obj->more_results()) {
|
||||
break;
|
||||
}
|
||||
if(!$mysqli_obj->next_result()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($fullReset){
|
||||
FileUtil::delInDir(__DIR__."/logs");
|
||||
FileUtil::delInDir(__DIR__."/data");
|
||||
if(file_exists(__DIR__.'/d_setting/DB.php')){
|
||||
@unlink(__DIR__.'/d_setting/DB.php');
|
||||
}
|
||||
if(file_exists(__DIR__.'/d_setting/UniqueConst.php')){
|
||||
@unlink(__DIR__.'/d_setting/UniqueConst.php');
|
||||
}
|
||||
}
|
||||
|
||||
function dbConnFail($params){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'DB 접속에 실패했습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$db = new \MeekroDB($host,$username,$password,$dbName,$port,'utf8mb4');
|
||||
$db->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||
|
||||
$db->throw_exception_on_nonsql_error = false;
|
||||
$db->nonsql_error_handler = 'dbConnFail';
|
||||
|
||||
|
||||
$mysqli_obj = $db->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
|
||||
|
||||
$prefix = basename(__DIR__);
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
__DIR__.'/d_setting/DB.orig.php',
|
||||
__DIR__.'/d_setting/DB.php',[
|
||||
'host'=>$host,
|
||||
'user'=>$username,
|
||||
'password'=>$password,
|
||||
'dbName'=>$dbName,
|
||||
'port'=>$port,
|
||||
'prefix'=>$prefix
|
||||
], true
|
||||
);
|
||||
|
||||
|
||||
|
||||
if($result !== true){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$result
|
||||
]);
|
||||
}
|
||||
|
||||
ResetHelper::clearDB();
|
||||
|
||||
AppConf::getList()[$prefix]->closeServer();
|
||||
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'reason'=>'success'
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
include "lib.php";
|
||||
include "func.php";
|
||||
|
||||
WebUtil::requireAJAX();
|
||||
|
||||
$session = Session::requireLogin([])->setReadOnly();
|
||||
if($session->userGrade < 6){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'관리자 아님'
|
||||
]);
|
||||
}
|
||||
|
||||
$fullReset = Util::getPost('full_reset', 'bool', false);
|
||||
$host = Util::getPost('db_host');
|
||||
$port = Util::getPost('db_port', 'int');
|
||||
$username = Util::getPost('db_id');
|
||||
$password = Util::getPost('db_pw');
|
||||
$dbName = Util::getPost('db_name');
|
||||
|
||||
if(!$host || !$port || !$username || !$password || !$dbName){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'입력 값이 올바르지 않습니다'
|
||||
]);
|
||||
}
|
||||
|
||||
if($fullReset && class_exists('\\sammo\\DB')){
|
||||
$mysqli_obj = DB::db()->get();
|
||||
|
||||
if($mysqli_obj->multi_query(file_get_contents(__DIR__.'/sql/reset.sql'))){
|
||||
while(true){
|
||||
if (!$mysqli_obj->more_results()) {
|
||||
break;
|
||||
}
|
||||
if(!$mysqli_obj->next_result()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($fullReset){
|
||||
FileUtil::delInDir(__DIR__."/logs");
|
||||
FileUtil::delInDir(__DIR__."/data");
|
||||
if(file_exists(__DIR__.'/d_setting/DB.php')){
|
||||
@unlink(__DIR__.'/d_setting/DB.php');
|
||||
}
|
||||
if(file_exists(__DIR__.'/d_setting/UniqueConst.php')){
|
||||
@unlink(__DIR__.'/d_setting/UniqueConst.php');
|
||||
}
|
||||
}
|
||||
|
||||
function dbConnFail($params){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>'DB 접속에 실패했습니다.'
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
$db = new \MeekroDB($host,$username,$password,$dbName,$port,'utf8mb4');
|
||||
$db->connect_options[MYSQLI_OPT_INT_AND_FLOAT_NATIVE] = true;
|
||||
|
||||
$db->throw_exception_on_nonsql_error = false;
|
||||
$db->nonsql_error_handler = 'dbConnFail';
|
||||
|
||||
|
||||
$mysqli_obj = $db->get(); //로그인에 실패할 경우 자동으로 dbConnFail()이 실행됨.
|
||||
|
||||
$prefix = basename(__DIR__);
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
__DIR__.'/d_setting/DB.orig.php',
|
||||
__DIR__.'/d_setting/DB.php',[
|
||||
'host'=>$host,
|
||||
'user'=>$username,
|
||||
'password'=>$password,
|
||||
'dbName'=>$dbName,
|
||||
'port'=>$port,
|
||||
'prefix'=>$prefix
|
||||
], true
|
||||
);
|
||||
|
||||
|
||||
|
||||
if($result !== true){
|
||||
Json::die([
|
||||
'result'=>false,
|
||||
'reason'=>$result
|
||||
]);
|
||||
}
|
||||
|
||||
ResetHelper::clearDB();
|
||||
|
||||
ServConfig::getServerList()[$prefix]->closeServer();
|
||||
|
||||
Json::die([
|
||||
'result'=>true,
|
||||
'reason'=>'success'
|
||||
]);
|
||||
+357
-357
@@ -1,358 +1,358 @@
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
class ResetHelper{
|
||||
private function __construct(){
|
||||
|
||||
}
|
||||
|
||||
static public function clearDB(){
|
||||
$servRoot = realpath(__DIR__.'/../');
|
||||
|
||||
if(!file_exists($servRoot.'/logs') || !file_exists($servRoot.'/data')){
|
||||
if(!is_writable($servRoot)){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'logs, data 디렉토리를 생성할 권한이 없습니다.'
|
||||
];
|
||||
}
|
||||
mkdir($servRoot.'/logs', 0755);
|
||||
mkdir($servRoot.'/data', 0755);
|
||||
}
|
||||
|
||||
if(!is_writable($servRoot.'/logs')){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'logs 디렉토리의 쓰기 권한이 없습니다'
|
||||
];
|
||||
}
|
||||
|
||||
if(!is_writable($servRoot.'/data')){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'data 디렉토리의 쓰기 권한이 없습니다'
|
||||
];
|
||||
}
|
||||
|
||||
if(!is_writable($servRoot.'/d_setting')){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting 디렉토리의 쓰기 권한이 없습니다'
|
||||
];
|
||||
}
|
||||
|
||||
if(!file_exists($servRoot.'/logs/preserved')){
|
||||
mkdir($servRoot.'/logs/preserved', 0755);
|
||||
}
|
||||
|
||||
if(!file_exists($servRoot.'/logs/.htaccess')){
|
||||
@file_put_contents($servRoot.'/logs/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
if(!file_exists($servRoot.'/data/.htaccess')){
|
||||
@file_put_contents($servRoot.'/data/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
$dir = new \DirectoryIterator($servRoot.'/logs');
|
||||
foreach ($dir as $fileinfo) {
|
||||
/** @var \DirectoryIterator $fileinfo */
|
||||
if (!$fileinfo->isDir() || $fileinfo->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$basename = $fileinfo->getFilename();
|
||||
if($basename == 'preserved'){
|
||||
continue;
|
||||
}
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
exec("move ".escapeshellarg($servRoot.'/logs/'.$basename)." ".escapeshellarg($servRoot.'/logs/preserved/'.$basename));
|
||||
} else {
|
||||
exec("mv ".escapeshellarg($servRoot.'/logs/'.$basename)." ".escapeshellarg($servRoot.'/logs/preserved/'.$basename));
|
||||
}
|
||||
}
|
||||
|
||||
$prefix = DB::prefix();
|
||||
AppConf::getList()[$prefix]->closeServer();
|
||||
|
||||
$db = DB::db();
|
||||
$mysqli_obj = $db->get();
|
||||
|
||||
$serverID = DB::prefix().'_'.date("ymd").'_'.Util::randomStr(4);
|
||||
|
||||
mkdir($servRoot.'/logs/'.$serverID, 0755);
|
||||
mkdir($servRoot.'/data/'.$serverID, 0755);
|
||||
|
||||
$seasonIdx = 1;
|
||||
if($db->queryFirstField('SHOW TABLES LIKE %s', 'storage') !== null){
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$nextSeasonIdx = $gameStor->next_season_idx;
|
||||
if($nextSeasonIdx !== null){
|
||||
$seasonIdx = $nextSeasonIdx;
|
||||
}
|
||||
$gameStor->resetCache();
|
||||
}
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
$servRoot.'/d_setting/UniqueConst.orig.php',
|
||||
$servRoot.'/d_setting/UniqueConst.php',[
|
||||
'serverID'=>$serverID,
|
||||
'serverName'=>AppConf::getList()[$prefix]->getKorName(),
|
||||
'seasonIdx'=>$seasonIdx,
|
||||
], true
|
||||
);
|
||||
|
||||
copy(
|
||||
$servRoot.'/d_setting/GameConst.orig.php',
|
||||
$servRoot.'/d_setting/GameConst.php',
|
||||
);
|
||||
|
||||
if($mysqli_obj->multi_query(file_get_contents($servRoot.'/sql/reset.sql'))){
|
||||
while(true){
|
||||
if (!$mysqli_obj->more_results()) {
|
||||
break;
|
||||
}
|
||||
if(!$mysqli_obj->next_result()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($mysqli_obj->multi_query(file_get_contents($servRoot.'/sql/schema.sql'))){
|
||||
while(true){
|
||||
if (!$mysqli_obj->more_results()) {
|
||||
break;
|
||||
}
|
||||
if(!$mysqli_obj->next_result()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->resetValues();
|
||||
$gameStor->next_season_idx = $seasonIdx;
|
||||
|
||||
return [
|
||||
'result'=>true,
|
||||
'serverID'=>$serverID,
|
||||
'seasonIdx'=>$seasonIdx
|
||||
];
|
||||
}
|
||||
|
||||
static public function buildScenario(
|
||||
int $turnterm,
|
||||
int $sync,
|
||||
int $scenario,
|
||||
int $fiction,
|
||||
int $extend,
|
||||
int $npcmode,
|
||||
int $show_img_level,
|
||||
int $tournament_trig,
|
||||
string $join_mode,
|
||||
string $turntime,
|
||||
?array $autorun_user
|
||||
):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;
|
||||
}
|
||||
|
||||
$serverID = $clearResult['serverID'];
|
||||
$seasonIdx = $clearResult['seasonIdx'];
|
||||
|
||||
$scenarioObj = new Scenario($scenario, false);
|
||||
$scenarioObj->buildConf();
|
||||
|
||||
$startyear = $scenarioObj->getYear()??GameConst::$defaultStartYear;
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$db->insert('plock', [
|
||||
'plock'=>1,
|
||||
'locktime'=>TimeUtil::now(true)
|
||||
]);
|
||||
|
||||
$prevWinner = $db->queryFirstField('SELECT l12name FROM emperior ORDER BY `no` DESC LIMIT 1');
|
||||
$serverCnt = $db->queryFirstField('SELECT count(*) FROM ng_games') + 1;
|
||||
|
||||
CityConst::build();
|
||||
$cityPositions = [];
|
||||
foreach(CityConst::all() as $city){
|
||||
$cityPositions[$city->id] = [
|
||||
$city->name,
|
||||
$city->posX,
|
||||
$city->posY
|
||||
];
|
||||
}
|
||||
Util::generateFileUsingSimpleTemplate(
|
||||
__DIR__.'/../templates/base_map.orig.js',
|
||||
__DIR__.'/../d_shared/base_map.js',
|
||||
[
|
||||
'cityPosition'=>Json::encode($cityPositions),
|
||||
'regionMap'=>Json::encode(CityConst::$regionMap),
|
||||
'levelMap'=>Json::encode(CityConst::$levelMap),
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
if($sync == 0) {
|
||||
// 현재 시간을 1월로 맞춤
|
||||
$starttime = cutTurn($turntime, $turnterm);
|
||||
$month = 1;
|
||||
$year = $startyear;
|
||||
} else {
|
||||
// 현재 시간과 동기화
|
||||
[$starttime, $yearPulled, $month] = cutDay($turntime, $turnterm);
|
||||
if($yearPulled){
|
||||
$year = $startyear-1;
|
||||
}
|
||||
else{
|
||||
$year = $startyear;
|
||||
}
|
||||
}
|
||||
|
||||
$killturn = 4800 / $turnterm;
|
||||
if($npcmode == 1) { $killturn = intdiv($killturn, 3); }
|
||||
|
||||
$develcost = ($year - $startyear + 10) * 2;
|
||||
|
||||
$env = [
|
||||
'scenario'=>$scenario,
|
||||
'scenario_text'=>$scenarioObj->getTitle(),
|
||||
'icon_path'=>$scenarioObj->getIconPath(),
|
||||
'startyear'=>$startyear,
|
||||
'year'=> $year,
|
||||
'month'=> $month,
|
||||
'init_year'=> $year,
|
||||
'init_month'=>$month,
|
||||
'map_theme' => $scenarioObj->getMapTheme(),
|
||||
'season'=>$seasonIdx,
|
||||
'msg'=>'공지사항',//TODO:공지사항
|
||||
'maxgeneral'=>GameConst::$defaultMaxGeneral,
|
||||
'maxnation'=>GameConst::$defaultMaxNation,
|
||||
'conlimit'=>30000,
|
||||
'develcost'=>$develcost,
|
||||
'turntime'=>$turntime,
|
||||
'starttime'=>$starttime,
|
||||
'opentime'=>$turntime,
|
||||
'turnterm'=>$turnterm,
|
||||
'killturn'=>$killturn,
|
||||
'genius'=>GameConst::$defaultMaxGenius,
|
||||
'show_img_level'=>$show_img_level,
|
||||
'join_mode'=>$join_mode,
|
||||
'npcmode'=>$npcmode,
|
||||
'extended_general'=>$extend,
|
||||
'fiction'=>$fiction,
|
||||
'tnmt_trig'=>$tournament_trig,
|
||||
'prev_winner'=>$prevWinner,
|
||||
'autorun_user'=>$autorun_user,
|
||||
'tournament'=>0,
|
||||
'server_cnt'=>$serverCnt,
|
||||
];
|
||||
|
||||
$db->insert('betting', [
|
||||
'general_id'=>0,
|
||||
'bet0'=>0,
|
||||
'bet1'=>0,
|
||||
'bet2'=>0,
|
||||
'bet3'=>0,
|
||||
'bet4'=>0,
|
||||
'bet5'=>0,
|
||||
'bet6'=>0,
|
||||
'bet7'=>0,
|
||||
'bet8'=>0,
|
||||
'bet9'=>0,
|
||||
'bet10'=>0,
|
||||
'bet11'=>0,
|
||||
'bet12'=>0,
|
||||
'bet13'=>0,
|
||||
'bet14'=>0,
|
||||
'bet15'=>0,
|
||||
]);
|
||||
|
||||
foreach(RootDB::db()->query('SELECT `no`, `name`, `picture`, `imgsvr` FROM member WHERE grade >= 5') as $admin){
|
||||
$db->insert('general', [
|
||||
'owner'=>$admin['no'],
|
||||
'name'=>$admin['name'],
|
||||
'picture'=>$admin['picture'],
|
||||
'imgsvr'=>$admin['imgsvr'],
|
||||
'turntime'=>$turntime,
|
||||
'killturn'=>9999,
|
||||
'crewtype'=>GameUnitConst::DEFAULT_CREWTYPE
|
||||
]);
|
||||
$generalID = $db->insertId();
|
||||
$turnRows = [];
|
||||
foreach(Util::range(GameConst::$maxTurn) as $turnIdx){
|
||||
$turnRows[] = [
|
||||
'general_id'=>$generalID,
|
||||
'turn_idx'=>$turnIdx,
|
||||
'action'=>'휴식',
|
||||
'arg'=>null,
|
||||
'brief'=>'휴식'
|
||||
];
|
||||
}
|
||||
$db->insert('general_turn', $turnRows);
|
||||
|
||||
|
||||
$rank_data = [];
|
||||
foreach(array_keys(General::RANK_COLUMN) as $rankColumn){
|
||||
$rank_data[] = [
|
||||
'general_id'=>$generalID,
|
||||
'nation_id'=>0,
|
||||
'type'=>$rankColumn,
|
||||
'value'=>0
|
||||
];
|
||||
}
|
||||
$db->insert('rank_data', $rank_data);
|
||||
$db->insert('betting', [
|
||||
'general_id'=>$generalID,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach($env as $key=>$value){
|
||||
$gameStor->$key = $value;
|
||||
}
|
||||
|
||||
$db->insert('ng_games', [
|
||||
'server_id'=>$serverID,
|
||||
'date'=>$turntime,
|
||||
'winner_nation'=>null,
|
||||
'map'=>$scenarioObj->getMapTheme(),
|
||||
'season'=>$seasonIdx,
|
||||
'scenario'=>$scenario,
|
||||
'scenario_name'=>$scenarioObj->getTitle(),
|
||||
'env'=>Json::encode($env)
|
||||
]);
|
||||
|
||||
$scenarioObj->build($env);
|
||||
|
||||
$db->update('plock', [
|
||||
'plock'=>0
|
||||
], true);
|
||||
|
||||
LogHistory(1);
|
||||
|
||||
$prefix = DB::prefix();
|
||||
AppConf::getList()[$prefix]->closeServer();
|
||||
opcache_reset();
|
||||
|
||||
return [
|
||||
'result'=>true
|
||||
];
|
||||
}
|
||||
<?php
|
||||
namespace sammo;
|
||||
|
||||
class ResetHelper{
|
||||
private function __construct(){
|
||||
|
||||
}
|
||||
|
||||
static public function clearDB(){
|
||||
$servRoot = realpath(__DIR__.'/../');
|
||||
|
||||
if(!file_exists($servRoot.'/logs') || !file_exists($servRoot.'/data')){
|
||||
if(!is_writable($servRoot)){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'logs, data 디렉토리를 생성할 권한이 없습니다.'
|
||||
];
|
||||
}
|
||||
mkdir($servRoot.'/logs', 0755);
|
||||
mkdir($servRoot.'/data', 0755);
|
||||
}
|
||||
|
||||
if(!is_writable($servRoot.'/logs')){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'logs 디렉토리의 쓰기 권한이 없습니다'
|
||||
];
|
||||
}
|
||||
|
||||
if(!is_writable($servRoot.'/data')){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'data 디렉토리의 쓰기 권한이 없습니다'
|
||||
];
|
||||
}
|
||||
|
||||
if(!is_writable($servRoot.'/d_setting')){
|
||||
return [
|
||||
'result'=>false,
|
||||
'reason'=>'d_setting 디렉토리의 쓰기 권한이 없습니다'
|
||||
];
|
||||
}
|
||||
|
||||
if(!file_exists($servRoot.'/logs/preserved')){
|
||||
mkdir($servRoot.'/logs/preserved', 0755);
|
||||
}
|
||||
|
||||
if(!file_exists($servRoot.'/logs/.htaccess')){
|
||||
@file_put_contents($servRoot.'/logs/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
if(!file_exists($servRoot.'/data/.htaccess')){
|
||||
@file_put_contents($servRoot.'/data/.htaccess', 'Deny from all');
|
||||
}
|
||||
|
||||
$dir = new \DirectoryIterator($servRoot.'/logs');
|
||||
foreach ($dir as $fileinfo) {
|
||||
/** @var \DirectoryIterator $fileinfo */
|
||||
if (!$fileinfo->isDir() || $fileinfo->isDot()) {
|
||||
continue;
|
||||
}
|
||||
$basename = $fileinfo->getFilename();
|
||||
if($basename == 'preserved'){
|
||||
continue;
|
||||
}
|
||||
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
||||
exec("move ".escapeshellarg($servRoot.'/logs/'.$basename)." ".escapeshellarg($servRoot.'/logs/preserved/'.$basename));
|
||||
} else {
|
||||
exec("mv ".escapeshellarg($servRoot.'/logs/'.$basename)." ".escapeshellarg($servRoot.'/logs/preserved/'.$basename));
|
||||
}
|
||||
}
|
||||
|
||||
$prefix = DB::prefix();
|
||||
ServConfig::getServerList()[$prefix]->closeServer();
|
||||
|
||||
$db = DB::db();
|
||||
$mysqli_obj = $db->get();
|
||||
|
||||
$serverID = DB::prefix().'_'.date("ymd").'_'.Util::randomStr(4);
|
||||
|
||||
mkdir($servRoot.'/logs/'.$serverID, 0755);
|
||||
mkdir($servRoot.'/data/'.$serverID, 0755);
|
||||
|
||||
$seasonIdx = 1;
|
||||
if($db->queryFirstField('SHOW TABLES LIKE %s', 'storage') !== null){
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$nextSeasonIdx = $gameStor->next_season_idx;
|
||||
if($nextSeasonIdx !== null){
|
||||
$seasonIdx = $nextSeasonIdx;
|
||||
}
|
||||
$gameStor->resetCache();
|
||||
}
|
||||
|
||||
$result = Util::generateFileUsingSimpleTemplate(
|
||||
$servRoot.'/d_setting/UniqueConst.orig.php',
|
||||
$servRoot.'/d_setting/UniqueConst.php',[
|
||||
'serverID'=>$serverID,
|
||||
'serverName'=>ServConfig::getServerList()[$prefix]->getKorName(),
|
||||
'seasonIdx'=>$seasonIdx,
|
||||
], true
|
||||
);
|
||||
|
||||
copy(
|
||||
$servRoot.'/d_setting/GameConst.orig.php',
|
||||
$servRoot.'/d_setting/GameConst.php',
|
||||
);
|
||||
|
||||
if($mysqli_obj->multi_query(file_get_contents($servRoot.'/sql/reset.sql'))){
|
||||
while(true){
|
||||
if (!$mysqli_obj->more_results()) {
|
||||
break;
|
||||
}
|
||||
if(!$mysqli_obj->next_result()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($mysqli_obj->multi_query(file_get_contents($servRoot.'/sql/schema.sql'))){
|
||||
while(true){
|
||||
if (!$mysqli_obj->more_results()) {
|
||||
break;
|
||||
}
|
||||
if(!$mysqli_obj->next_result()){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$gameStor->resetValues();
|
||||
$gameStor->next_season_idx = $seasonIdx;
|
||||
|
||||
return [
|
||||
'result'=>true,
|
||||
'serverID'=>$serverID,
|
||||
'seasonIdx'=>$seasonIdx
|
||||
];
|
||||
}
|
||||
|
||||
static public function buildScenario(
|
||||
int $turnterm,
|
||||
int $sync,
|
||||
int $scenario,
|
||||
int $fiction,
|
||||
int $extend,
|
||||
int $npcmode,
|
||||
int $show_img_level,
|
||||
int $tournament_trig,
|
||||
string $join_mode,
|
||||
string $turntime,
|
||||
?array $autorun_user
|
||||
):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;
|
||||
}
|
||||
|
||||
$serverID = $clearResult['serverID'];
|
||||
$seasonIdx = $clearResult['seasonIdx'];
|
||||
|
||||
$scenarioObj = new Scenario($scenario, false);
|
||||
$scenarioObj->buildConf();
|
||||
|
||||
$startyear = $scenarioObj->getYear()??GameConst::$defaultStartYear;
|
||||
|
||||
$db = DB::db();
|
||||
$gameStor = KVStorage::getStorage($db, 'game_env');
|
||||
$db->insert('plock', [
|
||||
'plock'=>1,
|
||||
'locktime'=>TimeUtil::now(true)
|
||||
]);
|
||||
|
||||
$prevWinner = $db->queryFirstField('SELECT l12name FROM emperior ORDER BY `no` DESC LIMIT 1');
|
||||
$serverCnt = $db->queryFirstField('SELECT count(*) FROM ng_games') + 1;
|
||||
|
||||
CityConst::build();
|
||||
$cityPositions = [];
|
||||
foreach(CityConst::all() as $city){
|
||||
$cityPositions[$city->id] = [
|
||||
$city->name,
|
||||
$city->posX,
|
||||
$city->posY
|
||||
];
|
||||
}
|
||||
Util::generateFileUsingSimpleTemplate(
|
||||
__DIR__.'/../templates/base_map.orig.js',
|
||||
__DIR__.'/../d_shared/base_map.js',
|
||||
[
|
||||
'cityPosition'=>Json::encode($cityPositions),
|
||||
'regionMap'=>Json::encode(CityConst::$regionMap),
|
||||
'levelMap'=>Json::encode(CityConst::$levelMap),
|
||||
],
|
||||
true
|
||||
);
|
||||
|
||||
if($sync == 0) {
|
||||
// 현재 시간을 1월로 맞춤
|
||||
$starttime = cutTurn($turntime, $turnterm);
|
||||
$month = 1;
|
||||
$year = $startyear;
|
||||
} else {
|
||||
// 현재 시간과 동기화
|
||||
[$starttime, $yearPulled, $month] = cutDay($turntime, $turnterm);
|
||||
if($yearPulled){
|
||||
$year = $startyear-1;
|
||||
}
|
||||
else{
|
||||
$year = $startyear;
|
||||
}
|
||||
}
|
||||
|
||||
$killturn = 4800 / $turnterm;
|
||||
if($npcmode == 1) { $killturn = intdiv($killturn, 3); }
|
||||
|
||||
$develcost = ($year - $startyear + 10) * 2;
|
||||
|
||||
$env = [
|
||||
'scenario'=>$scenario,
|
||||
'scenario_text'=>$scenarioObj->getTitle(),
|
||||
'icon_path'=>$scenarioObj->getIconPath(),
|
||||
'startyear'=>$startyear,
|
||||
'year'=> $year,
|
||||
'month'=> $month,
|
||||
'init_year'=> $year,
|
||||
'init_month'=>$month,
|
||||
'map_theme' => $scenarioObj->getMapTheme(),
|
||||
'season'=>$seasonIdx,
|
||||
'msg'=>'공지사항',//TODO:공지사항
|
||||
'maxgeneral'=>GameConst::$defaultMaxGeneral,
|
||||
'maxnation'=>GameConst::$defaultMaxNation,
|
||||
'conlimit'=>30000,
|
||||
'develcost'=>$develcost,
|
||||
'turntime'=>$turntime,
|
||||
'starttime'=>$starttime,
|
||||
'opentime'=>$turntime,
|
||||
'turnterm'=>$turnterm,
|
||||
'killturn'=>$killturn,
|
||||
'genius'=>GameConst::$defaultMaxGenius,
|
||||
'show_img_level'=>$show_img_level,
|
||||
'join_mode'=>$join_mode,
|
||||
'npcmode'=>$npcmode,
|
||||
'extended_general'=>$extend,
|
||||
'fiction'=>$fiction,
|
||||
'tnmt_trig'=>$tournament_trig,
|
||||
'prev_winner'=>$prevWinner,
|
||||
'autorun_user'=>$autorun_user,
|
||||
'tournament'=>0,
|
||||
'server_cnt'=>$serverCnt,
|
||||
];
|
||||
|
||||
$db->insert('betting', [
|
||||
'general_id'=>0,
|
||||
'bet0'=>0,
|
||||
'bet1'=>0,
|
||||
'bet2'=>0,
|
||||
'bet3'=>0,
|
||||
'bet4'=>0,
|
||||
'bet5'=>0,
|
||||
'bet6'=>0,
|
||||
'bet7'=>0,
|
||||
'bet8'=>0,
|
||||
'bet9'=>0,
|
||||
'bet10'=>0,
|
||||
'bet11'=>0,
|
||||
'bet12'=>0,
|
||||
'bet13'=>0,
|
||||
'bet14'=>0,
|
||||
'bet15'=>0,
|
||||
]);
|
||||
|
||||
foreach(RootDB::db()->query('SELECT `no`, `name`, `picture`, `imgsvr` FROM member WHERE grade >= 5') as $admin){
|
||||
$db->insert('general', [
|
||||
'owner'=>$admin['no'],
|
||||
'name'=>$admin['name'],
|
||||
'picture'=>$admin['picture'],
|
||||
'imgsvr'=>$admin['imgsvr'],
|
||||
'turntime'=>$turntime,
|
||||
'killturn'=>9999,
|
||||
'crewtype'=>GameUnitConst::DEFAULT_CREWTYPE
|
||||
]);
|
||||
$generalID = $db->insertId();
|
||||
$turnRows = [];
|
||||
foreach(Util::range(GameConst::$maxTurn) as $turnIdx){
|
||||
$turnRows[] = [
|
||||
'general_id'=>$generalID,
|
||||
'turn_idx'=>$turnIdx,
|
||||
'action'=>'휴식',
|
||||
'arg'=>null,
|
||||
'brief'=>'휴식'
|
||||
];
|
||||
}
|
||||
$db->insert('general_turn', $turnRows);
|
||||
|
||||
|
||||
$rank_data = [];
|
||||
foreach(array_keys(General::RANK_COLUMN) as $rankColumn){
|
||||
$rank_data[] = [
|
||||
'general_id'=>$generalID,
|
||||
'nation_id'=>0,
|
||||
'type'=>$rankColumn,
|
||||
'value'=>0
|
||||
];
|
||||
}
|
||||
$db->insert('rank_data', $rank_data);
|
||||
$db->insert('betting', [
|
||||
'general_id'=>$generalID,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach($env as $key=>$value){
|
||||
$gameStor->$key = $value;
|
||||
}
|
||||
|
||||
$db->insert('ng_games', [
|
||||
'server_id'=>$serverID,
|
||||
'date'=>$turntime,
|
||||
'winner_nation'=>null,
|
||||
'map'=>$scenarioObj->getMapTheme(),
|
||||
'season'=>$seasonIdx,
|
||||
'scenario'=>$scenario,
|
||||
'scenario_name'=>$scenarioObj->getTitle(),
|
||||
'env'=>Json::encode($env)
|
||||
]);
|
||||
|
||||
$scenarioObj->build($env);
|
||||
|
||||
$db->update('plock', [
|
||||
'plock'=>0
|
||||
], true);
|
||||
|
||||
LogHistory(1);
|
||||
|
||||
$prefix = DB::prefix();
|
||||
ServConfig::getServerList()[$prefix]->closeServer();
|
||||
opcache_reset();
|
||||
|
||||
return [
|
||||
'result'=>true
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user