diff --git a/application/core/Callbacks/CallbackManager.php b/application/core/Callbacks/CallbackManager.php index 5a6752bf..9dc28fec 100644 --- a/application/core/Callbacks/CallbackManager.php +++ b/application/core/Callbacks/CallbackManager.php @@ -16,6 +16,7 @@ class CallbackManager { * Constants */ // ManiaControl callbacks + // TODO: move into Callbacks interface const CB_ONINIT = 'ManiaControl.OnInit'; const CB_AFTERINIT = 'ManiaControl.AfterInit'; const CB_ONSHUTDOWN = 'ManiaControl.OnShutdown'; diff --git a/application/core/Maps/Map.php b/application/core/Maps/Map.php index db552fc1..c1344540 100644 --- a/application/core/Maps/Map.php +++ b/application/core/Maps/Map.php @@ -39,7 +39,7 @@ class Map { public $titleUid = ''; public $startTime = -1; public $lastUpdate = 0; - + public $karma = null; /** * Create a new Map Object from Rpc Data diff --git a/application/core/Players/PlayerCommands.php b/application/core/Players/PlayerCommands.php index bbc6859a..83418ffe 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\MatchSettingsManager; +use ManiaControl\Server\Server; 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(MatchSettingsManager::CB_TEAM_MODE_CHANGED, $this, 'teamStatusChanged'); + $this->maniaControl->callbackManager->registerCallbackListener(Server::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 7da6aa12..88ccc885 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->matchSettingsManager->isTeamMode()) { + if ($this->maniaControl->server->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 fc6e50ed..8a2bbac3 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->matchSettingsManager->setTeamMode(true); + $this->maniaControl->server->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->matchSettingsManager->setTeamMode(true); + $this->maniaControl->server->setTeamMode(true); } $prevJoinState = $player->hasJoinedGame; diff --git a/application/core/Server/MatchSettingsManager.php b/application/core/Server/MatchSettingsManager.php deleted file mode 100644 index 781df149..00000000 --- a/application/core/Server/MatchSettingsManager.php +++ /dev/null @@ -1,96 +0,0 @@ - - * @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 d330517f..7dfc05e7 100644 --- a/application/core/Server/Server.php +++ b/application/core/Server/Server.php @@ -19,7 +19,8 @@ class Server implements CallbackListener { /* * Constants */ - const TABLE_SERVERS = 'mc_servers'; + const TABLE_SERVERS = 'mc_servers'; + const CB_TEAM_MODE_CHANGED = 'Server.TeamModeChanged'; /* * Public Properties @@ -37,12 +38,12 @@ class Server implements CallbackListener { public $usageReporter = null; public $rankingManager = null; public $scriptManager = null; - public $matchSettingsManager = null; /* * Private Properties */ private $maniaControl = null; + private $teamMode = null; /** * Construct a new Server @@ -53,11 +54,10 @@ 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->matchSettingsManager = new MatchSettingsManager($maniaControl); + $this->serverCommands = new ServerCommands($maniaControl); + $this->usageReporter = new UsageReporter($maniaControl); + $this->rankingManager = new RankingManager($maniaControl); + $this->scriptManager = new ScriptManager($maniaControl); // Register for callbacks $this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_ONINIT, $this, 'onInit'); @@ -290,7 +290,7 @@ class Server implements CallbackListener { // Build file name $map = $this->maniaControl->mapManager->getCurrentMap(); - $gameMode = $this->matchSettingsManager->getGameMode(); + $gameMode = $this->getGameMode(); $time = time(); $fileName = "GhostReplays/Ghost.{$login}.{$gameMode}.{$time}.{$map->uid}.Replay.Gbx"; @@ -327,6 +327,42 @@ class Server implements CallbackListener { return (is_dir($directory) && is_writable($directory)); } + /** + * 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; + } + /** * Wait for the Server to have the given Status * @@ -361,37 +397,27 @@ 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); + $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 * - * @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); + return $this->teamMode; } } diff --git a/application/plugins/MCTeam/CustomVotesPlugin.php b/application/plugins/MCTeam/CustomVotesPlugin.php index de0c2a9f..27b8fe81 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\MatchSettingsManager; +use ManiaControl\Server\Server; 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(MatchSettingsManager::CB_TEAM_MODE_CHANGED, $this, 'constructMenu'); + $this->maniaControl->callbackManager->registerCallbackListener(Server::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->matchSettingsManager->isTeamMode()) { + if ($this->maniaControl->server->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 4af944d2..2465f321 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->matchSettingsManager->getGameMode(); + $gameMode = $this->maniaControl->server->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 ff0ba3d0..a8056120 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->matchSettingsManager->getGameMode(true); + $gameMode = $this->maniaControl->server->getGameMode(true); if ($gameMode == 'Script') { $scriptName = $this->maniaControl->client->getScriptName(); $properties['gamemode'] = $scriptName["CurrentValue"]; @@ -384,7 +384,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $self->maniaControl->log("MX-Karma Votes successfully fetched"); } else { $self->maniaControl->log("Error while fetching votes: " . $data->data->message); - if($data->data->message == "invalid session"){ + if ($data->data->message == "invalid session") { unset($this->mxKarma['session']); return; } @@ -444,7 +444,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { return; } - $gameMode = $this->maniaControl->server->matchSettingsManager->getGameMode(true); + $gameMode = $this->maniaControl->server->getGameMode(true); if (count($votes) == 0) { return; @@ -481,7 +481,7 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin { $self->maniaControl->log("Votes successfully permitted"); } else { $self->maniaControl->log("Error while updating votes: " . $data->data->message); - if($data->data->message == "invalid session"){ + if ($data->data->message == "invalid session") { unset($this->mxKarma['session']); return; }