summaryrefslogtreecommitdiff
path: root/src/game-server/commandhandler.cpp
diff options
context:
space:
mode:
authorPhilipp Sehmisch <mana@crushnet.org>2010-01-17 02:25:39 +0100
committerPhilipp Sehmisch <mana@crushnet.org>2010-01-17 02:27:35 +0100
commitd7b6565c7f25f02b3e1c0b9d8f50590bcc78bea9 (patch)
treebed7b09fc5df01d76c69f5b22a6f904f10599085 /src/game-server/commandhandler.cpp
parentc9c199007fb6b77f8cd13ffdb560cd18ff3c5af4 (diff)
downloadmanaserv-d7b6565c7f25f02b3e1c0b9d8f50590bcc78bea9.tar.gz
manaserv-d7b6565c7f25f02b3e1c0b9d8f50590bcc78bea9.tar.bz2
manaserv-d7b6565c7f25f02b3e1c0b9d8f50590bcc78bea9.tar.xz
manaserv-d7b6565c7f25f02b3e1c0b9d8f50590bcc78bea9.zip
Added commands for setting permissions by alias
Diffstat (limited to 'src/game-server/commandhandler.cpp')
-rw-r--r--src/game-server/commandhandler.cpp116
1 files changed, 116 insertions, 0 deletions
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")