This repository has been archived by the owner on Mar 3, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automated Game Start and Stop (#449)
* Automated Game Start and Stop * Games will automatically start and stop at their scheduled times. Administrators can still manually start or stop a game regardless of the configured schedule. * Both Control::genAutoBegin() and Control::genAutoEnd() were added to check the current time against the scheduled start or stop time and perform the relevant action (Control::genBegin or Control::getEnd). * Control::genAutoRun() checks the current game status and determine if the game should be starting or ending, calling the appropriate function (Control::genAutoBegin or Control::getAutoEnd) and is exclusively used in the new autorun.php script. * Control::genRunAutoRunScript() runs the new autorun.php script, ensuring the script is not already running before starting a new copy. * The Router class was updated to include a call to Control::genRunAutoRunScript(), this ensures the script is always running. This script status check, and execution when needed, only takes place on a full page load. * The autorun.php script runs Control::genAutoRun() and sleeps up to 30 seconds. * If the game is scheduled to start or stop within 30 seconds, the script will sleep for the necessary amount of time. * Games will always start with at most a 29-second difference from the scheduled time. This discrepancy can only take place if the schedule is changed within 30 seconds of the previously scheduled time. Otherwise, the execution will happen at the scheduled time. * This automation is self-contained and requires no additional dependencies or external services (like cron, etc.). * * Allow administrators to define the cycle time (in seconds) for the autorun process. This time will be used for the sliding sleep. * * Added sanitization to the autorun script path/file.
- Loading branch information
1 parent
899ab2b
commit ca40091
Showing
6 changed files
with
150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?hh | ||
|
||
if (php_sapi_name() !== 'cli') { | ||
http_response_code(405); // method not allowed | ||
exit(0); | ||
} | ||
|
||
require_once (__DIR__.'/../Db.php'); | ||
require_once (__DIR__.'/../Utils.php'); | ||
require_once (__DIR__.'/../models/Model.php'); | ||
require_once (__DIR__.'/../models/Importable.php'); | ||
require_once (__DIR__.'/../models/Exportable.php'); | ||
require_once (__DIR__.'/../models/Level.php'); | ||
require_once (__DIR__.'/../models/Progressive.php'); | ||
require_once (__DIR__.'/../models/Configuration.php'); | ||
require_once (__DIR__.'/../models/Control.php'); | ||
require_once (__DIR__.'/../models/Team.php'); | ||
require_once (__DIR__.'/../models/MultiTeam.php'); | ||
require_once (__DIR__.'/../models/ScoreLog.php'); | ||
require_once (__DIR__.'/../models/HintLog.php'); | ||
require_once (__DIR__.'/../models/FailureLog.php'); | ||
|
||
while (1) { | ||
\HH\Asio\join(Control::genAutoRun()); | ||
|
||
$conf_sleep = \HH\Asio\join(Configuration::gen('autorun_cycle')); | ||
$conf_sleep_secs = intval($conf_sleep->getValue()); | ||
$sleep = $conf_sleep_secs; | ||
$conf_game = \HH\Asio\join(Configuration::gen('game')); | ||
$config_start_ts = \HH\Asio\join(Configuration::gen('start_ts')); | ||
$start_ts = intval($config_start_ts->getValue()); | ||
$config_end_ts = \HH\Asio\join(Configuration::gen('end_ts')); | ||
$end_ts = intval($config_end_ts->getValue()); | ||
|
||
if (($conf_game->getValue() === '1') && | ||
(($end_ts - time()) < $conf_sleep_secs)) { | ||
$sleep = $end_ts - time(); | ||
} else if (($conf_game->getValue() === '0') && | ||
(($start_ts - time()) < $conf_sleep_secs)) { | ||
$sleep = $start_ts - time(); | ||
} | ||
|
||
if ($sleep < 0) { | ||
$sleep = $conf_sleep_secs; | ||
} | ||
|
||
sleep($sleep); | ||
} |