From 947014cf3c9477b44bafe389653f28074e9b43b3 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 18 Jan 2009 13:57:39 +0100 Subject: Added @where and @rights chat commands for querying the own location and access level. Improved feedback for erroneous chat commands. --- src/game-server/commandhandler.cpp | 94 +++++++++++++++++++++++++++++++------- 1 file changed, 77 insertions(+), 17 deletions(-) diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index 5268d131..26c097d8 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -19,6 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "defines.h" #include "commandhandler.hpp" #include "accountconnection.hpp" @@ -39,7 +41,7 @@ static void say(const std::string error, Character *player) GameState::sayTo(player, NULL, error); } -static bool handlePermissions(Character *player, unsigned int permissions) +static bool checkPermission(Character *player, unsigned int permissions) { if (player->getAccountLevel() & permissions) { @@ -93,25 +95,30 @@ static void handleHelp(Character *player, std::string &args) { if (player->getAccountLevel() & AL_PLAYER) { - say("Game Master Commands:", player); + say("=General Commands=", player); say("@help [command]", player); say("@report ", player); + say("@where", player); + say("@rights", player); } if (player->getAccountLevel() & AL_TESTER) { + say("=Tester Commands=", player); say("@warp ", player); say("@goto ", player); } if (player->getAccountLevel() & AL_GM) { + say("=Game Master Commands=", player); say("@recall ", player); say("@ban ", player); } if (player->getAccountLevel() & AL_DEV) { + say("=Developer Commands=", player); say("@item ", player); say("@drop ", player); say("@money ", player); @@ -121,7 +128,7 @@ static void handleHelp(Character *player, std::string &args) if (player->getAccountLevel() & AL_ADMIN) { - say("Administrator Commands", player); + say("=Administrator Commands=", player); say("@reload", player); say("@setgroup ", player); say("@announce ", player); @@ -149,6 +156,7 @@ static void handleWarp(Character *player, std::string &args) if (character == "" || mapstr == "" || xstr == "" || ystr == "") { say("Invalid number of arguments given.", player); + say("Usage: @warp ", player); return; } @@ -230,6 +238,7 @@ static void handleItem(Character *player, std::string &args) if (character == "" || itemclass == "" || valuestr == "") { say("Invalid number of arguments given.", player); + say("Usage: @item ", player); return; } @@ -299,6 +308,7 @@ static void handleDrop(Character *player, std::string &args) if (itemclass == "" || valuestr == "") { say("Invalid number of arguments given.", player); + say("Usage: @drop ", player); return; } @@ -349,6 +359,7 @@ static void handleMoney(Character *player, std::string &args) if (character == "" || valuestr == "") { say("Invalid number of arguments given", player); + say("Usage: @money ", player); return; } @@ -397,6 +408,7 @@ static void handleSpawn(Character *player, std::string &args) if (monsterclass == "" || valuestr == "") { say("Invalid amount of arguments given.", player); + say("Usage: @spawn ", player); return; } @@ -453,6 +465,7 @@ static void handleGoto(Character *player, std::string &args) if (character == "") { say("Invalid amount of arguments given.", player); + say("Usage: @goto ", player); return; } @@ -481,6 +494,7 @@ static void handleRecall(Character *player, std::string &args) if (character == "") { say("Invalid amount of arguments given.", player); + say("Usage: @recall ", player); return; } @@ -518,6 +532,7 @@ static void handleBan(Character *player, std::string &args) if (character == "" || valuestr == "") { say("Invalid number of arguments given.", player); + say("Usage: @ban ", player); return; } @@ -562,6 +577,7 @@ static void handleSetGroup(Character *player, std::string &args) if (character == "" || levelstr == "") { say("Invalid number of arguments given.", player); + say("Usage: @setgroup ", player); return; } @@ -628,6 +644,7 @@ static void handleAttribute(Character *player, std::string &args) if (character == "" || valuestr == "" || attrstr == "") { say("Invalid number of arguments given.", player); + say("Usage: @attribute ", player); return; } @@ -683,6 +700,7 @@ static void handleReport(Character *player, std::string &args) if (bugReport == "") { say("Invalid number of arguments given.", player); + say("Usage: @report ", player); return; } @@ -696,12 +714,44 @@ static void handleAnnounce(Character *player, std::string &args) if (msg == "") { say("Invalid number of arguments given.", player); + say("Usage: @announce ", player); return; } GameState::sayToAll(msg); } +static void handleWhere(Character *player) +{ + std::stringstream str; + str << "Your current location is map " + << player->getMapId() + << " [" + << player->getPosition().x + << ":" + << player->getPosition().y + << "]"; + say (str.str(), player); +} + +static void handleRights(Character *player) +{ + std::stringstream str; + str << "Your rights level is: " + << player->getAccountLevel() + << " (AL_PLAYER"; + if (checkPermission(player, AL_TESTER)) + str << ", AL_TESTER"; + if (checkPermission(player, AL_GM)) + str << ", AL_GM"; + if (checkPermission(player, AL_ADMIN)) + str << ", AL_ADMIN"; + str << ")"; + say(str.str(), player); +} + + + void CommandHandler::handleCommand(Character *player, const std::string &command) { @@ -714,72 +764,82 @@ void CommandHandler::handleCommand(Character *player, // handle the command if (type == "help") { - if (handlePermissions(player, AL_PLAYER)) + 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 (handlePermissions(player, AL_TESTER)) + if (checkPermission(player, AL_TESTER)) handleWarp(player, args); } else if (type == "item") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleItem(player, args); } else if (type == "drop") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleDrop(player, args); } else if (type == "money") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleMoney(player, args); } else if (type == "spawn") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleSpawn(player, args); } else if (type == "goto") { - if (handlePermissions(player, AL_TESTER)) + if (checkPermission(player, AL_TESTER)) handleGoto(player, args); } else if (type == "recall") { - if (handlePermissions(player, AL_GM)) + if (checkPermission(player, AL_GM)) handleRecall(player, args); } else if (type == "reload") { - if (handlePermissions(player, AL_ADMIN)) + if (checkPermission(player, AL_ADMIN)) handleReload(player); } else if (type == "ban") { - if (handlePermissions(player, AL_GM)) + if (checkPermission(player, AL_GM)) handleBan(player, args); } else if (type == "setgroup") { - if (handlePermissions(player, AL_ADMIN)) + if (checkPermission(player, AL_ADMIN)) handleSetGroup(player, args); } else if (type == "attribute") { - if (handlePermissions(player, AL_DEV)) + if (checkPermission(player, AL_DEV)) handleAttribute(player, args); } else if (type == "report") { - if (handlePermissions(player, AL_PLAYER)) + if (checkPermission(player, AL_PLAYER)) handleReport(player, args); } else if (type == "announce") { - if (handlePermissions(player, AL_ADMIN)) + if (checkPermission(player, AL_ADMIN)) handleAnnounce(player, args); } else -- cgit v1.2.3-60-g2f50