diff options
-rw-r--r-- | example/serverdata/permissions.xml | 1 | ||||
-rw-r--r-- | 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 6ad941d6..aa224421 100644 --- a/example/serverdata/permissions.xml +++ b/example/serverdata/permissions.xml @@ -35,6 +35,7 @@ <allow>@kill</allow> <allow>@log</allow> <allow>@logsay</allow> + <allow>@permissions</allow> </class> <class level="5"> </class> diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 6064811e..a81af954 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", "<character> <permission class>", "Gives a permission class to the account a character belongs to", &handleGivePermission}, {"takepermission", "<character> <permission class>", @@ -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<std::string> classes = + PermissionManager::getClassList(ch); + for (std::list<std::string>::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 <character>", 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::list<std::string>classes; - classes = PermissionManager::getClassList(player); - - std::stringstream str; - str << "Your rights level is: " - << (unsigned int)player->getAccountLevel() - << " ( "; - - for (std::list<std::string>::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) |