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

View File

@ -23,7 +23,6 @@ use Maniaplanet\DedicatedServer\Xmlrpc\FaultException;
* @copyright 2014 ManiaControl Team
* @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 {
/*
* 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('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('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('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.');
@ -124,7 +124,7 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
}
/**
* Handle removemap command
* Handle //removemap command
*
* @param array $chatCallback
* @param Player $player
@ -141,10 +141,32 @@ class MapCommands implements CommandListener, ManialinkPageAnswerListener, Callb
return;
}
//RemoveMap
// Remove map
$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
*

View File

@ -41,7 +41,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* Constants
*/
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_START_SWITCH_VOTE = 'MapList.StartMapSwitchVote';
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)) {
// erase map quad
$eraseLabel = new Label_Button();
$mapFrame->add($eraseLabel);
$eraseLabel->setX($width / 2 - 5);
$eraseLabel->setZ(0.2);
$eraseLabel->setSize(3, 3);
$eraseLabel->setTextSize(1);
$eraseLabel->setText('x');
$eraseLabel->setTextColor('a00');
// remove map button
$removeButton = new Label_Button();
$mapFrame->add($removeButton);
$removeButton->setX($width / 2 - 5);
$removeButton->setZ(0.2);
$removeButton->setSize(3, 3);
$removeButton->setTextSize(1);
$removeButton->setText('x');
$removeButton->setTextColor('a00');
$confirmFrame = $this->buildConfirmFrame($maniaLink, $posY, $map->uid, true);
$eraseLabel->addToggleFeature($confirmFrame);
$removeButton->addToggleFeature($confirmFrame);
$description = 'Remove Map: $<' . $map->name . '$>';
$eraseLabel->addTooltipLabelFeature($descriptionLabel, $description);
$removeButton->addTooltipLabelFeature($descriptionLabel, $description);
}
if ($this->maniaControl->authenticationManager->checkPermission($player, MapManager::SETTING_PERMISSION_ADD_MAP)) {
// Switch to map
// Switch to button
$switchLabel = new Label_Button();
$mapFrame->add($switchLabel);
$switchLabel->setX($width / 2 - 9);
@ -513,10 +513,10 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
* @param ManiaLink $maniaLink
* @param float $posY
* @param bool $mapUid
* @param bool $erase
* @param bool $remove
* @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
// 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->setSize(3, 3);
if (!$erase) {
$quad->setAction(self::ACTION_SWITCH_MAP . '.' . $mapUid);
$buttLabel->setText('»');
$buttLabel->setTextColor('0f0');
$buttLabel->setTextSize(2);
} else {
if ($remove) {
$buttLabel->setTextSize(1);
$buttLabel->setText('x');
$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;
}
@ -611,7 +611,7 @@ class MapList implements ManialinkPageAnswerListener, CallbackListener {
$this->maniaControl->mapManager->updateMap($player, $mapUid);
$this->showMapList($player);
break;
case self::ACTION_ERASE_MAP:
case self::ACTION_REMOVE_MAP:
$this->maniaControl->mapManager->removeMap($player, $mapUid);
break;
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() . '!';
$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->undefineVote('switchmap');

View File

@ -40,6 +40,7 @@ class MapManager implements CallbackListener {
const CB_KARMA_UPDATED = 'MapManager.KarmaUpdated';
const SETTING_PERMISSION_ADD_MAP = 'Add 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_CHECK_UPDATE = 'Check Map Update';
const SETTING_PERMISSION_SKIP_MAP = 'Skip Map';
@ -99,6 +100,7 @@ class MapManager implements CallbackListener {
// Define Rights
$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_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_CHECK_UPDATE, 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) {
// Check if ManiaControl can even write to the maps dir
$mapDir = $this->maniaControl->client->getMapsDirectory();
// Delete map file
if (!@unlink($mapDir . $map->fileName)) {
trigger_error("Couldn't remove Map '{$mapDir}{$map->fileName}'.");
$this->maniaControl->chat->sendError("ManiaControl couldn't remove the MapFile.", $admin);
return;
if ($this->maniaControl->server->checkAccess($mapDir)) {
// Delete map file
if (!@unlink($mapDir . $map->fileName)) {
$this->maniaControl->chat->sendError("Couldn't erase the map file.", $admin);
$eraseFile = false;
}
} else {
$this->maniaControl->chat->sendError("Couldn't erase the map file (no access).", $admin);
$eraseFile = false;
}
}
// Show 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->log($message, true);
}