diff options
author | Jared Adams <jaxad0127@gmail.com> | 2010-12-06 11:32:58 -0700 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2010-12-06 11:40:16 -0700 |
commit | ec95564944562bbd020f005d155f6ce3943eea02 (patch) | |
tree | bbcbbc2a7231ed2de81d73af32a767d6e588a671 /src/game-server/commandhandler.cpp | |
parent | d62fdc6d7b84e19c8adb72bca35c0b5b0dfe5405 (diff) | |
download | manaserv-ec95564944562bbd020f005d155f6ce3943eea02.tar.gz manaserv-ec95564944562bbd020f005d155f6ce3943eea02.tar.bz2 manaserv-ec95564944562bbd020f005d155f6ce3943eea02.tar.xz manaserv-ec95564944562bbd020f005d155f6ce3943eea02.zip |
Improve warp commands
@warp no longer takes a character. @charwarp was added to handle
that ('#' still means the player). Both can take a map name,
map id (preceded by '#') or '#' for the player's current map.
Logging of warp commands now logs destination map and player
warped (for @charwarp).
Diffstat (limited to 'src/game-server/commandhandler.cpp')
-rw-r--r-- | src/game-server/commandhandler.cpp | 135 |
1 files changed, 120 insertions, 15 deletions
diff --git a/src/game-server/commandhandler.cpp b/src/game-server/commandhandler.cpp index b1d965be..d9445334 100644 --- a/src/game-server/commandhandler.cpp +++ b/src/game-server/commandhandler.cpp @@ -27,6 +27,7 @@ #include "game-server/inventory.h" #include "game-server/item.h" #include "game-server/itemmanager.h" +#include "game-server/mapcomposite.h" #include "game-server/mapmanager.h" #include "game-server/monster.h" #include "game-server/monstermanager.h" @@ -51,6 +52,7 @@ static void handleReport(Character*, std::string&); static void handleWhere(Character*, std::string&); static void handleRights(Character*, std::string&); static void handleWarp(Character*, std::string&); +static void handleCharWarp(Character*, std::string&); static void handleGoto(Character*, std::string&); static void handleRecall(Character*, std::string&); static void handleBan(Character*, std::string&); @@ -76,8 +78,10 @@ static CmdRef const cmdRef[] = "Tells you your location in the game world", &handleWhere}, {"rights", "" , "Tells you your current permissions", &handleRights}, - {"warp", "<character> <map> <x> <y>", + {"warp", "<map> <x> <y>", "Teleports your character to a different location in the game world", &handleWarp}, + {"charwarp", "<character> <map> <x> <y>", + "Teleports the given character to a different location in the game world", &handleCharWarp}, {"goto", "<character>", "Teleports you to the location of another character", &handleGoto}, {"recall", "<character>", @@ -237,6 +241,90 @@ static void handleWarp(Character *player, std::string &args) { int x, y; MapComposite *map; + + // get the arguments + std::string mapstr = getArgument(args); + std::string xstr = getArgument(args); + std::string ystr = getArgument(args); + + // if any of them are empty strings, no argument was given + if (mapstr == "" || xstr == "" || ystr == "") + { + say("Invalid number of arguments given.", player); + say("Usage: @warp <map> <x> <y>", player); + return; + } + + // if it contains # then it means the player's map + if (mapstr == "#") + { + map = player->getMap(); + } + else + { + if (mapstr[0] == '#') + { + mapstr = mapstr.substr(1); + // check for valid map id + int id; + if (!utils::isNumeric(mapstr)) + { + say("Invalid map", player); + return; + } + + id = utils::stringToInt(mapstr); + + // get the map + map = MapManager::getMap(id); + if (!map) + { + say("Invalid map", player); + return; + } + } + else + { + map = MapManager::getMap(mapstr); + + if (!map) + { + say("Invalid map", player); + return; + } + } + } + + if (!utils::isNumeric(xstr)) + { + say("Invalid x", player); + return; + } + + if (!utils::isNumeric(ystr)) + { + say("Invalid y", player); + return; + } + + // change the x and y to integers + x = utils::stringToInt(xstr); + y = utils::stringToInt(ystr); + + // now warp the player + GameState::warp(player, map, x, y); + + // log transaction + std::stringstream ss; + ss << "User warped to " << map->getName() << " (" << x << ", " << y << ")"; + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_WARP, + ss.str()); +} + +static void handleCharWarp(Character *player, std::string &args) +{ + int x, y; + MapComposite *map; Character *other; // get the arguments @@ -276,22 +364,36 @@ static void handleWarp(Character *player, std::string &args) } else { - // check for valid map id - int id; - if (!utils::isNumeric(mapstr)) + if (mapstr[0] == '#') { - say("Invalid map", player); - return; - } + mapstr = mapstr.substr(1); + // check for valid map id + int id; + if (!utils::isNumeric(mapstr)) + { + say("Invalid map", player); + return; + } - id = utils::stringToInt(mapstr); + id = utils::stringToInt(mapstr); - // get the map - map = MapManager::getMap(id); - if (!map) + // get the map + map = MapManager::getMap(id); + if (!map) + { + say("Invalid map", player); + return; + } + } + else { - say("Invalid map", player); - return; + map = MapManager::getMap(mapstr); + + if (!map) + { + say("Invalid map", player); + return; + } } } @@ -315,8 +417,11 @@ static void handleWarp(Character *player, std::string &args) GameState::warp(other, map, x, y); // log transaction - std::string msg = "User warped to " + xstr + "x" + ystr; - accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_WARP, msg); + std::stringstream ss; + ss << "User warped " << other->getName() << " to " << map->getName() << + " (" << x << ", " << y << ")"; + accountHandler->sendTransaction(player->getDatabaseID(), TRANS_CMD_WARP, + ss.str()); } static void handleItem(Character *player, std::string &args) |