deploy first version of Trackmania Rounds Plugin

This commit is contained in:
kremsy 2017-05-17 12:18:15 +02:00
parent 1eea876a3b
commit e0290b6947
4 changed files with 206 additions and 57 deletions

View File

@ -429,16 +429,17 @@ class AuthenticationManager implements CallbackListener, EchoListener, Communica
* @param int $authLevelNeeded * @param int $authLevelNeeded
*/ */
public function definePermissionLevel($rightName, $authLevelNeeded) { public function definePermissionLevel($rightName, $authLevelNeeded) {
$this->maniaControl->getSettingManager()->initSetting($this, $rightName, $this->getPermissionLevelNameArray($authLevelNeeded)); $this->maniaControl->getSettingManager()->initSetting($this, $rightName, self::getPermissionLevelNameArray($authLevelNeeded));
} }
/** /**
* Get the PermissionLevelNameArray * Get the PermissionLevelNameArray
* *
* @api
* @param $authLevelNeeded * @param $authLevelNeeded
* @return array[] * @return array[]
*/ */
private function getPermissionLevelNameArray($authLevelNeeded) { public static function getPermissionLevelNameArray($authLevelNeeded) {
switch ($authLevelNeeded) { switch ($authLevelNeeded) {
case self::AUTH_LEVEL_MODERATOR: case self::AUTH_LEVEL_MODERATOR:
return array(self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN); return array(self::AUTH_NAME_MODERATOR, self::AUTH_NAME_ADMIN, self::AUTH_NAME_SUPERADMIN, self::AUTH_NAME_MASTERADMIN);

View File

@ -474,6 +474,31 @@ class ModeScriptEventManager implements UsageInformationAble {
$this->triggerModeScriptEvent('Trackmania.SetPointsRepartition', $pointArray); $this->triggerModeScriptEvent('Trackmania.SetPointsRepartition', $pointArray);
} }
/**
* Sets the Trackmania Player Points
*
* @param \ManiaControl\Players\Player $player
* @param string|int $roundPoints //< The round points, use an empty string to not update.
* @param string|int $mapPoints //< The map points, use an empty string to not update.
* @param string|int $matchPoints //< The match points, use an empty string to not update.
*/
public function setTrackmaniaPlayerPoints(Player $player, $roundPoints = "", $mapPoints = "", $matchPoints = "") {
$login = Player::parseLogin($player);
$this->triggerModeScriptEvent('Trackmania.SetPlayerPoints', array($login, strval($roundPoints), strval($mapPoints), strval($matchPoints)));
}
/**
* Sets the Trackmania Team Points
*
* @param int $teamId //< Id of the team t. Can be 1 or 2.
* @param string|int $roundPoints
* @param string|int $mapPoints
* @param string|int $matchPoints
*/
public function setTrackmaniaTeamPoints($teamId, $roundPoints = "", $mapPoints = "", $matchPoints = "") {
$this->triggerModeScriptEvent('Trackmania.SetTeamPoints', array(strval($teamId), strval($roundPoints), strval($mapPoints), strval($matchPoints)));
}
/** /**
* Request the current ui properties. This method will trigger the "Shootmania.UIProperties" callback. * Request the current ui properties. This method will trigger the "Shootmania.UIProperties" callback.
* *

View File

@ -40,7 +40,6 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
const SETTING_PERMISSION_SHOW_SYSTEMINFO = 'Show SystemInfo'; const SETTING_PERMISSION_SHOW_SYSTEMINFO = 'Show SystemInfo';
const SETTING_PERMISSION_SHUTDOWN_SERVER = 'Shutdown Server'; const SETTING_PERMISSION_SHUTDOWN_SERVER = 'Shutdown Server';
const SETTING_PERMISSION_CHANGE_SERVERSETTINGS = 'Change ServerSettings'; const SETTING_PERMISSION_CHANGE_SERVERSETTINGS = 'Change ServerSettings';
const SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION = 'Handle Points Distribution Settings';
const SETTING_PERMISSION_END_ROUND = 'Force end of current Trackmania Round'; const SETTING_PERMISSION_END_ROUND = 'Force end of current Trackmania Round';
/* /*
@ -106,12 +105,7 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->updateWarmUpMenuItems(); $this->updateWarmUpMenuItems();
if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'tm') { if ($this->maniaControl->getMapManager()->getCurrentMap()->getGame() === 'tm') {
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_END_ROUND, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_END_ROUND, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->getCommandManager()->registerCommandListener('setpointsdistribution', $this, 'commandSetPointsRepartition', true, 'Sets the Rounds Point Repartition.');
$this->maniaControl->getCommandManager()->registerCommandListener('getpointsdistribution', $this, 'commandGetPointsRepartition', true, 'Gets the Rounds Point Repartition.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('endround', 'end'), $this, 'commandTrackManiaEndRound', true, 'Ends the Current Round.'); $this->maniaControl->getCommandManager()->registerCommandListener(array('endround', 'end'), $this, 'commandTrackManiaEndRound', true, 'Ends the Current Round.');
} }
} }
@ -466,55 +460,6 @@ class Commands implements CallbackListener, CommandListener, ManialinkPageAnswer
$this->maniaControl->getChat()->sendSuccess("Changed max spectators to: {$amount}", $player); $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 Distribution Changed!', $player);
$this->commandGetPointsRepartition($chatCallback, $player);
} else {
$this->maniaControl->getChat()->sendError('You must provide a point Distribution in the following form: 10,8,6,4,3 !', $player);
}
}
/**
* 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) use ($player) {
$pointRepartitionString = "";
foreach ($structure->getPointsRepartition() as $points) {
$pointRepartitionString .= $points . ',';
}
$pointRepartitionString = substr($pointRepartitionString, 0, -1);
$this->maniaControl->getChat()->sendInformation('Current Points Distribution: ' . $pointRepartitionString, $player);
});
}
/** /**
* Handle //endround command * Handle //endround command
* *

View File

@ -0,0 +1,178 @@
<?php
namespace MCTeam;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\Structures\TrackMania\OnPointsRepartitionStructure;
use ManiaControl\Commands\CommandListener;
use ManiaControl\ManiaControl;
use ManiaControl\Players\Player;
use ManiaControl\Plugins\Plugin;
/**
* ManiaControl ServerRanking Plugin
*
* @author ManiaControl Team <mail@maniacontrol.com>
* @copyright 2014-2017 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/
class TrackmaniaRoundsPlugin implements Plugin, CommandListener {
/*
* Constants
*/
const PLUGIN_ID = 6;
const PLUGIN_VERSION = 0.1;
const PLUGIN_NAME = 'Trackmania Rounds Plugin';
const PLUGIN_AUTHOR = 'MCTeam';
const MAX_POINT_DISTRIBUTIONS = 8;
const SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION = 'Handle Points Distribution Settings';
const SETTING_POINT_DISTRIBUTION_NAME = 'Server Distribution Name ';
const SETTING_POINT_DISTRIBUTION_VALUE = 'Server Distribution Value ';
/*
* Private properties
*/
/** @var ManiaControl $maniaControl * */
private $maniaControl = null;
/**
* @see \ManiaControl\Plugins\Plugin::prepare()
*/
public static function prepare(ManiaControl $maniaControl) {
}
/**
* @see \ManiaControl\Plugins\Plugin::load()
*/
public function load(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
//Authentication Permission Level
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION, AuthenticationManager::getPermissionLevelNameArray(AuthenticationManager::AUTH_LEVEL_ADMIN));
//Settings
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POINT_DISTRIBUTION_NAME . 1, "motogp");
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POINT_DISTRIBUTION_VALUE . 1, "25,20,16,13,11,10,9,8,7,6,5,4,3,2,1,1,1,1,1");
for ($i = 2; $i <= self::MAX_POINT_DISTRIBUTIONS; $i++) {
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POINT_DISTRIBUTION_NAME . $i, "distribution " . $i);
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_POINT_DISTRIBUTION_VALUE . $i, "");
}
// Commands
$this->maniaControl->getCommandManager()->registerCommandListener(array('setrpoints',
'setpointsdistribution'), $this, 'commandSetPointsRepartition', true, 'Sets the Rounds Point Repartition.');
$this->maniaControl->getCommandManager()->registerCommandListener(array('getrpoints',
'getpointsdistribution'), $this, 'commandGetPointsRepartition', true, 'Gets the Rounds Point Repartition.');
}
/**
* Handle //setpointsrepartition command
*
* @param array $chatCallback
* @param \ManiaControl\Players\Player $player
*/
public function commandSetPointsRepartition(array $chatCallback, Player $player) {
$permission = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION);
if (!AuthenticationManager::checkRight($player, $permission)) {
$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);
if (count($pointArray) > 0) {
for ($i = 1; $i <= self::MAX_POINT_DISTRIBUTIONS; $i++) {
$name = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POINT_DISTRIBUTION_NAME . $i);
if ($name == $pointString) {
$pointString = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_POINT_DISTRIBUTION_VALUE . $i);
$pointArray = explode(',', $pointString);
break;
}
}
}
$this->maniaControl->getModeScriptEventManager()->setTrackmaniaPointsRepartition($pointArray);
$this->maniaControl->getChat()->sendInformation('Points Distribution Changed!', $player);
$this->commandGetPointsRepartition($chatCallback, $player);
} else {
$this->maniaControl->getChat()->sendError('You must provide a point Distribution in the following form: 10,8,6,4,3 !', $player);
}
}
/**
* Handle //getpointsrepartition command
*
* @param array $chatCallback
* @param \ManiaControl\Players\Player $player
*/
public function commandGetPointsRepartition(array $chatCallback, Player $player) {
$permission = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PERMISSION_TM_HANDLE_POINTS_REPARTITION);
if (!AuthenticationManager::checkRight($player, $permission)) {
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
return;
}
$this->maniaControl->getModeScriptEventManager()->getTrackmaniaPointsRepartition()->setCallable(function (OnPointsRepartitionStructure $structure) use ($player) {
$pointRepartitionString = "";
foreach ($structure->getPointsRepartition() as $points) {
$pointRepartitionString .= $points . ',';
}
$pointRepartitionString = substr($pointRepartitionString, 0, -1);
$this->maniaControl->getChat()->sendInformation('Current Points Distribution: ' . $pointRepartitionString, $player);
});
}
/**
* @see \ManiaControl\Plugins\Plugin::getId()
*/
public static function getId() {
return self::PLUGIN_ID;
}
/**
* @see \ManiaControl\Plugins\Plugin::getName()
*/
public static function getName() {
return self::PLUGIN_NAME;
}
/**
* @see \ManiaControl\Plugins\Plugin::getVersion()
*/
public static function getVersion() {
return self::PLUGIN_VERSION;
}
/**
* @see \ManiaControl\Plugins\Plugin::getAuthor()
*/
public static function getAuthor() {
return self::PLUGIN_AUTHOR;
}
/**
* @see \ManiaControl\Plugins\Plugin::getDescription()
*/
public static function getDescription() {
return "Plugin offers simple functionalites for Trackmania Round, Team and Cup Modes";
}
/**
* @see \ManiaControl\Plugins\Plugin::unload()
*/
public function unload() {
}
}