diff --git a/application/core/Players/PlayerCommands.php b/application/core/Players/PlayerCommands.php index c8b84843..f33f2ece 100644 --- a/application/core/Players/PlayerCommands.php +++ b/application/core/Players/PlayerCommands.php @@ -5,16 +5,18 @@ namespace ManiaControl\Players; use FML\Controls\Quads\Quad_Icons128x32_1; use FML\Controls\Quads\Quad_UIConstruction_Buttons; use ManiaControl\Admin\AuthenticationManager; +use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Commands\CommandListener; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkPageAnswerListener; +use ManiaControl\Server\Server; /** * Class offering various Admin Commands related to Players * * @author steeffeen & kremsy */ -class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { +class PlayerCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener { /** * Constants */ @@ -61,12 +63,8 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_BOT, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_TEAM_BALANCE, AuthenticationManager::AUTH_LEVEL_MODERATOR); - // Action Balance Teams - $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance'); - $itemQuad = new Quad_Icons128x32_1(); - $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); - $itemQuad->setAction(self::ACTION_BALANCE_TEAMS); - $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 40, 'Balance Teams'); + //CallbackManager + $this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_STATUS_CHANGED, $this, 'teamStatusChanged'); // Action Open Playerlist $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_OPEN_PLAYERLIST, $this, 'command_playerList'); @@ -76,6 +74,22 @@ class PlayerCommands implements CommandListener, ManialinkPageAnswerListener { $this->maniaControl->actionsMenu->addMenuItem($itemQuad, true, 15, 'Open Playerlist'); } + /** + * Handle TeamStatusChanged + * @param array $callback + */ + public function teamStatusChanged(array $callback) { + $status = $callback[1]; + //Add Balance Team Icon if it's a teamMode + if ($status) { + // Action Balance Teams + $this->maniaControl->manialinkManager->registerManialinkPageAnswerListener(self::ACTION_BALANCE_TEAMS, $this, 'command_TeamBalance'); + $itemQuad = new Quad_Icons128x32_1(); + $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); + $itemQuad->setAction(self::ACTION_BALANCE_TEAMS); + $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 40, 'Balance Teams'); + } + } /** * Handle //teambalance command diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 9bfda355..edcfa13c 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -277,29 +277,31 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer // Description Label $script->addTooltip($playerQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Advanced Player Actions on " . $listPlayer->nickname)); - // Force to Red-Team Quad - $redQuad = new Quad_Emblems(); - $playerFrame->add($redQuad); - $redQuad->setX($x + 145); - $redQuad->setZ(0.1); - $redQuad->setSubStyle($redQuad::SUBSTYLE_2); - $redQuad->setSize(3.8, 3.8); - $redQuad->setAction(self::ACTION_FORCE_RED . "." . $listPlayer->login); + if($this->maniaControl->server->isTeamMode()){ + // Force to Red-Team Quad + $redQuad = new Quad_Emblems(); + $playerFrame->add($redQuad); + $redQuad->setX($x + 145); + $redQuad->setZ(0.1); + $redQuad->setSubStyle($redQuad::SUBSTYLE_2); + $redQuad->setSize(3.8, 3.8); + $redQuad->setAction(self::ACTION_FORCE_RED . "." . $listPlayer->login); - // Force to Red-Team Description Label - $script->addTooltip($redQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force " . $listPlayer->nickname . '$z to Red Team!')); + // Force to Red-Team Description Label + $script->addTooltip($redQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force " . $listPlayer->nickname . '$z to Red Team!')); - // Force to Blue-Team Quad - $blueQuad = new Quad_Emblems(); - $playerFrame->add($blueQuad); - $blueQuad->setX($x + 141); - $blueQuad->setZ(0.1); - $blueQuad->setSubStyle($blueQuad::SUBSTYLE_1); - $blueQuad->setSize(3.8, 3.8); - $blueQuad->setAction(self::ACTION_FORCE_BLUE . "." . $listPlayer->login); + // Force to Blue-Team Quad + $blueQuad = new Quad_Emblems(); + $playerFrame->add($blueQuad); + $blueQuad->setX($x + 141); + $blueQuad->setZ(0.1); + $blueQuad->setSubStyle($blueQuad::SUBSTYLE_1); + $blueQuad->setSize(3.8, 3.8); + $blueQuad->setAction(self::ACTION_FORCE_BLUE . "." . $listPlayer->login); - // Force to Blue-Team Description Label - $script->addTooltip($blueQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force " . $listPlayer->nickname . '$z to Blue Team!')); + // Force to Blue-Team Description Label + $script->addTooltip($blueQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force " . $listPlayer->nickname . '$z to Blue Team!')); + } // Force to Spectator Quad $spectatorQuad = new Quad_BgRaceScore2(); diff --git a/application/core/Players/PlayerManager.php b/application/core/Players/PlayerManager.php index 4551a7f9..f236a5be 100644 --- a/application/core/Players/PlayerManager.php +++ b/application/core/Players/PlayerManager.php @@ -128,6 +128,11 @@ class PlayerManager implements CallbackListener { $playerItem->hoursSinceZoneInscription = $detailedPlayerInfo->hoursSinceZoneInscription; + //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); + } + $player = new Player($playerItem); $player->hasJoinedGame = true; $this->addPlayer($player); @@ -186,8 +191,14 @@ class PlayerManager implements CallbackListener { return; } - $player->teamId = $callback[1][0]["TeamId"]; + $player->ladderRank = $callback[1][0]["LadderRanking"]; + $player->teamId = $callback[1][0]["TeamId"]; + + //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); + } $prevJoinState = $player->hasJoinedGame; @@ -316,7 +327,7 @@ class PlayerManager implements CallbackListener { if (!isset($row)) { return null; } - + $player = new Player(false); $player->index = $playerIndex; $player->login = $row->login; diff --git a/application/core/Server/Server.php b/application/core/Server/Server.php index 0d78b4ae..2794a16f 100644 --- a/application/core/Server/Server.php +++ b/application/core/Server/Server.php @@ -18,7 +18,8 @@ class Server implements CallbackListener { /** * Constants */ - const TABLE_SERVERS = 'mc_servers'; + const TABLE_SERVERS = 'mc_servers'; + const CB_TEAM_STATUS_CHANGED = 'ServerCallback.TeamStatusChanged'; /** * Public Properties @@ -33,10 +34,12 @@ class Server implements CallbackListener { public $serverCommands = null; public $usageReporter = null; + /** * Private Properties */ private $maniaControl = null; + private $teamMode = false; /** * Construct a new Server @@ -126,6 +129,28 @@ class Server implements CallbackListener { $this->updateProperties(); } + /** + * Set if the Server Runs a Team-Mode or not + * + * @param bool $teamMode + */ + public function setTeamMode($teamMode = true) { + $this->teamMode = $teamMode; + + // Trigger callback + $this->maniaControl->callbackManager->triggerCallback(self::CB_TEAM_STATUS_CHANGED, array(self::CB_TEAM_STATUS_CHANGED, $teamMode)); + } + + /** + * Check if the Server Runs a TeamMode + * + * @return bool + */ + public function isTeamMode() { + return $this->teamMode; + } + + /** * Fetch Game Data Directory * diff --git a/application/core/Server/ServerCommands.php b/application/core/Server/ServerCommands.php index 570abd79..a15d53d9 100644 --- a/application/core/Server/ServerCommands.php +++ b/application/core/Server/ServerCommands.php @@ -83,7 +83,6 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage //Check if Pause exists in current GameMode $scriptInfos = $this->maniaControl->client->getModeScriptInfo(); - $pauseExists = false; foreach($scriptInfos->commandDescs as $param) { if ($param->name == "Command_ForceWarmUp") { @@ -122,6 +121,7 @@ class ServerCommands implements CallbackListener, CommandListener, ManialinkPage $this->maniaControl->actionsMenu->addMenuItem($itemQuad, false, 30, 'Cancel Vote'); } + /** * Handle //cancelvote command *