From 0834d2c587de322c432eb067ba2c38f4bb137b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Sun, 11 May 2014 15:28:53 +0200 Subject: [PATCH] match settings manager --- application/core/Bills/BillData.php | 4 +- application/core/Database/Database.php | 1 + application/core/Players/PlayerCommands.php | 4 +- application/core/Players/PlayerList.php | 2 +- application/core/Players/PlayerManager.php | 4 +- application/core/Plugins/PluginMenu.php | 3 + .../core/Server/MatchSettingsManager.php | 96 +++++++++++++++ application/core/Server/Server.php | 110 +++++++----------- .../plugins/MCTeam/CustomVotesPlugin.php | 6 +- .../MCTeam/Dedimania/DedimaniaPlugin.php | 2 +- application/plugins/MCTeam/KarmaPlugin.php | 4 +- 11 files changed, 154 insertions(+), 82 deletions(-) create mode 100644 application/core/Server/MatchSettingsManager.php diff --git a/application/core/Bills/BillData.php b/application/core/Bills/BillData.php index 51bf66ba..6f2200c4 100644 --- a/application/core/Bills/BillData.php +++ b/application/core/Bills/BillData.php @@ -2,8 +2,6 @@ namespace ManiaControl\Bills; -use ManiaControl\Players\Player; - /** * ManiaControl BillData Structure * @@ -26,7 +24,7 @@ class BillData { * Construct new BillData * * @param mixed $function - * @param Player/string $player + * @param Player /string $player * @param int $amount * @param bool $pay * @param string $receiverLogin diff --git a/application/core/Database/Database.php b/application/core/Database/Database.php index 39c8ce64..9fe30e8d 100644 --- a/application/core/Database/Database.php +++ b/application/core/Database/Database.php @@ -33,6 +33,7 @@ class Database implements TimerListener { $this->maniaControl = $maniaControl; // Get mysql server information + /** @var \SimpleXMLElement $databaseXmlTag */ $databaseXmlTag = $this->maniaControl->config->database; $host = $databaseXmlTag->xpath('host'); if (!$host) { diff --git a/application/core/Players/PlayerCommands.php b/application/core/Players/PlayerCommands.php index 83418ffe..bbc6859a 100644 --- a/application/core/Players/PlayerCommands.php +++ b/application/core/Players/PlayerCommands.php @@ -9,7 +9,7 @@ use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Commands\CommandListener; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkPageAnswerListener; -use ManiaControl\Server\Server; +use ManiaControl\Server\MatchSettingsManager; use Maniaplanet\DedicatedServer\Xmlrpc\Exception; /** @@ -62,7 +62,7 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, Ca $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_TEAM_BALANCE, AuthenticationManager::AUTH_LEVEL_MODERATOR); //CallbackManager - $this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'teamStatusChanged'); + $this->maniaControl->callbackManager->registerCallbackListener(MatchSettingsManager::CB_TEAM_MODE_CHANGED, $this, 'teamStatusChanged'); // Action Open Playerlist $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList'); diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 88ccc885..7da6aa12 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -326,7 +326,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer $playerQuad->addTooltipLabelFeature($descriptionLabel, $description); } - if ($this->maniaControl->server->isTeamMode()) { + if ($this->maniaControl->server->matchSettingsManager->isTeamMode()) { if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_TEAM)) { // Force to Red-Team Quad $redQuad = new Quad_Emblems(); diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 8a2bbac3..fc6e50ed 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -122,7 +122,7 @@ class PlayerManager implements CallbackListener, TimerListener { //Check if the Player is in a Team, to notify if its a TeamMode or not if ($playerItem->teamId != -1) { - $this->maniaControl->server->setTeamMode(true); + $this->maniaControl->server->matchSettingsManager->setTeamMode(true); } $player = new Player($this->maniaControl, true); @@ -321,7 +321,7 @@ class PlayerManager implements CallbackListener, TimerListener { //Check if the Player is in a Team, to notify if its a TeamMode or not if ($player->teamId != -1) { - $this->maniaControl->server->setTeamMode(true); + $this->maniaControl->server->matchSettingsManager->setTeamMode(true); } $prevJoinState = $player->hasJoinedGame; diff --git a/application/core/Plugins/PluginMenu.php b/application/core/Plugins/PluginMenu.php index 84ff71c1..edc2caf7 100644 --- a/application/core/Plugins/PluginMenu.php +++ b/application/core/Plugins/PluginMenu.php @@ -135,6 +135,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns return strcmp($a::getName(), $b::getName()); }); + $pageFrame = null; foreach ($pluginClasses as $index => $pluginClass) { /** @var Plugin $pluginClass */ if ($index % $pageMaxCount === 0) { @@ -253,6 +254,8 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns $y = 0; $index = 0; $settingHeight = 5.; + $pageFrame = null; + foreach ($settings as $setting) { if ($index % $pageSettingsMaxCount === 0) { $pageFrame = new Frame(); diff --git a/application/core/Server/MatchSettingsManager.php b/application/core/Server/MatchSettingsManager.php new file mode 100644 index 00000000..781df149 --- /dev/null +++ b/application/core/Server/MatchSettingsManager.php @@ -0,0 +1,96 @@ + + * @copyright 2014 ManiaControl Team + * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 + */ +class MatchSettingsManager implements CallbackListener { + /* + * Constants + */ + const CB_TEAM_MODE_CHANGED = 'MatchSettings.TeamModeChanged'; + + /* + * Private Properties + */ + private $maniaControl = null; + private $teamMode = null; + + /** + * Construct a new Match Settings Manager + * + * @param ManiaControl $maniaControl + */ + public function __construct(ManiaControl $maniaControl) { + $this->maniaControl = $maniaControl; + } + + /** + * Set whether the Server Runs a Team-Based Mode or not + * + * @param bool $teamMode + */ + public function setTeamMode($teamMode = true) { + $oldStatus = $this->teamMode; + $this->teamMode = (bool)$teamMode; + + // Trigger callback + if ($oldStatus !== $this->teamMode | $oldStatus === null) { + $this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode); + } + } + + /** + * Check if the Server Runs a Team-Based Mode + * + * @return bool + */ + public function isTeamMode() { + return $this->teamMode; + } + + + /** + * Fetch the current Game Mode + * + * @param bool $stringValue + * @param int $parseValue + * @return int | string + */ + public function getGameMode($stringValue = false, $parseValue = null) { + if (is_int($parseValue)) { + $gameMode = $parseValue; + } else { + $gameMode = $this->maniaControl->client->getGameMode(); + } + if ($stringValue) { + switch ($gameMode) { + case 0: + return 'Script'; + case 1: + return 'Rounds'; + case 2: + return 'TimeAttack'; + case 3: + return 'Team'; + case 4: + return 'Laps'; + case 5: + return 'Cup'; + case 6: + return 'Stunts'; + default: + return 'Unknown'; + } + } + return $gameMode; + } +} diff --git a/application/core/Server/Server.php b/application/core/Server/Server.php index f89ec379..d330517f 100644 --- a/application/core/Server/Server.php +++ b/application/core/Server/Server.php @@ -19,8 +19,7 @@ class Server implements CallbackListener { /* * Constants */ - const TABLE_SERVERS = 'mc_servers'; - const CB_TEAM_MODE_CHANGED = 'ServerCallback.TeamModeChanged'; + const TABLE_SERVERS = 'mc_servers'; /* * Public Properties @@ -38,12 +37,12 @@ class Server implements CallbackListener { public $usageReporter = null; public $rankingManager = null; public $scriptManager = null; + public $matchSettingsManager = null; /* * Private Properties */ private $maniaControl = null; - private $teamMode = false; /** * Construct a new Server @@ -54,10 +53,11 @@ class Server implements CallbackListener { $this->maniaControl = $maniaControl; $this->initTables(); - $this->serverCommands = new ServerCommands($maniaControl); - $this->usageReporter = new UsageReporter($maniaControl); - $this->rankingManager = new RankingManager($maniaControl); - $this->scriptManager = new ScriptManager($maniaControl); + $this->serverCommands = new ServerCommands($maniaControl); + $this->usageReporter = new UsageReporter($maniaControl); + $this->rankingManager = new RankingManager($maniaControl); + $this->scriptManager = new ScriptManager($maniaControl); + $this->matchSettingsManager = new MatchSettingsManager($maniaControl); // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit'); @@ -223,30 +223,6 @@ class Server implements CallbackListener { $statement->close(); } - /** - * Set if the Server Runs a Team-Mode or not - * - * @param bool $teamMode - */ - public function setTeamMode($teamMode = true) { - $oldStatus = $this->teamMode; - $this->teamMode = $teamMode; - - // Trigger callback - if ($oldStatus != $this->teamMode) { - $this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_MODE_CHANGED, $teamMode); - } - } - - /** - * Check if the Server Runs a TeamMode - * - * @return bool - */ - public function isTeamMode() { - return $this->teamMode; - } - /** * Fetch Maps Directory * @@ -314,7 +290,7 @@ class Server implements CallbackListener { // Build file name $map = $this->maniaControl->mapManager->getCurrentMap(); - $gameMode = $this->getGameMode(); + $gameMode = $this->matchSettingsManager->getGameMode(); $time = time(); $fileName = "GhostReplays/Ghost.{$login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx"; @@ -351,42 +327,6 @@ class Server implements CallbackListener { return (is_dir($directory) && is_writable($directory)); } - /** - * Fetch current Game Mode - * - * @param bool $stringValue - * @param int $parseValue - * @return int | string - */ - public function getGameMode($stringValue = false, $parseValue = null) { - if (is_int($parseValue)) { - $gameMode = $parseValue; - } else { - $gameMode = $this->maniaControl->client->getGameMode(); - } - if ($stringValue) { - switch ($gameMode) { - case 0: - return 'Script'; - case 1: - return 'Rounds'; - case 2: - return 'TimeAttack'; - case 3: - return 'Team'; - case 4: - return 'Laps'; - case 5: - return 'Cup'; - case 6: - return 'Stunts'; - default: - return 'Unknown'; - } - } - return $gameMode; - } - /** * Wait for the Server to have the given Status * @@ -420,4 +360,38 @@ class Server implements CallbackListener { } return true; } + + + /** + * Set whether the Server Runs a Team-Based Mode or not + * + * @deprecated Use MatchSettingsManager instead + * @param bool $teamMode + */ + public function setTeamMode($teamMode = true) { + $this->matchSettingsManager->setTeamMode($teamMode); + } + + /** + * Check if the Server Runs a Team-Based Mode + * + * @deprecated Use MatchSettingsManager instead + * @return bool + */ + public function isTeamMode() { + $this->matchSettingsManager->isTeamMode(); + } + + + /** + * Fetch the current Game Mode + * + * @deprecated Use MatchSettingsManager instead + * @param bool $stringValue + * @param int $parseValue + * @return int | string + */ + public function getGameMode($stringValue = false, $parseValue = null) { + $this->matchSettingsManager->getGameMode($stringValue, $parseValue); + } } diff --git a/application/plugins/MCTeam/CustomVotesPlugin.php b/application/plugins/MCTeam/CustomVotesPlugin.php index 27b8fe81..de0c2a9f 100644 --- a/application/plugins/MCTeam/CustomVotesPlugin.php +++ b/application/plugins/MCTeam/CustomVotesPlugin.php @@ -25,7 +25,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; -use ManiaControl\Server\Server; +use ManiaControl\Server\MatchSettingsManager; use ManiaControl\Server\ServerCommands; use Maniaplanet\DedicatedServer\Structures\VoteRatio; use Maniaplanet\DedicatedServer\Xmlrpc\NotInScriptModeException; @@ -139,7 +139,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer'); $this->maniaControl->callbackManager->registerCallbackListener(self::CB_CUSTOM_VOTE_FINISHED, $this, 'handleVoteFinished'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerConnect'); - $this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_MODE_CHANGED, $this, 'constructMenu'); + $this->maniaControl->callbackManager->registerCallbackListener(MatchSettingsManager::CB_TEAM_MODE_CHANGED, $this, 'constructMenu'); //Settings $this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.); @@ -243,7 +243,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap'); $this->addVoteMenuItem($itemQuad, 15, 'Vote for a Mapskip'); - if ($this->maniaControl->server->isTeamMode()) { + if ($this->maniaControl->server->matchSettingsManager->isTeamMode()) { //Menu TeamBalance $itemQuad = new Quad_Icons128x32_1(); $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); diff --git a/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php b/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php index 2465f321..4af944d2 100644 --- a/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php +++ b/application/plugins/MCTeam/Dedimania/DedimaniaPlugin.php @@ -358,7 +358,7 @@ class DedimaniaPlugin implements CallbackListener, CommandListener, TimerListene * @return String */ private function getGameModeString() { - $gameMode = $this->maniaControl->server->getGameMode(); + $gameMode = $this->maniaControl->server->matchSettingsManager->getGameMode(); $scriptNameResponse = $this->maniaControl->client->getScriptName(); $scriptName = str_replace('.Script.txt', '', $scriptNameResponse["CurrentValue"]); if ($gameMode === null) { diff --git a/application/plugins/MCTeam/KarmaPlugin.php b/application/plugins/MCTeam/KarmaPlugin.php index fccd6abe..ff0ba3d0 100644 --- a/application/plugins/MCTeam/KarmaPlugin.php +++ b/application/plugins/MCTeam/KarmaPlugin.php @@ -335,7 +335,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $properties = array(); - $gameMode = $this->maniaControl->server->getGameMode(true); + $gameMode = $this->maniaControl->server->matchSettingsManager->getGameMode(true); if ($gameMode == 'Script') { $scriptName = $this->maniaControl->client->getScriptName(); $properties['gamemode'] = $scriptName["CurrentValue"]; @@ -444,7 +444,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { return; } - $gameMode = $this->maniaControl->server->getGameMode(true); + $gameMode = $this->maniaControl->server->matchSettingsManager->getGameMode(true); if (count($votes) == 0) { return;