script manager class
improved script callback enabling
This commit is contained in:
parent
27b7fba2cc
commit
8148da6753
@ -418,9 +418,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
// TODO remove
|
||||
if ($this->errorHandler) {
|
||||
$this->errorHandler->handleException($e, false);
|
||||
}
|
||||
$this->errorHandler->handleException($e, false);
|
||||
$this->quit($e->getMessage());
|
||||
}
|
||||
|
||||
@ -430,31 +428,7 @@ class ManiaControl implements CommandListener, TimerListener {
|
||||
// Hide old widgets
|
||||
$this->client->sendHideManialinkPage();
|
||||
|
||||
// Enable script callbacks if needed
|
||||
if ($this->server->getGameMode() != 0) {
|
||||
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!');
|
||||
// Enable script callbacks
|
||||
$this->server->scriptManager->enableScriptCallbacks();
|
||||
}
|
||||
}
|
||||
|
60
application/core/Server/ScriptManager.php
Normal file
60
application/core/Server/ScriptManager.php
Normal 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;
|
||||
}
|
||||
}
|
@ -39,6 +39,7 @@ class Server implements CallbackListener {
|
||||
public $serverCommands = null;
|
||||
public $usageReporter = null;
|
||||
public $rankingManager = null;
|
||||
public $scriptManager = null;
|
||||
|
||||
/*
|
||||
* Private Properties
|
||||
@ -58,6 +59,7 @@ class Server implements CallbackListener {
|
||||
$this->serverCommands = new ServerCommands($maniaControl);
|
||||
$this->usageReporter = new UsageReporter($maniaControl);
|
||||
$this->rankingManager = new RankingManager($maniaControl);
|
||||
$this->scriptManager = new ScriptManager($maniaControl);
|
||||
|
||||
// Register for callbacks
|
||||
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit');
|
||||
|
Loading…
Reference in New Issue
Block a user