2013-11-10 17:29:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace ManiaControl;
|
|
|
|
|
2013-12-31 12:42:07 +01:00
|
|
|
use ManiaControl\Admin\ActionsMenu;
|
2013-11-13 01:43:12 +01:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2020-02-29 15:14:48 +01:00
|
|
|
use ManiaControl\Admin\ColorManager;
|
2014-02-25 18:34:35 +01:00
|
|
|
use ManiaControl\Bills\BillManager;
|
2014-06-20 16:19:30 +02:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
2013-11-12 15:48:25 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
2014-05-24 16:39:12 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
use ManiaControl\Callbacks\CallQueueManager;
|
2015-06-19 01:37:31 +02:00
|
|
|
use ManiaControl\Callbacks\EchoManager;
|
2014-02-22 11:14:35 +01:00
|
|
|
use ManiaControl\Callbacks\TimerListener;
|
2014-01-30 22:35:32 +01:00
|
|
|
use ManiaControl\Callbacks\TimerManager;
|
2013-11-24 23:55:54 +01:00
|
|
|
use ManiaControl\Commands\CommandListener;
|
2013-11-12 15:48:25 +01:00
|
|
|
use ManiaControl\Commands\CommandManager;
|
2015-06-26 11:48:21 +02:00
|
|
|
use ManiaControl\Communication\CommunicationAnswer;
|
2015-06-23 17:12:23 +02:00
|
|
|
use ManiaControl\Communication\CommunicationListener;
|
|
|
|
use ManiaControl\Communication\CommunicationManager;
|
|
|
|
use ManiaControl\Communication\CommunicationMethods;
|
2014-07-25 15:45:10 +02:00
|
|
|
use ManiaControl\Configurator\Configurator;
|
2014-05-02 17:40:47 +02:00
|
|
|
use ManiaControl\Database\Database;
|
2014-02-07 12:30:53 +01:00
|
|
|
use ManiaControl\Files\AsynchronousFileReader;
|
2014-02-07 00:27:10 +01:00
|
|
|
use ManiaControl\Files\FileUtil;
|
2017-03-26 12:56:44 +02:00
|
|
|
use ManiaControl\General\UsageInformationAble;
|
|
|
|
use ManiaControl\General\UsageInformationTrait;
|
2013-11-28 03:47:08 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
2022-03-03 18:00:30 +01:00
|
|
|
use ManiaControl\Manialinks\ToggleInterfaceManager;
|
2013-11-12 15:48:25 +01:00
|
|
|
use ManiaControl\Maps\MapManager;
|
2013-11-24 23:55:54 +01:00
|
|
|
use ManiaControl\Players\Player;
|
2013-11-13 01:43:12 +01:00
|
|
|
use ManiaControl\Players\PlayerManager;
|
2013-11-12 15:48:25 +01:00
|
|
|
use ManiaControl\Plugins\PluginManager;
|
2017-03-24 22:08:51 +01:00
|
|
|
use ManiaControl\Script\ModeScriptEventManager;
|
2013-11-19 20:29:37 +01:00
|
|
|
use ManiaControl\Server\Server;
|
2014-01-27 17:29:48 +01:00
|
|
|
use ManiaControl\Settings\SettingManager;
|
2014-01-01 17:59:29 +01:00
|
|
|
use ManiaControl\Statistics\StatisticManager;
|
2020-03-16 00:12:36 +01:00
|
|
|
use ManiaControl\Update\ChangeLog;
|
2014-02-10 22:54:49 +01:00
|
|
|
use ManiaControl\Update\UpdateManager;
|
2014-05-13 14:32:30 +02:00
|
|
|
use ManiaControl\Utils\CommandLineHelper;
|
2014-06-15 00:51:43 +02:00
|
|
|
use ManiaControl\Utils\SystemUtil;
|
2014-01-16 17:19:01 +01:00
|
|
|
use Maniaplanet\DedicatedServer\Connection;
|
2014-06-13 17:11:45 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\AuthenticationException;
|
2014-04-27 15:21:57 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
|
2013-12-31 12:42:07 +01:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
/**
|
|
|
|
* ManiaControl Server Controller for ManiaPlanet Server
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2020-01-22 10:39:35 +01:00
|
|
|
* @copyright 2014-2020 ManiaControl Team
|
2014-05-02 17:40:47 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
2017-03-26 12:56:44 +02:00
|
|
|
class ManiaControl implements CallbackListener, CommandListener, TimerListener, CommunicationListener, UsageInformationAble {
|
|
|
|
use UsageInformationTrait;
|
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-11-10 17:29:21 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2020-07-18 13:26:41 +02:00
|
|
|
const VERSION = '0.256';
|
2022-04-13 10:59:03 +02:00
|
|
|
const ISTRACKMANIACONTROL = True;
|
2022-02-10 19:16:14 +01:00
|
|
|
const API_VERSION = '2038-01-19';
|
|
|
|
const MIN_DEDIVERSION = '2020-07-01_00_00';
|
2017-05-11 22:43:15 +02:00
|
|
|
const SCRIPT_TIMEOUT = 40;
|
2017-03-22 18:00:17 +01:00
|
|
|
const URL_WEBSERVICE = 'https://ws.maniacontrol.com/';
|
2014-01-31 16:55:01 +01:00
|
|
|
const SETTING_PERMISSION_SHUTDOWN = 'Shutdown ManiaControl';
|
2020-04-24 18:51:38 +02:00
|
|
|
const SETTING_PERMISSION_REBOOT = 'Reboot ManiaControl';
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-08-02 22:31:46 +02:00
|
|
|
* Public properties
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
/** @var SettingManager $settingManager
|
2017-04-15 13:21:49 +02:00
|
|
|
* @see getSettingManager()
|
2017-04-02 16:20:16 +02:00
|
|
|
* @deprecated use getSettingManager()
|
|
|
|
*/
|
|
|
|
public $settingManager = null;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Private properties
|
|
|
|
*/
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var ActionsMenu $actionsMenu
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getActionsMenu()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $actionsMenu = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var AuthenticationManager $authenticationManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getAuthenticationManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $authenticationManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var CallbackManager $callbackManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getCallbackManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $callbackManager = null;
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
/** @var CallQueueManager $callQueueManager
|
|
|
|
* @see getCallQueueManager()
|
|
|
|
*/
|
|
|
|
private $callQueueManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var Chat $chat
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getChat()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $chat = null;
|
2020-03-16 00:12:36 +01:00
|
|
|
/** @var ChangeLog $changeLog
|
|
|
|
* @see getChangeLog()
|
|
|
|
*/
|
|
|
|
private $changeLog = null;
|
2020-02-29 15:14:48 +01:00
|
|
|
/** @var ColorManager $colorManager
|
|
|
|
* @see getColorManager()
|
|
|
|
*/
|
|
|
|
private $colorManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var \SimpleXMLElement $config
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getConfig()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $config = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var Configurator $configurator
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getConfigurator()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $configurator = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var Connection $client
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getClient()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $client = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var CommandManager $commandManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getCommandManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $commandManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var Database $database
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getDatabase()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $database = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var ManialinkManager $manialinkManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getManialinkManager
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $manialinkManager = null;
|
2022-03-03 18:00:30 +01:00
|
|
|
/** @var ToggleInterfaceManager $toggleInterfaceManager
|
|
|
|
* @see getToggleInterfaceManager
|
|
|
|
*/
|
|
|
|
private $toggleInterfaceManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var MapManager $mapManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getMapManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $mapManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var PlayerManager $playerManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getPlayerManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $playerManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var PluginManager $pluginManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getPluginManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $pluginManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var Server $server
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getServer()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $server = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var StatisticManager $statisticManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getStatisticManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $statisticManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var UpdateManager $updateManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getUpdateManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $updateManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var ErrorHandler $errorHandler
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getErrorHandler()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $errorHandler = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var TimerManager $timerManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getTimerManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $timerManager = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var AsynchronousFileReader $fileReader
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getFileReader()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $fileReader = null;
|
2014-08-25 15:46:11 +02:00
|
|
|
/** @var BillManager $billManager
|
2014-10-24 20:08:21 +02:00
|
|
|
* @see getBillManager()
|
2014-08-25 15:46:11 +02:00
|
|
|
*/
|
2017-04-02 16:20:16 +02:00
|
|
|
private $billManager = null;
|
2013-11-10 17:29:21 +01:00
|
|
|
|
2015-06-19 01:37:31 +02:00
|
|
|
/** @var EchoManager $echoManager */
|
2017-03-22 17:57:21 +01:00
|
|
|
private $echoManager = null;
|
|
|
|
|
|
|
|
/** @var CommunicationManager $communicationManager */
|
2015-06-22 20:22:17 +02:00
|
|
|
private $communicationManager = null;
|
2015-06-19 01:37:31 +02:00
|
|
|
|
2017-03-22 17:57:21 +01:00
|
|
|
/** @var ModeScriptEventManager $modeScriptEventManager */
|
|
|
|
private $modeScriptEventManager = null;
|
|
|
|
|
2017-03-26 13:58:23 +02:00
|
|
|
private $dedicatedServerBuildVersion = "";
|
|
|
|
|
2017-04-02 16:20:16 +02:00
|
|
|
private $requestQuitMessage = null;
|
|
|
|
|
2017-04-15 13:21:49 +02:00
|
|
|
private $startTime = -1;
|
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
/**
|
2014-08-02 22:31:46 +02:00
|
|
|
* Construct a new ManiaControl instance
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
|
|
|
public function __construct() {
|
2014-08-05 01:49:13 +02:00
|
|
|
Logger::log('Loading ManiaControl v' . self::VERSION . ' ...');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-06-26 11:07:53 +02:00
|
|
|
$this->errorHandler = new ErrorHandler($this);
|
|
|
|
|
2014-05-01 20:21:40 +02:00
|
|
|
$this->loadConfig();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-17 17:38:44 +01:00
|
|
|
// Load ManiaControl Modules
|
2017-03-22 17:57:21 +01:00
|
|
|
$this->callbackManager = new CallbackManager($this);
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
$this->callQueueManager = new CallQueueManager($this);
|
2017-03-22 17:57:21 +01:00
|
|
|
$this->modeScriptEventManager = new ModeScriptEventManager($this);
|
|
|
|
$this->echoManager = new EchoManager($this);
|
|
|
|
$this->communicationManager = new CommunicationManager($this);
|
|
|
|
$this->timerManager = new TimerManager($this);
|
|
|
|
$this->database = new Database($this);
|
|
|
|
$this->fileReader = new AsynchronousFileReader($this);
|
|
|
|
$this->billManager = new BillManager($this);
|
|
|
|
$this->settingManager = new SettingManager($this);
|
|
|
|
$this->statisticManager = new StatisticManager($this);
|
|
|
|
$this->manialinkManager = new ManialinkManager($this);
|
2022-03-03 18:00:30 +01:00
|
|
|
$this->toggleInterfaceManager = new ToggleInterfaceManager($this);
|
2017-03-22 17:57:21 +01:00
|
|
|
$this->actionsMenu = new ActionsMenu($this);
|
|
|
|
$this->chat = new Chat($this);
|
|
|
|
$this->commandManager = new CommandManager($this);
|
|
|
|
$this->server = new Server($this);
|
|
|
|
$this->authenticationManager = new AuthenticationManager($this);
|
|
|
|
$this->playerManager = new PlayerManager($this);
|
2020-02-29 15:14:48 +01:00
|
|
|
$this->colorManager = new ColorManager($this);
|
2017-03-22 17:57:21 +01:00
|
|
|
$this->mapManager = new MapManager($this);
|
|
|
|
$this->configurator = new Configurator($this);
|
|
|
|
$this->pluginManager = new PluginManager($this);
|
|
|
|
$this->updateManager = new UpdateManager($this);
|
2020-03-16 00:12:36 +01:00
|
|
|
$this->changeLog = new ChangeLog($this);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getErrorHandler()->init();
|
2014-05-29 22:46:38 +02:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Permissions
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_REBOOT, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
// Commands
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getCommandManager()->registerCommandListener('version', $this, 'commandVersion', false, 'Shows ManiaControl version.');
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->getCommandManager()->registerCommandListener('reboot', $this, 'commandReboot', true, 'Reboots ManiaControl.');
|
2020-04-26 09:47:33 +02:00
|
|
|
$this->getCommandManager()->registerCommandListener('restart', $this, 'commandRestart', true, 'Restarts ManiaControl.');
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getCommandManager()->registerCommandListener('shutdown', $this, 'commandShutdown', true, 'Shuts ManiaControl down.');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-01 20:21:40 +02:00
|
|
|
// Check connection every 30 seconds
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getTimerManager()->registerTimerListening($this, 'checkConnection', 1000 * 30);
|
2015-06-23 17:12:23 +02:00
|
|
|
|
|
|
|
// Communication Methods
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::REBOOT_MANIA_CONTROL, $this, function ($data) {
|
2015-06-23 17:12:23 +02:00
|
|
|
//Delay Shutdown to send answer first
|
|
|
|
$this->getTimerManager()->registerOneTimeListening($this, function () use ($data) {
|
|
|
|
if (is_object($data) && property_exists($data, "message")) {
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->reboot($data->message);
|
2017-05-24 21:02:47 +02:00
|
|
|
} else {
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->reboot();
|
2015-06-23 17:12:23 +02:00
|
|
|
}
|
2015-06-26 16:53:41 +02:00
|
|
|
}, 3000);
|
2015-06-26 11:48:21 +02:00
|
|
|
return new CommunicationAnswer();
|
2015-06-23 17:12:23 +02:00
|
|
|
});
|
2014-04-19 00:32:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-01 20:21:40 +02:00
|
|
|
/**
|
|
|
|
* Load the Config XML-File
|
|
|
|
*/
|
|
|
|
private function loadConfig() {
|
2014-05-02 17:40:47 +02:00
|
|
|
$configId = CommandLineHelper::getParameter('-config');
|
2014-05-01 20:21:40 +02:00
|
|
|
$configFileName = ($configId ? $configId : 'server.xml');
|
2014-08-05 02:17:41 +02:00
|
|
|
$config = FileUtil::loadConfig($configFileName);
|
2014-08-03 01:34:18 +02:00
|
|
|
if (!$config) {
|
2014-05-15 13:04:05 +02:00
|
|
|
$this->quit("Error loading Configuration XML-File! ('{$configFileName}')", true);
|
2014-05-01 20:21:40 +02:00
|
|
|
}
|
2014-08-03 01:34:18 +02:00
|
|
|
if ($config->count() < 3) {
|
2014-05-27 08:57:26 +02:00
|
|
|
$this->quit("Your Configuration File ('{$configFileName}') doesn't seem to be maintained properly. Please check it again!", true);
|
2014-05-01 20:21:40 +02:00
|
|
|
}
|
2014-08-03 01:34:18 +02:00
|
|
|
$this->config = $config;
|
2014-05-01 20:21:40 +02:00
|
|
|
}
|
|
|
|
|
2014-05-15 13:04:05 +02:00
|
|
|
/**
|
|
|
|
* Quit ManiaControl and log the given message
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @param bool $errorPrefix
|
|
|
|
*/
|
|
|
|
public function quit($message = null, $errorPrefix = false) {
|
2014-08-25 18:01:48 +02:00
|
|
|
if ($this->getClient()) {
|
2014-08-28 16:25:04 +02:00
|
|
|
if ($this->getCallbackManager()) {
|
|
|
|
// OnShutdown callback
|
|
|
|
$this->getCallbackManager()->triggerCallback(Callbacks::ONSHUTDOWN);
|
2014-08-25 18:01:48 +02:00
|
|
|
}
|
|
|
|
|
2014-09-01 03:42:13 +02:00
|
|
|
if ($chat = $this->getChat()) {
|
2014-08-28 16:25:04 +02:00
|
|
|
// Announce quit
|
2014-09-01 03:42:13 +02:00
|
|
|
try {
|
|
|
|
$chat->sendInformation('ManiaControl shutting down.');
|
|
|
|
} catch (TransportException $e) {
|
|
|
|
}
|
2014-08-28 16:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hide UI
|
2014-09-01 03:42:13 +02:00
|
|
|
try {
|
|
|
|
$this->getClient()->sendHideManialinkPage();
|
|
|
|
} catch (TransportException $e) {
|
|
|
|
}
|
2014-08-28 16:25:04 +02:00
|
|
|
|
|
|
|
// Delete client
|
|
|
|
Connection::delete($this->getClient());
|
|
|
|
$this->client = null;
|
|
|
|
}
|
2014-08-25 18:01:48 +02:00
|
|
|
|
2014-08-02 20:51:48 +02:00
|
|
|
SystemUtil::quit($message, $errorPrefix);
|
2014-05-29 22:54:43 +02:00
|
|
|
}
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
/**
|
2014-08-25 15:10:46 +02:00
|
|
|
* Return the client
|
2014-08-03 01:34:18 +02:00
|
|
|
*
|
2014-08-25 15:10:46 +02:00
|
|
|
* @return Connection
|
2014-08-03 01:34:18 +02:00
|
|
|
*/
|
2014-08-25 15:10:46 +02:00
|
|
|
public function getClient() {
|
|
|
|
return $this->client;
|
|
|
|
}
|
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
/**
|
|
|
|
* Return the callback manager
|
|
|
|
*
|
|
|
|
* @return CallbackManager
|
|
|
|
*/
|
|
|
|
public function getCallbackManager() {
|
|
|
|
return $this->callbackManager;
|
|
|
|
}
|
|
|
|
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
/**
|
|
|
|
* Return the call queue manager
|
|
|
|
*
|
|
|
|
* @return CallQueueManager
|
|
|
|
*/
|
|
|
|
public function getCallQueueManager() {
|
|
|
|
return $this->callQueueManager;
|
|
|
|
}
|
|
|
|
|
2015-06-19 01:37:31 +02:00
|
|
|
/**
|
|
|
|
* Return the echo manager
|
|
|
|
*
|
|
|
|
* @return EchoManager
|
|
|
|
*/
|
|
|
|
public function getEchoManager() {
|
|
|
|
return $this->echoManager;
|
|
|
|
}
|
|
|
|
|
2015-06-21 20:45:48 +02:00
|
|
|
/**
|
|
|
|
* Return the socket manager
|
|
|
|
*
|
2015-06-22 20:22:17 +02:00
|
|
|
* @return CommunicationManager
|
2015-06-21 20:45:48 +02:00
|
|
|
*/
|
2015-06-22 20:22:17 +02:00
|
|
|
public function getCommunicationManager() {
|
|
|
|
return $this->communicationManager;
|
2015-06-21 20:45:48 +02:00
|
|
|
}
|
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
/**
|
|
|
|
* Return the chat
|
|
|
|
*
|
|
|
|
* @return Chat
|
|
|
|
*/
|
|
|
|
public function getChat() {
|
|
|
|
return $this->chat;
|
|
|
|
}
|
|
|
|
|
2020-03-16 00:12:36 +01:00
|
|
|
/**
|
|
|
|
* Return the changelog
|
|
|
|
*
|
|
|
|
* @return ChangeLog
|
|
|
|
*/
|
|
|
|
public function getChangeLog() {
|
|
|
|
return $this->changeLog;
|
|
|
|
}
|
|
|
|
|
2014-08-25 15:10:46 +02:00
|
|
|
/**
|
|
|
|
* Return the error handler
|
|
|
|
*
|
|
|
|
* @return ErrorHandler
|
|
|
|
*/
|
|
|
|
public function getErrorHandler() {
|
|
|
|
return $this->errorHandler;
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the authentication manager
|
|
|
|
*
|
|
|
|
* @return AuthenticationManager
|
|
|
|
*/
|
|
|
|
public function getAuthenticationManager() {
|
|
|
|
return $this->authenticationManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-25 15:10:46 +02:00
|
|
|
* Return the command manager
|
2014-08-03 01:34:18 +02:00
|
|
|
*
|
2014-08-25 15:10:46 +02:00
|
|
|
* @return CommandManager
|
2014-08-03 01:34:18 +02:00
|
|
|
*/
|
2014-08-25 15:10:46 +02:00
|
|
|
public function getCommandManager() {
|
|
|
|
return $this->commandManager;
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-25 15:10:46 +02:00
|
|
|
* Return the timer manager
|
2014-08-03 01:34:18 +02:00
|
|
|
*
|
2014-08-25 15:10:46 +02:00
|
|
|
* @return TimerManager
|
2014-08-03 01:34:18 +02:00
|
|
|
*/
|
2014-08-25 15:10:46 +02:00
|
|
|
public function getTimerManager() {
|
|
|
|
return $this->timerManager;
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-25 15:10:46 +02:00
|
|
|
* Print a message to console and log
|
2014-08-03 01:34:18 +02:00
|
|
|
*
|
2014-08-25 15:10:46 +02:00
|
|
|
* @param string $message
|
|
|
|
* @param bool $stripCodes
|
|
|
|
* @deprecated
|
|
|
|
* @see Logger::log()
|
2014-08-03 01:34:18 +02:00
|
|
|
*/
|
2014-08-25 15:10:46 +02:00
|
|
|
public function log($message, $stripCodes = false) {
|
|
|
|
Logger::log($message, $stripCodes);
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-25 15:10:46 +02:00
|
|
|
* Return the actions menu
|
2014-08-03 01:34:18 +02:00
|
|
|
*
|
2014-08-25 15:10:46 +02:00
|
|
|
* @return ActionsMenu
|
2014-08-03 01:34:18 +02:00
|
|
|
*/
|
2014-08-25 15:10:46 +02:00
|
|
|
public function getActionsMenu() {
|
|
|
|
return $this->actionsMenu;
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-25 15:10:46 +02:00
|
|
|
* Return the config
|
2014-08-03 01:34:18 +02:00
|
|
|
*
|
2014-08-25 15:10:46 +02:00
|
|
|
* @return \SimpleXMLElement
|
2014-08-03 01:34:18 +02:00
|
|
|
*/
|
2014-08-25 15:10:46 +02:00
|
|
|
public function getConfig() {
|
|
|
|
return $this->config;
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-08-25 15:10:46 +02:00
|
|
|
* Return the configurator
|
2014-08-03 01:34:18 +02:00
|
|
|
*
|
2014-08-25 15:10:46 +02:00
|
|
|
* @return Configurator
|
2014-08-03 01:34:18 +02:00
|
|
|
*/
|
2014-08-25 15:10:46 +02:00
|
|
|
public function getConfigurator() {
|
|
|
|
return $this->configurator;
|
2014-08-03 01:34:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the database
|
|
|
|
*
|
|
|
|
* @return Database
|
|
|
|
*/
|
|
|
|
public function getDatabase() {
|
|
|
|
return $this->database;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the manialink manager
|
|
|
|
*
|
|
|
|
* @return ManialinkManager
|
|
|
|
*/
|
|
|
|
public function getManialinkManager() {
|
|
|
|
return $this->manialinkManager;
|
|
|
|
}
|
|
|
|
|
2022-03-03 18:00:30 +01:00
|
|
|
/**
|
|
|
|
* Return the ToggleInterface manager
|
|
|
|
*
|
|
|
|
* @return ToggleInterfaceManager
|
|
|
|
*/
|
|
|
|
public function getToggleInterfaceManager() {
|
|
|
|
return $this->toggleInterfaceManager;
|
|
|
|
}
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
/**
|
|
|
|
* Return the map manager
|
|
|
|
*
|
|
|
|
* @return MapManager
|
|
|
|
*/
|
|
|
|
public function getMapManager() {
|
|
|
|
return $this->mapManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the player manager
|
|
|
|
*
|
|
|
|
* @return PlayerManager
|
|
|
|
*/
|
|
|
|
public function getPlayerManager() {
|
|
|
|
return $this->playerManager;
|
|
|
|
}
|
|
|
|
|
2020-02-29 15:14:48 +01:00
|
|
|
/**
|
|
|
|
* Return the color manager
|
|
|
|
*
|
|
|
|
* @return ColorManager
|
|
|
|
*/
|
|
|
|
public function getColorManager() {
|
|
|
|
return $this->colorManager;
|
|
|
|
}
|
|
|
|
|
2014-08-03 01:34:18 +02:00
|
|
|
/**
|
|
|
|
* Return the setting manager
|
|
|
|
*
|
|
|
|
* @return SettingManager
|
|
|
|
*/
|
|
|
|
public function getSettingManager() {
|
|
|
|
return $this->settingManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the statistic manager
|
|
|
|
*
|
|
|
|
* @return StatisticManager
|
|
|
|
*/
|
|
|
|
public function getStatisticManager() {
|
|
|
|
return $this->statisticManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the bill manager
|
|
|
|
*
|
|
|
|
* @return BillManager
|
|
|
|
*/
|
|
|
|
public function getBillManager() {
|
|
|
|
return $this->billManager;
|
|
|
|
}
|
|
|
|
|
2017-03-22 17:57:21 +01:00
|
|
|
/**
|
|
|
|
* @return ModeScriptEventManager
|
|
|
|
*/
|
|
|
|
public function getModeScriptEventManager() {
|
|
|
|
return $this->modeScriptEventManager;
|
|
|
|
}
|
|
|
|
|
2014-04-19 00:32:34 +02:00
|
|
|
/**
|
2014-08-02 20:51:48 +02:00
|
|
|
* Check connection
|
2014-04-19 00:32:34 +02:00
|
|
|
*/
|
2014-05-13 16:40:05 +02:00
|
|
|
public function checkConnection() {
|
2014-08-28 16:25:04 +02:00
|
|
|
if ($this->getClient()->getIdleTime() > 180) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getClient()->getServerName();
|
2014-04-19 00:32:34 +02:00
|
|
|
}
|
2013-11-10 17:29:21 +01:00
|
|
|
}
|
|
|
|
|
2013-12-09 15:53:10 +01:00
|
|
|
/**
|
2014-05-02 17:40:47 +02:00
|
|
|
* Handle Version Command
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-06-13 16:59:25 +02:00
|
|
|
public function commandVersion(array $chatCallback, Player $player) {
|
2022-03-03 19:20:50 +01:00
|
|
|
$message = 'This server is using TrackManiaControl v' . ManiaControl::VERSION . '!';
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getChat()->sendInformation($message, $player);
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2020-04-24 18:51:38 +02:00
|
|
|
* Handle Reboot AdminCommand
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
2020-04-24 18:51:38 +02:00
|
|
|
public function commandReboot(array $chatCallback, Player $player) {
|
|
|
|
if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_REBOOT)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getAuthenticationManager()->sendNotAllowed($player);
|
2014-05-02 17:40:47 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->reboot("ManiaControl Reboot requested by '{$player->login}'!");
|
2014-05-02 17:40:47 +02:00
|
|
|
}
|
|
|
|
|
2020-04-26 09:47:33 +02:00
|
|
|
/**
|
|
|
|
* Handle Restart AdminCommand
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function commandRestart(array $chatCallback, Player $player) {
|
|
|
|
if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_REBOOT)) {
|
|
|
|
$this->getAuthenticationManager()->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
2020-05-30 23:33:52 +02:00
|
|
|
$message = $this->getChat()->formatMessage(
|
|
|
|
'The command %s got disabled, reboot ManiaControl with %s instead!',
|
|
|
|
'//restart',
|
|
|
|
'//reboot'
|
|
|
|
);
|
|
|
|
$this->getChat()->sendError($message, $player);
|
2020-04-26 09:47:33 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @deprecated
|
|
|
|
* Restart ManiaControl
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
*/
|
|
|
|
public function restart($message = null) {
|
|
|
|
$this->reboot($message);
|
|
|
|
}
|
|
|
|
|
2014-05-02 17:40:47 +02:00
|
|
|
/**
|
2020-04-24 18:51:38 +02:00
|
|
|
* Reboot ManiaControl
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param string $message
|
2013-12-09 15:53:10 +01:00
|
|
|
*/
|
2020-04-24 18:51:38 +02:00
|
|
|
public function reboot($message = null) {
|
|
|
|
// Trigger callback on Reboot
|
|
|
|
$this->getCallbackManager()->triggerCallback(Callbacks::ONREBOOT);
|
2015-06-26 16:53:41 +02:00
|
|
|
|
2020-04-24 18:51:38 +02:00
|
|
|
// Announce reboot
|
2014-09-01 03:42:13 +02:00
|
|
|
try {
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->getChat()->sendInformation('Rebooting ManiaControl...', null, true, false);
|
2014-09-01 03:42:13 +02:00
|
|
|
} catch (TransportException $e) {
|
|
|
|
}
|
2020-04-24 18:51:38 +02:00
|
|
|
Logger::log('Rebooting ManiaControl... ' . $message);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-02 20:51:48 +02:00
|
|
|
// Start new instance
|
2017-04-15 23:00:24 +02:00
|
|
|
if (!defined('PHP_UNIT_TEST')) {
|
2020-04-24 18:51:38 +02:00
|
|
|
SystemUtil::reboot();
|
2017-04-15 23:00:24 +02:00
|
|
|
}
|
2014-06-12 14:02:16 +02:00
|
|
|
|
2014-08-02 20:51:48 +02:00
|
|
|
// Quit old instance
|
2020-04-24 18:51:38 +02:00
|
|
|
$this->quit('Quitting ManiaControl to reboot.');
|
2013-12-09 15:53:10 +01:00
|
|
|
}
|
|
|
|
|
2014-01-01 19:25:51 +01:00
|
|
|
/**
|
2014-06-13 16:59:25 +02:00
|
|
|
* Handle Shutdown Command
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
|
|
|
* @param array $chat
|
2014-01-01 19:25:51 +01:00
|
|
|
* @param Player $player
|
|
|
|
*/
|
2014-06-13 16:59:25 +02:00
|
|
|
public function commandShutdown(array $chat, Player $player) {
|
2014-08-25 18:01:48 +02:00
|
|
|
if (!$this->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getAuthenticationManager()->sendNotAllowed($player);
|
2014-01-01 19:25:51 +01:00
|
|
|
return;
|
|
|
|
}
|
2014-06-20 16:34:19 +02:00
|
|
|
$this->requestQuit("ManiaControl Shutdown requested by '{$player->login}'!");
|
2013-11-24 23:55:54 +01:00
|
|
|
}
|
|
|
|
|
2014-06-23 16:14:47 +02:00
|
|
|
/**
|
|
|
|
* Request ManiaControl to quit
|
|
|
|
*
|
|
|
|
* @param mixed $message
|
|
|
|
*/
|
|
|
|
public function requestQuit($message = true) {
|
|
|
|
$this->requestQuitMessage = $message;
|
|
|
|
}
|
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
/**
|
|
|
|
* Run ManiaControl
|
2017-04-15 13:21:49 +02:00
|
|
|
*
|
|
|
|
* @param int $runTime Time in Seconds until its terminating (used for PHPUnit Tests)
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
2017-04-15 13:21:49 +02:00
|
|
|
public function run($runTime = -1) {
|
2014-08-05 01:49:13 +02:00
|
|
|
Logger::log('Starting ManiaControl v' . self::VERSION . '!');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-07-19 23:33:15 +02:00
|
|
|
try {
|
2023-12-01 19:05:24 +01:00
|
|
|
// Manage SIGTERM signal
|
2023-12-23 21:10:31 +01:00
|
|
|
if (extension_loaded('pcntl')) {
|
|
|
|
pcntl_signal(SIGTERM, function() {
|
|
|
|
$this->quit("Stop signal received from the OS.", false);
|
|
|
|
});
|
|
|
|
}
|
2023-12-01 19:05:24 +01:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Connect to server
|
2014-07-19 23:33:15 +02:00
|
|
|
$this->connect();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Check if the version of the server is high enough
|
2017-03-26 13:58:23 +02:00
|
|
|
$version = $this->getClient()->getVersion();
|
|
|
|
$this->dedicatedServerBuildVersion = $version->build;
|
|
|
|
if ($this->dedicatedServerBuildVersion < self::MIN_DEDIVERSION) {
|
|
|
|
$this->quit("The Server has Version '{$this->dedicatedServerBuildVersion}', while at least '" . self::MIN_DEDIVERSION . "' is required!", true);
|
2014-08-28 16:25:04 +02:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Listen for shutdown
|
|
|
|
$this->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_SERVERSTOP, $this, 'handleServerStopCallback');
|
2014-06-20 16:19:30 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// OnInit callback
|
|
|
|
$this->getCallbackManager()->triggerCallback(Callbacks::ONINIT);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Load plugins
|
|
|
|
$this->getPluginManager()->loadPlugins();
|
2017-05-13 19:27:38 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
$this->getUpdateManager()->getPluginUpdateManager()->checkPluginsUpdate();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// AfterInit callback
|
|
|
|
$this->getCallbackManager()->triggerCallback(Callbacks::AFTERINIT);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Loading finished
|
|
|
|
Logger::log('Loading completed!');
|
|
|
|
Logger::log('Link: ' . $this->getServer()->getJoinLink());
|
2022-03-03 19:20:50 +01:00
|
|
|
$this->getChat()->sendInformation('TrackManiaControl v' . self::VERSION . ' successfully started!');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2017-04-15 13:21:49 +02:00
|
|
|
$this->startTime = time();
|
2017-04-16 14:43:13 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Main loop
|
|
|
|
while (!$this->requestQuitMessage) {
|
|
|
|
$this->loop();
|
2017-04-15 13:21:49 +02:00
|
|
|
|
|
|
|
//Used for PHPUnit Tests
|
|
|
|
if ($runTime > 0) {
|
|
|
|
if (time() > ($this->startTime + $runTime)) {
|
|
|
|
$this->requestQuit("Run Time Exceeded");
|
|
|
|
}
|
|
|
|
}
|
2014-08-28 16:25:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Shutdown
|
2017-04-15 23:00:24 +02:00
|
|
|
$this->quit($this->requestQuitMessage);
|
2014-08-28 16:25:04 +02:00
|
|
|
} catch (TransportException $exception) {
|
|
|
|
Logger::logError('Connection interrupted!');
|
|
|
|
$this->getErrorHandler()->handleException($exception);
|
|
|
|
SystemUtil::quit($exception->getMessage(), true);
|
|
|
|
}
|
2014-05-09 13:46:04 +02:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
/**
|
|
|
|
* Connect to ManiaPlanet server
|
2017-04-16 14:43:13 +02:00
|
|
|
* Public only for PHPUnit Tests
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
2017-04-16 14:43:13 +02:00
|
|
|
public function connect() {
|
2013-11-10 17:29:21 +01:00
|
|
|
// Load remote client
|
2014-08-13 11:05:52 +02:00
|
|
|
$serverConfig = $this->getServer()->loadConfig();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-08-05 01:49:13 +02:00
|
|
|
Logger::log("Connecting to Server at {$serverConfig->host}:{$serverConfig->port}...");
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-17 16:32:53 +01:00
|
|
|
try {
|
2014-08-03 01:34:18 +02:00
|
|
|
$this->client = Connection::factory($serverConfig->host, $serverConfig->port, self::SCRIPT_TIMEOUT, $serverConfig->user, $serverConfig->pass, self::API_VERSION);
|
2014-06-23 16:14:47 +02:00
|
|
|
} catch (TransportException $exception) {
|
|
|
|
$message = "Couldn't connect to the server: '{$exception->getMessage()}'";
|
|
|
|
$this->quit($message, true);
|
|
|
|
} catch (AuthenticationException $exception) {
|
2014-08-03 01:34:18 +02:00
|
|
|
$message = "Couldn't authenticate on Server with User '{$serverConfig->user}' & Pass '{$serverConfig->pass}'! " . $exception->getMessage();
|
2014-05-09 14:08:39 +02:00
|
|
|
$this->quit($message, true);
|
2014-03-20 16:19:50 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Enable callback system
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getClient()->enableCallbacks(true);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Wait for server to be ready
|
2014-08-28 16:25:04 +02:00
|
|
|
if (!$this->getServer()->waitForStatus(4)) {
|
2014-07-19 23:33:15 +02:00
|
|
|
$this->quit("Server couldn't get ready!");
|
2013-11-10 17:29:21 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Connect finished
|
2014-08-05 01:49:13 +02:00
|
|
|
Logger::log('Server Connection successfully established!');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-31 14:50:45 +01:00
|
|
|
// Hide old widgets
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getClient()->sendHideManialinkPage();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-05-06 02:17:11 +02:00
|
|
|
// Enable script callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getServer()->getScriptManager()->enableScriptCallbacks();
|
2013-11-10 17:29:21 +01:00
|
|
|
}
|
2014-05-09 14:08:39 +02:00
|
|
|
|
2017-03-26 13:58:23 +02:00
|
|
|
/**
|
|
|
|
* Get The Build Version of the Dedicated Server
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getDedicatedServerBuildVersion() {
|
|
|
|
return $this->dedicatedServerBuildVersion;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-08-25 15:10:46 +02:00
|
|
|
/**
|
|
|
|
* Return the server
|
|
|
|
*
|
|
|
|
* @return Server
|
|
|
|
*/
|
|
|
|
public function getServer() {
|
|
|
|
return $this->server;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the plugin manager
|
|
|
|
*
|
|
|
|
* @return PluginManager
|
|
|
|
*/
|
|
|
|
public function getPluginManager() {
|
|
|
|
return $this->pluginManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the update manager
|
|
|
|
*
|
|
|
|
* @return UpdateManager
|
|
|
|
*/
|
|
|
|
public function getUpdateManager() {
|
|
|
|
return $this->updateManager;
|
|
|
|
}
|
|
|
|
|
2014-05-09 14:08:39 +02:00
|
|
|
/**
|
|
|
|
* Perform the Main Loop
|
|
|
|
*/
|
|
|
|
private function loop() {
|
|
|
|
$loopStart = microtime(true);
|
|
|
|
|
2017-06-22 15:07:00 +02:00
|
|
|
//Trigger a Callback on entering the Loop
|
|
|
|
$this->getCallbackManager()->triggerCallback(Callbacks::PRELOOP, $loopStart);
|
|
|
|
|
2014-05-09 16:33:33 +02:00
|
|
|
// Extend script timeout
|
2017-04-15 23:00:24 +02:00
|
|
|
if (!defined('PHP_UNIT_TEST')) {
|
2017-04-15 13:21:49 +02:00
|
|
|
set_time_limit(self::SCRIPT_TIMEOUT);
|
|
|
|
}
|
2014-05-09 14:08:39 +02:00
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Manage callbacks
|
|
|
|
$this->getCallbackManager()->manageCallbacks();
|
2014-05-09 14:08:39 +02:00
|
|
|
|
Multiple Features to improve ManiaControl usability (#234)
* ServerUIPropertiesMenu for Configurator to edit builtin UIProperties of MP
* fixed unregister-functions of CallbackManager
* Reducing menuItemHeight in Configurator to avoid overlapping of the menu items
* Fully rebuild the admins menu after a player rights changed
* Added function to FileUtil to improve realpath, so symbolic links can be resolved
* Fixed indentation
* Update FileUtil.php
Fixed error in case of an absolute path on Unix-like systems.
* New CallQueue which runs once inbetween the MC-loops
* Added important queued call to be executed earlier
* ErrorMethod made optional, as in some cases, there might be nothing to fail
* Clean up repository from unnecessary files
* Added easy installation script for DB on Unix-like systems
* Replaced deprecated is_real by is_float
* Add milliseconds with dot instead of double colon
* Resolved deprecated curly braces error
* gitignore all hidden files (except git and gitignore)
* Update MC-update-check-interval, so that a restart is not required
* Update gitignore to not ignore changes in MCTeam-Plugins
* Update gitignore again
* And another try
* fixed MasterAdmin //delrec, added personal /delrec-command with permission-setting
* Increase version number of local records plugin
* Add Permission to delete any record
* Reworked notifications of locals, removed private only, added private at rank
* Fix formatting
* Allow AuthenticationManager to store Plugin Permissions
* Method to check, if a named function call is already queued
* Added command disable feature
* Reset timer if DeltaTime updated, so it does not try to catch up missed timings
* Added private notification setting
* To reduce load of multiple records (especially in rounds), queue call chat notifications
* Added internal function to plugin manager to return plugin menu
* restore .idea codestyle files
* Update MC-Version number to 0.250
2020-02-24 17:20:51 +01:00
|
|
|
// Manage queued calls
|
|
|
|
$this->getCallQueueManager()->manageCallQueue();
|
|
|
|
|
2014-08-28 16:25:04 +02:00
|
|
|
// Manage async file reader
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->getFileReader()->appendData();
|
2014-05-09 14:08:39 +02:00
|
|
|
|
|
|
|
// Yield for next tick
|
|
|
|
$loopEnd = microtime(true);
|
|
|
|
$loopDuration = $loopEnd - $loopStart;
|
2014-10-24 20:08:21 +02:00
|
|
|
$sleepTime = (int) (2500 - $loopDuration * 1000000);
|
2014-05-09 14:08:39 +02:00
|
|
|
if ($sleepTime > 0) {
|
|
|
|
usleep($sleepTime);
|
|
|
|
}
|
2017-06-22 15:07:00 +02:00
|
|
|
|
|
|
|
//Trigger a Callback after the Loop
|
|
|
|
$this->getCallbackManager()->triggerCallback(Callbacks::AFTERLOOP, $loopDuration);
|
2014-05-09 14:08:39 +02:00
|
|
|
}
|
2014-06-20 16:19:30 +02:00
|
|
|
|
2014-08-25 15:10:46 +02:00
|
|
|
/**
|
|
|
|
* Return the file reader
|
|
|
|
*
|
|
|
|
* @return AsynchronousFileReader
|
|
|
|
*/
|
|
|
|
public function getFileReader() {
|
|
|
|
return $this->fileReader;
|
|
|
|
}
|
|
|
|
|
2014-06-20 16:19:30 +02:00
|
|
|
/**
|
|
|
|
* Handle Server Stop Callback
|
|
|
|
*/
|
2014-06-20 16:22:45 +02:00
|
|
|
public function handleServerStopCallback() {
|
2014-06-20 16:34:19 +02:00
|
|
|
$this->requestQuit('The Server has been shut down!');
|
|
|
|
}
|
2017-03-22 17:57:21 +01:00
|
|
|
|
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
}
|