summaryrefslogtreecommitdiff
path: root/src/game-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/commandhandler.cpp257
-rw-r--r--src/game-server/main-game.cpp3
2 files changed, 170 insertions, 90 deletions
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp
index 60f0905c..ee5e121d 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)
{
@@ -130,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);
}
@@ -660,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;
@@ -792,94 +906,57 @@ 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 == "givepermission")
+ handleGivePermission(player, args);
+ else if (type == "takepermission")
+ handleTakePermission(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;
}
}
diff --git a/src/game-server/main-game.cpp b/src/game-server/main-game.cpp
index a35c9531..b49f46de 100644
--- a/src/game-server/main-game.cpp
+++ b/src/game-server/main-game.cpp
@@ -36,6 +36,7 @@
#endif
#include "common/configuration.hpp"
+#include "common/permissionmanager.hpp"
#include "game-server/accountconnection.hpp"
#include "game-server/gamehandler.hpp"
#include "game-server/skillmanager.hpp"
@@ -65,6 +66,7 @@ using utils::Logger;
#define DEFAULT_MAPSDB_FILE "maps.xml"
#define DEFAULT_MONSTERSDB_FILE "monsters.xml"
#define DEFAULT_STATUSDB_FILE "mana-status-effect.xml"
+#define DEFAULT_PERMISSION_FILE "permissions.xml"
static int const WORLD_TICK_SKIP = 2; /** tolerance for lagging behind in world calculation) **/
@@ -169,6 +171,7 @@ void initialize()
ItemManager::initialize(DEFAULT_ITEMSDB_FILE);
MonsterManager::initialize(DEFAULT_MONSTERSDB_FILE);
StatusManager::initialize(DEFAULT_STATUSDB_FILE);
+ PermissionManager::initialize(DEFAULT_PERMISSION_FILE);
// --- Initialize the global handlers
// FIXME: Make the global handlers global vars or part of a bigger