Add graphical support for Legacy-Modes
This commit is contained in:
parent
38c239202f
commit
4532f2f5e7
@ -45,12 +45,25 @@ interface CommunicationMethods {
|
|||||||
*/
|
*/
|
||||||
const SET_SERVER_OPTIONS = "ServerOptions.SetServerOptions";
|
const SET_SERVER_OPTIONS = "ServerOptions.SetServerOptions";
|
||||||
|
|
||||||
/** Provides the ModeScriptSettings
|
/** Provides the GameModeSettings
|
||||||
|
* no Parameters
|
||||||
|
*/
|
||||||
|
const GET_GAMEMODE_SETTINGS = "GameModeSettings.GetGameModeSettings";
|
||||||
|
|
||||||
|
/** Set GameModeSettings
|
||||||
|
* Required Parameter
|
||||||
|
* - gameModeSettings (array(settingName1 => value1, settingName2 => value2...))
|
||||||
|
*/
|
||||||
|
const SET_GAMEMODE_SETTINGS = "GameModeSettings.SetGameModeSettings";
|
||||||
|
|
||||||
|
/** @deprecated
|
||||||
|
* Provides the ModeScriptSettings
|
||||||
* no Parameters
|
* no Parameters
|
||||||
*/
|
*/
|
||||||
const GET_SCRIPT_SETTINGS = "ScriptSettings.GetScriptSettings";
|
const GET_SCRIPT_SETTINGS = "ScriptSettings.GetScriptSettings";
|
||||||
|
|
||||||
/** Set ModeScriptSettings
|
/** @deprecated
|
||||||
|
* Set ModeScriptSettings
|
||||||
* Required Parameter
|
* Required Parameter
|
||||||
* - scriptSettings (array(settingName1 => value1, settingName2 => value2...))
|
* - scriptSettings (array(settingName1 => value1, settingName2 => value2...))
|
||||||
*/
|
*/
|
||||||
|
@ -54,8 +54,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
private $serverOptionsMenu = null;
|
private $serverOptionsMenu = null;
|
||||||
/** @var ServerUIPropertiesMenu $serverUIPropertiesMenu */
|
/** @var ServerUIPropertiesMenu $serverUIPropertiesMenu */
|
||||||
private $serverUIPropertiesMenu = null;
|
private $serverUIPropertiesMenu = null;
|
||||||
/** @var ScriptSettings $scriptSettings */
|
/** @var GameModeSettings $gameModeSettings */
|
||||||
private $scriptSettings = null;
|
private $gameModeSettings = null;
|
||||||
/** @var VoteRatiosMenu $voteRatiosMenu */
|
/** @var VoteRatiosMenu $voteRatiosMenu */
|
||||||
private $voteRatiosMenu = null;
|
private $voteRatiosMenu = null;
|
||||||
/** @var ManiaControlSettings $maniaControlSettings */
|
/** @var ManiaControlSettings $maniaControlSettings */
|
||||||
@ -101,8 +101,8 @@ class Configurator implements CallbackListener, CommandListener, ManialinkPageAn
|
|||||||
$this->addMenu($this->serverUIPropertiesMenu);
|
$this->addMenu($this->serverUIPropertiesMenu);
|
||||||
|
|
||||||
// Create script settings
|
// Create script settings
|
||||||
$this->scriptSettings = new ScriptSettings($maniaControl);
|
$this->gameModeSettings = new GameModeSettings($maniaControl);
|
||||||
$this->addMenu($this->scriptSettings);
|
$this->addMenu($this->gameModeSettings);
|
||||||
|
|
||||||
// Create vote ratios menu
|
// Create vote ratios menu
|
||||||
$this->voteRatiosMenu = new VoteRatiosMenu($maniaControl);
|
$this->voteRatiosMenu = new VoteRatiosMenu($maniaControl);
|
||||||
|
@ -20,25 +20,34 @@ use ManiaControl\Communication\CommunicationMethods;
|
|||||||
use ManiaControl\Logger;
|
use ManiaControl\Logger;
|
||||||
use ManiaControl\ManiaControl;
|
use ManiaControl\ManiaControl;
|
||||||
use ManiaControl\Players\Player;
|
use ManiaControl\Players\Player;
|
||||||
|
use Maniaplanet\DedicatedServer\Structures\GameInfos;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
|
||||||
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class offering a Configurator for Script Settings
|
* Class offering a Configurator for Mode Settings
|
||||||
*
|
*
|
||||||
* @author ManiaControl Team <mail@maniacontrol.com>
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
||||||
* @copyright 2014-2020 ManiaControl Team
|
* @copyright 2014-2020 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, CommunicationListener {
|
class GameModeSettings implements ConfiguratorMenu, CallbackListener, CommunicationListener {
|
||||||
/*
|
/*
|
||||||
* Constants
|
* Constants
|
||||||
*/
|
*/
|
||||||
const ACTION_PREFIX_SETTING = 'ScriptSetting.';
|
const ACTION_PREFIX_SETTING = 'GameModeSetting.';
|
||||||
const CB_SCRIPTSETTING_CHANGED = 'ScriptSettings.SettingChanged';
|
const CB_GAMEMODESETTING_CHANGED = 'GameModeSettings.SettingChanged';
|
||||||
const CB_SCRIPTSETTINGS_CHANGED = 'ScriptSettings.SettingsChanged';
|
const CB_GAMEMODESETTINGS_CHANGED = 'GameModeSettings.SettingsChanged';
|
||||||
|
/** @deprecated */
|
||||||
|
const CB_SCRIPTSETTING_CHANGED = 'GameModeSettings.SettingChanged';
|
||||||
|
/** @deprecated */
|
||||||
|
const CB_SCRIPTSETTINGS_CHANGED = 'GameModeSettings.SettingsChanged';
|
||||||
|
const TABLE_GAMEMODE_SETTINGS = 'mc_gamemodesettings';
|
||||||
|
/** @deprecated */
|
||||||
const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings';
|
const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings';
|
||||||
const SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN = 'Load Stored Script-Settings on Map-Begin';
|
const SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN = 'Load Stored GameMode-Settings on Map-Begin';
|
||||||
|
const SETTING_PERMISSION_CHANGE_MODE_SETTINGS = 'Change GameMode-Settings';
|
||||||
|
/** @deprecated */
|
||||||
const SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS = 'Change Script-Settings';
|
const SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS = 'Change Script-Settings';
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -64,7 +73,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, false);
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, false);
|
||||||
|
|
||||||
// Permissions
|
// Permissions
|
||||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MODE_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||||
|
|
||||||
//TODO remove to somewhere cleaner
|
//TODO remove to somewhere cleaner
|
||||||
//Communication Listenings
|
//Communication Listenings
|
||||||
@ -78,14 +87,14 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
*/
|
*/
|
||||||
private function initTables() {
|
private function initTables() {
|
||||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||||
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_GAMEMODE_SETTINGS . "` (
|
||||||
`index` int(11) NOT NULL AUTO_INCREMENT,
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
`serverIndex` int(11) NOT NULL,
|
`serverIndex` int(11) NOT NULL,
|
||||||
`settingName` varchar(100) NOT NULL DEFAULT '',
|
`settingName` varchar(100) NOT NULL DEFAULT '',
|
||||||
`settingValue` varchar(500) NOT NULL DEFAULT '',
|
`settingValue` varchar(500) NOT NULL DEFAULT '',
|
||||||
PRIMARY KEY (`index`),
|
PRIMARY KEY (`index`),
|
||||||
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
||||||
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Script Settings' AUTO_INCREMENT=1;";
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Mode Settings' AUTO_INCREMENT=1;";
|
||||||
|
|
||||||
$statement = $mysqli->prepare($query);
|
$statement = $mysqli->prepare($query);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
@ -98,17 +107,8 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO remove later again (added in v0.165)
|
$dropQuery = "DROP TABLE IF EXISTS `" . self::TABLE_SCRIPT_SETTINGS . "`;";
|
||||||
//For Mysql 5.7 add Default Values
|
$result = $mysqli->query($dropQuery);
|
||||||
$alterQuery = "ALTER TABLE `" . self::TABLE_SCRIPT_SETTINGS . "` CHANGE settingName settingName varchar(100) DEFAULT ''";
|
|
||||||
$result = $mysqli->query($alterQuery);
|
|
||||||
if (!$result) {
|
|
||||||
trigger_error($mysqli->error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
$alterQuery = "ALTER TABLE `" . self::TABLE_SCRIPT_SETTINGS . "` CHANGE settingValue settingValue varchar(500) DEFAULT ''";
|
|
||||||
$result = $mysqli->query($alterQuery);
|
|
||||||
if (!$result) {
|
if (!$result) {
|
||||||
trigger_error($mysqli->error);
|
trigger_error($mysqli->error);
|
||||||
return false;
|
return false;
|
||||||
@ -122,7 +122,42 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
* @see \ManiaControl\Configurator\ConfiguratorMenu::getTitle()
|
* @see \ManiaControl\Configurator\ConfiguratorMenu::getTitle()
|
||||||
*/
|
*/
|
||||||
public static function getTitle() {
|
public static function getTitle() {
|
||||||
return 'Script Settings';
|
return 'GameMode-Settings';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the settings of the GameMode into an Array
|
||||||
|
* @return array|false
|
||||||
|
*/
|
||||||
|
public function getGameModeSettingsArray() {
|
||||||
|
if ($this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
||||||
|
return $this->maniaControl->getClient()->getModeScriptSettings();
|
||||||
|
} else {
|
||||||
|
$gameModeSettings = get_object_vars($this->maniaControl->getClient()->getCurrentGameInfo());
|
||||||
|
foreach ($gameModeSettings as $name => $value) {
|
||||||
|
unset($gameModeSettings[$name]);
|
||||||
|
$gameModeSettings[ucfirst($name)] = $value;
|
||||||
|
}
|
||||||
|
return $gameModeSettings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the settings of the GameMode from an Array.
|
||||||
|
* Returns true, if successful.
|
||||||
|
* @param array $settings
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function setGameModeSettingsArray(array $settings) {
|
||||||
|
if ($this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
||||||
|
return $this->maniaControl->getClient()->setModeScriptSettings($settings);
|
||||||
|
} else {
|
||||||
|
$success = true;
|
||||||
|
foreach ($settings as $key => $value) {
|
||||||
|
$success &= $this->maniaControl->getClient()->execute('Set'.$key, array($value));
|
||||||
|
}
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -138,15 +173,16 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function loadSettingsFromDatabase() {
|
public function loadSettingsFromDatabase() {
|
||||||
|
$gameModeSettings = null;
|
||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
||||||
} catch (GameModeException $e) {
|
} catch (\Exception $e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||||
$serverIndex = $this->maniaControl->getServer()->index;
|
$serverIndex = $this->maniaControl->getServer()->index;
|
||||||
$query = "SELECT * FROM `" . self::TABLE_SCRIPT_SETTINGS . "`
|
$query = "SELECT * FROM `" . self::TABLE_GAMEMODE_SETTINGS . "`
|
||||||
WHERE serverIndex = {$serverIndex};";
|
WHERE serverIndex = {$serverIndex};";
|
||||||
$result = $mysqli->query($query);
|
$result = $mysqli->query($query);
|
||||||
if ($mysqli->error) {
|
if ($mysqli->error) {
|
||||||
@ -156,18 +192,24 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
|
|
||||||
$loadedSettings = array();
|
$loadedSettings = array();
|
||||||
while ($row = $result->fetch_object()) {
|
while ($row = $result->fetch_object()) {
|
||||||
if (!isset($scriptSettings[$row->settingName])) {
|
if (!isset($gameModeSettings[$row->settingName])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$loadedSettings[$row->settingName] = $row->settingValue;
|
$loadedSettings[$row->settingName] = $row->settingValue;
|
||||||
settype($loadedSettings[$row->settingName], gettype($scriptSettings[$row->settingName]));
|
settype($loadedSettings[$row->settingName], gettype($gameModeSettings[$row->settingName]));
|
||||||
}
|
}
|
||||||
$result->free();
|
$result->free();
|
||||||
if (empty($loadedSettings)) {
|
if (empty($loadedSettings)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->maniaControl->getClient()->setModeScriptSettings($loadedSettings);
|
try {
|
||||||
|
$this->setGameModeSettingsArray($loadedSettings);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -187,22 +229,25 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
$script->addFeature($paging);
|
$script->addFeature($paging);
|
||||||
$frame = new Frame();
|
$frame = new Frame();
|
||||||
|
|
||||||
|
$scriptParams = null;
|
||||||
|
$gameModeSettings = null;
|
||||||
|
$error = null;
|
||||||
try {
|
try {
|
||||||
$scriptInfo = $this->maniaControl->getClient()->getModeScriptInfo();
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
||||||
} catch (GameModeException $e) {
|
|
||||||
|
if ($this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
||||||
|
$scriptInfo = $this->maniaControl->getClient()->getModeScriptInfo();
|
||||||
|
$scriptParams = $scriptInfo->paramDescs;
|
||||||
|
} else {
|
||||||
|
$scriptParams = $gameModeSettings;
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
$label = new Label();
|
$label = new Label();
|
||||||
$frame->addChild($label);
|
$frame->addChild($label);
|
||||||
$label->setText($e->getMessage());
|
$label->setText($e->getMessage());
|
||||||
return $frame;
|
return $frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
$scriptParams = $scriptInfo->paramDescs;
|
|
||||||
|
|
||||||
try {
|
|
||||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
|
||||||
} catch (GameModeException $e) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
$pagerSize = 9.;
|
$pagerSize = 9.;
|
||||||
$settingHeight = 5.;
|
$settingHeight = 5.;
|
||||||
@ -236,12 +281,17 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
// Setting pages
|
// Setting pages
|
||||||
$pageFrame = null;
|
$pageFrame = null;
|
||||||
$posY = 0.;
|
$posY = 0.;
|
||||||
|
$index = 0;
|
||||||
|
|
||||||
foreach ($scriptParams as $index => $scriptParam) {
|
foreach ($scriptParams as $key => $scriptParam) {
|
||||||
/** @var \Maniaplanet\DedicatedServer\Structures\ScriptSettings $scriptParam */
|
$settingName = null;
|
||||||
$settingName = $scriptParam->name;
|
if ($this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
||||||
|
$settingName = $scriptParam->name;
|
||||||
|
} else {
|
||||||
|
$settingName = $key;
|
||||||
|
}
|
||||||
|
|
||||||
if (!isset($scriptSettings[$settingName])) {
|
if (!isset($gameModeSettings[$settingName])) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,43 +309,46 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
$nameLabel = new Label_Text();
|
$nameLabel = new Label_Text();
|
||||||
$settingFrame->addChild($nameLabel);
|
$settingFrame->addChild($nameLabel);
|
||||||
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
|
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
|
||||||
$nameLabel->setX($width * -0.46);
|
|
||||||
$nameLabel->setSize($width * 0.4, $settingHeight);
|
$nameLabel->setSize($width * 0.4, $settingHeight);
|
||||||
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
||||||
$nameLabel->setTextSize($labelTextSize);
|
|
||||||
$nameLabel->setText($settingName);
|
$nameLabel->setText($settingName);
|
||||||
|
$nameLabel->setTextSize($labelTextSize);
|
||||||
|
$nameLabel->setX($width * -0.46);
|
||||||
|
|
||||||
$settingValue = $scriptSettings[$settingName];
|
$settingValue = $gameModeSettings[$settingName];
|
||||||
|
|
||||||
if (is_bool($settingValue)) {
|
if (is_bool($settingValue)) {
|
||||||
// Boolean checkbox
|
// Boolean checkbox
|
||||||
$quad = new Quad();
|
$quad = new Quad();
|
||||||
$quad->setX($width / 2 * 0.545);
|
|
||||||
$quad->setSize(4, 4);
|
$quad->setSize(4, 4);
|
||||||
|
$quad->setX($width / 2 * 0.545);
|
||||||
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $settingName, $settingValue, $quad);
|
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $settingName, $settingValue, $quad);
|
||||||
$settingFrame->addChild($checkBox);
|
$settingFrame->addChild($checkBox);
|
||||||
} else {
|
} else {
|
||||||
// Value entry
|
// Value entry
|
||||||
$entry = new Entry();
|
$entry = new Entry();
|
||||||
$settingFrame->addChild($entry);
|
$settingFrame->addChild($entry);
|
||||||
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
|
||||||
$entry->setX($width / 2 * 0.55);
|
|
||||||
$entry->setTextSize(1);
|
|
||||||
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
|
||||||
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
|
||||||
$entry->setDefault($settingValue);
|
$entry->setDefault($settingValue);
|
||||||
|
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
||||||
|
$entry->setSize($width * 0.3, $settingHeight * 0.9);
|
||||||
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
||||||
|
$entry->setTextSize(1);
|
||||||
|
$entry->setX($width / 2 * 0.55);
|
||||||
}
|
}
|
||||||
|
|
||||||
$descriptionLabel = new Label();
|
if ($this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
||||||
$pageFrame->addChild($descriptionLabel);
|
$descriptionLabel = new Label();
|
||||||
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
|
$pageFrame->addChild($descriptionLabel);
|
||||||
$descriptionLabel->setPosition($width * -0.45, $height * -0.44);
|
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
|
||||||
$descriptionLabel->setSize($width * 0.7, $settingHeight);
|
$descriptionLabel->setPosition($width * -0.45, $height * -0.44);
|
||||||
$descriptionLabel->setTextSize($labelTextSize);
|
$descriptionLabel->setSize($width * 0.7, $settingHeight);
|
||||||
$descriptionLabel->setTranslate(true);
|
$descriptionLabel->setTextSize($labelTextSize);
|
||||||
$nameLabel->addTooltipLabelFeature($descriptionLabel, $scriptParam->desc);
|
$descriptionLabel->setTranslate(true);
|
||||||
|
$nameLabel->addTooltipLabelFeature($descriptionLabel, $scriptParam->desc);
|
||||||
|
}
|
||||||
|
|
||||||
$posY -= $settingHeight;
|
$posY -= $settingHeight;
|
||||||
|
$index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $frame;
|
return $frame;
|
||||||
@ -305,7 +358,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
* @see \ManiaControl\Configurator\ConfiguratorMenu::saveConfigData()
|
* @see \ManiaControl\Configurator\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_MODE_SETTINGS)) {
|
||||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -313,9 +366,10 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$gameModeSettings = null;
|
||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
||||||
} catch (GameModeException $e) {
|
} catch (\Exception $e) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,25 +378,25 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
$newSettings = array();
|
$newSettings = array();
|
||||||
foreach ($configData[3] as $setting) {
|
foreach ($configData[3] as $setting) {
|
||||||
$settingName = substr($setting['Name'], $prefixLength);
|
$settingName = substr($setting['Name'], $prefixLength);
|
||||||
if (!isset($scriptSettings[$settingName])) {
|
if (!isset($gameModeSettings[$settingName])) {
|
||||||
var_dump('no setting ' . $settingName);
|
var_dump('no setting ' . $settingName);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($setting['Value'] == $scriptSettings[$settingName]) {
|
if ($setting['Value'] == $gameModeSettings[$settingName]) {
|
||||||
// Not changed
|
// Not changed
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
$newSettings[$settingName] = $setting['Value'];
|
$newSettings[$settingName] = $setting['Value'];
|
||||||
settype($newSettings[$settingName], gettype($scriptSettings[$settingName]));
|
settype($newSettings[$settingName], gettype($gameModeSettings[$settingName]));
|
||||||
}
|
}
|
||||||
|
|
||||||
$success = $this->applyNewScriptSettings($newSettings, $player);
|
$success = $this->applyNewModeSettings($newSettings, $player);
|
||||||
if ($success) {
|
if ($success) {
|
||||||
$this->maniaControl->getChat()->sendSuccess('Script Settings saved!', $player);
|
$this->maniaControl->getChat()->sendSuccess('GameMode-Settings saved!', $player);
|
||||||
} else {
|
} else {
|
||||||
$this->maniaControl->getChat()->sendError('Script Settings Saving failed!', $player);
|
$this->maniaControl->getChat()->sendError('GameMode-Settings Saving failed!', $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reopen the Menu
|
// Reopen the Menu
|
||||||
@ -357,21 +411,24 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function applyNewScriptSettings(array $newSettings, Player $player) {
|
private function applyNewModeSettings(array $newSettings, Player $player) {
|
||||||
if (empty($newSettings)) {
|
if (empty($newSettings)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$this->maniaControl->getClient()->setModeScriptSettings($newSettings);
|
$success = $this->setGameModeSettingsArray($newSettings);
|
||||||
} catch (FaultException $e) {
|
if (!$success) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->maniaControl->getChat()->sendException($e, $player);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Save Settings into Database
|
// Save Settings into Database
|
||||||
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
||||||
$query = "INSERT INTO `" . self::TABLE_SCRIPT_SETTINGS . "` (
|
$query = "INSERT INTO `" . self::TABLE_GAMEMODE_SETTINGS . "` (
|
||||||
`serverIndex`,
|
`serverIndex`,
|
||||||
`settingName`,
|
`settingName`,
|
||||||
`settingValue`
|
`settingValue`
|
||||||
@ -389,13 +446,17 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
$statement->bind_param('iss', $this->maniaControl->getServer()->index, $settingName, $settingValue);
|
$statement->bind_param('iss', $this->maniaControl->getServer()->index, $settingName, $settingValue);
|
||||||
|
|
||||||
// Notifications
|
// Notifications
|
||||||
|
if (!$this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
||||||
|
$this->maniaControl->getChat()->sendInformation('Changes will only take effect after a map skip or restart!', $player);
|
||||||
|
}
|
||||||
|
|
||||||
$settingsCount = count($newSettings);
|
$settingsCount = count($newSettings);
|
||||||
$settingIndex = 0;
|
$settingIndex = 0;
|
||||||
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($player);
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($player);
|
||||||
$chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set ScriptSetting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
$chatMessage = '$ff0' . $title . ' ' . $player->getEscapedNickname() . ' set GameMode-Setting' . ($settingsCount > 1 ? 's' : '') . ' ';
|
||||||
foreach ($newSettings as $setting => $value) {
|
foreach ($newSettings as $settingName => $settingValue) {
|
||||||
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $setting) . '$z$s$ff0 ';
|
$chatMessage .= '$<' . '$fff' . preg_replace('/^S_/', '', $settingName) . '$z$ff0 ';
|
||||||
$chatMessage .= 'to $fff' . $this->parseSettingValue($value) . '$>';
|
$chatMessage .= 'to $fff' . $this->parseSettingValue($settingValue) . '$>';
|
||||||
|
|
||||||
if ($settingIndex <= $settingsCount - 2) {
|
if ($settingIndex <= $settingsCount - 2) {
|
||||||
$chatMessage .= ', ';
|
$chatMessage .= ', ';
|
||||||
@ -408,13 +469,13 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Trigger own callback
|
// Trigger own callback
|
||||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SCRIPTSETTING_CHANGED, $setting, $value);
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTING_CHANGED, $settingName, $settingValue);
|
||||||
|
|
||||||
$settingIndex++;
|
$settingIndex++;
|
||||||
}
|
}
|
||||||
$statement->close();
|
$statement->close();
|
||||||
|
|
||||||
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_SCRIPTSETTINGS_CHANGED);
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTINGS_CHANGED);
|
||||||
|
|
||||||
$chatMessage .= '!';
|
$chatMessage .= '!';
|
||||||
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
||||||
@ -439,17 +500,73 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
* Initializes the communication Listenings
|
* Initializes the communication Listenings
|
||||||
*/
|
*/
|
||||||
private function initalizeCommunicationListenings() {
|
private function initalizeCommunicationListenings() {
|
||||||
//Communication Listenings
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GET_GAMEMODE_SETTINGS, $this, function ($data) {
|
||||||
|
try {
|
||||||
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return new CommunicationAnswer($e->getMessage(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return new CommunicationAnswer($gameModeSettings);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::SET_GAMEMODE_SETTINGS, $this, function ($data) {
|
||||||
|
if (!is_object($data) || !property_exists($data, "gameModeSettings")) {
|
||||||
|
return new CommunicationAnswer("No valid GameMode-Settings provided!", true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$gameModeSettings = null;
|
||||||
|
try {
|
||||||
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return new CommunicationAnswer($e->getMessage(), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$newSettings = array();
|
||||||
|
foreach ($data->gameModeSettings as $name => $value) {
|
||||||
|
if (!isset($gameModeSettings[$name])) {
|
||||||
|
var_dump('no setting ' . $name);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($value == $gameModeSettings[$name]) {
|
||||||
|
// unchanged
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$newSettings[$name] = $value;
|
||||||
|
settype($newSettings[$name], gettype($gameModeSettings[$name]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// No new Settings
|
||||||
|
if (empty($newSettings)) {
|
||||||
|
return new CommunicationAnswer(array("success" => true));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Trigger GameModeSettings Changed Callback
|
||||||
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTINGS_CHANGED);
|
||||||
|
|
||||||
|
// Set the Settings
|
||||||
|
try {
|
||||||
|
$success = $this->setGameModeSettingsArray($newSettings);
|
||||||
|
return new CommunicationAnswer(array("success" => $success));
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return new CommunicationAnswer($e->getMessage(), true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GET_SCRIPT_SETTINGS, $this, function ($data) {
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GET_SCRIPT_SETTINGS, $this, function ($data) {
|
||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||||
} catch (GameModeException $e) {
|
} catch (\Exception $e) {
|
||||||
return new CommunicationAnswer($e->getMessage(), true);
|
return new CommunicationAnswer($e->getMessage(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CommunicationAnswer($scriptSettings);
|
return new CommunicationAnswer($scriptSettings);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/** @deprecated */
|
||||||
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::SET_SCRIPT_SETTINGS, $this, function ($data) {
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::SET_SCRIPT_SETTINGS, $this, function ($data) {
|
||||||
if (!is_object($data) || !property_exists($data, "scriptSettings")) {
|
if (!is_object($data) || !property_exists($data, "scriptSettings")) {
|
||||||
return new CommunicationAnswer("No valid ScriptSettings provided!", true);
|
return new CommunicationAnswer("No valid ScriptSettings provided!", true);
|
||||||
@ -457,7 +574,7 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener, Communicatio
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
||||||
} catch (GameModeException $e) {
|
} catch (\Exception $e) {
|
||||||
return new CommunicationAnswer($e->getMessage(), true);
|
return new CommunicationAnswer($e->getMessage(), true);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user