diff --git a/application/core/Maps/MapList.php b/application/core/Maps/MapList.php index 0e8a68be..a3d602c9 100644 --- a/application/core/Maps/MapList.php +++ b/application/core/Maps/MapList.php @@ -332,7 +332,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { $switchLabel->setText('ยป'); $switchLabel->setTextColor('0f0'); - $switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1) . '.' . $map->uid); + $switchLabel->setAction(self::ACTION_START_SWITCH_VOTE . '.' . ($id - 1)); $script->addTooltip($switchLabel, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => 'Start Map-Switch vote: $<' . $map->name . '$>')); } else if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) { @@ -528,8 +528,11 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener { $votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN); $mapList = $this->maniaControl->mapManager->getMaps(); $map = $mapList[$mapId]; + + $message = '$<' . $player->nickname . '$>$s started a vote to switch to $<' . $map->name . '$>!'; + /** @var Map $map */ - $votesPlugin->defineVote('switchmap', "Goto " . $map->name, true); + $votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message); $votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) { $this->maniaControl->chat->sendInformation('$sVote Successfully -> Map switched!'); diff --git a/application/core/Players/PlayerList.php b/application/core/Players/PlayerList.php index 6a04bcf3..b56c156b 100644 --- a/application/core/Players/PlayerList.php +++ b/application/core/Players/PlayerList.php @@ -2,6 +2,7 @@ namespace ManiaControl\Players; +use CustomVotesPlugin; use FML\Controls\Control; use FML\Controls\Frame; use FML\Controls\Labels\Label_Button; @@ -35,6 +36,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer const ACTION_FORCE_RED = 'PlayerList.ForceRed'; const ACTION_FORCE_BLUE = 'PlayerList.ForceBlue'; const ACTION_FORCE_SPEC = 'PlayerList.ForceSpec'; + const ACTION_FORCE_SPEC_VOTE = 'PlayerList.ForceSpecVote'; const ACTION_FORCE_PLAY = 'PlayerList.ForcePlay'; const ACTION_PLAYER_ADV = 'PlayerList.PlayerAdvancedActions'; const ACTION_CLOSE_PLAYER_ADV = 'PlayerList.ClosePlayerAdvWidget'; @@ -42,6 +44,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer const ACTION_UNMUTE_PLAYER = 'PlayerList.UnMutePlayer'; const ACTION_WARN_PLAYER = 'PlayerList.WarnPlayer'; const ACTION_KICK_PLAYER = 'PlayerList.KickPlayer'; + const ACTION_KICK_PLAYER_VOTE = 'PlayerList.KickPlayerVote'; const ACTION_BAN_PLAYER = 'PlayerList.BanPlayer'; const ACTION_ADD_AS_MASTER = 'PlayerList.PlayerAddAsMaster'; const ACTION_ADD_AS_ADMIN = 'PlayerList.PlayerAddAsAdmin'; @@ -49,6 +52,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer const ACTION_REVOKE_RIGHTS = 'PlayerList.RevokeRights'; const ACTION_OPEN_PLAYER_DETAILED = 'PlayerList.OpenPlayerDetailed'; const ACTION_SPECTATE_PLAYER = 'PlayerList.SpectatePlayer'; + const DEFAULT_CUSTOM_VOTE_PLUGIN = 'CustomVotesPlugin'; const SHOWN_MAIN_WINDOW = -1; const MAX_PLAYERS_PER_PAGE = 15; @@ -277,8 +281,10 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer // Description Label $script->addTooltip($playerQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Advanced Player Actions on " . $listPlayer->nickname)); + } - if ($this->maniaControl->server->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(); $playerFrame->add($redQuad); @@ -289,7 +295,7 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer $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!')); + $script->addTooltip($redQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force $<" . $listPlayer->nickname . '$> to Red Team!')); // Force to Blue-Team Quad $blueQuad = new Quad_Emblems(); @@ -301,8 +307,23 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer $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!')); - } else { + $script->addTooltip($blueQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force $<" . $listPlayer->nickname . '$> to Blue Team!')); + + } else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) { + // Kick Player Vote + $kickQuad = new Quad_UIConstruction_Buttons(); + $playerFrame->add($kickQuad); + $kickQuad->setX($x + 141); + $kickQuad->setZ(0.1); + $kickQuad->setSubStyle($kickQuad::SUBSTYLE_Validate_Step2); + $kickQuad->setSize(3.8, 3.8); + $kickQuad->setAction(self::ACTION_KICK_PLAYER_VOTE . "." . $listPlayer->login); + + // Force to Spectator Description Label + $script->addTooltip($kickQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Vote a kick vote on $<" . $listPlayer->nickname . '$>!')); + } + } else { + if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_PLAY)) { // Force to Play $playQuad = new Quad_Emblems(); $playerFrame->add($playQuad); @@ -315,7 +336,9 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer // Force to Blue-Team Description Label $script->addTooltip($playQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force " . $listPlayer->nickname . '$z to Play!')); } + } + if ($this->maniaControl->authenticationManager->checkPermission($player, PlayerActions::SETTING_PERMISSION_FORCE_PLAYER_SPEC)) { // Force to Spectator Quad $spectatorQuad = new Quad_BgRaceScore2(); $playerFrame->add($spectatorQuad); @@ -327,7 +350,20 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer // Force to Spectator Description Label $script->addTooltip($spectatorQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Force " . $listPlayer->nickname . '$z to Spectator!')); + } else if ($this->maniaControl->pluginManager->isPluginActive(self::DEFAULT_CUSTOM_VOTE_PLUGIN)) { + // Force to Spectator Quad + $spectatorQuad = new Quad_BgRaceScore2(); + $playerFrame->add($spectatorQuad); + $spectatorQuad->setX($x + 137); + $spectatorQuad->setZ(0.1); + $spectatorQuad->setSubStyle($spectatorQuad::SUBSTYLE_Spectator); + $spectatorQuad->setSize(3.8, 3.8); + $spectatorQuad->setAction(self::ACTION_FORCE_SPEC_VOTE . "." . $listPlayer->login); + + // Force to Spectator Description Label + $script->addTooltip($spectatorQuad, $descriptionLabel, array(Script::OPTION_TOOLTIP_TEXT => "Vote for force " . $listPlayer->nickname . '$z to Spectator!')); } + $y -= 4; $i++; if ($i % self::MAX_PLAYERS_PER_PAGE == 0) { @@ -667,6 +703,54 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer case self::ACTION_REVOKE_RIGHTS: $this->maniaControl->playerManager->playerActions->revokeAuthLevel($adminLogin, $targetLogin); break; + case self::ACTION_FORCE_SPEC_VOTE: + /** @var $votesPlugin CustomVotesPlugin */ + $votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN); + + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + + $startMessage = '$<' . $admin->nickname . '$>$s started a vote to force $<' . $target->nickname . '$> into spectator!'; + + $votesPlugin->defineVote('forcespec', "Force $<" . $target->nickname . "$> Spec", true, $startMessage); + + $votesPlugin->startVote($admin, 'forcespec', function ($result) use (&$votesPlugin, &$target) { + $this->maniaControl->chat->sendInformation('$sVote Successfully -> Player $<' . $target->nickname . '$> forced to Spectator!'); + $votesPlugin->undefineVote('forcespec'); + + try { + $this->maniaControl->client->forceSpectator($target->login, PlayerActions::SPECTATOR_BUT_KEEP_SELECTABLE); + $this->maniaControl->client->spectatorReleasePlayerSlot($target->login); + } catch(\Exception $e) { + //do nothing + } + }); + break; + case self::ACTION_KICK_PLAYER_VOTE: + /** @var $votesPlugin CustomVotesPlugin */ + $votesPlugin = $this->maniaControl->pluginManager->getPlugin(self::DEFAULT_CUSTOM_VOTE_PLUGIN); + + $admin = $this->maniaControl->playerManager->getPlayer($adminLogin); + $target = $this->maniaControl->playerManager->getPlayer($targetLogin); + + $startMessage = '$<' . $admin->nickname . '$>$s started a vote to kick $<' . $target->nickname . '$>!'; + + + $votesPlugin->defineVote('kick', "Kick $<" . $target->nickname . "$>", true, $startMessage); + + $votesPlugin->startVote($admin, 'kick', function ($result) use (&$votesPlugin, &$target) { + $this->maniaControl->chat->sendInformation('$sVote Successfully -> $<' . $target->nickname . '$> got Kicked!'); + $votesPlugin->undefineVote('kick'); + + $message = '$39F You got kicked due a Public vote!$z '; + try { + $this->maniaControl->client->kick($target->login, $message); + } catch(\Exception $e) { + $this->maniaControl->chat->sendError('Error occurred: ' . $e->getMessage(), $target->login); + return; + } + }); + break; } } @@ -692,4 +776,4 @@ class PlayerList implements ManialinkPageAnswerListener, CallbackListener, Timer } } } -} \ No newline at end of file +} \ No newline at end of file diff --git a/application/plugins/ChatMessagePlugin.php b/application/plugins/ChatMessagePlugin.php index 17cd1bbf..e6092204 100644 --- a/application/plugins/ChatMessagePlugin.php +++ b/application/plugins/ChatMessagePlugin.php @@ -308,7 +308,7 @@ class ChatMessagePlugin implements CommandListener, Plugin { $msg = '$i$ff0 $<' . $player->nickname . '$>$s$39f chooses to boot back to the real world!'; $this->maniaControl->chat->sendChat($msg, null, true); - $message = '$39F Thanks for Playing, please come back soon!$z'; + $message = '$39F Thanks for Playing, please come back soon!$z '; try { $this->maniaControl->client->kick($player->login, $message); } catch(\Exception $e) { @@ -327,7 +327,7 @@ class ChatMessagePlugin implements CommandListener, Plugin { $msg = '$i$ff0 $<' . $player->nickname . '$>$s$f00 said: "@"#!" and ragequitted!'; $this->maniaControl->chat->sendChat($msg, null, true); - $message = '$39F Thanks for Playing, please come back soon!$z'; + $message = '$39F Thanks for Playing, please come back soon!$z '; try { $this->maniaControl->client->kick($player->login, $message); } catch(\Exception $e) { diff --git a/application/plugins/CustomVotes.php b/application/plugins/CustomVotes.php index 5bb59b30..2b3003fa 100644 --- a/application/plugins/CustomVotes.php +++ b/application/plugins/CustomVotes.php @@ -23,6 +23,7 @@ use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Players\Player; use ManiaControl\Players\PlayerManager; use ManiaControl\Plugins\Plugin; +use ManiaControl\Server\Server; use ManiaControl\Server\ServerCommands; use Maniaplanet\DedicatedServer\Structures\VoteRatio; @@ -105,6 +106,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_PLAYERJOINED, $this, 'handlePlayerConnect'); + $this->maniaControl->callbackManager->registerCallbackListener(Server::CB_TEAM_STATUS_CHANGED, $this, 'constructMenu'); //Settings $this->maniaControl->settingManager->initSetting($this, self::SETTING_VOTE_ICON_POSX, 156.); @@ -264,12 +266,13 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $itemQuad->setAction(self::ACTION_START_VOTE . 'skipmap'); $this->addVoteMenuItem($itemQuad, 15, 'Vote for a Mapskip'); - //Menu TeamBalance - $itemQuad = new Quad_Icons128x32_1(); - $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); - $itemQuad->setAction(self::ACTION_START_VOTE . 'teambalance'); - $this->addVoteMenuItem($itemQuad, 20, 'Vote for Team-Balance'); - + if ($this->maniaControl->server->isTeamMode()) { + //Menu TeamBalance + $itemQuad = new Quad_Icons128x32_1(); + $itemQuad->setSubStyle($itemQuad::SUBSTYLE_RT_Team); + $itemQuad->setAction(self::ACTION_START_VOTE . 'teambalance'); + $this->addVoteMenuItem($itemQuad, 20, 'Vote for Team-Balance'); + } //Show the Menu's icon $this->showIcon(); } @@ -352,11 +355,13 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP * @param bool $idBased * @param $neededRatio */ - public function defineVote($voteIndex, $voteName, $idBased = false, $neededRatio = -1) { + public function defineVote($voteIndex, $voteName, $idBased = false, $startText = '', $neededRatio = -1) { if ($neededRatio == -1) { $neededRatio = $this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_RATIO); } - $this->voteCommands[$voteIndex] = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio); + $voteCommand = new VoteCommand($voteIndex, $voteName, $idBased, $neededRatio); + $voteCommand->startText = $startText; + $this->voteCommands[$voteIndex] = $voteCommand; } /** @@ -410,7 +415,13 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $this->currentVote->neededPlayerRatio = floatval($this->maniaControl->settingManager->getSetting($this, self::SETTING_DEFAULT_PLAYER_RATIO)); $this->currentVote->function = $function; - $this->maniaControl->chat->sendSuccess('$<' . $player->nickname . '$>$s started a $<' . $this->currentVote->voteCommand->name . '$>!'); + if ($this->currentVote->voteCommand->startText != '') { + $message = $this->currentVote->voteCommand->startText; + } else { + $message = '$<' . $player->nickname . '$>$s started a $<' . $this->currentVote->voteCommand->name . '$>!'; + } + + $this->maniaControl->chat->sendSuccess($message); } /** @@ -506,7 +517,7 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP $frame = new Frame(); $maniaLink->add($frame); $frame->setSize($width, $height); - $frame->setPosition($pos_x, $pos_y); + $frame->setPosition($pos_x, $pos_y, 30); // Background Quad $backgroundQuad = new Quad(); @@ -767,10 +778,11 @@ class CustomVotesPlugin implements CommandListener, CallbackListener, ManialinkP * Vote Command Structure */ class VoteCommand { - public $index; - public $name; - public $neededRatio; - public $idBased; + public $index = ''; + public $name = ''; + public $neededRatio = 0; + public $idBased = false; + public $startText = ''; public function __construct($index, $name, $idBased, $neededRatio) { $this->index = $index;