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;
|
2014-02-25 18:34:35 +01:00
|
|
|
use ManiaControl\Bills\BillManager;
|
2013-11-12 15:48:25 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackManager;
|
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;
|
2013-11-28 03:47:08 +01:00
|
|
|
use ManiaControl\Configurators\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;
|
2013-11-28 03:47:08 +01:00
|
|
|
use ManiaControl\Manialinks\ManialinkManager;
|
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;
|
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;
|
2014-02-10 22:54:49 +01:00
|
|
|
use ManiaControl\Update\UpdateManager;
|
2014-01-16 17:19:01 +01:00
|
|
|
use Maniaplanet\DedicatedServer\Connection;
|
2014-02-13 14:21:25 +01:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
2014-04-19 22:59:11 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
|
2014-04-27 15:21:57 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\TransportException;
|
2013-12-31 12:42:07 +01:00
|
|
|
|
2014-02-18 15:54:36 +01:00
|
|
|
require_once __DIR__ . '/Libs/Maniaplanet/DedicatedServer/Connection.php';
|
|
|
|
require_once __DIR__ . '/Libs/GbxDataFetcher/gbxdatafetcher.inc.php';
|
|
|
|
require_once __DIR__ . '/Libs/FML/autoload.php';
|
2014-02-18 18:13:59 +01:00
|
|
|
require_once __DIR__ . '/Libs/Symfony/autoload.php';
|
|
|
|
require_once __DIR__ . '/Libs/curl-easy/autoload.php';
|
|
|
|
|
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>
|
|
|
|
* @copyright 2014 ManiaControl Team
|
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
2014-02-22 11:14:35 +01:00
|
|
|
class ManiaControl implements CommandListener, TimerListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-11-10 17:29:21 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2014-05-02 17:40:47 +02:00
|
|
|
const VERSION = '0.12';
|
|
|
|
const API_VERSION = '2013-04-16';
|
|
|
|
const MIN_DEDIVERSION = '2014-04-02_18_00';
|
|
|
|
const OS_UNIX = 'Unix';
|
|
|
|
const OS_WIN = 'Windows';
|
|
|
|
const CONNECT_TIMEOUT = 50;
|
|
|
|
const SCRIPT_TIMEOUT = 20;
|
|
|
|
const URL_WEBSERVICE = 'http://ws.maniacontrol.com/';
|
2014-01-31 16:55:01 +01:00
|
|
|
const SETTING_PERMISSION_SHUTDOWN = 'Shutdown ManiaControl';
|
2014-05-02 17:40:47 +02:00
|
|
|
const SETTING_PERMISSION_RESTART = 'Restart ManiaControl';
|
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
|
|
|
* Public Properties
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
2013-12-31 12:42:07 +01:00
|
|
|
public $actionsMenu = null;
|
2013-11-13 01:43:12 +01:00
|
|
|
public $authenticationManager = null;
|
2013-11-12 15:48:25 +01:00
|
|
|
public $callbackManager = null;
|
2013-11-10 17:29:21 +01:00
|
|
|
public $chat = null;
|
2014-05-01 20:21:40 +02:00
|
|
|
public $config = null;
|
2013-11-28 03:47:08 +01:00
|
|
|
public $configurator = null;
|
2014-05-01 20:21:40 +02:00
|
|
|
/**
|
|
|
|
* @var Connection $client
|
|
|
|
*/
|
2013-11-10 17:29:21 +01:00
|
|
|
public $client = null;
|
2013-11-12 15:48:25 +01:00
|
|
|
public $commandManager = null;
|
2013-11-10 17:29:21 +01:00
|
|
|
public $database = null;
|
2013-11-28 02:04:06 +01:00
|
|
|
public $manialinkManager = null;
|
2013-11-12 15:48:25 +01:00
|
|
|
public $mapManager = null;
|
|
|
|
public $playerManager = null;
|
|
|
|
public $pluginManager = null;
|
2013-11-10 17:29:21 +01:00
|
|
|
public $server = null;
|
|
|
|
public $settingManager = null;
|
2013-12-31 17:31:05 +01:00
|
|
|
public $statisticManager = null;
|
2014-05-02 15:35:52 +02:00
|
|
|
/** @var UpdateManager $updateManager */
|
2013-12-17 17:38:44 +01:00
|
|
|
public $updateManager = null;
|
2014-01-27 20:28:37 +01:00
|
|
|
public $errorHandler = null;
|
2014-01-30 22:35:32 +01:00
|
|
|
public $timerManager = null;
|
2014-02-07 12:30:53 +01:00
|
|
|
public $fileReader = null;
|
2014-02-25 18:34:35 +01:00
|
|
|
public $billManager = null;
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
|
|
|
* Private Properties
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
|
|
|
private $shutdownRequested = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct ManiaControl
|
|
|
|
*/
|
|
|
|
public function __construct() {
|
2014-03-20 16:19:50 +01:00
|
|
|
// Construct Error Handler
|
2014-01-27 20:28:37 +01:00
|
|
|
$this->errorHandler = new ErrorHandler($this);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-31 14:50:45 +01:00
|
|
|
$this->log('Loading ManiaControl v' . self::VERSION . '...');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
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
|
2014-05-02 17:40:47 +02:00
|
|
|
$this->callbackManager = new CallbackManager($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);
|
|
|
|
$this->actionsMenu = new ActionsMenu($this);
|
|
|
|
$this->chat = new Chat($this);
|
|
|
|
$this->commandManager = new CommandManager($this);
|
|
|
|
$this->server = new Server($this);
|
2013-11-26 13:49:36 +01:00
|
|
|
$this->authenticationManager = new AuthenticationManager($this);
|
2014-05-02 17:40:47 +02:00
|
|
|
$this->playerManager = new PlayerManager($this);
|
|
|
|
$this->mapManager = new MapManager($this);
|
|
|
|
$this->configurator = new Configurator($this);
|
|
|
|
$this->pluginManager = new PluginManager($this);
|
|
|
|
$this->updateManager = new UpdateManager($this);
|
|
|
|
|
2014-03-20 16:19:50 +01:00
|
|
|
// Define Permission Levels
|
2014-01-31 16:55:01 +01:00
|
|
|
$this->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SHUTDOWN, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
|
|
|
$this->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_RESTART, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-17 17:38:44 +01:00
|
|
|
// Register for commands
|
2014-05-01 01:41:19 +02:00
|
|
|
$this->commandManager->registerCommandListener('version', $this, 'command_Version', false, 'Shows ManiaControl version.');
|
|
|
|
$this->commandManager->registerCommandListener('restart', $this, 'command_Restart', true, 'Restarts ManiaControl.');
|
|
|
|
$this->commandManager->registerCommandListener('shutdown', $this, 'command_Shutdown', 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-04-20 15:13:31 +02:00
|
|
|
$this->timerManager->registerTimerListening($this, 'checkConnection', 1000 * 30);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-04-28 14:14:04 +02:00
|
|
|
$this->errorHandler->init();
|
2014-04-19 00:32:34 +02:00
|
|
|
}
|
|
|
|
|
2014-05-02 17:40:47 +02:00
|
|
|
/**
|
|
|
|
* Print a message to console and log
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @param bool $stripCodes
|
|
|
|
*/
|
|
|
|
public function log($message, $stripCodes = false) {
|
|
|
|
if ($stripCodes) {
|
|
|
|
$message = Formatter::stripCodes($message);
|
|
|
|
}
|
|
|
|
logMessage($message);
|
|
|
|
}
|
|
|
|
|
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-05-02 17:40:47 +02:00
|
|
|
$this->config = FileUtil::loadConfig($configFileName);
|
2014-05-01 20:21:40 +02:00
|
|
|
if (!$this->config) {
|
|
|
|
trigger_error("Error loading Configuration XML-File! ('{$configFileName}')", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
if (!$this->config->server->port || $this->config->server->port == 'port') {
|
|
|
|
trigger_error("Your Configuration File ('{$configFileName}') doesn't seem to be maintained. Please check it again!", E_USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-19 00:32:34 +02:00
|
|
|
/**
|
|
|
|
* Checks connection every xxx Minutes
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
2014-04-19 00:32:34 +02:00
|
|
|
* @param $time
|
|
|
|
*/
|
2014-04-19 22:59:11 +02:00
|
|
|
public function checkConnection($time) {
|
|
|
|
if ($this->client->getIdleTime() > 180) {
|
2014-04-19 00:32:34 +02:00
|
|
|
$this->client->getServerName();
|
|
|
|
}
|
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
|
|
|
|
*/
|
|
|
|
public function command_Version(array $chatCallback, Player $player) {
|
|
|
|
$message = 'This server is using ManiaControl v' . ManiaControl::VERSION . '!';
|
|
|
|
$this->chat->sendInformation($message, $player->login);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle Restart AdminCommand
|
|
|
|
*
|
|
|
|
* @param array $chatCallback
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function command_Restart(array $chatCallback, Player $player) {
|
|
|
|
if (!$this->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_RESTART)) {
|
|
|
|
$this->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->restart("ManiaControl Restart requested by '{$player->login}'!");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Restart ManiaControl
|
|
|
|
*
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param string $message
|
2013-12-09 15:53:10 +01:00
|
|
|
*/
|
2014-05-02 17:40:47 +02:00
|
|
|
public function restart($message = null) {
|
|
|
|
// Shutdown callback
|
|
|
|
$this->callbackManager->triggerCallback(CallbackManager::CB_ONSHUTDOWN);
|
|
|
|
|
|
|
|
// Announce restart
|
|
|
|
$this->chat->sendInformation('Restarting ManiaControl...');
|
|
|
|
if ($message) {
|
|
|
|
$this->log($message);
|
2014-01-05 14:13:18 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
|
|
|
// Hide widgets
|
|
|
|
$this->client->sendHideManialinkPage();
|
|
|
|
|
|
|
|
$this->log('Restarting ManiaControl!');
|
|
|
|
|
|
|
|
// Execute start script in background
|
|
|
|
// TODO: restart the .php script itself ($_SERVER['scriptname'] or something + $argv)
|
|
|
|
if ($this->getOS(self::OS_UNIX)) {
|
2014-05-03 21:37:28 +02:00
|
|
|
$command = 'sh ' . escapeshellarg(ManiaControlDir . 'ManiaControl.sh') . ' > /dev/null &';
|
2014-05-02 17:40:47 +02:00
|
|
|
exec($command);
|
|
|
|
} else {
|
2014-05-03 21:37:28 +02:00
|
|
|
$command = escapeshellarg(ManiaControlDir . "ManiaControl.bat");
|
2014-05-02 17:40:47 +02:00
|
|
|
system($command); // TODO, windows stucks here as long controller is running
|
|
|
|
}
|
|
|
|
exit();
|
2013-12-09 15:53:10 +01:00
|
|
|
}
|
|
|
|
|
2014-01-01 17:59:29 +01:00
|
|
|
/**
|
|
|
|
* Get the Operating System on which ManiaControl is running
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
2014-01-01 17:59:29 +01:00
|
|
|
* @param string $compareOS
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getOS($compareOS = null) {
|
|
|
|
$windows = defined('PHP_WINDOWS_VERSION_MAJOR');
|
2014-01-27 20:28:37 +01:00
|
|
|
if ($compareOS) {
|
2014-01-01 17:59:29 +01:00
|
|
|
// Return bool whether OS equals $compareOS
|
2014-01-27 20:28:37 +01:00
|
|
|
if ($compareOS == self::OS_WIN) {
|
2014-01-01 17:59:29 +01:00
|
|
|
return $windows;
|
|
|
|
}
|
|
|
|
return !$windows;
|
|
|
|
}
|
|
|
|
// Return OS
|
2014-01-27 20:28:37 +01:00
|
|
|
if ($windows) {
|
2014-01-01 17:59:29 +01:00
|
|
|
return self::OS_WIN;
|
|
|
|
}
|
|
|
|
return self::OS_UNIX;
|
|
|
|
}
|
|
|
|
|
2014-01-01 19:25:51 +01: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
|
|
|
|
*/
|
|
|
|
public function command_Shutdown(array $chat, Player $player) {
|
2014-01-31 16:55:01 +01:00
|
|
|
if (!$this->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_SHUTDOWN)) {
|
2014-01-01 19:25:51 +01:00
|
|
|
$this->authenticationManager->sendNotAllowed($player);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$this->quit("ManiaControl Shutdown requested by '{$player->login}'!");
|
2013-11-24 23:55:54 +01:00
|
|
|
}
|
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
/**
|
|
|
|
* Quit ManiaControl and log the given message
|
2014-05-02 17:40:47 +02:00
|
|
|
*
|
2013-12-31 12:42:07 +01:00
|
|
|
* @param string $message
|
2013-11-10 17:29:21 +01:00
|
|
|
*/
|
2014-01-01 19:25:51 +01:00
|
|
|
public function quit($message = null) {
|
2014-01-27 20:28:37 +01:00
|
|
|
if ($message) {
|
2014-01-10 13:08:26 +01:00
|
|
|
$this->log($message);
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-01 19:25:51 +01:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle PHP Process Shutdown
|
|
|
|
*/
|
|
|
|
public function handleShutdown() {
|
2013-12-09 15:43:08 +01:00
|
|
|
// OnShutdown callback
|
2014-02-19 15:44:00 +01:00
|
|
|
$this->callbackManager->triggerCallback(CallbackManager::CB_ONSHUTDOWN);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-01 19:25:51 +01:00
|
|
|
// Announce quit
|
|
|
|
$this->chat->sendInformation('ManiaControl shutting down.');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-03-01 10:49:07 +01:00
|
|
|
if ($this->client) {
|
|
|
|
try {
|
|
|
|
// Hide manialinks
|
|
|
|
$this->client->sendHideManialinkPage();
|
|
|
|
// Close the client connection
|
|
|
|
$this->client->delete($this->server->ip, $this->server->port);
|
2014-05-02 17:40:47 +02:00
|
|
|
} catch (TransportException $e) {
|
2014-03-01 10:49:07 +01:00
|
|
|
$this->errorHandler->triggerDebugNotice($e->getMessage() . " File: " . $e->getFile() . " Line: " . $e->getLine());
|
2014-02-27 15:03:01 +01:00
|
|
|
}
|
2014-02-01 21:37:38 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-03-20 16:19:50 +01:00
|
|
|
// Check and Trigger Fatal Errors
|
2014-02-13 20:41:55 +01:00
|
|
|
$error = error_get_last();
|
|
|
|
if ($error && ($error['type'] & E_FATAL)) {
|
|
|
|
$this->errorHandler->errorHandler($error['type'], $error['message'], $error['file'], $error['line']);
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-03-20 16:19:50 +01:00
|
|
|
// Disable Garbage Collector
|
2014-02-22 12:49:59 +01:00
|
|
|
$this->collectGarbage();
|
2014-02-22 11:14:35 +01:00
|
|
|
gc_disable();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-31 18:24:40 +01:00
|
|
|
$this->log('Quitting ManiaControl!');
|
2013-11-10 17:29:21 +01:00
|
|
|
exit();
|
|
|
|
}
|
|
|
|
|
2014-01-01 17:59:29 +01:00
|
|
|
/**
|
2014-05-02 17:40:47 +02:00
|
|
|
* Collect Garbage
|
2014-01-01 17:59:29 +01:00
|
|
|
*/
|
2014-05-02 17:40:47 +02:00
|
|
|
public function collectGarbage() {
|
|
|
|
gc_collect_cycles();
|
2014-01-01 17:59:29 +01:00
|
|
|
}
|
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
/**
|
|
|
|
* Run ManiaControl
|
|
|
|
*/
|
|
|
|
public function run() {
|
2013-12-31 18:24:40 +01:00
|
|
|
$this->log('Starting ManiaControl v' . self::VERSION . '!');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-09 15:43:08 +01:00
|
|
|
// Register shutdown handler
|
2014-01-01 19:25:51 +01:00
|
|
|
register_shutdown_function(array($this, 'handleShutdown'));
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-15 21:48:23 +01:00
|
|
|
// Connect to server
|
|
|
|
$this->connect();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-04-14 12:18:44 +02:00
|
|
|
// Check if the version of the server is high enough
|
|
|
|
$version = $this->client->getVersion();
|
2014-05-01 20:21:40 +02:00
|
|
|
if ($version->build < self::MIN_DEDIVERSION) {
|
2014-05-02 04:04:13 +02:00
|
|
|
trigger_error("The Server has Version '{$version->build}', while at least '" . self::MIN_DEDIVERSION . "' is required!", E_USER_ERROR);
|
2014-04-30 00:19:18 +02:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-09 15:43:08 +01:00
|
|
|
// OnInit callback
|
2014-02-19 15:44:00 +01:00
|
|
|
$this->callbackManager->triggerCallback(CallbackManager::CB_ONINIT);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-18 10:26:32 +01:00
|
|
|
// Load plugins
|
|
|
|
$this->pluginManager->loadPlugins();
|
2014-05-02 04:04:13 +02:00
|
|
|
$this->updateManager->pluginUpdateManager->checkPluginsUpdate();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-12 21:07:54 +01:00
|
|
|
// AfterInit callback
|
2014-02-19 15:44:00 +01:00
|
|
|
$this->callbackManager->triggerCallback(CallbackManager::CB_AFTERINIT);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-03-20 16:19:50 +01:00
|
|
|
// Enable Garbage Collecting
|
2014-02-22 11:14:35 +01:00
|
|
|
gc_enable();
|
|
|
|
$this->timerManager->registerTimerListening($this, 'collectGarbage', 1000 * 60);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-10 13:08:26 +01:00
|
|
|
// Announce ManiaControl
|
|
|
|
$this->chat->sendInformation('ManiaControl v' . self::VERSION . ' successfully started!');
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-10 13:08:26 +01:00
|
|
|
// Loading finished
|
|
|
|
$this->log('Loading completed!');
|
2014-02-13 20:41:55 +01:00
|
|
|
$this->log('Link: maniaplanet://#join=' . $this->server->login . '@' . $this->server->titleId);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Main loop
|
2014-05-01 20:21:40 +02:00
|
|
|
while (!$this->shutdownRequested) {
|
2013-11-10 17:29:21 +01:00
|
|
|
$loopStart = microtime(true);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Disable script timeout
|
2014-01-20 20:51:03 +01:00
|
|
|
set_time_limit(self::SCRIPT_TIMEOUT);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-14 13:51:23 +01:00
|
|
|
try {
|
|
|
|
// Manager callbacks
|
|
|
|
$this->callbackManager->manageCallbacks();
|
2014-05-02 17:40:47 +02:00
|
|
|
} catch (TransportException $e) {
|
2014-04-19 00:32:34 +02:00
|
|
|
$this->log("Connection interrupted!");
|
2014-03-20 16:19:50 +01:00
|
|
|
// TODO remove
|
2014-03-01 10:49:07 +01:00
|
|
|
if ($this->errorHandler) {
|
2014-04-28 19:12:40 +02:00
|
|
|
$this->errorHandler->exceptionHandler($e, false);
|
2014-03-01 10:46:28 +01:00
|
|
|
}
|
2014-02-14 18:17:05 +01:00
|
|
|
$this->quit($e->getMessage());
|
2014-02-14 13:51:23 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-02-14 13:52:20 +01:00
|
|
|
// Manage FileReader
|
|
|
|
$this->fileReader->appendData();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Yield for next tick
|
2014-01-31 16:55:01 +01:00
|
|
|
$loopEnd = microtime(true);
|
2014-05-02 17:40:47 +02:00
|
|
|
|
|
|
|
$sleepTime = (int)(2000 - ($loopEnd - $loopStart) * 1000000);
|
2014-01-27 20:28:37 +01:00
|
|
|
if ($sleepTime > 0) {
|
2013-11-10 17:29:21 +01:00
|
|
|
usleep($sleepTime);
|
|
|
|
}
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Shutdown
|
2013-12-09 15:43:08 +01:00
|
|
|
$this->quit();
|
2013-11-10 17:29:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect to ManiaPlanet server
|
|
|
|
*/
|
|
|
|
private function connect() {
|
|
|
|
// Load remote client
|
2014-04-27 15:12:09 +02:00
|
|
|
$this->server->loadConfig();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-03-20 16:19:50 +01:00
|
|
|
$this->log("Connecting to server at {$this->server->config->host}:{$this->server->config->port}...");
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-17 16:32:53 +01:00
|
|
|
try {
|
2014-04-19 00:32:34 +02:00
|
|
|
$this->client = Connection::factory($this->server->config->host, $this->server->config->port, self::CONNECT_TIMEOUT, $this->server->config->login, $this->server->config->pass);
|
2014-05-02 17:40:47 +02:00
|
|
|
} catch (Exception $e) {
|
2014-03-20 16:19:50 +01:00
|
|
|
trigger_error("Couldn't authenticate on server with user '{$this->server->config->login}'! " . $e->getMessage(), E_USER_ERROR);
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Enable callback system
|
2014-02-13 14:21:25 +01:00
|
|
|
$this->client->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-03-01 10:49:07 +01:00
|
|
|
try {
|
|
|
|
if (!$this->server->waitForStatus(4)) {
|
|
|
|
trigger_error("Server couldn't get ready!", E_USER_ERROR);
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
} catch (Exception $e) {
|
2014-03-20 16:19:50 +01:00
|
|
|
// TODO remove
|
2014-03-01 10:49:07 +01:00
|
|
|
if ($this->errorHandler) {
|
|
|
|
$this->errorHandler->triggerDebugNotice("Fatal Exception: " . $e->getMessage() . " Trace: " . $e->getTraceAsString());
|
|
|
|
}
|
|
|
|
$this->quit($e->getMessage());
|
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
|
2013-12-31 14:50:45 +01:00
|
|
|
$this->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-01-16 17:19:01 +01:00
|
|
|
$this->client->sendHideManialinkPage();
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-11-10 17:29:21 +01:00
|
|
|
// Enable script callbacks if needed
|
2014-04-19 00:32:34 +02:00
|
|
|
if ($this->server->getGameMode() != 0) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-17 16:32:53 +01:00
|
|
|
try {
|
|
|
|
$scriptSettings = $this->client->getModeScriptSettings();
|
2014-05-02 17:40:47 +02:00
|
|
|
} catch (NotInScriptModeException $e) {
|
2014-04-19 22:59:11 +02:00
|
|
|
return;
|
2013-12-09 15:43:08 +01:00
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-04-19 00:32:34 +02:00
|
|
|
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2013-12-09 15:43:08 +01:00
|
|
|
$scriptSettings['S_UseScriptCallbacks'] = true;
|
2014-01-17 16:32:53 +01:00
|
|
|
try {
|
|
|
|
$this->client->setModeScriptSettings($scriptSettings);
|
2014-05-02 17:40:47 +02:00
|
|
|
} catch (Exception $e) {
|
2014-05-01 20:21:40 +02:00
|
|
|
// TODO temp added 19.04.2014
|
2014-04-27 15:21:57 +02:00
|
|
|
$this->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage());
|
2014-05-02 17:40:47 +02:00
|
|
|
|
2014-01-18 22:06:07 +01:00
|
|
|
trigger_error("Couldn't set mode script settings to enable script callbacks. " . $e->getMessage());
|
2013-12-09 15:43:08 +01:00
|
|
|
return;
|
2013-11-10 17:29:21 +01:00
|
|
|
}
|
2013-12-31 14:50:45 +01:00
|
|
|
$this->log('Script Callbacks successfully enabled!');
|
2013-11-10 17:29:21 +01:00
|
|
|
}
|
|
|
|
}
|