From e0fc91bd6a2830127b116f6a37f024e17ac594e7 Mon Sep 17 00:00:00 2001 From: Erik Schilling Date: Wed, 2 Nov 2011 01:11:31 +0800 Subject: Added @permissions command MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Added @permissions which lists the permissions of a player. Made @givepermission giving feedback on success. Reviewed-by: Thorbjørn Lindeijer. --- example/serverdata/permissions.xml | 1 + src/game-server/commandhandler.cpp | 65 +++++++++++++++++++++++++++----------- 2 files changed, 48 insertions(+), 18 deletions(-) diff --git a/example/serverdata/permissions.xml b/example/serverdata/permissions.xml index 6ad941d..aa22442 100644 --- a/example/serverdata/permissions.xml +++ b/example/serverdata/permissions.xml @@ -35,6 +35,7 @@ @kill @log @logsay + @permissions diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 6064811..a81af95 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -64,6 +64,7 @@ static void handleMoney(Character*, std::string&); static void handleSpawn(Character*, std::string&); static void handleAttribute(Character*, std::string&); static void handleReload(Character*, std::string&); +static void handlePermissions(Character*, std::string&); static void handleGivePermission(Character*, std::string&); static void handleTakePermission(Character*, std::string&); static void handleAnnounce(Character*, std::string&); @@ -110,6 +111,8 @@ static CmdRef const cmdRef[] = "Changes the character attributes of a character", &handleAttribute}, {"reload", "", "Makes the server reload all configuration files", &handleReload}, + {"permissions", "", + "Tells you the permissions of another player", &handlePermissions}, {"givepermission", " ", "Gives a permission class to the account a character belongs to", &handleGivePermission}, {"takepermission", " ", @@ -161,6 +164,24 @@ static bool checkPermission(Character *player, unsigned int permissions) /** * Returns the next argument, and remove it from the given string. */ + +static std::string playerRights(Character *ch) +{ + std::stringstream str; + str << (unsigned int)ch->getAccountLevel(); + str << " ( "; + std::list classes = + PermissionManager::getClassList(ch); + for (std::list::iterator i = classes.begin(); + i != classes.end(); + i++) + { + str << (*i) << " "; + } + str << ")"; + return str.str(); +} + static std::string getArgument(std::string &args) { std::string argument; @@ -860,6 +881,27 @@ static void handleBan(Character *player, std::string &args) accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_BAN, msg); } +static void handlePermissions(Character *player, std::string &args) +{ + std::string character = getArgument(args); + if (character.empty()) + { + say("Invaild number of arguments given.", player); + say("Usage: @permissions ", player); + return; + } + + Character *other = getPlayer(character); + if (!other) + { + say("Invalid character", player); + return; + } + + say(other->getName() + " has the permissions: " + + playerRights(other), player); +} + static void handleGivePermission(Character *player, std::string &args) { Character *other; @@ -914,7 +956,10 @@ static void handleGivePermission(Character *player, std::string &args) // 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); + say("You gave " + other->getName() + + " the rights of a " + strPermission, player); + say("Congratulations, " + player->getName() + + " gave you the rights of a " + strPermission, other); } } @@ -1089,23 +1134,7 @@ static void handleWhere(Character *player, std::string &) static void handleRights(Character *player, std::string &) { - std::listclasses; - classes = PermissionManager::getClassList(player); - - std::stringstream str; - str << "Your rights level is: " - << (unsigned int)player->getAccountLevel() - << " ( "; - - for (std::list::iterator i = classes.begin(); - i != classes.end(); - i++) - { - str << (*i) << " "; - } - str << ")"; - - say(str.str(), player); + say("Your rights level is: " + playerRights(player), player); } static void handleHistory(Character *player, std::string &args) -- cgit