moved scriptmanager
This commit is contained in:
parent
602ec5b7fc
commit
f2ab40a50f
74
core/Script/ScriptManager.php
Normal file
74
core/Script/ScriptManager.php
Normal file
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace ManiaControl\Script;
|
||||
|
||||
use ManiaControl\Logger;
|
||||
use ManiaControl\ManiaControl;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||
|
||||
/**
|
||||
* Manager for Game Mode Script related Stuff
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ScriptManager {
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
private $isScriptMode = null;
|
||||
|
||||
/**
|
||||
* Construct a new script manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable script callbacks
|
||||
*
|
||||
* @param bool $enable
|
||||
* @return bool
|
||||
*/
|
||||
public function enableScriptCallbacks() {
|
||||
if (!$this->isScriptMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
var_dump("test");
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO remove later, than only the last 2 lines are needed in future
|
||||
if (array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
||||
$scriptSettings['S_UseScriptCallbacks'] = true;
|
||||
$this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
|
||||
}
|
||||
|
||||
$this->maniaControl->getModeScriptEventManager()->enableCallbacks();
|
||||
Logger::logInfo("Script Callbacks successfully enabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the Server is running in Script Mode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isScriptMode() {
|
||||
if (is_null($this->isScriptMode)) {
|
||||
$gameMode = $this->maniaControl->getClient()->getGameMode();
|
||||
$this->isScriptMode = ($gameMode === 0);
|
||||
}
|
||||
return $this->isScriptMode;
|
||||
}
|
||||
}
|
@ -1,74 +1,4 @@
|
||||
<?php
|
||||
// Self Destroy due moving (added 26.03.2017, remove later)
|
||||
unlink(__FILE__);
|
||||
|
||||
namespace ManiaControl\Server;
|
||||
|
||||
use ManiaControl\Logger;
|
||||
use ManiaControl\ManiaControl;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||
|
||||
/**
|
||||
* Manager for Game Mode Script related Stuff
|
||||
*
|
||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||
* @copyright 2014-2017 ManiaControl Team
|
||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||
*/
|
||||
class ScriptManager {
|
||||
/*
|
||||
* Private properties
|
||||
*/
|
||||
/** @var ManiaControl $maniaControl */
|
||||
private $maniaControl = null;
|
||||
private $isScriptMode = null;
|
||||
|
||||
/**
|
||||
* Construct a new script manager instance
|
||||
*
|
||||
* @param ManiaControl $maniaControl
|
||||
*/
|
||||
public function __construct(ManiaControl $maniaControl) {
|
||||
$this->maniaControl = $maniaControl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable script callbacks
|
||||
*
|
||||
* @param bool $enable
|
||||
* @return bool
|
||||
*/
|
||||
public function enableScriptCallbacks() {
|
||||
if (!$this->isScriptMode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||
} catch (GameModeException $e) {
|
||||
var_dump("test");
|
||||
return false;
|
||||
}
|
||||
|
||||
//TODO remove later, than only the last 2 lines are needed in future
|
||||
if (array_key_exists('S_UseScriptCallbacks', $scriptSettings)) {
|
||||
$scriptSettings['S_UseScriptCallbacks'] = true;
|
||||
$this->maniaControl->getClient()->setModeScriptSettings($scriptSettings);
|
||||
}
|
||||
|
||||
$this->maniaControl->getModeScriptEventManager()->enableCallbacks();
|
||||
Logger::logInfo("Script Callbacks successfully enabled!");
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the Server is running in Script Mode
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isScriptMode() {
|
||||
if (is_null($this->isScriptMode)) {
|
||||
$gameMode = $this->maniaControl->getClient()->getGameMode();
|
||||
$this->isScriptMode = ($gameMode === 0);
|
||||
}
|
||||
return $this->isScriptMode;
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ use ManiaControl\Commands\CommandListener;
|
||||
use ManiaControl\Logger;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Players\Player;
|
||||
use ManiaControl\Script\ScriptManager;
|
||||
use ManiaControl\Utils\CommandLineHelper;
|
||||
use Maniaplanet\DedicatedServer\Xmlrpc\Exception;
|
||||
|
||||
@ -56,7 +57,7 @@ class Server implements CallbackListener, CommandListener {
|
||||
* @see getRankingManager()
|
||||
*/
|
||||
public $rankingManager = null;
|
||||
/** @var ScriptManager $scriptManager
|
||||
/** @var \ManiaControl\Script\ScriptManager $scriptManager
|
||||
* @deprecated
|
||||
* @see getScriptManager()
|
||||
*/
|
||||
@ -178,7 +179,7 @@ class Server implements CallbackListener, CommandListener {
|
||||
/**
|
||||
* Return the script manager
|
||||
*
|
||||
* @return ScriptManager
|
||||
* @return \ManiaControl\Script\ScriptManager
|
||||
*/
|
||||
public function getScriptManager() {
|
||||
return $this->scriptManager;
|
||||
|
Loading…
Reference in New Issue
Block a user