diff --git a/f_install/j_create_admin.php b/f_install/j_create_admin.php
index bdae3551..a88ce7c5 100644
--- a/f_install/j_create_admin.php
+++ b/f_install/j_create_admin.php
@@ -46,7 +46,7 @@ if($memberCnt > 0){
$userSalt = bin2hex(random_bytes(8));
$finalPassword = Util::hashPassword($userSalt, $password);
-$nowDate = TimeUtil::DatetimeNow();
+$nowDate = TimeUtil::now();
$rootDB->insert('member',[
'oauth_type' => 'NONE',
diff --git a/f_install/j_setup_db.php b/f_install/j_setup_db.php
index 1580ff93..403c27b4 100644
--- a/f_install/j_setup_db.php
+++ b/f_install/j_setup_db.php
@@ -174,8 +174,8 @@ if ($mysqli_obj->multi_query(file_get_contents(__dir__.'/sql/common_schema.sql')
$rootDB->insert('system', array(
'REG' => 'N',
'LOGIN' => 'N',
- 'CRT_DATE' => TimeUtil::DatetimeNow(),
- 'MDF_DATE' => TimeUtil::DatetimeNow()
+ 'CRT_DATE' => TimeUtil::now(),
+ 'MDF_DATE' => TimeUtil::now()
));
$globalSalt = bin2hex(random_bytes(16));
diff --git a/hwe/_119_b.php b/hwe/_119_b.php
index cf83c7ba..5a55fbbe 100644
--- a/hwe/_119_b.php
+++ b/hwe/_119_b.php
@@ -35,7 +35,7 @@ case "분당김":
$starttime = (new \DateTimeImmutable($gameStor->starttime))->sub(new \DateInterval("PT{$minute}M"));
$tnmt_time = (new \DateTimeImmutable($gameStor->tnmt_time))->sub(new \DateInterval("PT{$minute}M"));
- $gameStor->turntime = $turntime->format('Y-m-d H:i:s');
+ $gameStor->turntime = $turntime->format('Y-m-d H:i:s.u');
$gameStor->starttime = $starttime->format('Y-m-d H:i:s');
$gameStor->tnmt_time = $tnmt_time->format('Y-m-d H:i:s');
@@ -52,7 +52,7 @@ case "분지연":
$starttime = (new \DateTimeImmutable($gameStor->starttime))->add(new \DateInterval("PT{$minute}M"));
$tnmt_time = (new \DateTimeImmutable($gameStor->tnmt_time))->add(new \DateInterval("PT{$minute}M"));
- $gameStor->turntime = $turntime->format('Y-m-d H:i:s');
+ $gameStor->turntime = $turntime->format('Y-m-d H:i:s.u');
$gameStor->starttime = $starttime->format('Y-m-d H:i:s');
$gameStor->tnmt_time = $tnmt_time->format('Y-m-d H:i:s');
diff --git a/hwe/_admin1_submit.php b/hwe/_admin1_submit.php
index 55f7b25e..49d25ae1 100644
--- a/hwe/_admin1_submit.php
+++ b/hwe/_admin1_submit.php
@@ -93,16 +93,18 @@ switch ($btn) {
for ($i=0; $i < $count; $i++) {
$gen = MYDB_fetch_array($result);
$turntime = getRandTurn($turnterm);
- $query = "update general set turntime='$turntime' where no='{$gen['no']}'";
- MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), "");
+ $db->update('general', [
+ 'turntime'=>$turntime
+ ], 'no=%i', $gen['no']);
}
// 턴시간이 너무 멀리 떨어진 선수 제대로 보정
} else {
- $query = "select no,turntime from general";
- $result = MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect), "");
- $count = MYDB_num_rows($result);
- for ($i=0; $i < $count; $i++) {
- $gen = MYDB_fetch_array($result);
+ $servTurnTime = new \DateTime($admin['turntime']);
+ $timeUnit = new \DateInterval("T{$unit}S");
+ foreach($db->query('SELECT no,turntime FROM general') as $gen){
+ $genTurnTime = new \DateTime($gen['turntime']);
+ $timeDiff = $genTurnTime->diff($servTurnTime);
+
$num = intdiv((strtotime($gen['turntime']) - strtotime($admin['turntime'])), $unit);
if ($num > 0) {
$gen['turntime'] = date("Y-m-d H:i:s", strtotime($gen['turntime']) - $unit * $num);
diff --git a/hwe/_admin2_submit.php b/hwe/_admin2_submit.php
index 9c87706d..3a24199c 100644
--- a/hwe/_admin2_submit.php
+++ b/hwe/_admin2_submit.php
@@ -48,7 +48,7 @@ switch($btn) {
DB::db()->query('update general set block=0 where no IN %li', $genlist);
break;
case "1단계 블럭":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db->update('general', [
'block'=>1,
'killturn'=>24
@@ -60,7 +60,7 @@ switch($btn) {
], 'id IN %li', $uid);
break;
case "2단계 블럭":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db->update('general', [
'gold'=>0,
'rice'=>0,
@@ -74,7 +74,7 @@ switch($btn) {
], 'id IN %li', $uid);
break;
case "3단계 블럭":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db->update('general', [
'gold'=>0,
'rice'=>0,
@@ -93,7 +93,7 @@ switch($btn) {
], '`no` IN %li', $genlist);
break;
case "강제 사망":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db->update('general', [
'turn0'=>EncodeCommand(0, 0, 0, 0),
'killturn'=>0,
diff --git a/hwe/_admin4_submit.php b/hwe/_admin4_submit.php
index 80ba7711..c91ba0ba 100644
--- a/hwe/_admin4_submit.php
+++ b/hwe/_admin4_submit.php
@@ -26,7 +26,7 @@ switch($btn) {
DB::db()->query('update general set block=0 where no IN %li', $genlist);
break;
case "1단계 블럭":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db = DB::db();
$db->query('update general set block=1,killturn=24 where no IN %li',$genlist);
//FIXME: subquery로 하는게 더 빠를 듯.
@@ -34,14 +34,14 @@ switch($btn) {
RootDB::db()->query('update member set block_num=block_num+1,block_date=%s where id IN %ls', $date, $uid);
break;
case "2단계 블럭":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db = DB::db();
$db->query('update general set block=2,killturn=24 where no IN %li',$genlist);
$uid = $db->queryFirstColumn('select owner from general where no IN %li', $genlist);
RootDB::db()->query('update member set block_num=block_num+1,block_date=%s where id IN %ls', $date, $uid);
break;
case "3단계 블럭":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db = DB::db();
$db->query('update general set block=3,killturn=24 where no IN %li',$genlist);
$uid = $db->queryFirstColumn('select owner from general where no IN %li', $genlist);
@@ -51,12 +51,12 @@ switch($btn) {
DB::db()->query('update general set killturn=8000 where no IN %li',$genlist);
break;
case "강제 사망":
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
DB::db()->query('update general set turn0=%s,killturn=0,turntime=%s where no IN %li',EncodeCommand(0, 0, 0, 0),$date, $genlist);
break;
case "메세지 전달":
//TODO:새 갠메 시스템으로 변경
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$src = MessageTarget::buildQuick($session->generalID);
for($i=0; $i < count($genlist); $i++) {
$msgObj = new Message(
diff --git a/hwe/_admin8.php b/hwe/_admin8.php
index 344c7749..a9f49525 100644
--- a/hwe/_admin8.php
+++ b/hwe/_admin8.php
@@ -114,7 +114,7 @@ for ($i=0; $i < $dipcount; $i++) {
case 7: $state = "불가침"; break;
}
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$note = "";
if ($dip['fixed'] != "") {
if ($dip['state'] == 7) {
diff --git a/hwe/a_traffic.php b/hwe/a_traffic.php
index 8d418c8f..29b977c9 100644
--- a/hwe/a_traffic.php
+++ b/hwe/a_traffic.php
@@ -31,7 +31,7 @@ foreach($log as $i=>$value){
}
$year[] = $admin['year'];
$month[] = $admin['month'];
-$date[] = date('Y-m-d H:i:s');
+$date[] = TimeUtil::now();
if ($admin['maxrefresh'] == 0) {
$admin['maxrefresh'] = 1;
diff --git a/hwe/b_chiefcenter.php b/hwe/b_chiefcenter.php
index aa1a1359..137eb942 100644
--- a/hwe/b_chiefcenter.php
+++ b/hwe/b_chiefcenter.php
@@ -32,7 +32,7 @@ if($me['level'] == 0 || ($me['level'] == 1 && $me['belong'] < $nation['secretlim
if($me['level'] >= 5) { $btn = "submit"; $btn2 = "button"; }
else { $btn = "hidden"; $btn2 = "hidden"; }
-$date = date('Y-m-d H:i:s');
+$date = TimeUtil::now();
// 명령 목록
$admin = $gameStor->getValues(['year','month','turnterm']);
@@ -106,7 +106,7 @@ function turn(type) {
= 20) { $num = 0; }
$msg = $title."|".$msg;
$msg = addslashes(SQ2DQ($msg));
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$query = "update nation set coreboard{$num}='$msg',coreboard{$num}_who='{$me['no']}',coreboard{$num}_when='$date' where nation='{$me['nation']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$query = "update nation set coreindex='$num' where nation='{$me['nation']}'";
diff --git a/hwe/c_nationboard.php b/hwe/c_nationboard.php
index ba254a09..2d220b3d 100644
--- a/hwe/c_nationboard.php
+++ b/hwe/c_nationboard.php
@@ -38,7 +38,7 @@ if(getBlockLevel() != 1 && getBlockLevel() != 3) {
if($num >= 20) { $num = 0; }
$msg = $title."|".$msg;
$msg = addslashes(SQ2DQ($msg));
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$query = "update nation set board{$num}='$msg',board{$num}_who='{$me['no']}',board{$num}_when='$date' where nation='{$me['nation']}'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
$query = "update nation set boardindex='$num' where nation='{$me['nation']}'";
diff --git a/hwe/commandlist.php b/hwe/commandlist.php
index 07df1300..8d19523a 100644
--- a/hwe/commandlist.php
+++ b/hwe/commandlist.php
@@ -75,7 +75,7 @@ function myCommandList() {
$gameStor = KVStorage::getStorage($db, 'game_env');
$userID = Session::getUserID();
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
// 명령 목록
$admin = $gameStor->getValues(['year','month','turnterm']);
diff --git a/hwe/func.php b/hwe/func.php
index 78933fe3..e1bfac03 100644
--- a/hwe/func.php
+++ b/hwe/func.php
@@ -1246,7 +1246,7 @@ function increaseRefresh($type="", $cnt=1) {
$generalID = $session->generalID;
$userGrade = $session->userGrade;
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
@@ -1336,7 +1336,7 @@ function updateTraffic() {
$db->update('general', ['refresh'=>0], true);
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
//일시|년|월|총갱신|접속자|최다갱신자
file_put_contents(__dir__."/logs/".UniqueConst::$serverID."/_traffic.txt",
Json::encode([
@@ -1524,17 +1524,17 @@ function checkTurn() {
$session = Session::getInstance();
- pushLockLog(["- checkTurn() : ".date('Y-m-d H:i:s')." : ".$session->userName]);
+ pushLockLog(["- checkTurn() : ".TimeUtil::now()." : ".$session->userName]);
// 파일락 해제
if(!flock($fp, LOCK_UN)) { return; }
// 세마포어 해제
//if(!@sem_release($sema)) { echo "치명적 에러! Hide_D에게 문의하세요!"; exit(1); }
- pushLockLog(["- checkTurn() 입 : ".date('Y-m-d H:i:s')." : ".$session->userName]);
+ pushLockLog(["- checkTurn() 입 : ".TimeUtil::now()." : ".$session->userName]);
//if(STEP_LOG) delStepLog();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', 진입');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', 진입');
//천통시에는 동결
if($gameStor->isunited == 2) {
@@ -1543,17 +1543,17 @@ function checkTurn() {
}
$gameStor->cacheAll();
// 1턴이상 갱신 없었으면 서버 지연
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', checkDelay');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', checkDelay');
checkDelay();
// 접속자수, 접속국가, 국가별 접속장수 갱신
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', checkDelay');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', checkDelay');
updateOnline();
//접속자 수 따라서 갱신제한 변경
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', CheckOverhead');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', CheckOverhead');
CheckOverhead();
//서버정보
- $date = date('Y-m-d H:i:s');
+ $date = TimeUtil::now();
// 최종 처리 월턴의 다음 월턴시간 구함
$prevTurn = cutTurn($gameStor->turntime, $gameStor->turnterm);
$nextTurn = addTurn($prevTurn, $gameStor->turnterm);
@@ -1570,30 +1570,30 @@ function checkTurn() {
//if(PROCESS_LOG) $processlog[0] = "[{$date}] 월턴 이전 갱신: name({$general['name']}), no({$general['no']}), turntime({$general['turntime']}), turn0({$general['turn0']})";
//if(PROCESS_LOG) pushProcessLog($processlog);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processAI');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processAI');
if($general['npc'] >= 2) { processAI($general['no']); } // npc AI 처리
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', PreprocessCommand');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', PreprocessCommand');
PreprocessCommand($general['no']);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processCommand');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processCommand');
processCommand($general['no']);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateCommand');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateCommand');
updateCommand($general['no']);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateTurntime');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateTurntime');
updateTurntime($general['no']);
}
// 트래픽 업데이트
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateTraffic');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateTraffic');
updateTraffic();
// 1달마다 처리하는 것들, 벌점 감소 및 건국,전턴,합병 -1, 군량 소모
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', preUpdateMonthly');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', preUpdateMonthly');
$result = preUpdateMonthly();
if($result == false) {
- pushLockLog(["-- checkTurn() 오류출 : ".date('Y-m-d H:i:s')." : ".$session->userName]);
+ pushLockLog(["-- checkTurn() 오류출 : ".TimeUtil::now()." : ".$session->userName]);
// 잡금 해제
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', unlock');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', unlock');
$gameStor->resetCache(true);
unlock();
return false;
@@ -1602,7 +1602,7 @@ function checkTurn() {
// 그 시각 년도,월 저장
list($gameStor->year, $gameStor->month) = turnDate($nextTurn);
- pushLockLog(["-- checkTurn() ".$gameStor->month."월 : ".date('Y-m-d H:i:s')." : ".$session->userName]);
+ pushLockLog(["-- checkTurn() ".$gameStor->month."월 : ".TimeUtil::now()." : ".$session->userName]);
// 이벤트 핸들러 동작
foreach (DB::db()->query('SELECT * from event') as $rawEvent) {
@@ -1617,46 +1617,46 @@ function checkTurn() {
// 분기계산. 장수들 턴보다 먼저 있다면 먼저처리
if($gameStor->month == 1) {
// NPC 등장
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processGoldIncome');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processGoldIncome');
processGoldIncome();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processSpring');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processSpring');
processSpring();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateYearly');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateYearly');
updateYearly();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateQuaterly');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateQuaterly');
updateQuaterly();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', disaster');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', disaster');
disaster();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', tradeRate');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', tradeRate');
tradeRate();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', addAge');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', addAge');
addAge();
// 새해 알림
$alllog[] = "◆>{$gameStor->month}월:{$gameStor->year}>년이 되었습니다.";
pushGeneralPublicRecord($alllog, $gameStor->year, $gameStor->month);
} elseif($gameStor->month == 4) {
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateQuaterly');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateQuaterly');
updateQuaterly();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', disaster');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', disaster');
disaster();
} elseif($gameStor->month == 7) {
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processRiceIncome');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processRiceIncome');
processRiceIncome();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processFall');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processFall');
processFall();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateQuaterly');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateQuaterly');
updateQuaterly();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', disaster');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', disaster');
disaster();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', tradeRate');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', tradeRate');
tradeRate();
} elseif($gameStor->month == 10) {
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateQuaterly');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateQuaterly');
updateQuaterly();
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', disaster');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', disaster');
disaster();
}
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', postUpdateMonthly');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', postUpdateMonthly');
postUpdateMonthly();
// 다음달로 넘김
@@ -1664,7 +1664,7 @@ function checkTurn() {
$nextTurn = addTurn($prevTurn, $gameStor->turnterm);
}
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', '.__LINE__);
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', '.__LINE__);
// 이시각 정각 시까지 업데이트 완료했음
$gameStor->turntime = $prevTurn;
@@ -1683,20 +1683,20 @@ function checkTurn() {
//if(PROCESS_LOG) $processlog[0] = "[{$date}] 월턴 이후 갱신: name({$general['name']}), no({$general['no']}), turntime({$general['turntime']}), turn0({$general['turn0']})";
//if(PROCESS_LOG) pushProcessLog($processlog);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processAI');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processAI');
if($general['npc'] >= 2) { processAI($general['no']); } // npc AI 처리
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', PreprocessCommand');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', PreprocessCommand');
PreprocessCommand($general['no']);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processCommand');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processCommand');
processCommand($general['no']);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateCommand');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateCommand');
updateCommand($general['no']);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', updateTurntime');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', updateTurntime');
updateTurntime($general['no']);
}
} while($gencount > 0);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', '.__LINE__);
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', '.__LINE__);
$gameStor->turntime = $date;
@@ -1704,19 +1704,19 @@ function checkTurn() {
$query = "update general set injury='80' where injury>'80'";
MYDB_query($query, $connect) or Error(__LINE__.MYDB_error($connect),"");
//토너먼트 처리
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processTournament');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processTournament');
processTournament();
//거래 처리
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', processAuction');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', processAuction');
processAuction();
// 잡금 해제
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', unlock');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', unlock');
$gameStor->resetCache(true);
unlock();
- pushLockLog(["- checkTurn() 출 : ".date('Y-m-d H:i:s')." : ".$session->userName]);
+ pushLockLog(["- checkTurn() 출 : ".TimeUtil::now()." : ".$session->userName]);
- //if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', finish');
+ //if(STEP_LOG) pushStepLog(TimeUtil::now().', finish');
return true;
}
@@ -2120,7 +2120,7 @@ function CheckHall($no) {
return;
}
- $unitedDate = date('Y-m-d H:i:s');
+ $unitedDate = TimeUtil::now();
$nation = getNationStaticInfo($general['nation']);
$serverCnt = $db->queryFirstField('SELECT count(*) FROM ng_games');
@@ -2960,15 +2960,29 @@ function SabotageInjury($city, $type=0) {
}
function getRandTurn($term) {
- $randtime = rand(0, 60 * $term - 1);
- $turntime = date('Y-m-d H:i:s', strtotime('now') + $randtime);
+ $randSecond = Util::randRangeInt(0, 60 * $term - 1);
+ $randFraction = Util::randRangeInt(0, 999999) / 1000000;//6자리 소수
+
+ $randTime = new \DateInterval("PT0S");
+ $randTime->s = $randSecond;
+ $randTime->f = $randFraction;
- return $turntime;
+ $turnTime = new \DateTime();
+ $turnTime->add($randTime);
+
+ return $turnTime->format('Y-m-d H:i:s.u');
}
function getRandTurn2($term) {
- $randtime = rand(0, 60 * $term - 1);
- $turntime = date('Y-m-d H:i:s', strtotime('now') - $randtime);
+ $randSecond = Util::randRangeInt(0, 60 * $term - 1);
+ $randFraction = Util::randRangeInt(0, 999999) / 1000000;//6자리 소수
+
+ $randTime = new \DateInterval("PT0S");
+ $randTime->s = $randSecond;
+ $randTime->f = $randFraction;
- return $turntime;
+ $turnTime = new \DateTime();
+ $turnTime->sub($randTime);
+
+ return $turnTime->format('Y-m-d H:i:s.u');
}
diff --git a/hwe/func_history.php b/hwe/func_history.php
index 09aaa3f1..b5e59e01 100644
--- a/hwe/func_history.php
+++ b/hwe/func_history.php
@@ -278,7 +278,7 @@ function getGeneralPublicRecordWithDate($year, $month) {
}
function LogHistory($isFirst=0) {
- if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Start');
+ if(STEP_LOG) pushStepLog(TimeUtil::now().', LogHistory Start');
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
@@ -329,7 +329,7 @@ function LogHistory($isFirst=0) {
$cityStr .= "$cityCount
";
}
- if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', contents collected');
+ if(STEP_LOG) pushStepLog(TimeUtil::now().', contents collected');
$db->insert('history', [
'server_id' => UniqueConst::$serverID,
@@ -344,6 +344,6 @@ function LogHistory($isFirst=0) {
'city' => $cityStr
]);
- if(STEP_LOG) pushStepLog(date('Y-m-d H:i:s').', LogHistory Finish');
+ if(STEP_LOG) pushStepLog(TimeUtil::now().', LogHistory Finish');
return true;
}
diff --git a/hwe/j_select_npc.php b/hwe/j_select_npc.php
index 9d57a066..7fea9450 100644
--- a/hwe/j_select_npc.php
+++ b/hwe/j_select_npc.php
@@ -98,7 +98,7 @@ pushAdminLog(["가입 : {$userID} // {$session->userName} // {$pick} // ".getenv
$rootDB->insert('member_log', [
'member_no' => $userID,
- 'date'=>date('Y-m-d H:i:s'),
+ 'date'=>TimeUtil::now(),
'action_type'=>'make_general',
'action'=>Json::encode([
'server'=>DB::prefix(),
diff --git a/hwe/j_simulate_battle.php b/hwe/j_simulate_battle.php
index 98ed5da8..b8076db5 100644
--- a/hwe/j_simulate_battle.php
+++ b/hwe/j_simulate_battle.php
@@ -70,7 +70,7 @@ $month = $query['month'];
$repeatCnt = $query['repeatCnt'];
$rawAttacker = $query['attackerGeneral'];
-$rawAttacker['turntime'] = date('Y-m-d H:i:s');
+$rawAttacker['turntime'] = TimeUtil::now();
$rawAttackerCity = $query['attackerCity'];
$rawAttackerNation = $query['attackerNation'];
diff --git a/hwe/join_post.php b/hwe/join_post.php
index 8b9a0369..607a33dd 100644
--- a/hwe/join_post.php
+++ b/hwe/join_post.php
@@ -177,7 +177,7 @@ if ($admin['scenario'] >= 1000) {
$turntime = getRandTurn($admin['turnterm']);
-$lastconnect = date('Y-m-d H:i:s');
+$lastconnect = TimeUtil::now();
if ($lastconnect >= $turntime) {
$turntime = addTurn($turntime, $admin['turnterm']);
}
@@ -270,7 +270,7 @@ pushAdminLog(["가입 : {$userID} // {$name} // {$generalID}".getenv("REMOTE_ADD
$rootDB->insert('member_log', [
'member_no' => $userID,
- 'date'=>date('Y-m-d H:i:s'),
+ 'date'=>TimeUtil::now(),
'action_type'=>'make_general',
'action'=>Json::encode([
'server'=>DB::prefix(),
diff --git a/hwe/sammo/ResetHelper.php b/hwe/sammo/ResetHelper.php
index 8b38c7d1..a83e6156 100644
--- a/hwe/sammo/ResetHelper.php
+++ b/hwe/sammo/ResetHelper.php
@@ -163,7 +163,7 @@ class ResetHelper{
);
- $turntime = date('Y-m-d H:i:s');
+ $turntime = TimeUtil::now();
$time = substr($turntime, 11, 2);
if($sync == 0) {
// 현재 시간을 1월로 맞춤
diff --git a/hwe/sql/schema.sql b/hwe/sql/schema.sql
index 102d6fe6..0cc33506 100644
--- a/hwe/sql/schema.sql
+++ b/hwe/sql/schema.sql
@@ -51,8 +51,8 @@ CREATE TABLE `general` (
`book` INT(2) NULL DEFAULT '0',
`horse` INT(2) NULL DEFAULT '0',
`item` INT(2) NULL DEFAULT '0',
- `turntime` DATETIME NULL DEFAULT NULL,
- `recwar` DATETIME NULL DEFAULT NULL,
+ `turntime` DATETIME(6) NULL DEFAULT NULL,
+ `recwar` DATETIME(6) NULL DEFAULT NULL,
`makenation` CHAR(255) NULL DEFAULT NULL,
`makelimit` INT(2) NULL DEFAULT '0',
`killturn` INT(3) NULL DEFAULT NULL,
@@ -577,7 +577,7 @@ CREATE TABLE IF NOT EXISTS `ng_old_generals` (
`owner` INT(11) NULL DEFAULT NULL,
`name` VARCHAR(32) NOT NULL,
`last_yearmonth` INT(11) NOT NULL,
- `turntime` DATETIME NOT NULL,
+ `turntime` DATETIME(6) NOT NULL,
`data` MEDIUMTEXT NOT NULL,
PRIMARY KEY (`id`),
UNIQUE INDEX `by_no` (`server_id`, `general_no`),
diff --git a/i_entrance/j_delete_me.php b/i_entrance/j_delete_me.php
index 033a89b8..e7fbecdb 100644
--- a/i_entrance/j_delete_me.php
+++ b/i_entrance/j_delete_me.php
@@ -39,7 +39,7 @@ if($userInfo['delete_after']){
}
$db->update('member',[
- 'delete_after'=>TimeUtil::DatetimeFromNowMinute(60*24*30)
+ 'delete_after'=>TimeUtil::nowAddMinutes(60*24*30)
], 'no=%i', $userID);
if(!$db->affectedRows()){
diff --git a/i_entrance/j_set_userlist.php b/i_entrance/j_set_userlist.php
index d16ee794..1ba88ed6 100644
--- a/i_entrance/j_set_userlist.php
+++ b/i_entrance/j_set_userlist.php
@@ -68,7 +68,7 @@ if($action == 'allow_join'){
}
if($action == 'scrub_deleted'){
- $deleteUntil = TimeUtil::DateToday();
+ $deleteUntil = TimeUtil::today();
$db->delete('member', 'delete_after < %s', $deleteUntil);
$cnt = $db->affectedRows();
@@ -111,7 +111,7 @@ if($action == 'scrub_icon'){
}
if($action == 'scrub_old_user'){
- $deleteUntil = TimeUtil::DatetimeFromNowMinute(-60*24*30*6);
+ $deleteUntil = TimeUtil::nowAddMinutes(-60*24*30*6);
$targetUser = [];
$members = $db->query('SELECT member.no, max(member_log.date) as loginDate from member
left join member_log on member.`NO` = member_log.member_no and
diff --git a/j_login.php b/j_login.php
index e5e6939f..bed7c852 100644
--- a/j_login.php
+++ b/j_login.php
@@ -47,7 +47,7 @@ function kakaoOAuthCheck(array $userInfo) : ?array {
return [false, 'OAuth 정보가 보관되어 있지 않습니다. 카카오 로그인을 수행해 주세요.'];
}
- $now = TimeUtil::DatetimeNow();
+ $now = TimeUtil::now();
if($now > $refreshTokenValidUntil){
return [false, '로그인 토큰이 만료되었습니다. 카카오 로그인을 수행해 주세요.'];
@@ -66,14 +66,14 @@ function kakaoOAuthCheck(array $userInfo) : ?array {
trigger_error("refreshToken 에러 ".Json::encode($refreshResult).",".$refreshToken.",".substr(\kakao\KakaoKey::REST_KEY, 0, 6), E_USER_NOTICE);
return [false, '로그인 토큰 자동 갱신을 실패했습니다. 카카오 로그인을 수행해 주세요.'];
}
- $accessTokenValidUntil = TimeUtil::DatetimeFromNowSecond($refreshResult['expires_in']);
+ $accessTokenValidUntil = TimeUtil::nowAddSeconds($refreshResult['expires_in']);
$oauthInfo['accessToken'] = $accessToken;
$oauthInfo['accessTokenValidUntil'] = $accessTokenValidUntil;
$refreshToken = $refreshResult['refresh_token']??null;
if($refreshToken){
- $refreshTokenValidUntil = TimeUtil::DatetimeFromNowSecond($refreshResult['refresh_token_expires_in']);
+ $refreshTokenValidUntil = TimeUtil::nowAddSeconds($refreshResult['refresh_token_expires_in']);
$oauthInfo['refreshToken'] = $refreshToken;
$oauthInfo['refresh_token_expires_in'] = $refresh_token_expires_in;
@@ -126,7 +126,7 @@ if($canLogin != 'Y' && $userInfo['grade'] < 5){
]);
}
-$nowDate = TimeUtil::DatetimeNow();
+$nowDate = TimeUtil::now();
if($userInfo['delete_after']){
if($userInfo['delete_after'] < $nowDate){
$RootDB->delete('member', 'no=%i', $userInfo['no']);
diff --git a/oauth_kakao/j_change_pw.php b/oauth_kakao/j_change_pw.php
index 37b23c3a..5628e7d4 100644
--- a/oauth_kakao/j_change_pw.php
+++ b/oauth_kakao/j_change_pw.php
@@ -5,7 +5,7 @@ require(__dir__.'/../vendor/autoload.php');
use \kakao\Kakao_REST_API_Helper as Kakao_REST_API_Helper;
-$now = TimeUtil::DatetimeNow();
+$now = TimeUtil::now();
$session = Session::requireLogin([
'reason'=>'로그인이 되어있지 않습니다'
@@ -52,7 +52,7 @@ if($nextPasswordChange && $now < $nextPasswordChange){
]);
}
-$nextPasswordChange = TimeUtil::DatetimeFromNowHour(4);
+$nextPasswordChange = TimeUtil::nowAddHours(4);
$oauthInfo['nextPasswordChange'] = $nextPasswordChange;
diff --git a/oauth_kakao/j_check_OTP.php b/oauth_kakao/j_check_OTP.php
index 95509e36..2c6c0e5a 100644
--- a/oauth_kakao/j_check_OTP.php
+++ b/oauth_kakao/j_check_OTP.php
@@ -46,7 +46,7 @@ if(!$oauthInfo){
$OTPValue = $oauthInfo['OTPValue']??null;
$OTPTrialUntil = $oauthInfo['OTPTrialUntil']??null;
$OTPTrialCount = $oauthInfo['OTPTrialCount']??0;
-$now = TimeUtil::DatetimeNow();
+$now = TimeUtil::now();
if(!$OTPTrialUntil || $OTPTrialUntil <= $now){
$session->logout();
@@ -78,7 +78,7 @@ if($OTPValue != $otp){
]);
}
-$tokenValidUntil = TimeUtil::DatetimeFromNowDay(10);
+$tokenValidUntil = TimeUtil::nowAddDays(10);
$session->setReqOTP(false, $tokenValidUntil);
RootDB::db()->update('member', [
'oauth_info'=>Json::encode($oauthInfo),
diff --git a/oauth_kakao/j_join_process.php b/oauth_kakao/j_join_process.php
index daeb7522..56796f94 100644
--- a/oauth_kakao/j_join_process.php
+++ b/oauth_kakao/j_join_process.php
@@ -16,7 +16,7 @@ if($canJoin != 'Y'){
]);
}
-$nowDate = TimeUtil::DatetimeNow();
+$nowDate = TimeUtil::now();
$access_token = $session->access_token;
$expires = $session->expires;
@@ -105,10 +105,10 @@ if($expires < $nowDate){
}
$access_token = $result['access_token'];
- $expires = TimeUtil::DatetimeFromNowSecond($result['expires_in']);
+ $expires = TimeUtil::nowAddSeconds($result['expires_in']);
if(isset($result['refresh_token'])){
$refresh_token = Util::array_get($result['refresh_token']);
- $refresh_token_expires = TimeUtil::DatetimeFromNowSecond($result['refresh_token_expires_in']);
+ $refresh_token_expires = TimeUtil::nowAddSeconds($result['refresh_token_expires_in']);
}
}
diff --git a/oauth_kakao/j_login_oauth.php b/oauth_kakao/j_login_oauth.php
index a8f914ad..8a4115dd 100644
--- a/oauth_kakao/j_login_oauth.php
+++ b/oauth_kakao/j_login_oauth.php
@@ -21,7 +21,7 @@ if($canLogin != 'Y'){
]);
}
-$now = TimeUtil::DatetimeNow();
+$now = TimeUtil::now();
$access_token = $session->access_token;
$expires = $session->expires;
@@ -63,10 +63,10 @@ if($expires < $now){
}
$access_token = $result['access_token'];
- $expires = TimeUtil::DatetimeFromNowSecond($result['expires_in']);
+ $expires = TimeUtil::nowAddSeconds($result['expires_in']);
if(isset($result['refresh_token'])){
$refresh_token = Util::array_get($result['refresh_token']);
- $refresh_token_expires = TimeUtil::DatetimeFromNowSecond($result['refresh_token_expires_in']);
+ $refresh_token_expires = TimeUtil::nowAddSeconds($result['refresh_token_expires_in']);
}
}
diff --git a/oauth_kakao/j_reset_token.php b/oauth_kakao/j_reset_token.php
index 92f6c143..3df29b08 100644
--- a/oauth_kakao/j_reset_token.php
+++ b/oauth_kakao/j_reset_token.php
@@ -21,8 +21,8 @@ if(!$tokenValidUntil){
]);
}
-$now = TimeUtil::DatetimeNow();
-$expectedDate = TimeUtil::DatetimeFromNowDay(5);
+$now = TimeUtil::now();
+$expectedDate = TimeUtil::nowAddDays(5);
if($expectedDate <= $tokenValidUntil){
Json::die([
diff --git a/oauth_kakao/lib.join.php b/oauth_kakao/lib.join.php
index 9f9565cf..cbced23a 100644
--- a/oauth_kakao/lib.join.php
+++ b/oauth_kakao/lib.join.php
@@ -50,7 +50,7 @@ function checkEmailDup($email){
$userInfo = RootDB::db()->queryFirstField('SELECT `no`, `delete_after` FROM member WHERE `email` = %s LIMIT 1', $email);
if($userInfo){
- $nowDate = TimeUtil::DatetimeNow();
+ $nowDate = TimeUtil::now();
if (!$userInfo['delete_after']) {
return '이미 사용중인 이메일입니다. 관리자에게 문의해주세요.';
}
@@ -80,7 +80,7 @@ function createOTPbyUserNO(int $userNo):bool{
$OTPValue = $oauthInfo['OTPValue']??null;
$OTPTrialUntil = $oauthInfo['OTPTrialUntil']??null;
- $now = TimeUtil::DatetimeNow();
+ $now = TimeUtil::now();
if($OTPTrialUntil && $OTPValue && $OTPTrialUntil > $now){
@@ -108,7 +108,7 @@ function createOTP(string $accessToken):?array{
$restAPI = new Kakao_REST_API_Helper($accessToken);
$OTPValue = Util::randRangeInt(10000, 99999);
- $OTPTrialUntil = TimeUtil::DatetimeFromNowSecond(180);
+ $OTPTrialUntil = TimeUtil::nowAddSeconds(180);
$sendResult = $restAPI->talk_to_me_default([
"object_type"=> "text",
diff --git a/oauth_kakao/oauth.php b/oauth_kakao/oauth.php
index c39f2f4c..ce954caa 100644
--- a/oauth_kakao/oauth.php
+++ b/oauth_kakao/oauth.php
@@ -33,11 +33,11 @@ if (Util::array_get($result['expires_in'], -1) <= 0) {
$session = Session::getInstance();
$restAPI->set_access_token($result['access_token']);
-$now = TimeUtil::DatetimeNow();
+$now = new \DateTimeImmutable();
$session->access_token = $result['access_token'];
-$session->expires = TimeUtil::DatetimeFromSecond($now, $result['expires_in']);
+$session->expires = $now->add(TimeUtil::secondsToDateInterval($result['expires_in']))->format('Y-m-d H:i:s');
$session->refresh_token = Util::array_get($result['refresh_token']);
-$session->refresh_token_expires = TimeUtil::DatetimeFromSecond($now, $result['refresh_token_expires_in']);
+$session->refresh_token_expires = $now->add(TimeUtil::secondsToDateInterval($result['refresh_token_expires_in']))->format('Y-m-d H:i:s');
$session->tmpx = Json::encode($result);
diff --git a/src/sammo/Session.php b/src/sammo/Session.php
index 9394252c..b18f2413 100644
--- a/src/sammo/Session.php
+++ b/src/sammo/Session.php
@@ -280,7 +280,7 @@ class Session
$db->update('general', [
'logcnt' => $db->sqleval('logcnt+1'),
'ip' => Util::get_client_ip(true),
- 'lastConnect' => date('Y-m-d H:i:s')
+ 'lastConnect' => TimeUtil::now()
], 'owner = %i', $userID);
$this->set($serverID.static::GAME_KEY_DATE, $now);
@@ -344,7 +344,7 @@ class Session
if(!$this->tokenValidUntil){
return false;
}
- $now = TimeUtil::DatetimeNow();
+ $now = TimeUtil::now();
if($this->tokenValidUntil < $now){
return false;
}
diff --git a/src/sammo/TimeUtil.php b/src/sammo/TimeUtil.php
index addaf22b..d42cf7df 100644
--- a/src/sammo/TimeUtil.php
+++ b/src/sammo/TimeUtil.php
@@ -3,13 +3,13 @@ namespace sammo;
class TimeUtil
{
- public static function DateToday()
+ public static function today()
{
$obj = new \DateTime();
return $obj->format('Y-m-d');
}
- public static function DatetimeNow(bool $withFraction=false)
+ public static function now(bool $withFraction=false)
{
$obj = new \DateTime();
if(!$withFraction){
@@ -18,67 +18,47 @@ class TimeUtil
return $obj->format('Y-m-d H:i:s.u');
}
- public static function DatetimeFromNowDay($day, bool $withFraction=false)
+ public static function nowAddDays($day, bool $withFraction=false)
{
$obj = new \DateTime();
- $obj->modify("{$day} days");
+ $obj->add(static::secondsToDateInterval($day * 3600 * 24));
if(!$withFraction){
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
}
- public static function DatetimeFromNowHour($hour, bool $withFraction=false)
+ public static function nowAddHours($hour, bool $withFraction=false)
{
$obj = new \DateTime();
- $obj->modify("{$hour} hours");
+ $obj->add(static::secondsToDateInterval($hour * 3600));
if(!$withFraction){
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
}
- public static function DatetimeFromNowMinute($minute, bool $withFraction=false)
+ public static function nowAddMinutes($minute, bool $withFraction=false)
{
$obj = new \DateTime();
- $obj->modify("{$minute} minutes");
+ $obj->add(static::secondsToDateInterval($minute * 60));
if(!$withFraction){
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
}
- public static function DatetimeFromNowSecond($second, bool $withFraction=false)
+ public static function nowAddSeconds($second, bool $withFraction=false)
{
$obj = new \DateTime();
- $obj->modify("{$second} seconds");
+ $obj->add(static::secondsToDateInterval($second));
if(!$withFraction){
return $obj->format('Y-m-d H:i:s');
}
return $obj->format('Y-m-d H:i:s.u');
}
- public static function DatetimeFromMinute($date, $minute, bool $withFraction=false)
- {
- $obj = new \DateTime($date);
- $obj->modify("{$minute} minutes");
- if(!$withFraction){
- return $obj->format('Y-m-d H:i:s');
- }
- return $obj->format('Y-m-d H:i:s.u');
- }
-
- public static function DatetimeFromSecond($date, $second, bool $withFraction=false)
- {
- $obj = new \DateTime($date);
- $obj->modify("{$second} seconds");
- if(!$withFraction){
- return $obj->format('Y-m-d H:i:s');
- }
- return $obj->format('Y-m-d H:i:s.u');
- }
-
- public static function SecondsToDateInterval(float $fullSeconds): \DateInterval{
+ public static function secondsToDateTime(float $fullSeconds): \DateTime{
$seconds = floor($fullSeconds);
$fraction = $fullSeconds - $seconds;
@@ -86,10 +66,21 @@ class TimeUtil
$interval->s = $seconds;
$interval->f = $fraction;
- $d0 = new \DateTimeImmutable("@0");
- $d1 = $d0->add($interval);
+ $dateTime = new \DateTime("@0");
+ $dateTime->add($interval);
+ return $dateTime;
+ }
- return $d1->diff($d0);
+ public static function secondsToDateInterval(float $fullSeconds): \DateInterval{
+ $dateBase = new \DateTime("@0");
+
+ return static::secondsToDateTime($fullSeconds)->diff($d0);
+ }
+
+ public static function DateTimeToSeconds(\DateTime $dateTime): float{
+ $dateBase = new \DateTime("@0");
+
+ return static::DateIntervalToSeconds($dateTime->diff($dateBase));
}
public static function DateIntervalToSeconds(\DateInterval $interval): float{
@@ -112,4 +103,6 @@ class TimeUtil
return $seconds;
}
+
+
}