proper use of 'remove' and 'erase' map

- added auth level for 'erase' actions
This commit is contained in:
steeffeen 2014-07-05 12:19:38 +02:00
parent d5cfa925b2
commit 2cca641d2e
4 changed files with 69 additions and 41 deletions

View File

@ -170,7 +170,7 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$pageFrame->add($mapFrame); $pageFrame->add($mapFrame);
$mapFrame->setY($posY); $mapFrame->setY($posY);
if ($index % 2 !== 0) { if ($index % 2 === 0) {
// Striped background line // Striped background line
$lineQuad = new Quad_BgsPlayerCard(); $lineQuad = new Quad_BgsPlayerCard();
$mapFrame->add($lineQuad); $mapFrame->add($lineQuad);
@ -195,9 +195,8 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
$nameLabel->setAction($folderAction); $nameLabel->setAction($folderAction);
} else { } else {
// File // File
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
// Add file button // 'Add' button
$addButton = new Label_Button(); $addButton = new Label_Button();
$mapFrame->add($addButton); $mapFrame->add($addButton);
$addButton->setPosition($width / 2 - 9, 0, 0.2) $addButton->setPosition($width / 2 - 9, 0, 0.2)
@ -207,8 +206,8 @@ class DirectoryBrowser implements ManialinkPageAnswerListener {
->setAction(self::ACTION_ADD_FILE); ->setAction(self::ACTION_ADD_FILE);
} }
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP)) {
// Erase file button // 'Erase' button
$eraseButton = new Label_Button(); $eraseButton = new Label_Button();
$mapFrame->add($eraseButton); $mapFrame->add($eraseButton);
$eraseButton->setPosition($width / 2 - 9, 0, 0.2) $eraseButton->setPosition($width / 2 - 9, 0, 0.2)

View File

@ -23,7 +23,6 @@ use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
* @copyright 2014 ManiaControl Team * @copyright 2014 ManiaControl Team
* @license http://www.gnu.org/licenses/ GNU General Public License, Version 3 * @license http://www.gnu.org/licenses/ GNU General Public License, Version 3
*/ */
// TODO: dedicated commands for remove map and erase map
class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener { class MapCommands implements CommandListener, ManialinkPageAnswerListener, CallbackListener {
/* /*
* Constants * Constants
@ -53,7 +52,8 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
$this->maniaControl->commandManager->registerCommandListener(array('restartmap', 'resmap', 'res'), $this, 'command_RestartMap', true, 'Restarts the current map.'); $this->maniaControl->commandManager->registerCommandListener(array('restartmap', 'resmap', 'res'), $this, 'command_RestartMap', true, 'Restarts the current map.');
$this->maniaControl->commandManager->registerCommandListener(array('replaymap', 'replay'), $this, 'command_ReplayMap', true, 'Replays the current map (after the end of the map).'); $this->maniaControl->commandManager->registerCommandListener(array('replaymap', 'replay'), $this, 'command_ReplayMap', true, 'Replays the current map (after the end of the map).');
$this->maniaControl->commandManager->registerCommandListener(array('addmap', 'add'), $this, 'command_AddMap', true, 'Adds map from ManiaExchange.'); $this->maniaControl->commandManager->registerCommandListener(array('addmap', 'add'), $this, 'command_AddMap', true, 'Adds map from ManiaExchange.');
$this->maniaControl->commandManager->registerCommandListener(array('removemap', 'removethis', 'erasemap', 'erasethis'), $this, 'command_RemoveMap', true, 'Removes the current map.'); $this->maniaControl->commandManager->registerCommandListener(array('removemap', 'removethis'), $this, 'command_RemoveMap', true, 'Removes the current map.');
$this->maniaControl->commandManager->registerCommandListener(array('erasemap', 'erasethis'), $this, 'command_EraseMap', true, 'Erases the current map.');
$this->maniaControl->commandManager->registerCommandListener(array('shufflemaps', 'shuffle'), $this, 'command_ShuffleMaps', true, 'Shuffles the maplist.'); $this->maniaControl->commandManager->registerCommandListener(array('shufflemaps', 'shuffle'), $this, 'command_ShuffleMaps', true, 'Shuffles the maplist.');
$this->maniaControl->commandManager->registerCommandListener(array('writemaplist', 'wml'), $this, 'command_WriteMapList', true, 'Writes the current maplist to a file.'); $this->maniaControl->commandManager->registerCommandListener(array('writemaplist', 'wml'), $this, 'command_WriteMapList', true, 'Writes the current maplist to a file.');
$this->maniaControl->commandManager->registerCommandListener(array('readmaplist', 'rml'), $this, 'command_ReadMapList', true, 'Loads a maplist into the server.'); $this->maniaControl->commandManager->registerCommandListener(array('readmaplist', 'rml'), $this, 'command_ReadMapList', true, 'Loads a maplist into the server.');
@ -124,7 +124,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
} }
/** /**
* Handle removemap command * Handle //removemap command
* *
* @param array $chatCallback * @param array $chatCallback
* @param Player $player * @param Player $player
@ -141,10 +141,32 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
return; return;
} }
//RemoveMap // Remove map
$this->maniaControl->mapManager->removeMap($player, $map->uid); $this->maniaControl->mapManager->removeMap($player, $map->uid);
} }
/**
* Handle //erasemap command
*
* @param array $chatCallback
* @param Player $player
*/
public function command_EraseMap(array $chatCallback, Player $player) {
if (!$this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ERASE_MAP)) {
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
// Get map
$map = $this->maniaControl->mapManager->getCurrentMap();
if (!$map) {
$this->maniaControl->chat->sendError("Couldn't erase map.", $player);
return;
}
// Erase map
$this->maniaControl->mapManager->removeMap($player, $map->uid, true);
}
/** /**
* Handle shufflemaps command * Handle shufflemaps command
* *

View File

@ -41,7 +41,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Constants * Constants
*/ */
const ACTION_UPDATE_MAP = 'MapList.UpdateMap'; const ACTION_UPDATE_MAP = 'MapList.UpdateMap';
const ACTION_ERASE_MAP = 'MapList.EraseMap'; const ACTION_REMOVE_MAP = 'MapList.RemoveMap';
const ACTION_SWITCH_MAP = 'MapList.SwitchMap'; const ACTION_SWITCH_MAP = 'MapList.SwitchMap';
const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote'; const ACTION_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
const ACTION_QUEUED_MAP = 'MapList.QueueMap'; const ACTION_QUEUED_MAP = 'MapList.QueueMap';
@ -366,24 +366,24 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
} }
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_REMOVE_MAP)) {
// erase map quad // remove map button
$eraseLabel = new Label_Button(); $removeButton = new Label_Button();
$mapFrame->add($eraseLabel); $mapFrame->add($removeButton);
$eraseLabel->setX($width / 2 - 5); $removeButton->setX($width / 2 - 5);
$eraseLabel->setZ(0.2); $removeButton->setZ(0.2);
$eraseLabel->setSize(3, 3); $removeButton->setSize(3, 3);
$eraseLabel->setTextSize(1); $removeButton->setTextSize(1);
$eraseLabel->setText('x'); $removeButton->setText('x');
$eraseLabel->setTextColor('a00'); $removeButton->setTextColor('a00');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $posY, $map->uid, true); $confirmFrame = $this->buildConfirmFrame($maniaLink, $posY, $map->uid, true);
$eraseLabel->addToggleFeature($confirmFrame); $removeButton->addToggleFeature($confirmFrame);
$description = 'Remove Map: $<' . $map->name . '$>'; $description = 'Remove Map: $<' . $map->name . '$>';
$eraseLabel->addTooltipLabelFeature($descriptionLabel, $description); $removeButton->addTooltipLabelFeature($descriptionLabel, $description);
} }
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) { if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
// Switch to map // Switch to button
$switchLabel = new Label_Button(); $switchLabel = new Label_Button();
$mapFrame->add($switchLabel); $mapFrame->add($switchLabel);
$switchLabel->setX($width / 2 - 9); $switchLabel->setX($width / 2 - 9);
@ -513,10 +513,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param ManiaLink $maniaLink * @param ManiaLink $maniaLink
* @param float $posY * @param float $posY
* @param bool $mapUid * @param bool $mapUid
* @param bool $erase * @param bool $remove
* @return Frame * @return Frame
*/ */
public function buildConfirmFrame(Manialink $maniaLink, $posY, $mapUid, $erase = false) { public function buildConfirmFrame(Manialink $maniaLink, $posY, $mapUid, $remove = false) {
// TODO: get rid of the confirm frame to decrease xml size & network usage // TODO: get rid of the confirm frame to decrease xml size & network usage
// SUGGESTION: just send them as own manialink again on clicking? // SUGGESTION: just send them as own manialink again on clicking?
@ -551,16 +551,16 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$buttLabel->setPosition(3.2, 0.4, 0.2); $buttLabel->setPosition(3.2, 0.4, 0.2);
$buttLabel->setSize(3, 3); $buttLabel->setSize(3, 3);
if (!$erase) { if ($remove) {
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . $mapUid);
$buttLabel->setText('»');
$buttLabel->setTextColor('0f0');
$buttLabel->setTextSize(2);
} else {
$buttLabel->setTextSize(1); $buttLabel->setTextSize(1);
$buttLabel->setText('x');
$buttLabel->setTextColor('a00'); $buttLabel->setTextColor('a00');
$quad->setAction(self::ACTION_ERASE_MAP . '.' . $mapUid); $buttLabel->setText('x');
$quad->setAction(self::ACTION_REMOVE_MAP . '.' . $mapUid);
} else {
$buttLabel->setTextSize(2);
$buttLabel->setTextColor('0f0');
$buttLabel->setText('»');
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . $mapUid);
} }
return $confirmFrame; return $confirmFrame;
} }
@ -611,7 +611,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->mapManager->updateMap($player, $mapUid); $this->maniaControl->mapManager->updateMap($player, $mapUid);
$this->showMapList($player); $this->showMapList($player);
break; break;
case self::ACTION_ERASE_MAP: case self::ACTION_REMOVE_MAP:
$this->maniaControl->mapManager->removeMap($player, $mapUid); $this->maniaControl->mapManager->removeMap($player, $mapUid);
break; break;
case self::ACTION_SWITCH_MAP: case self::ACTION_SWITCH_MAP:
@ -639,7 +639,8 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$message = $player->getEscapedNickname() . '$s started a vote to switch to ' . $map->getEscapedName() . '!'; $message = $player->getEscapedNickname() . '$s started a vote to switch to ' . $map->getEscapedName() . '!';
$votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message)->setStopCallback(Callbacks::ENDMAP); $votesPlugin->defineVote('switchmap', "Goto " . $map->name, true, $message)
->setStopCallback(Callbacks::ENDMAP);
$votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) { $votesPlugin->startVote($player, 'switchmap', function ($result) use (&$votesPlugin, &$map) {
$votesPlugin->undefineVote('switchmap'); $votesPlugin->undefineVote('switchmap');

View File

@ -40,6 +40,7 @@ class MapManager implements CallbackListener {
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated'; const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
const SETTING_PERMISSION_ADD_MAP = 'Add Maps'; const SETTING_PERMISSION_ADD_MAP = 'Add Maps';
const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps'; const SETTING_PERMISSION_REMOVE_MAP = 'Remove Maps';
const SETTING_PERMISSION_ERASE_MAP = 'Erase Maps';
const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps'; const SETTING_PERMISSION_SHUFFLE_MAPS = 'Shuffle Maps';
const SETTING_PERMISSION_CHECK_UPDATE = 'Check Map Update'; const SETTING_PERMISSION_CHECK_UPDATE = 'Check Map Update';
const SETTING_PERMISSION_SKIP_MAP = 'Skip Map'; const SETTING_PERMISSION_SKIP_MAP = 'Skip Map';
@ -99,6 +100,7 @@ class MapManager implements CallbackListener {
// Define Rights // Define Rights
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ADD_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_REMOVE_MAP, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_ERASE_MAP, AuthenticationManager::AUTH_LEVEL_SUPERADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SHUFFLE_MAPS, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHECK_UPDATE, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_CHECK_UPDATE, AuthenticationManager::AUTH_LEVEL_MODERATOR);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SKIP_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_SKIP_MAP, AuthenticationManager::AUTH_LEVEL_MODERATOR);
@ -222,18 +224,22 @@ class MapManager implements CallbackListener {
if ($eraseFile) { if ($eraseFile) {
// Check if ManiaControl can even write to the maps dir // Check if ManiaControl can even write to the maps dir
$mapDir = $this->maniaControl->client->getMapsDirectory(); $mapDir = $this->maniaControl->client->getMapsDirectory();
if ($this->maniaControl->server->checkAccess($mapDir)) {
// Delete map file // Delete map file
if (!@unlink($mapDir . $map->fileName)) { if (!@unlink($mapDir . $map->fileName)) {
trigger_error("Couldn't remove Map '{$mapDir}{$map->fileName}'."); $this->maniaControl->chat->sendError("Couldn't erase the map file.", $admin);
$this->maniaControl->chat->sendError("ManiaControl couldn't remove the MapFile.", $admin); $eraseFile = false;
return; }
} else {
$this->maniaControl->chat->sendError("Couldn't erase the map file (no access).", $admin);
$eraseFile = false;
} }
} }
// Show Message // Show Message
if ($message) { if ($message) {
$message = $admin->getEscapedNickname() . ' removed ' . $map->getEscapedName() . '!'; $action = ($eraseFile ? 'erased' : 'removed');
$message = $admin->getEscapedNickname() . ' ' . $action . ' ' . $map->getEscapedName() . '!';
$this->maniaControl->chat->sendSuccess($message); $this->maniaControl->chat->sendSuccess($message);
$this->maniaControl->log($message, true); $this->maniaControl->log($message, true);
} }