diff options
-rw-r--r-- | src/common/permissionmanager.cpp | 16 | ||||
-rw-r--r-- | src/common/permissionmanager.hpp | 2 | ||||
-rw-r--r-- | src/game-server/commandhandler.cpp | 116 |
3 files changed, 133 insertions, 1 deletions
diff --git a/src/common/permissionmanager.cpp b/src/common/permissionmanager.cpp index 1e97e02e..e363ebcd 100644 --- a/src/common/permissionmanager.cpp +++ b/src/common/permissionmanager.cpp @@ -27,6 +27,7 @@ static std::map<std::string, unsigned char> permissions; +static std::map<std::string, unsigned char> aliases; static std::string permissionFile; void addPermission(std::string permission, char mask) @@ -114,7 +115,8 @@ void PermissionManager::reload() // To be implemented } else if (xmlStrEqual(perNode->name, BAD_CAST "alias")){ const char* alias = (const char*)perNode->xmlChildrenNode->content; - // To be implemented + if (alias && strlen(alias) > 0) + aliases[alias] = classmask; } } } @@ -145,3 +147,15 @@ PermissionManager::Result PermissionManager::checkPermission(const Character* ch return PMR_DENIED; } } + +unsigned char PermissionManager::getMaskFromAlias(const std::string &alias) +{ + std::map<std::string, unsigned char>::iterator i = aliases.find(alias); + + if (i == aliases.end()) + { + return 0x00; + } else { + return i->second; + } +} diff --git a/src/common/permissionmanager.hpp b/src/common/permissionmanager.hpp index 4989d0ac..7a815d03 100644 --- a/src/common/permissionmanager.hpp +++ b/src/common/permissionmanager.hpp @@ -49,6 +49,8 @@ namespace PermissionManager */ Result checkPermission(const Character* character, std::string permission); + unsigned char getMaskFromAlias(const std::string & alias); + } #endif diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 0dccd086..ee5e121d 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -132,6 +132,8 @@ static void handleHelp(Character *player, std::string &args) say("=Administrator Commands=", player); say("@reload", player); say("@setgroup <character> <AL level>", player); + say("@givepermission <character> <permission class>", player); + say("@takepermission <character> <permission class>", player); say("@announce <message>", player); say("@history <number of transactions>", player); } @@ -662,6 +664,116 @@ static void handleSetGroup(Character *player, std::string &args) accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_SETGROUP, msg); } +static void handleGivePermission(Character *player, std::string &args) +{ + Character *other; + int level = 0; + + // get the arguments + std::string character = getArgument(args); + std::string strPermission = getArgument(args); + + // check all arguments are there + if (character == "" || strPermission == "") + { + say("Invalid number of arguments given.", player); + say("Usage: @givepermission <character> <permission class>", player); + return; + } + + // check if its to effect the player + if (character == "#") + { + other = player; + } + else + { + // check for valid player + other = getPlayer(character); + if (!other) + { + say("Invalid character", player); + return; + } + } + + unsigned char permission = PermissionManager::getMaskFromAlias(strPermission); + + if (permission & other->getAccountLevel()) + { + say(player->getName()+" already has the permission "+strPermission, player); + } else { + permission += other->getAccountLevel(); + // change the player's account level + other->setAccountLevel(permission); + accountHandler->changeAccountLevel(other, permission); + + // log transaction + std::string msg = "User gave right " + strPermission + " to " + other->getName(); + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_SETGROUP, msg); + say("Congratulations, "+player->getName()+" gave you the rights of a "+strPermission, other); + } +} + +static void handleTakePermission(Character *player, std::string &args) +{ + Character *other; + int level = 0; + + // get the arguments + std::string character = getArgument(args); + std::string strPermission = getArgument(args); + + // check all arguments are there + if (character == "" || strPermission == "") + { + say("Invalid number of arguments given.", player); + say("Usage: @takepermission <character> <permission class>", player); + return; + } + + // check if its to effect the player + if (character == "#") + { + other = player; + } + else + { + // check for valid player + other = getPlayer(character); + if (!other) + { + say("Invalid character", player); + return; + } + } + + unsigned char permission = PermissionManager::getMaskFromAlias(strPermission); + + if (permission == 0x00) + { + say("Unknown permission class", player); + return; + } + + + if (!(permission & other->getAccountLevel())) + { + say(player->getName()+" hasn't got the permission "+strPermission, player); + } else { + permission = other->getAccountLevel() - permission; + // change the player's account level + other->setAccountLevel(permission); + accountHandler->changeAccountLevel(other, permission); + + // log transaction + std::string msg = "User took right " + strPermission + " to " + other->getName(); + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_SETGROUP, msg); + say("Sorry, "+player->getName()+" revoked your rights of a "+strPermission, other); + } +} + + static void handleAttribute(Character *player, std::string &args) { Character *other; @@ -830,6 +942,10 @@ void CommandHandler::handleCommand(Character *player, handleBan(player, args); else if (type == "setgroup") handleSetGroup(player, args); + else if (type == "givepermission") + handleGivePermission(player, args); + else if (type == "takepermission") + handleTakePermission(player, args); else if (type == "attribute") handleAttribute(player, args); else if (type == "report") |