From 31be7e74098672e4be5969688ad76d58e41fcfa8 Mon Sep 17 00:00:00 2001 From: kremsy Date: Mon, 8 May 2017 22:42:43 +0200 Subject: [PATCH] Trackmania Added Points repartition commands --- core/Script/ModeScriptEventManager.php | 2 +- core/Server/Commands.php | 82 ++++++++++++++++++++++---- 2 files changed, 72 insertions(+), 12 deletions(-) diff --git a/core/Script/ModeScriptEventManager.php b/core/Script/ModeScriptEventManager.php index 056a6ab1..34ab8c2c 100644 --- a/core/Script/ModeScriptEventManager.php +++ b/core/Script/ModeScriptEventManager.php @@ -468,7 +468,7 @@ class ModeScriptEventManager implements UsageInformationAble { * @param array String Array of Points */ public function setTrackmaniaPointsRepartition($pointArray) { - $this->maniaControl->getClient()->triggerModeScriptEvent('Trackmania.GetPointsRepartition', array($pointArray)); + $this->maniaControl->getClient()->triggerModeScriptEvent('Trackmania.SetPointsRepartition', $pointArray); } /** diff --git a/core/Server/Commands.php b/core/Server/Commands.php index 66789c1f..68679ef4 100644 --- a/core/Server/Commands.php +++ b/core/Server/Commands.php @@ -9,6 +9,7 @@ use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\Callbacks; use ManiaControl\Callbacks\Structures\Common\StatusCallbackStructure; +use ManiaControl\Callbacks\Structures\TrackMania\OnPointsRepartitionStructure; use ManiaControl\Callbacks\TimerListener; use ManiaControl\Commands\CommandListener; use ManiaControl\Logger; @@ -28,17 +29,18 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer /* * Constants */ - const ACTION_SET_PAUSE = 'ServerCommands.SetPause'; - const ACTION_EXTEND_WARMUP = 'ServerCommands.ExtendWarmup'; - const ACTION_END_WARMUP = 'ServerCommands.EndWarmup'; - const ACTION_CANCEL_VOTE = 'ServerCommands.CancelVote'; - const CB_VOTE_CANCELLED = 'ServerCommands.VoteCancelled'; - const SETTING_PERMISSION_CANCEL_VOTE = 'Cancel Vote'; - const SETTING_PERMISSION_SET_PAUSE = 'Set Pause'; - const SETTING_PERMISSION_HANDLE_WARMUP = 'Handle Warmup'; - const SETTING_PERMISSION_SHOW_SYSTEMINFO = 'Show SystemInfo'; - const SETTING_PERMISSION_SHUTDOWN_SERVER = 'Shutdown Server'; - const SETTING_PERMISSION_CHANGE_SERVERSETTINGS = 'Change ServerSettings'; + const ACTION_SET_PAUSE = 'ServerCommands.SetPause'; + const ACTION_EXTEND_WARMUP = 'ServerCommands.ExtendWarmup'; + const ACTION_END_WARMUP = 'ServerCommands.EndWarmup'; + const ACTION_CANCEL_VOTE = 'ServerCommands.CancelVote'; + const CB_VOTE_CANCELLED = 'ServerCommands.VoteCancelled'; + const SETTING_PERMISSION_CANCEL_VOTE = 'Cancel Vote'; + const SETTING_PERMISSION_SET_PAUSE = 'Set Pause'; + const SETTING_PERMISSION_HANDLE_WARMUP = 'Handle Warmup'; + const SETTING_PERMISSION_SHOW_SYSTEMINFO = 'Show SystemInfo'; + const SETTING_PERMISSION_SHUTDOWN_SERVER = 'Shutdown Server'; + const SETTING_PERMISSION_CHANGE_SERVERSETTINGS = 'Change ServerSettings'; + const SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION = 'Handle Points Repartion Settings'; /* * Private properties @@ -95,6 +97,13 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer $this->updateCancelVoteMenuItem(); $this->updateWarmUpMenuItems(); + + if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'tm') { + $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION, AuthenticationManager::AUTH_LEVEL_SUPERADMIN); + + $this->maniaControl->getCommandManager()->registerCommandListener('setpointsrepartition', $this, 'commandSetPointsRepartition', true, 'Gets the Rounds Point Repartition.'); + $this->maniaControl->getCommandManager()->registerCommandListener('getpointsrepartition', $this, 'commandGetPointsRepartition', true, 'Sets the Rounds Point Repartition.'); + } } /** @@ -121,6 +130,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer } + /** * Handle the WarmupStatus Callback, and removes or adds the Menu Items for extending / Stopping warmup * @@ -445,4 +455,54 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer $this->maniaControl->getClient()->setMaxSpectators($amount); $this->maniaControl->getChat()->sendSuccess("Changed max spectators to: {$amount}", $player); } + + /** + * Handle //setpointsrepartition command + * + * @param array $chatCallback + * @param \ManiaControl\Players\Player $player + */ + public function commandSetPointsRepartition(array $chatCallback, Player $player) { + if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION)) { + $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); + return; + } + + // Check for delayed shutdown + $params = explode(' ', $chatCallback[1][2]); + if (count($params) >= 1) { + $pointString = $params[1]; + $pointArray = explode(',', $pointString); + $this->maniaControl->getModeScriptEventManager()->setTrackmaniaPointsRepartition($pointArray); + $this->maniaControl->getChat()->sendInformation('Points Repartition Changed!'); + $this->commandGetPointsRepartition($chatCallback, $player); + } else { + $this->maniaControl->getChat()->sendError('You must provide a point Repartition in the following form: 10,8,6,4,3 !'); + } + + } + + /** + * Handle //getpointsrepartition command + * + * @param array $chatCallback + * @param \ManiaControl\Players\Player $player + */ + public function commandGetPointsRepartition(array $chatCallback, Player $player) { + if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION)) { + $this->maniaControl->getAuthenticationManager()->sendNotAllowed($player); + return; + } + + $this->maniaControl->getModeScriptEventManager()->getTrackmaniaPointsRepartition()->setCallable(function (OnPointsRepartitionStructure $structure) { + $pointRepartitionString = ""; + foreach ($structure->getPointsRepartition() as $points) { + $pointRepartitionString .= $points . ','; + } + $pointRepartitionString = substr($pointRepartitionString, 0, -1); + + $this->maniaControl->getChat()->sendInformation('Current Points Repartition: ' . $pointRepartitionString); + }); + + } }