2013-11-28 17:36:39 +01:00
|
|
|
<?php
|
|
|
|
|
2014-07-25 15:45:10 +02:00
|
|
|
namespace ManiaControl\Configurator;
|
2013-11-28 17:36:39 +01:00
|
|
|
|
2014-06-15 02:55:50 +02:00
|
|
|
use FML\Components\CheckBox;
|
2014-01-02 23:49:21 +01:00
|
|
|
use FML\Controls\Entry;
|
|
|
|
use FML\Controls\Frame;
|
|
|
|
use FML\Controls\Label;
|
|
|
|
use FML\Controls\Labels\Label_Text;
|
2014-06-15 02:26:50 +02:00
|
|
|
use FML\Controls\Quad;
|
2014-01-02 23:49:21 +01:00
|
|
|
use FML\Controls\Quads\Quad_Icons64x64_1;
|
2014-04-27 16:22:12 +02:00
|
|
|
use FML\Script\Features\Paging;
|
2013-12-31 10:40:03 +01:00
|
|
|
use FML\Script\Script;
|
2014-04-13 19:05:54 +02:00
|
|
|
use ManiaControl\Admin\AuthenticationManager;
|
2013-12-30 20:12:53 +01:00
|
|
|
use ManiaControl\Callbacks\CallbackListener;
|
2014-04-28 20:50:38 +02:00
|
|
|
use ManiaControl\Callbacks\Callbacks;
|
2015-07-11 14:57:54 +02:00
|
|
|
use ManiaControl\Communication\CommunicationAnswer;
|
|
|
|
use ManiaControl\Communication\CommunicationListener;
|
|
|
|
use ManiaControl\Communication\CommunicationMethods;
|
2014-08-05 01:49:13 +02:00
|
|
|
use ManiaControl\Logger;
|
2013-11-28 17:36:39 +01:00
|
|
|
use ManiaControl\ManiaControl;
|
|
|
|
use ManiaControl\Players\Player;
|
2020-04-28 17:52:17 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Structures\GameInfos;
|
2017-02-11 23:26:28 +01:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
|
2014-05-13 17:59:37 +02:00
|
|
|
use Maniaplanet\DedicatedServer\Xmlrpc\GameModeException;
|
2013-11-28 17:36:39 +01:00
|
|
|
|
|
|
|
/**
|
2020-04-28 17:52:17 +02:00
|
|
|
* Class offering a Configurator for Mode Settings
|
2013-11-28 17:36:39 +01:00
|
|
|
*
|
2014-05-02 17:50:30 +02:00
|
|
|
* @author ManiaControl Team <mail@maniacontrol.com>
|
2020-01-22 10:39:35 +01:00
|
|
|
* @copyright 2014-2020 ManiaControl Team
|
2014-04-19 22:59:11 +02:00
|
|
|
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
|
2013-11-28 17:36:39 +01:00
|
|
|
*/
|
2020-04-28 17:52:17 +02:00
|
|
|
class GameModeSettings implements ConfiguratorMenu, CallbackListener, CommunicationListener {
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2013-11-28 17:36:39 +01:00
|
|
|
* Constants
|
|
|
|
*/
|
2020-05-18 08:06:41 +02:00
|
|
|
const ACTION_PREFIX_SETTING = 'GameModeSetting.';
|
|
|
|
const CB_GAMEMODESETTING_CHANGED = 'GameModeSettings.SettingChanged';
|
|
|
|
const CB_GAMEMODESETTINGS_CHANGED = 'GameModeSettings.SettingsChanged';
|
2020-04-28 17:52:17 +02:00
|
|
|
/** @deprecated */
|
2020-05-18 08:06:41 +02:00
|
|
|
const CB_SCRIPTSETTING_CHANGED = 'GameModeSettings.SettingChanged';
|
2020-04-28 17:52:17 +02:00
|
|
|
/** @deprecated */
|
2020-05-18 08:06:41 +02:00
|
|
|
const CB_SCRIPTSETTINGS_CHANGED = 'GameModeSettings.SettingsChanged';
|
|
|
|
|
|
|
|
const TABLE_GAMEMODE_SETTINGS = 'mc_gamemodesettings';
|
2020-04-28 17:52:17 +02:00
|
|
|
/** @deprecated */
|
2020-05-18 08:06:41 +02:00
|
|
|
const TABLE_SCRIPT_SETTINGS = 'mc_scriptsettings';
|
|
|
|
|
|
|
|
const DESCRIPTION_HIDDEN = '<hidden>';
|
|
|
|
|
|
|
|
const SETTING_HIDE_SETTINGS_WITH_DESCRIPTION_HIDDEN = 'Hide Settings with Description "' . self::DESCRIPTION_HIDDEN . '"';
|
2022-04-13 10:56:53 +02:00
|
|
|
const SETTING_LOAD_DEFAULT_SETTINGS_STARTUP = 'Load Stored GameMode-Settings on Startup';
|
2020-05-18 08:06:41 +02:00
|
|
|
const SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN = 'Load Stored GameMode-Settings on Map-Begin';
|
|
|
|
const SETTING_PERMISSION_CHANGE_MODE_SETTINGS = 'Change GameMode-Settings';
|
2020-04-28 17:52:17 +02:00
|
|
|
/** @deprecated */
|
2020-05-18 08:06:41 +02:00
|
|
|
const SETTING_PERMISSION_CHANGE_SCRIPT_SETTINGS = 'Change Script-Settings';
|
|
|
|
const SETTING_SORT_SETTINGS = 'Sort Settings';
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-04-12 12:14:37 +02:00
|
|
|
/*
|
2014-07-25 16:28:47 +02:00
|
|
|
* Private properties
|
2013-11-28 17:36:39 +01:00
|
|
|
*/
|
2014-08-02 22:31:46 +02:00
|
|
|
/** @var ManiaControl $maniaControl */
|
2013-11-28 17:36:39 +01:00
|
|
|
private $maniaControl = null;
|
|
|
|
|
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Construct a new script settings instance
|
2013-11-28 17:36:39 +01:00
|
|
|
*
|
2013-12-31 13:51:30 +01:00
|
|
|
* @param ManiaControl $maniaControl
|
2013-11-28 17:36:39 +01:00
|
|
|
*/
|
|
|
|
public function __construct(ManiaControl $maniaControl) {
|
|
|
|
$this->maniaControl = $maniaControl;
|
2014-06-15 02:26:50 +02:00
|
|
|
$this->initTables();
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-07-25 16:28:47 +02:00
|
|
|
// Callbacks
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::ONINIT, $this, 'onInit');
|
|
|
|
$this->maniaControl->getCallbackManager()->registerCallbackListener(Callbacks::BEGINMAP, $this, 'onBeginMap');
|
2014-08-03 01:34:18 +02:00
|
|
|
|
|
|
|
// Settings
|
2020-05-18 08:06:41 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_HIDE_SETTINGS_WITH_DESCRIPTION_HIDDEN, true);
|
2022-04-14 01:00:19 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_STARTUP, false);
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN, false);
|
2020-05-18 08:06:41 +02:00
|
|
|
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_SORT_SETTINGS, true);
|
2014-04-13 19:05:54 +02:00
|
|
|
|
2014-07-25 16:28:47 +02:00
|
|
|
// Permissions
|
2020-04-28 17:52:17 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_CHANGE_MODE_SETTINGS, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
2015-07-11 14:57:54 +02:00
|
|
|
|
|
|
|
//TODO remove to somewhere cleaner
|
|
|
|
//Communication Listenings
|
|
|
|
$this->initalizeCommunicationListenings();
|
2014-01-04 17:30:29 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 12:17:29 +01:00
|
|
|
/**
|
2014-07-25 16:28:47 +02:00
|
|
|
* Create all necessary database tables
|
2014-01-05 12:17:29 +01:00
|
|
|
*
|
|
|
|
* @return boolean
|
|
|
|
*/
|
2014-01-04 17:30:29 +01:00
|
|
|
private function initTables() {
|
2014-08-13 11:05:52 +02:00
|
|
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
2020-05-11 17:40:37 +02:00
|
|
|
|
|
|
|
$renameQuery = "ALTER TABLE `" . self::TABLE_SCRIPT_SETTINGS . "` RENAME TO `" . self::TABLE_GAMEMODE_SETTINGS . "`;";
|
|
|
|
$result = $mysqli->query($renameQuery);
|
|
|
|
if (!$result) {
|
2020-05-19 13:45:42 +02:00
|
|
|
if ($mysqli->errno === 1146) {
|
2020-05-16 22:16:07 +02:00
|
|
|
// old doesn't exist, good, continue to force creation
|
2020-05-19 13:45:42 +02:00
|
|
|
} elseif ($mysqli->errno === 1050) {
|
2020-05-16 22:16:07 +02:00
|
|
|
// new one exists, drop the old table, get out
|
|
|
|
$dropQuery = "DROP TABLE `" . self::TABLE_SCRIPT_SETTINGS . "`;";
|
|
|
|
$result = $mysqli->query($dropQuery);
|
|
|
|
if (!$result) {
|
|
|
|
trigger_error($mysqli->error, E_USER_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
2020-05-11 17:40:37 +02:00
|
|
|
} else {
|
2020-05-16 22:16:07 +02:00
|
|
|
// other error (successful rename would not have us got here)
|
|
|
|
trigger_error($mysqli->error, E_USER_ERROR);
|
|
|
|
return false;
|
2020-05-11 17:40:37 +02:00
|
|
|
}
|
|
|
|
}
|
2020-05-16 22:16:07 +02:00
|
|
|
// else rename happened, continue to force creation
|
2020-05-11 17:40:37 +02:00
|
|
|
|
|
|
|
$query = "CREATE TABLE IF NOT EXISTS `" . self::TABLE_GAMEMODE_SETTINGS . "` (
|
2014-02-13 14:58:04 +01:00
|
|
|
`index` int(11) NOT NULL AUTO_INCREMENT,
|
|
|
|
`serverIndex` int(11) NOT NULL,
|
2017-03-09 21:02:03 +01:00
|
|
|
`settingName` varchar(100) NOT NULL DEFAULT '',
|
|
|
|
`settingValue` varchar(500) NOT NULL DEFAULT '',
|
2014-02-13 14:58:04 +01:00
|
|
|
PRIMARY KEY (`index`),
|
2014-01-05 14:41:19 +01:00
|
|
|
UNIQUE KEY `setting` (`serverIndex`, `settingName`)
|
2020-05-11 17:40:37 +02:00
|
|
|
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='GameMode-Settings' AUTO_INCREMENT=1;";
|
2014-01-04 17:30:29 +01:00
|
|
|
$statement = $mysqli->prepare($query);
|
2014-02-01 20:03:17 +01:00
|
|
|
if ($mysqli->error) {
|
2014-01-04 17:30:29 +01:00
|
|
|
trigger_error($mysqli->error, E_USER_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$statement->execute();
|
2014-02-01 20:03:17 +01:00
|
|
|
if ($statement->error) {
|
2014-01-04 17:30:29 +01:00
|
|
|
trigger_error($statement->error, E_USER_ERROR);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$statement->close();
|
2020-05-11 17:40:37 +02:00
|
|
|
|
2014-01-04 17:30:29 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-07-24 23:15:25 +02:00
|
|
|
/**
|
2017-03-09 21:02:03 +01:00
|
|
|
* @see \ManiaControl\Configurator\ConfiguratorMenu::getTitle()
|
2014-07-24 23:15:25 +02:00
|
|
|
*/
|
|
|
|
public static function getTitle() {
|
2020-04-28 17:52:17 +02:00
|
|
|
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 {
|
2020-04-30 12:04:48 +02:00
|
|
|
$gameModeSettings = $this->maniaControl->getClient()->getGameInfos();
|
|
|
|
|
|
|
|
$currentGameModeSettings = get_object_vars($gameModeSettings['CurrentGameInfos']);
|
|
|
|
unset($gameModeSettings['CurrentGameInfos']);
|
|
|
|
foreach ($currentGameModeSettings as $name => $value) {
|
|
|
|
unset($currentGameModeSettings[$name]);
|
|
|
|
$currentGameModeSettings[ucfirst($name)] = $value;
|
|
|
|
}
|
|
|
|
$gameModeSettings[0] = $currentGameModeSettings;
|
|
|
|
|
|
|
|
$nextGameModeSettings = get_object_vars($gameModeSettings['NextGameInfos']);
|
|
|
|
unset($gameModeSettings['NextGameInfos']);
|
|
|
|
foreach ($nextGameModeSettings as $name => $value) {
|
|
|
|
unset($nextGameModeSettings[$name]);
|
|
|
|
$nextGameModeSettings[ucfirst($name)] = $value;
|
2020-04-28 17:52:17 +02:00
|
|
|
}
|
2020-04-30 12:04:48 +02:00
|
|
|
$gameModeSettings[1] = $nextGameModeSettings;
|
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
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) {
|
2020-05-09 21:44:44 +02:00
|
|
|
static $settingToMethodReplace = array(
|
|
|
|
'LapsNbLaps' => 'SetNbLaps',
|
|
|
|
'RoundsForcedLaps' => 'SetRoundForcedLaps',
|
|
|
|
'RoundsPointsLimit' => 'SetRoundPointsLimit',
|
|
|
|
'RoundsUseNewRules' => 'SetUseNewRulesRound',
|
|
|
|
'TeamMaxPoints' => 'SetMaxPointsTeam',
|
|
|
|
'TeamUseNewRules' => 'SetUseNewRulesTeam',
|
|
|
|
);
|
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
if ($this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
|
|
|
return $this->maniaControl->getClient()->setModeScriptSettings($settings);
|
|
|
|
} else {
|
|
|
|
$success = true;
|
|
|
|
foreach ($settings as $key => $value) {
|
2020-05-09 21:44:44 +02:00
|
|
|
if (array_key_exists($key, $settingToMethodReplace)) {
|
|
|
|
$key = $settingToMethodReplace[$key];
|
|
|
|
} else {
|
|
|
|
$key = 'Set'.$key;
|
|
|
|
}
|
|
|
|
|
|
|
|
$success &= $this->maniaControl->getClient()->execute($key, array($value));
|
2020-04-28 17:52:17 +02:00
|
|
|
}
|
|
|
|
return $success;
|
|
|
|
}
|
2014-07-24 23:15:25 +02:00
|
|
|
}
|
|
|
|
|
2014-01-04 17:30:29 +01:00
|
|
|
/**
|
|
|
|
* Handle OnInit callback
|
|
|
|
*/
|
2014-02-19 15:44:00 +01:00
|
|
|
public function onInit() {
|
2022-04-13 10:56:53 +02:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_MAP_BEGIN)) {
|
|
|
|
$this->loadSettingsFromDatabase();
|
|
|
|
}
|
2014-02-12 19:19:08 +01:00
|
|
|
}
|
|
|
|
|
2014-01-04 17:30:29 +01:00
|
|
|
/**
|
|
|
|
* Load Settings from Database
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function loadSettingsFromDatabase() {
|
2020-04-28 17:52:17 +02:00
|
|
|
$gameModeSettings = null;
|
2014-02-12 19:19:08 +01:00
|
|
|
try {
|
2020-04-28 17:52:17 +02:00
|
|
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
2020-04-30 12:04:48 +02:00
|
|
|
if (!$this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
|
|
|
$gameModeSettings = $gameModeSettings[0];
|
|
|
|
}
|
2020-04-28 17:52:17 +02:00
|
|
|
} catch (\Exception $e) {
|
2014-04-19 22:59:11 +02:00
|
|
|
return false;
|
2014-02-09 18:22:47 +01:00
|
|
|
}
|
2014-01-17 17:09:25 +01:00
|
|
|
|
2014-08-13 11:05:52 +02:00
|
|
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
2014-08-03 01:34:18 +02:00
|
|
|
$serverIndex = $this->maniaControl->getServer()->index;
|
2020-04-28 17:52:17 +02:00
|
|
|
$query = "SELECT * FROM `" . self::TABLE_GAMEMODE_SETTINGS . "`
|
2014-06-22 18:38:07 +02:00
|
|
|
WHERE serverIndex = {$serverIndex};";
|
|
|
|
$result = $mysqli->query($query);
|
2014-02-01 20:03:17 +01:00
|
|
|
if ($mysqli->error) {
|
2014-01-04 17:30:29 +01:00
|
|
|
trigger_error($mysqli->error);
|
2014-01-05 12:17:29 +01:00
|
|
|
return false;
|
2014-01-04 17:30:29 +01:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-01-05 12:17:29 +01:00
|
|
|
$loadedSettings = array();
|
2014-05-02 17:50:30 +02:00
|
|
|
while ($row = $result->fetch_object()) {
|
2020-04-28 17:52:17 +02:00
|
|
|
if (!isset($gameModeSettings[$row->settingName])) {
|
2014-01-05 20:34:48 +01:00
|
|
|
continue;
|
2014-01-05 22:51:21 +01:00
|
|
|
}
|
2014-01-04 17:30:29 +01:00
|
|
|
$loadedSettings[$row->settingName] = $row->settingValue;
|
2020-04-28 17:52:17 +02:00
|
|
|
settype($loadedSettings[$row->settingName], gettype($gameModeSettings[$row->settingName]));
|
2014-01-04 17:30:29 +01:00
|
|
|
}
|
2014-05-18 23:34:47 +02:00
|
|
|
$result->free();
|
2014-06-22 18:38:07 +02:00
|
|
|
if (empty($loadedSettings)) {
|
2014-01-05 20:34:48 +01:00
|
|
|
return true;
|
2014-01-05 22:51:21 +01:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
try {
|
|
|
|
$this->setGameModeSettingsArray($loadedSettings);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2014-06-14 15:48:27 +02:00
|
|
|
* Handle Begin Map Callback
|
2013-11-28 17:36:39 +01:00
|
|
|
*/
|
2014-06-14 15:48:27 +02:00
|
|
|
public function onBeginMap() {
|
2022-04-14 01:00:19 +02:00
|
|
|
if ($this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_LOAD_DEFAULT_SETTINGS_STARTUP)) {
|
2014-05-02 17:50:30 +02:00
|
|
|
$this->loadSettingsFromDatabase();
|
|
|
|
}
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2013-12-12 19:41:37 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
/**
|
2017-03-09 21:02:03 +01:00
|
|
|
* @see \ManiaControl\Configurator\ConfiguratorMenu::getMenu()
|
2013-11-28 17:36:39 +01:00
|
|
|
*/
|
2014-04-30 05:27:23 +02:00
|
|
|
public function getMenu($width, $height, Script $script, Player $player) {
|
2020-05-18 08:06:41 +02:00
|
|
|
$isScriptMode = $this->maniaControl->getServer()->getScriptManager()->isScriptMode();
|
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
$paging = new Paging();
|
|
|
|
$script->addFeature($paging);
|
|
|
|
$frame = new Frame();
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
$scriptParams = null;
|
|
|
|
$gameModeSettings = null;
|
|
|
|
$error = null;
|
2014-02-13 00:26:18 +01:00
|
|
|
try {
|
2020-04-28 17:52:17 +02:00
|
|
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
|
|
|
|
2020-05-18 08:06:41 +02:00
|
|
|
if ($isScriptMode) {
|
2020-04-28 17:52:17 +02:00
|
|
|
$scriptInfo = $this->maniaControl->getClient()->getModeScriptInfo();
|
|
|
|
$scriptParams = $scriptInfo->paramDescs;
|
2020-05-18 08:06:41 +02:00
|
|
|
|
|
|
|
$hideSettingsWithDescriptionHidden = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_HIDE_SETTINGS_WITH_DESCRIPTION_HIDDEN);
|
|
|
|
if ($hideSettingsWithDescriptionHidden) {
|
|
|
|
$scriptParams = array_filter($scriptParams, function ($scriptParam) {
|
|
|
|
return $scriptParam->desc !== self::DESCRIPTION_HIDDEN;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
usort($scriptParams, function ($a, $b) {
|
|
|
|
return $a->name === $b->name ? 0 : ($a->name < $b->name ? -1 : 1);
|
|
|
|
});
|
2020-04-28 17:52:17 +02:00
|
|
|
} else {
|
2020-04-30 12:04:48 +02:00
|
|
|
$scriptParams = $gameModeSettings[0];
|
2020-05-18 08:06:41 +02:00
|
|
|
ksort($scriptParams);
|
2020-04-28 17:52:17 +02:00
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
2014-04-20 15:47:35 +02:00
|
|
|
$label = new Label();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($label);
|
2014-04-20 15:47:35 +02:00
|
|
|
$label->setText($e->getMessage());
|
|
|
|
return $frame;
|
2014-02-13 00:26:18 +01:00
|
|
|
}
|
2014-01-17 17:00:06 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
// Config
|
2014-01-05 20:34:48 +01:00
|
|
|
$pagerSize = 9.;
|
2013-11-28 17:36:39 +01:00
|
|
|
$settingHeight = 5.;
|
|
|
|
$labelTextSize = 2;
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
// Pagers
|
|
|
|
$pagerPrev = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pagerPrev);
|
2013-12-04 00:40:37 +01:00
|
|
|
$pagerPrev->setPosition($width * 0.39, $height * -0.44, 2);
|
2013-11-28 17:36:39 +01:00
|
|
|
$pagerPrev->setSize($pagerSize, $pagerSize);
|
2014-06-22 19:02:18 +02:00
|
|
|
$pagerPrev->setSubStyle($pagerPrev::SUBSTYLE_ArrowPrev);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
$pagerNext = new Quad_Icons64x64_1();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pagerNext);
|
2013-12-04 00:40:37 +01:00
|
|
|
$pagerNext->setPosition($width * 0.45, $height * -0.44, 2);
|
2013-11-28 17:36:39 +01:00
|
|
|
$pagerNext->setSize($pagerSize, $pagerSize);
|
2014-06-22 19:02:18 +02:00
|
|
|
$pagerNext->setSubStyle($pagerNext::SUBSTYLE_ArrowNext);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2017-03-25 18:40:15 +01:00
|
|
|
$paging->addButtonControl($pagerNext);
|
|
|
|
$paging->addButtonControl($pagerPrev);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-06-22 19:02:18 +02:00
|
|
|
$pageCountLabel = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pageCountLabel);
|
|
|
|
$pageCountLabel->setHorizontalAlign($pageCountLabel::RIGHT);
|
2013-12-04 00:40:37 +01:00
|
|
|
$pageCountLabel->setPosition($width * 0.35, $height * -0.44, 1);
|
2014-06-22 19:02:18 +02:00
|
|
|
$pageCountLabel->setStyle($pageCountLabel::STYLE_TextTitle1);
|
2013-11-28 17:36:39 +01:00
|
|
|
$pageCountLabel->setTextSize(2);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-05-02 17:50:30 +02:00
|
|
|
$paging->setLabel($pageCountLabel);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2020-05-18 08:06:41 +02:00
|
|
|
if (!$isScriptMode) {
|
2020-04-30 12:04:48 +02:00
|
|
|
$descriptionLabel = new Label();
|
|
|
|
$frame->addChild($descriptionLabel);
|
|
|
|
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
|
|
|
|
$descriptionLabel->setPosition($width * -0.45, $height * -0.44);
|
|
|
|
$descriptionLabel->setSize($width * 0.7, $settingHeight);
|
|
|
|
$descriptionLabel->setText('Changes only apply with map skip/restart');
|
|
|
|
$descriptionLabel->setTextColor('ff0');
|
|
|
|
$descriptionLabel->setTextSize($labelTextSize);
|
|
|
|
$descriptionLabel->setTranslate(true);
|
|
|
|
}
|
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
// Setting pages
|
2014-05-15 17:45:08 +02:00
|
|
|
$pageFrame = null;
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY = 0.;
|
2020-04-28 17:52:17 +02:00
|
|
|
$index = 0;
|
2014-05-15 17:45:08 +02:00
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
foreach ($scriptParams as $key => $scriptParam) {
|
|
|
|
$settingName = null;
|
2020-04-30 12:04:48 +02:00
|
|
|
$settingValue = null;
|
2020-05-18 08:06:41 +02:00
|
|
|
if ($isScriptMode) {
|
2020-04-28 17:52:17 +02:00
|
|
|
$settingName = $scriptParam->name;
|
2020-04-30 12:04:48 +02:00
|
|
|
if (!isset($gameModeSettings[$settingName])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$settingValue = $gameModeSettings[$settingName];
|
2020-04-28 17:52:17 +02:00
|
|
|
} else {
|
|
|
|
$settingName = $key;
|
2020-04-30 12:04:48 +02:00
|
|
|
if (!isset($gameModeSettings[0][$settingName]) && !isset($gameModeSettings[1][$settingName])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$settingValue = array(
|
|
|
|
0 => $gameModeSettings[0][$settingName],
|
|
|
|
1 => $gameModeSettings[1][$settingName]
|
|
|
|
);
|
2014-01-02 23:49:21 +01:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-05-15 17:45:08 +02:00
|
|
|
if ($index % 13 === 0) {
|
2013-11-28 17:36:39 +01:00
|
|
|
$pageFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$frame->addChild($pageFrame);
|
2020-04-30 12:04:48 +02:00
|
|
|
$posY = 0.41 * $height;
|
2017-03-25 18:40:15 +01:00
|
|
|
$paging->addPageControl($pageFrame);
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-12-09 09:07:55 +01:00
|
|
|
$settingFrame = new Frame();
|
2017-03-25 19:15:50 +01:00
|
|
|
$pageFrame->addChild($settingFrame);
|
2014-06-14 15:48:27 +02:00
|
|
|
$settingFrame->setY($posY);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-12-12 19:41:37 +01:00
|
|
|
$nameLabel = new Label_Text();
|
2017-03-25 19:15:50 +01:00
|
|
|
$settingFrame->addChild($nameLabel);
|
|
|
|
$nameLabel->setHorizontalAlign($nameLabel::LEFT);
|
2020-04-30 12:04:48 +02:00
|
|
|
$nameLabel->setSize(0.4 * $width, $settingHeight);
|
2013-12-12 19:41:37 +01:00
|
|
|
$nameLabel->setStyle($nameLabel::STYLE_TextCardSmall);
|
2013-11-28 17:36:39 +01:00
|
|
|
$nameLabel->setText($settingName);
|
2020-04-28 17:52:17 +02:00
|
|
|
$nameLabel->setTextSize($labelTextSize);
|
2020-04-30 12:04:48 +02:00
|
|
|
$nameLabel->setX(-0.46 * $width);
|
|
|
|
|
2020-05-18 08:06:41 +02:00
|
|
|
if (!$isScriptMode) {
|
2020-04-30 12:04:48 +02:00
|
|
|
if (is_bool($settingValue[0])) {
|
|
|
|
$activeQuad = new Quad_Icons64x64_1();
|
|
|
|
$settingFrame->addChild($activeQuad);
|
|
|
|
$activeQuad->setSize(0.9 * $settingHeight, 0.9 * $settingHeight);
|
|
|
|
if ($settingValue[0]) {
|
|
|
|
$activeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_LvlGreen);
|
|
|
|
} else {
|
|
|
|
$activeQuad->setSubStyle(Quad_Icons64x64_1::SUBSTYLE_LvlRed);
|
|
|
|
}
|
|
|
|
$activeQuad->setX(0.1 * $width);
|
|
|
|
} else {
|
|
|
|
$currentLabel = new Label_Text();
|
|
|
|
$settingFrame->addChild($currentLabel);
|
|
|
|
$currentLabel->setHorizontalAlign(Label_Text::RIGHT);
|
|
|
|
$currentLabel->setSize(0.2 * $width, 0.9 * $settingHeight);
|
|
|
|
$currentLabel->setStyle(Label_Text::STYLE_TextValueSmall);
|
|
|
|
$currentLabel->setText($settingValue[0]);
|
|
|
|
$currentLabel->setTextColor('aaa');
|
|
|
|
$currentLabel->setTextPrefix('$i');
|
|
|
|
$currentLabel->setTextSize(1);
|
|
|
|
$currentLabel->setX(0.11 * $width);
|
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2020-04-30 12:04:48 +02:00
|
|
|
$settingValue = $settingValue[1];
|
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-06-15 02:26:50 +02:00
|
|
|
if (is_bool($settingValue)) {
|
|
|
|
// Boolean checkbox
|
|
|
|
$quad = new Quad();
|
2013-12-30 20:12:53 +01:00
|
|
|
$quad->setSize(4, 4);
|
2020-04-30 12:04:48 +02:00
|
|
|
$quad->setX(0.27 * $width);
|
2014-06-15 02:26:50 +02:00
|
|
|
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $settingName, $settingValue, $quad);
|
2017-03-25 19:15:50 +01:00
|
|
|
$settingFrame->addChild($checkBox);
|
2014-01-05 20:34:48 +01:00
|
|
|
} else {
|
2014-06-15 02:26:50 +02:00
|
|
|
// Value entry
|
2013-12-30 20:12:53 +01:00
|
|
|
$entry = new Entry();
|
2017-03-25 19:15:50 +01:00
|
|
|
$settingFrame->addChild($entry);
|
2020-04-28 17:52:17 +02:00
|
|
|
$entry->setDefault($settingValue);
|
|
|
|
$entry->setName(self::ACTION_PREFIX_SETTING . $settingName);
|
2020-04-30 12:04:48 +02:00
|
|
|
$entry->setSize(0.3 * $width, 0.9 * $settingHeight);
|
2013-12-30 20:12:53 +01:00
|
|
|
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
|
|
|
|
$entry->setTextSize(1);
|
2020-04-30 12:04:48 +02:00
|
|
|
$entry->setX(0.275 * $width);
|
2013-12-09 09:07:55 +01:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2020-05-18 08:06:41 +02:00
|
|
|
if ($isScriptMode) {
|
2020-04-28 17:52:17 +02:00
|
|
|
$descriptionLabel = new Label();
|
|
|
|
$pageFrame->addChild($descriptionLabel);
|
|
|
|
$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
|
2020-04-30 12:04:48 +02:00
|
|
|
$descriptionLabel->setPosition(-0.45 * $width, -0.44 * $height);
|
|
|
|
$descriptionLabel->setSize(0.7 * $width, $settingHeight);
|
2020-04-28 17:52:17 +02:00
|
|
|
$descriptionLabel->setTextSize($labelTextSize);
|
|
|
|
$descriptionLabel->setTranslate(true);
|
|
|
|
$nameLabel->addTooltipLabelFeature($descriptionLabel, $scriptParam->desc);
|
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-06-14 15:48:27 +02:00
|
|
|
$posY -= $settingHeight;
|
2020-04-28 17:52:17 +02:00
|
|
|
$index++;
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-11-28 17:36:39 +01:00
|
|
|
return $frame;
|
|
|
|
}
|
|
|
|
|
2013-12-30 20:12:53 +01:00
|
|
|
/**
|
2017-03-09 21:02:03 +01:00
|
|
|
* @see \ManiaControl\Configurator\ConfiguratorMenu::saveConfigData()
|
2013-12-30 20:12:53 +01:00
|
|
|
*/
|
2014-06-15 02:26:50 +02:00
|
|
|
public function saveConfigData(array $configData, Player $player) {
|
2020-04-28 17:52:17 +02:00
|
|
|
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_CHANGE_MODE_SETTINGS)) {
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
2014-06-15 02:26:50 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!$configData[3] || strpos($configData[3][0]['Name'], self::ACTION_PREFIX_SETTING) !== 0) {
|
2014-01-02 23:49:21 +01:00
|
|
|
return;
|
2014-01-04 17:30:29 +01:00
|
|
|
}
|
2020-04-28 17:52:17 +02:00
|
|
|
|
|
|
|
$gameModeSettings = null;
|
2014-02-13 00:26:18 +01:00
|
|
|
try {
|
2020-04-28 17:52:17 +02:00
|
|
|
$gameModeSettings = $this->getGameModeSettingsArray();
|
2020-04-30 12:04:48 +02:00
|
|
|
if (!$this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
|
|
|
$gameModeSettings = $gameModeSettings[0];
|
|
|
|
}
|
2020-04-28 17:52:17 +02:00
|
|
|
} catch (\Exception $e) {
|
2014-04-19 22:59:11 +02:00
|
|
|
return;
|
2014-02-13 00:26:18 +01:00
|
|
|
}
|
|
|
|
|
2014-06-15 02:26:50 +02:00
|
|
|
$prefixLength = strlen(self::ACTION_PREFIX_SETTING);
|
|
|
|
|
|
|
|
$newSettings = array();
|
|
|
|
foreach ($configData[3] as $setting) {
|
|
|
|
$settingName = substr($setting['Name'], $prefixLength);
|
2020-04-28 17:52:17 +02:00
|
|
|
if (!isset($gameModeSettings[$settingName])) {
|
2014-06-15 02:26:50 +02:00
|
|
|
var_dump('no setting ' . $settingName);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
if ($setting['Value'] == $gameModeSettings[$settingName]) {
|
2014-06-15 02:26:50 +02:00
|
|
|
// Not changed
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
$newSettings[$settingName] = $setting['Value'];
|
2020-04-28 17:52:17 +02:00
|
|
|
settype($newSettings[$settingName], gettype($gameModeSettings[$settingName]));
|
2013-12-30 20:12:53 +01:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
$success = $this->applyNewModeSettings($newSettings, $player);
|
2014-06-15 02:26:50 +02:00
|
|
|
if ($success) {
|
2020-04-28 17:52:17 +02:00
|
|
|
$this->maniaControl->getChat()->sendSuccess('GameMode-Settings saved!', $player);
|
2014-06-15 02:26:50 +02:00
|
|
|
} else {
|
2020-04-28 17:52:17 +02:00
|
|
|
$this->maniaControl->getChat()->sendError('GameMode-Settings Saving failed!', $player);
|
2014-06-15 02:26:50 +02:00
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-07-24 23:15:25 +02:00
|
|
|
// Reopen the Menu
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getConfigurator()->showMenu($player, $this);
|
2013-12-31 14:50:28 +01:00
|
|
|
}
|
|
|
|
|
2015-07-11 14:57:54 +02:00
|
|
|
|
2013-12-31 14:50:28 +01:00
|
|
|
/**
|
|
|
|
* Apply the Array of new Script Settings
|
|
|
|
*
|
2014-01-05 20:34:48 +01:00
|
|
|
* @param array $newSettings
|
2013-12-31 14:50:28 +01:00
|
|
|
* @param Player $player
|
2014-06-15 02:26:50 +02:00
|
|
|
* @return bool
|
2013-12-31 14:50:28 +01:00
|
|
|
*/
|
2020-04-28 17:52:17 +02:00
|
|
|
private function applyNewModeSettings(array $newSettings, Player $player) {
|
2014-06-22 18:38:07 +02:00
|
|
|
if (empty($newSettings)) {
|
2014-04-19 22:59:11 +02:00
|
|
|
return true;
|
|
|
|
}
|
2014-01-20 20:51:03 +01:00
|
|
|
|
2017-02-11 23:26:28 +01:00
|
|
|
try {
|
2020-04-28 17:52:17 +02:00
|
|
|
$success = $this->setGameModeSettingsArray($newSettings);
|
|
|
|
if (!$success) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$this->maniaControl->getChat()->sendException($e, $player);
|
2017-02-11 23:26:28 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-04 17:30:29 +01:00
|
|
|
// Save Settings into Database
|
2014-08-13 11:05:52 +02:00
|
|
|
$mysqli = $this->maniaControl->getDatabase()->getMysqli();
|
2020-04-28 17:52:17 +02:00
|
|
|
$query = "INSERT INTO `" . self::TABLE_GAMEMODE_SETTINGS . "` (
|
2014-01-05 14:41:19 +01:00
|
|
|
`serverIndex`,
|
2014-01-04 17:30:29 +01:00
|
|
|
`settingName`,
|
|
|
|
`settingValue`
|
|
|
|
) VALUES (
|
|
|
|
?, ?, ?
|
|
|
|
) ON DUPLICATE KEY UPDATE
|
|
|
|
`settingValue` = VALUES(`settingValue`);";
|
|
|
|
$statement = $mysqli->prepare($query);
|
2014-02-01 20:03:17 +01:00
|
|
|
if ($mysqli->error) {
|
2014-01-04 17:30:29 +01:00
|
|
|
trigger_error($mysqli->error);
|
|
|
|
return false;
|
|
|
|
}
|
2014-06-22 18:38:07 +02:00
|
|
|
$settingName = null;
|
|
|
|
$settingValue = null;
|
2014-08-03 01:34:18 +02:00
|
|
|
$statement->bind_param('iss', $this->maniaControl->getServer()->index, $settingName, $settingValue);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-12-31 14:50:28 +01:00
|
|
|
// Notifications
|
2013-12-31 16:12:23 +01:00
|
|
|
$settingsCount = count($newSettings);
|
2014-01-05 20:34:48 +01:00
|
|
|
$settingIndex = 0;
|
2014-08-13 11:05:52 +02:00
|
|
|
$title = $this->maniaControl->getAuthenticationManager()->getAuthLevelName($player);
|
2020-05-27 00:01:36 +02:00
|
|
|
$chatMessage = $this->maniaControl->getChat()->formatMessage(
|
|
|
|
"\$ff0{$title} %s set GameMode-Setting" . ($settingsCount > 1 ? "s" : "") . " ",
|
|
|
|
$player
|
|
|
|
);
|
2020-04-28 17:52:17 +02:00
|
|
|
foreach ($newSettings as $settingName => $settingValue) {
|
2020-05-27 00:01:36 +02:00
|
|
|
$chatMessage .= $this->maniaControl->getChat()->formatMessage(
|
|
|
|
'%s to %s',
|
|
|
|
preg_replace('/^S_/', '', $settingName),
|
|
|
|
$this->parseSettingValue($settingValue)
|
|
|
|
);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-02-01 20:03:17 +01:00
|
|
|
if ($settingIndex <= $settingsCount - 2) {
|
2013-12-31 16:12:23 +01:00
|
|
|
$chatMessage .= ', ';
|
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2014-01-05 12:17:29 +01:00
|
|
|
// Add To Database
|
2014-01-04 17:30:29 +01:00
|
|
|
$statement->execute();
|
2014-02-01 20:03:17 +01:00
|
|
|
if ($statement->error) {
|
2014-01-04 17:30:29 +01:00
|
|
|
trigger_error($statement->error);
|
|
|
|
}
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-12-31 14:50:28 +01:00
|
|
|
// Trigger own callback
|
2020-04-28 17:52:17 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTING_CHANGED, $settingName, $settingValue);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-12-31 16:12:23 +01:00
|
|
|
$settingIndex++;
|
2013-12-31 14:50:28 +01:00
|
|
|
}
|
2014-01-04 17:30:29 +01:00
|
|
|
$statement->close();
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
$this->maniaControl->getCallbackManager()->triggerCallback(self::CB_GAMEMODESETTINGS_CHANGED);
|
2014-01-05 20:34:48 +01:00
|
|
|
|
2013-12-31 16:12:23 +01:00
|
|
|
$chatMessage .= '!';
|
2014-08-13 11:05:52 +02:00
|
|
|
$this->maniaControl->getChat()->sendInformation($chatMessage);
|
2014-08-05 02:08:41 +02:00
|
|
|
Logger::logInfo($chatMessage, true);
|
2014-01-04 17:30:29 +01:00
|
|
|
return true;
|
2013-12-31 14:50:28 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parse the Setting Value to a String Representation
|
|
|
|
*
|
|
|
|
* @param mixed $value
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
private function parseSettingValue($value) {
|
2014-02-01 20:03:17 +01:00
|
|
|
if (is_bool($value)) {
|
2013-12-31 14:50:28 +01:00
|
|
|
return ($value ? 'True' : 'False');
|
|
|
|
}
|
2015-07-11 14:57:54 +02:00
|
|
|
return (string) $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes the communication Listenings
|
|
|
|
*/
|
|
|
|
private function initalizeCommunicationListenings() {
|
2020-04-28 17:52:17 +02:00
|
|
|
$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();
|
2020-04-30 12:04:48 +02:00
|
|
|
if (!$this->maniaControl->getServer()->getScriptManager()->isScriptMode()) {
|
|
|
|
$gameModeSettings = $gameModeSettings[0];
|
|
|
|
}
|
2020-04-28 17:52:17 +02:00
|
|
|
} 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 */
|
2015-07-11 14:57:54 +02:00
|
|
|
$this->maniaControl->getCommunicationManager()->registerCommunicationListener(CommunicationMethods::GET_SCRIPT_SETTINGS, $this, function ($data) {
|
|
|
|
try {
|
|
|
|
$scriptSettings = $this->maniaControl->getClient()->getModeScriptSettings();
|
2020-04-28 17:52:17 +02:00
|
|
|
} catch (\Exception $e) {
|
2015-07-11 14:57:54 +02:00
|
|
|
return new CommunicationAnswer($e->getMessage(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
return new CommunicationAnswer($scriptSettings);
|
|
|
|
});
|
|
|
|
|
2020-04-28 17:52:17 +02:00
|
|
|
/** @deprecated */
|
2015-07-11 14:57:54 +02:00
|
|
|
$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();
|
2020-04-28 17:52:17 +02:00
|
|
|
} catch (\Exception $e) {
|
2015-07-11 14:57:54 +02:00
|
|
|
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));
|
|
|
|
});
|
2013-11-28 17:36:39 +01:00
|
|
|
}
|
|
|
|
}
|