communication listener implemented scriptsetting methods
This commit is contained in:
parent
cd5a9bf9ac
commit
e572412bbb
@ -16,6 +16,16 @@ interface CommunicationMethods {
|
|||||||
*/
|
*/
|
||||||
const RESTART_MANIA_CONTROL = "ManiaControl.Restart";
|
const RESTART_MANIA_CONTROL = "ManiaControl.Restart";
|
||||||
|
|
||||||
|
/** Provides the ModeScriptSettings
|
||||||
|
* no Parameters
|
||||||
|
*/
|
||||||
|
const GET_SCRIPT_SETTINGS = "ScriptSettings.GetScriptSettings";
|
||||||
|
|
||||||
|
/** Set ModeScriptSettings
|
||||||
|
* Required Parameter
|
||||||
|
* - scriptSettings (array(settingName1 => Value1, settingName2 => value2...))
|
||||||
|
*/
|
||||||
|
const SET_SCRIPT_SETTINGS = "ScriptSettings.SetScriptSettings";
|
||||||
|
|
||||||
/** Restarts the Current Map
|
/** Restarts the Current Map
|
||||||
* no Parameters
|
* no Parameters
|
||||||
|
@ -14,6 +14,9 @@ use FML\Script\Script;
|
|||||||
use ManiaControl\Admin\AuthenticationManager;
|
use ManiaControl\Admin\AuthenticationManager;
|
||||||
use ManiaControl\Callbacks\CallbackListener;
|
use ManiaControl\Callbacks\CallbackListener;
|
||||||
use ManiaControl\Callbacks\Callbacks;
|
use ManiaControl\Callbacks\Callbacks;
|
||||||
|
use ManiaControl\Communication\CommunicationAnswer;
|
||||||
|
use ManiaControl\Communication\CommunicationListener;
|
||||||
|
use ManiaControl\Communication\CommunicationMethods;
|
||||||
use ManiaControl\Logger;
|
use ManiaControl\Logger;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
@ -26,7 +29,7 @@ use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
|||||||
* @copyright 2014-2015 ManiaControl Team
|
* @copyright 2014-2015 ManiaControl Team
|
||||||
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
||||||
*/
|
*/
|
||||||
class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
class ScriptSettings implements ConfiguratorMenu, CallbackListener, CommunicationListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
@ -61,6 +64,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
|
|
||||||
|
//TODO remove to somewhere cleaner
|
||||||
|
//Communication Listenings
|
||||||
|
$this->initalizeCommunicationListenings();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -149,8 +156,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* Handle Begin Map Callback
|
* Handle Begin Map Callback
|
||||||
*/
|
*/
|
||||||
public function onBeginMap() {
|
public function onBeginMap() {
|
||||||
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)) {
|
||||||
) {
|
|
||||||
$this->loadSettingsFromDatabase();
|
$this->loadSettingsFromDatabase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -282,8 +288,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
* @see \ManiaControl\Configurators\ConfiguratorMenu::saveConfigData()
|
||||||
*/
|
*/
|
||||||
public function saveConfigData(array $configData, Player $player) {
|
public function saveConfigData(array $configData, Player $player) {
|
||||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS)) {
|
||||||
) {
|
|
||||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -327,6 +332,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply the Array of new Script Settings
|
* Apply the Array of new Script Settings
|
||||||
*
|
*
|
||||||
@ -408,4 +414,61 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
}
|
}
|
||||||
return (string) $value;
|
return (string) $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the communication Listenings
|
||||||
|
*/
|
||||||
|
private function initalizeCommunicationListenings() {
|
||||||
|
//Communication Listenings
|
||||||
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GET_SCRIPT_SETTINGS, $this, function ($data) {
|
||||||
|
try {
|
||||||
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||||
|
} catch (GameModeException $e) {
|
||||||
|
return new CommunicationAnswer($e->getMessage(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CommunicationAnswer($scriptSettings);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::SET_SCRIPT_SETTINGS, $this, function ($data) {
|
||||||
|
if (!is_object($data) || !property_exists($data, "scriptSettings")) {
|
||||||
|
return new CommunicationAnswer("No valid ScriptSettings provided!", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||||
|
} catch (GameModeException $e) {
|
||||||
|
return new CommunicationAnswer($e->getMessage(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newSettings = array();
|
||||||
|
foreach ($data->scriptSettings as $name => $value) {
|
||||||
|
if (!isset($scriptSettings[$name])) {
|
||||||
|
var_dump('no setting ' . $name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value == $scriptSettings[$name]) {
|
||||||
|
// Not changed
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newSettings[$name] = $value;
|
||||||
|
settype($newSettings[$name], gettype($scriptSettings[$name]));
|
||||||
|
}
|
||||||
|
|
||||||
|
//No new Settings
|
||||||
|
if (empty($newSettings)) {
|
||||||
|
return new CommunicationAnswer(array("success" => true));
|
||||||
|
}
|
||||||
|
|
||||||
|
//Trigger Scriptsettings Changed Callback
|
||||||
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED);
|
||||||
|
|
||||||
|
//Set the Settings
|
||||||
|
$success = $this->maniaControl->getClient()->setModeScriptSettings($newSettings);
|
||||||
|
|
||||||
|
return new CommunicationAnswer(array("success" => $success));
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -887,6 +887,9 @@ class MapManager implements CallbackListener, CommunicationListener {
|
|||||||
return count($this->maps);
|
return count($this->maps);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes the Communication Listenings
|
||||||
|
*/
|
||||||
private function initalizeCommunicationListenings() {
|
private function initalizeCommunicationListenings() {
|
||||||
// Communication Listenings
|
// Communication Listenings
|
||||||
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GET_CURRENT_MAP, $this, function ($data) {
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GET_CURRENT_MAP, $this, function ($data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user