From 320c8191dc7c00f326114ae5484cfee6f2da91e1 Mon Sep 17 00:00:00 2001 From: Hide_D Date: Sun, 11 Jun 2023 21:24:53 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20ServerTool::changeServerTerm=20-=20?= =?UTF-8?q?=EC=84=9C=EB=B2=84=20=ED=84=B4=20=EC=8B=9C=EA=B0=84=EC=9D=84=20?= =?UTF-8?q?=EB=B0=94=EA=BE=B8=EB=8A=94=20=EB=AA=85=EB=A0=B9=20-=20?= =?UTF-8?q?=EA=B8=B0=EC=A1=B4=20=5Fadmin1.php?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/sammo/ServerTool.php | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 hwe/sammo/ServerTool.php diff --git a/hwe/sammo/ServerTool.php b/hwe/sammo/ServerTool.php new file mode 100644 index 00000000..dc1cf690 --- /dev/null +++ b/hwe/sammo/ServerTool.php @@ -0,0 +1,79 @@ +getValues(['turntime', 'turnterm', 'year', 'startyear', 'month', 'isunited']); + + $reqGameLock = $admin['isunited'] != 2; + + $locked = false; + if($reqGameLock){ + for ($i = 0; $i < 5; $i++) { + $locked = tryLock(); + if ($locked) { + break; + } + usleep(500000); + } + + if (!$locked) { + return 'server busy'; + } + } + else{ + $locked = tryLock(); + } + + $oldunit = $admin['turnterm'] * 60; + $unit = $turnterm * 60; + + if($unit == $oldunit){ + if($locked){ + unlock(); + } + return null; + } + + $unitDiff = $unit / $oldunit; + + $servTurnTime = new \DateTimeImmutable($admin['turntime']); + foreach ($db->query('SELECT no,turntime FROM general') as $gen) { + $genTurnTime = new \DateTimeImmutable($gen['turntime']); + $timeDiff = TimeUtil::DateIntervalToSeconds($genTurnTime->diff($servTurnTime)); + $timeDiff *= $unitDiff; + $newGenTurnTime = $servTurnTime->add(TimeUtil::secondsToDateInterval($timeDiff)); + + $db->update('general', [ + 'turntime' => $newGenTurnTime->format('Y-m-d H:i:s.u') + ], 'no=%i', $gen['no']); + } + $turn = ($admin['year'] - $admin['startyear']) * 12 + $admin['month'] - 1; + $starttime = $servTurnTime->sub(TimeUtil::secondsToDateInterval($turn * $unit))->format('Y-m-d H:i:s'); + $starttime = cutTurn($starttime, $turnterm, false); + $gameStor->turnterm = $turnterm; + $gameStor->starttime = $starttime; + pushGlobalHistoryLog(["★턴시간이 {$turnterm}분으로 변경됩니다."]); + + if($locked){ + unlock(); + } + + return null; + } +}