script manager class

improved script callback enabling
This commit is contained in:
Steffen Schröder 2014-05-06 02:17:11 +02:00
parent 27b7fba2cc
commit 8148da6753
3 changed files with 65 additions and 29 deletions

View File

@ -418,9 +418,7 @@ class ManiaControl implements CommandListener, TimerListener {
} }
} catch (Exception $e) { } catch (Exception $e) {
// TODO remove // TODO remove
if ($this->errorHandler) {
$this->errorHandler->handleException($e, false); $this->errorHandler->handleException($e, false);
}
$this->quit($e->getMessage()); $this->quit($e->getMessage());
} }
@ -430,31 +428,7 @@ class ManiaControl implements CommandListener, TimerListener {
// Hide old widgets // Hide old widgets
$this->client->sendHideManialinkPage(); $this->client->sendHideManialinkPage();
// Enable script callbacks if needed // Enable script callbacks
if ($this->server->getGameMode() != 0) { $this->server->scriptManager->enableScriptCallbacks();
return;
}
try {
$scriptSettings = $this->client->getModeScriptSettings();
} catch (NotInScriptModeException $e) {
return;
}
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
return;
}
$scriptSettings['S_UseScriptCallbacks'] = true;
try {
$this->client->setModeScriptSettings($scriptSettings);
} catch (Exception $e) {
// TODO temp added 19.04.2014
$this->errorHandler->triggerDebugNotice("Exception line 437 ManiaControl.php " . $e->getMessage());
trigger_error("Couldn't set mode script settings to enable script callbacks. " . $e->getMessage());
return;
}
$this->log('Script Callbacks successfully enabled!');
} }
} }

View File

@ -0,0 +1,60 @@
<?php
namespace ManiaControl\Server;
use ManiaControl\ManiaControl;
use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException;
/**
* Manager for Game Mode Script related Stuff
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class ScriptManager {
/*
* Private Properties
*/
public $maniaControl = null;
/**
* Construct a new Script Manager
*
* @param ManiaControl $maniaControl
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
}
/**
* Enable Script Callbacks
*
* @param bool $enable
* @return bool
*/
public function enableScriptCallbacks($enable = true) {
try {
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
} catch (NotInScriptModeException $e) {
return false;
}
if (!array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
return false;
}
$scriptSettings['S_UseScriptCallbacks'] = (bool)$enable;
try {
$this->maniaControl->client->setModeScriptSettings($scriptSettings);
} catch (Exception $e) {
// TODO temp added 19.04.2014
$this->maniaControl->errorHandler->handleException($e, false);
trigger_error("Couldn't set mode script settings to enable script callbacks. " . $e->getMessage());
return false;
}
$this->maniaControl->log('Script Callbacks successfully enabled!');
return false;
}
}

View File

@ -39,6 +39,7 @@ class Server implements CallbackListener {
public $serverCommands = null; public $serverCommands = null;
public $usageReporter = null; public $usageReporter = null;
public $rankingManager = null; public $rankingManager = null;
public $scriptManager = null;
/* /*
* Private Properties * Private Properties
@ -58,6 +59,7 @@ class Server implements CallbackListener {
$this->serverCommands = new ServerCommands($maniaControl); $this->serverCommands = new ServerCommands($maniaControl);
$this->usageReporter = new UsageReporter($maniaControl); $this->usageReporter = new UsageReporter($maniaControl);
$this->rankingManager = new RankingManager($maniaControl); $this->rankingManager = new RankingManager($maniaControl);
$this->scriptManager = new ScriptManager($maniaControl);
// Register for callbacks // Register for callbacks
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit'); $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');