diff options
author | Philipp Sehmisch <mana@crushnet.org> | 2010-01-17 01:28:42 +0100 |
---|---|---|
committer | Philipp Sehmisch <mana@crushnet.org> | 2010-01-17 01:28:59 +0100 |
commit | c9c199007fb6b77f8cd13ffdb560cd18ff3c5af4 (patch) | |
tree | a6e4b3d0ab1ae7f26e3e0847ebc53b44c59a7efd /src/game-server/commandhandler.cpp | |
parent | 8bf0791932c8809fe5bd85d53859b8ce6197e4ed (diff) | |
download | manaserv-c9c199007fb6b77f8cd13ffdb560cd18ff3c5af4.tar.gz manaserv-c9c199007fb6b77f8cd13ffdb560cd18ff3c5af4.tar.bz2 manaserv-c9c199007fb6b77f8cd13ffdb560cd18ff3c5af4.tar.xz manaserv-c9c199007fb6b77f8cd13ffdb560cd18ff3c5af4.zip |
Added permission manager. Currently only used for @commands and doesn't support <deny> and <alias> yet.
Diffstat (limited to 'src/game-server/commandhandler.cpp')
-rw-r--r-- | src/game-server/commandhandler.cpp | 141 |
1 files changed, 51 insertions, 90 deletions
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 60f0905c..0dccd086 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -32,6 +32,7 @@ #include "game-server/monstermanager.hpp" #include "game-server/state.hpp" +#include "common/permissionmanager.hpp" #include "common/transaction.hpp" #include "utils/string.hpp" @@ -41,6 +42,7 @@ static void say(const std::string error, Character *player) GameState::sayTo(player, NULL, error); } +/* static bool checkPermission(Character *player, unsigned int permissions) { if (player->getAccountLevel() & permissions) @@ -51,7 +53,7 @@ static bool checkPermission(Character *player, unsigned int permissions) say("Invalid permissions", player); return false; -} +}*/ static std::string getArgument(std::string &args) { @@ -792,94 +794,53 @@ void CommandHandler::handleCommand(Character *player, std::string type(command, 1, pos == std::string::npos ? pos : pos - 1); std::string args(command, pos == std::string::npos ? command.size() : pos + 1); - // handle the command - if (type == "help") - { - if (checkPermission(player, AL_PLAYER)) - handleHelp(player, args); - } - else if (type == "where" || type == "location") - { - if (checkPermission(player, AL_PLAYER)) - handleWhere(player); - } - else if (type == "rights" || type == "right" || type == "permission") - { - if (checkPermission(player, AL_PLAYER)) - handleRights(player); - } - else if (type == "warp") - { - if (checkPermission(player, AL_TESTER)) - handleWarp(player, args); - } - else if (type == "item") - { - if (checkPermission(player, AL_DEV)) - handleItem(player, args); - } - else if (type == "drop") - { - if (checkPermission(player, AL_DEV)) - handleDrop(player, args); - } - else if (type == "money") - { - if (checkPermission(player, AL_DEV)) - handleMoney(player, args); - } - else if (type == "spawn") - { - if (checkPermission(player, AL_DEV)) - handleSpawn(player, args); - } - else if (type == "goto") - { - if (checkPermission(player, AL_TESTER)) - handleGoto(player, args); - } - else if (type == "recall") - { - if (checkPermission(player, AL_GM)) - handleRecall(player, args); - } - else if (type == "reload") - { - if (checkPermission(player, AL_ADMIN)) - handleReload(player); - } - else if (type == "ban") - { - if (checkPermission(player, AL_GM)) - handleBan(player, args); - } - else if (type == "setgroup") - { - if (checkPermission(player, AL_ADMIN)) - handleSetGroup(player, args); - } - else if (type == "attribute") - { - if (checkPermission(player, AL_DEV)) - handleAttribute(player, args); - } - else if (type == "report") - { - if (checkPermission(player, AL_PLAYER)) - handleReport(player, args); - } - else if (type == "announce") - { - if (checkPermission(player, AL_ADMIN)) - handleAnnounce(player, args); - } - else if (type == "history") - { - if (checkPermission(player, AL_ADMIN)) - handleHistory(player, args); - } - else - { - say("Command not found. Enter @help to view the list of available commands.", player); + PermissionManager::Result r = PermissionManager::checkPermission(player, "@"+type); + switch (r) + { + case PermissionManager::PMR_DENIED: + say("Permissions denied!", player); + break; + case PermissionManager::PMR_UNKNOWN: + say("Unknown command. Enter @help to view the list of available commands.", player); + break; + case PermissionManager::PMR_ALLOWED: + // handle the command + if (type == "help") handleHelp(player, args); + else if (type == "where" || type == "location") + handleWhere(player); + else if (type == "rights" || type == "right" || type == "permission") + handleRights(player); + else if (type == "warp") + handleWarp(player, args); + else if (type == "item") + handleItem(player, args); + else if (type == "drop") + handleDrop(player, args); + else if (type == "money") + handleMoney(player, args); + else if (type == "spawn") + handleSpawn(player, args); + else if (type == "goto") + handleGoto(player, args); + else if (type == "recall") + handleRecall(player, args); + else if (type == "reload") + handleReload(player); + else if (type == "ban") + handleBan(player, args); + else if (type == "setgroup") + handleSetGroup(player, args); + else if (type == "attribute") + handleAttribute(player, args); + else if (type == "report") + handleReport(player, args); + else if (type == "announce") + handleAnnounce(player, args); + else if (type == "history") + handleHistory(player, args); + else + say("Command not implemented.", player); + + break; } } |