summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/Makefile.am2
-rw-r--r--src/actionmanager.h2
-rw-r--r--src/commandhandler.cpp1383
-rw-r--r--src/commandhandler.h305
-rw-r--r--src/commands.cpp1210
-rw-r--r--src/commands.h193
-rw-r--r--src/gui/chatwindow.cpp2
-rw-r--r--src/gui/widgets/battletab.cpp1
-rw-r--r--src/gui/widgets/chattab.cpp3
-rw-r--r--src/gui/widgets/guildchattab.cpp1
-rw-r--r--src/gui/widgets/tradetab.cpp1
-rw-r--r--src/gui/widgets/whispertab.cpp8
-rw-r--r--src/net/ea/gui/guildtab.cpp1
-rw-r--r--src/net/ea/gui/partytab.cpp4
-rw-r--r--src/net/eathena/gui/guildtab.cpp1
-rw-r--r--src/net/eathena/gui/partytab.cpp1
-rw-r--r--src/net/tmwa/gui/guildtab.cpp1
-rw-r--r--src/net/tmwa/gui/partytab.cpp1
-rw-r--r--src/utils/stringutils.cpp16
-rw-r--r--src/utils/stringutils.h2
21 files changed, 1454 insertions, 1686 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0610d23b3..d07d67dca 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -529,6 +529,8 @@ SET(SRCS
channelmanager.h
commandhandler.cpp
commandhandler.h
+ commands.cpp
+ commands.h
compoundsprite.cpp
compoundsprite.h
configlistener.h
diff --git a/src/Makefile.am b/src/Makefile.am
index 124fb4c86..d906b30ec 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -533,6 +533,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \
channelmanager.h \
commandhandler.cpp \
commandhandler.h \
+ commands.cpp \
+ commands.h \
compoundsprite.cpp \
compoundsprite.h \
configlistener.h \
diff --git a/src/actionmanager.h b/src/actionmanager.h
index b415e1a5b..c04dceff5 100644
--- a/src/actionmanager.h
+++ b/src/actionmanager.h
@@ -119,4 +119,6 @@ namespace ActionManager
decHandler(questsWindowShow);
}
+#undef decHandler
+
#endif
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index 8fcfa6845..5cf6827ce 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -22,60 +22,18 @@
#include "commandhandler.h"
-#include "auctionmanager.h"
-#include "actorspritemanager.h"
-#include "channelmanager.h"
-#include "channel.h"
-#include "client.h"
-#include "configuration.h"
-#include "game.h"
-#include "guildmanager.h"
-#include "localplayer.h"
-#include "main.h"
-#include "party.h"
-
-#include "gui/chatwindow.h"
-#include "gui/helpwindow.h"
-#include "gui/gui.h"
-#include "gui/outfitwindow.h"
-#include "gui/shopwindow.h"
-#include "gui/socialwindow.h"
-#include "gui/tradewindow.h"
-#include "gui/sdlfont.h"
-
-#include "gui/widgets/channeltab.h"
-#include "gui/widgets/whispertab.h"
-
-#include "net/adminhandler.h"
-#include "net/beinghandler.h"
-#include "net/chathandler.h"
-#include "net/gamehandler.h"
-#include "net/guildhandler.h"
-#include "net/net.h"
-#include "net/partyhandler.h"
-#include "net/playerhandler.h"
-#include "net/tradehandler.h"
-
-#if defined USE_OPENGL
-#include "normalopenglgraphics.h"
-#endif
-
-#ifdef DEBUG_DUMP_LEAKS1
-#include "resources/image.h"
-#include "resources/resource.h"
-#include "resources/resourcemanager.h"
-#include "resources/subimage.h"
-#endif
+#include "gui/widgets/chattab.h"
#include "utils/gettext.h"
-#include "utils/process.h"
+#include "utils/stringutils.h"
#include "debug.h"
-extern std::string tradePartnerName;
-
CommandHandler::CommandHandler()
{
+ const int sz = sizeof(commands) / sizeof(CommandInfo);
+ for (int f = 0; f < sz; f ++)
+ mCommands[commands[f].name] = commands[f].func;
}
void CommandHandler::handleCommands(const std::string &command,
@@ -92,1332 +50,11 @@ void CommandHandler::handleCommand(const std::string &command,
const std::string type(command, 0, pos);
std::string args(command, pos == std::string::npos
? command.size() : pos + 1);
- args = trim(args);
- if (command == "closeall")
- handleCloseAll(args, tab);
- else if (type == "ignoreall")
- handleIgnoreAll(args, tab);
- else if (type == "help") // Do help before tabs so they can't override it
- handleHelp(args, tab);
- else if (type == "announce")
- handleAnnounce(args, tab);
- else if (type == "where")
- handleWhere(args, tab);
- else if (type == "who")
- handleWho(args, tab);
- else if (type == "msg" || type == "whisper" || type == "w")
- handleMsg(args, tab);
- else if (type == "query" || type == "q")
- handleQuery(args, tab);
- else if (type == "ignore")
- handleIgnore(args, tab);
- else if (type == "unignore")
- handleUnignore(args, tab);
- else if (type == "friend" || type == "befriend")
- handleFriend(args, tab);
- else if (type == "disregard")
- handleDisregard(args, tab);
- else if (type == "neutral")
- handleNeutral(args, tab);
- else if (type == "blacklist")
- handleBlackList(args, tab);
- else if (type == "enemy")
- handleEnemy(args, tab);
- else if (type == "erase")
- handleErase(args, tab);
- else if (type == "join")
- handleJoin(args, tab);
- else if (type == "list")
- handleListChannels(args, tab);
- else if (type == "clear")
- handleClear(args, tab);
- else if (type == "createparty")
- handleCreateParty(args, tab);
- else if (type == "createguild")
- handleCreateGuild(args, tab);
- else if (type == "party")
- handleParty(args, tab);
- else if (type == "me")
- handleMe(args, tab);
- else if (type == "toggle")
- handleToggle(args, tab);
- else if (type == "present")
- handlePresent(args, tab);
- else if (type == "quit")
- handleQuit(args, tab);
- else if (type == "all")
- handleShowAll(args, tab);
- else if (type == "move")
- handleMove(args, tab);
- else if (type == "target")
- handleTarget(args, tab);
- else if (type == "atkhuman")
- handleAttackHuman(args, tab);
- else if (type == "outfit")
- handleOutfit(args, tab);
- else if (type == "emote")
- handleEmote(args, tab);
- else if (type == "away")
- handleAway(args, tab);
- else if (type == "pseudoaway")
- handlePseudoAway(args, tab);
- else if (type == "follow")
- handleFollow(args, tab);
- else if (type == "heal")
- handleHeal(args, tab);
- else if (type == "navigate")
- handleNavigate(args, tab);
- else if (type == "imitation")
- handleImitation(args, tab);
- else if (type == "mail")
- handleMail(args, tab);
- else if (type == "trade")
- handleTrade(args, tab);
- else if (type == "priceload")
- handlePriceLoad(args, tab);
- else if (type == "pricesave")
- handlePriceSave(args, tab);
- else if (type == "cacheinfo")
- handleCacheInfo(args, tab);
- else if (type == "disconnect")
- handleDisconnect(args, tab);
- else if (type == "undress")
- handleUndress(args, tab);
- else if (type == "attack")
- handleAttack(args, tab);
- else if (type == "dirs")
- handleDirs(args, tab);
- else if (type == "info")
- handleInfo(args, tab);
- else if (type == "wait")
- handleWait(args, tab);
- else if (type == "uptime")
- handleUptime(args, tab);
- else if (type == "addpriorityattack")
- handleAddPriorityAttack(args, tab);
- else if (type == "addattack")
- handleAddAttack(args, tab);
- else if (type == "removeattack" || type == "removeignoreattack")
- handleRemoveAttack(args, tab);
- else if (type == "addignoreattack")
- handleAddIgnoreAttack(args, tab);
- else if (type == "dump")
- handleDump(args, tab);
- else if (type == "serverignoreall")
- handleServerIgnoreAll(args, tab);
- else if (type == "serverunignoreall")
- handleServerUnIgnoreAll(args, tab);
- else if (type == "setdrop")
- handleSetDrop(args, tab);
- else if (type == "error")
- handleError(args, tab);
- else if (type == "dumpg")
- handleDumpGraphics(args, tab);
- else if (type == "dumpt")
- handleDumpTests(args, tab);
- else if (type == "dumpogl")
- handleDumpOGL(args, tab);
- else if (type == "url")
- handleUrl(args, tab);
- else if (type == "open")
- handleOpen(args, tab);
- else if (tab->handleCommand(type, args))
- ;
- else if (type == "hack")
- handleHack(args, tab);
- else
+ args = trim(args);
+ const CommandsMapIter it = mCommands.find(type);
+ if (it != mCommands.end())
+ ((*it).second)(args, tab);
+ else if (!tab->handleCommand(type, args))
tab->chatLog(_("Unknown command."));
}
-
-signed char CommandHandler::parseBoolean(const std::string &value)
-{
- std::string opt = value.substr(0, 1);
-
- if (opt == "1" ||
- opt == "y" || opt == "Y" ||
- opt == "t" || opt == "T")
- return 1;
- else if (opt == "0" ||
- opt == "n" || opt == "N" ||
- opt == "f" || opt == "F")
- return 0;
- else
- return -1;
-}
-
-void CommandHandler::handleAnnounce(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- Net::getAdminHandler()->announce(args);
-}
-
-void CommandHandler::handleHelp(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (!helpWindow)
- return;
-
- if (!tab)
- {
- helpWindow->loadHelp("chatcommands");
- helpWindow->requestMoveToTop();
- return;
- }
- switch (tab->getType())
- {
- case ChatTab::TAB_PARTY:
- {
- helpWindow->loadHelp("chatparty");
- break;
- }
- case ChatTab::TAB_GUILD:
- {
- helpWindow->loadHelp("chatguild");
- break;
- }
- default:
- helpWindow->loadHelp("chatcommands");
- break;
- }
- helpWindow->requestMoveToTop();
-}
-
-void CommandHandler::handleWhere(const std::string &args A_UNUSED,
- ChatTab *const tab)
-{
- std::ostringstream where;
- where << Game::instance()->getCurrentMapName() << ", coordinates: "
- << ((player_node->getPixelX() - 16) / 32) << ", "
- << ((player_node->getPixelY() - 32) / 32);
-
- tab->chatLog(where.str(), BY_SERVER);
-}
-
-void CommandHandler::handleWho(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- Net::getChatHandler()->who();
-}
-
-void CommandHandler::handleMsg(const std::string &args, ChatTab *const tab)
-{
- std::string recvnick("");
- std::string msg("");
-
- if (args.substr(0, 1) == "\"")
- {
- const size_t pos = args.find('"', 1);
- if (pos != std::string::npos)
- {
- recvnick = args.substr(1, pos - 1);
- if (pos + 2 < args.length())
- msg = args.substr(pos + 2, args.length());
- }
- }
- else
- {
- const size_t pos = args.find(" ");
- if (pos != std::string::npos)
- {
- recvnick = args.substr(0, pos);
- if (pos + 1 < args.length())
- msg = args.substr(pos + 1, args.length());
- }
- else
- {
- recvnick = std::string(args);
- msg = "";
- }
- }
-
- trim(msg);
-
- if (msg.length() > 0)
- {
- std::string playerName = player_node->getName();
- std::string tempNick = recvnick;
-
- toLower(playerName);
- toLower(tempNick);
-
- if (tempNick.compare(playerName) == 0 || args.empty())
- return;
-
- chatWindow->addWhisper(recvnick, msg, BY_PLAYER);
- }
- else
- tab->chatLog(_("Cannot send empty whispers!"), BY_SERVER);
-}
-
-void CommandHandler::handleQuery(const std::string &args, ChatTab *const tab)
-{
- if (chatWindow)
- {
- if (chatWindow->addWhisperTab(args, true))
- {
- chatWindow->saveState();
- return;
- }
- }
-
- tab->chatLog(strprintf(_("Cannot create a whisper tab for nick \"%s\"! "
- "It either already exists, or is you."),
- args.c_str()), BY_SERVER);
-}
-
-void CommandHandler::handleClear(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (chatWindow)
- chatWindow->clearTab();
-}
-
-void CommandHandler::handleJoin(const std::string &args, ChatTab *const tab)
-{
- if (!tab)
- return;
-
- const size_t pos = args.find(' ');
- const std::string name(args, 0, pos);
- const std::string password(args, pos + 1);
- tab->chatLog(strprintf(_("Requesting to join channel %s."), name.c_str()));
- Net::getChatHandler()->enterChannel(name, password);
-}
-
-void CommandHandler::handleListChannels(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- Net::getChatHandler()->channelList();
-}
-
-void CommandHandler::handleCreateParty(const std::string &args,
- ChatTab *const tab)
-{
- if (!tab)
- return;
-
- if (args.empty())
- tab->chatLog(_("Party name is missing."), BY_SERVER);
- else
- Net::getPartyHandler()->create(args);
-}
-
-void CommandHandler::handleCreateGuild(const std::string &args,
- ChatTab *const tab)
-{
- if (!tab)
- return;
-
- if (args.empty())
- tab->chatLog(_("Guild name is missing."), BY_SERVER);
- else
- Net::getGuildHandler()->create(args);
-}
-
-void CommandHandler::handleParty(const std::string &args, ChatTab *const tab)
-{
- if (!tab)
- return;
-
- if (args != "")
- Net::getPartyHandler()->invite(args);
- else
- tab->chatLog(_("Please specify a name."), BY_SERVER);
-}
-
-void CommandHandler::handleMe(const std::string &args, ChatTab *const tab)
-{
- outString(tab, strprintf("*%s*", args.c_str()), args);
-}
-
-void CommandHandler::outString(ChatTab *const tab, const std::string &str,
- const std::string &def)
-{
- if (!tab)
- {
- Net::getChatHandler()->me(def);
- return;
- }
-
- switch (tab->getType())
- {
- case ChatTab::TAB_PARTY:
- {
- Net::getPartyHandler()->chat(str);
- break;
- }
- case ChatTab::TAB_GUILD:
- {
- if (!player_node)
- return;
- const Guild *const guild = player_node->getGuild();
- if (guild)
- {
- if (guild->getServerGuild())
- Net::getGuildHandler()->chat(guild->getId(), str);
- else if (guildManager)
- guildManager->chat(str);
- }
- break;
- }
- default:
- Net::getChatHandler()->me(def);
- break;
- }
-}
-
-void CommandHandler::handleToggle(const std::string &args, ChatTab *const tab)
-{
- if (args.empty())
- {
- if (chatWindow && tab)
- {
- tab->chatLog(chatWindow->getReturnTogglesChat() ?
- _("Return toggles chat.") : _("Message closes chat."));
- }
- return;
- }
-
- switch (parseBoolean(args))
- {
- case 1:
- if (tab)
- tab->chatLog(_("Return now toggles chat."));
- if (chatWindow)
- chatWindow->setReturnTogglesChat(true);
- return;
- case 0:
- if (tab)
- tab->chatLog(_("Message now closes chat."));
- if (chatWindow)
- chatWindow->setReturnTogglesChat(false);
- return;
- case -1:
- if (tab)
- tab->chatLog(strprintf(BOOLEAN_OPTIONS, "toggle"));
- return;
- default:
- return;
- }
-}
-
-void CommandHandler::handlePresent(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (chatWindow)
- chatWindow->doPresent();
-}
-
-void CommandHandler::handleIgnore(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- changeRelation(args, PlayerRelation::IGNORED, "ignored", tab);
-}
-
-void CommandHandler::handleFriend(const std::string &args, ChatTab *const tab)
-{
- changeRelation(args, PlayerRelation::FRIEND, _("friend"), tab);
-}
-
-void CommandHandler::handleDisregard(const std::string &args,
- ChatTab *const tab)
-{
- changeRelation(args, PlayerRelation::DISREGARDED, _("disregarded"), tab);
-}
-
-void CommandHandler::handleNeutral(const std::string &args, ChatTab *const tab)
-{
- changeRelation(args, PlayerRelation::NEUTRAL, _("neutral"), tab);
-}
-
-void CommandHandler::changeRelation(const std::string &args,
- const PlayerRelation::Relation relation,
- const std::string &relationText,
- ChatTab *const tab)
-{
- if (args.empty())
- {
- if (tab)
- tab->chatLog(_("Please specify a name."), BY_SERVER);
- return;
- }
-
- if (player_relations.getRelation(args) == relation)
- {
- if (tab)
- {
- tab->chatLog(strprintf(_("Player already %s!"),
- relationText.c_str()), BY_SERVER);
- }
- return;
- }
- else
- {
- player_relations.setRelation(args, relation);
- }
-
- if (player_relations.getRelation(args) == relation)
- {
- if (tab)
- {
- tab->chatLog(strprintf(_("Player successfully %s!"),
- relationText.c_str()), BY_SERVER);
- }
- }
- else
- {
- if (tab)
- {
- tab->chatLog(strprintf(_("Player could not be %s!"),
- relationText.c_str()), BY_SERVER);
- }
- }
-}
-
-void CommandHandler::handleUnignore(const std::string &args,
- ChatTab *const tab)
-{
- if (args.empty())
- {
- if (tab)
- tab->chatLog(_("Please specify a name."), BY_SERVER);
- return;
- }
-
- if (player_relations.getRelation(args) != PlayerRelation::NEUTRAL
- && player_relations.getRelation(args) != PlayerRelation::FRIEND)
- {
- player_relations.setRelation(args, PlayerRelation::NEUTRAL);
- }
- else
- {
- if (tab)
- tab->chatLog(_("Player wasn't ignored!"), BY_SERVER);
- return;
- }
-
- if (tab)
- {
- if (player_relations.getRelation(args) == PlayerRelation::NEUTRAL)
- tab->chatLog(_("Player no longer ignored!"), BY_SERVER);
- else
- tab->chatLog(_("Player could not be unignored!"), BY_SERVER);
- }
-}
-
-void CommandHandler::handleBlackList(const std::string &args,
- ChatTab *const tab)
-{
- changeRelation(args, PlayerRelation::BLACKLISTED, _("blacklisted"), tab);
-}
-
-void CommandHandler::handleEnemy(const std::string &args, ChatTab *const tab)
-{
- changeRelation(args, PlayerRelation::ENEMY2, _("enemy"), tab);
-}
-
-void CommandHandler::handleErase(const std::string &args, ChatTab *const tab)
-{
- if (args.empty())
- {
- if (tab)
- tab->chatLog(_("Please specify a name."), BY_SERVER);
- return;
- }
-
- if (player_relations.getRelation(args) == PlayerRelation::ERASED)
- {
- if (tab)
- tab->chatLog(_("Player already erased!"), BY_SERVER);
- return;
- }
- else
- {
- player_relations.setRelation(args, PlayerRelation::ERASED);
- }
-
- if (tab)
- {
- if (player_relations.getRelation(args) == PlayerRelation::ERASED)
- tab->chatLog(_("Player successfully erased!"), BY_SERVER);
- else
- tab->chatLog(_("Player could not be erased!"), BY_SERVER);
- }
-}
-
-void CommandHandler::handleQuit(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
-// quit();
-}
-
-void CommandHandler::handleShowAll(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (actorSpriteManager)
- actorSpriteManager->printAllToChat();
-}
-
-void CommandHandler::handleMove(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- int x = 0;
- int y = 0;
-
- if (player_node && parse2Int(args, x, y))
- player_node->moveTo(x, y);
-}
-
-void CommandHandler::handleNavigate(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!player_node)
- return;
-
- int x = 0;
- int y = 0;
-
- if (parse2Int(args, x, y))
- player_node->navigateTo(x, y);
- else
- player_node->navigateClean();
-}
-
-bool CommandHandler::parse2Int(const std::string &args, int &x, int &y)
-{
- bool isValid = false;
- const size_t pos = args.find(" ");
- if (pos != std::string::npos)
- {
- if (pos + 1 < args.length())
- {
- x = atoi(args.substr(0, pos).c_str());
- y = atoi(args.substr(pos + 1, args.length()).c_str());
- isValid = true;
- }
- }
- return isValid;
-}
-
-void CommandHandler::handleTarget(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager || !player_node)
- return;
-
- Being *const target = actorSpriteManager->findNearestByName(args);
- if (target)
- player_node->setTarget(target);
-}
-
-void CommandHandler::handleAttackHuman(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager || !player_node)
- return;
-
- Being *const target = actorSpriteManager->findNearestLivingBeing(
- player_node, 10, ActorSprite::PLAYER);
- if (target)
- {
- if (player_node->checAttackPermissions(target))
- {
- player_node->setTarget(target);
- player_node->attack2(target, true);
- }
- }
-}
-
-
-void CommandHandler::handleCloseAll(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (chatWindow)
- {
- chatWindow->removeAllWhispers();
- chatWindow->saveState();
- }
-}
-
-void CommandHandler::handleIgnoreAll(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (chatWindow)
- {
- chatWindow->ignoreAllWhispers();
- chatWindow->saveState();
- }
-}
-
-void CommandHandler::handleOutfit(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (outfitWindow)
- {
- if (!args.empty())
- {
- const std::string op = args.substr(0, 1);
- if (op == "n")
- outfitWindow->wearNextOutfit(true);
- else if (op == "p")
- outfitWindow->wearPreviousOutfit(true);
- else
- outfitWindow->wearOutfit(atoi(args.c_str()) - 1, false, true);
- }
- else
- {
- outfitWindow->wearOutfit(atoi(args.c_str()) - 1, false, true);
- }
- }
-}
-
-void CommandHandler::handleEmote(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (player_node)
- player_node->emote(static_cast<uint8_t>(atoi(args.c_str())));
-}
-
-void CommandHandler::handleAway(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (player_node)
- player_node->setAway(args);
-}
-
-void CommandHandler::handlePseudoAway(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (player_node)
- {
- player_node->setPseudoAway(args);
- player_node->updateStatus();
- }
-}
-
-void CommandHandler::handleFollow(const std::string &args, ChatTab *const tab)
-{
- if (!player_node)
- return;
-
- if (!args.empty())
- {
- player_node->setFollow(args);
- }
- else if (tab && tab->getType() == ChatTab::TAB_WHISPER)
- {
- player_node->setFollow(static_cast<WhisperTab*>(tab)->getNick());
- }
-}
-
-void CommandHandler::handleImitation(const std::string &args,
- ChatTab *const tab)
-{
- if (!player_node)
- return;
-
- if (!args.empty())
- player_node->setImitate(args);
- else if (tab && tab->getType() == ChatTab::TAB_WHISPER)
- player_node->setImitate(static_cast<WhisperTab*>(tab)->getNick());
- else
- player_node->setImitate("");
-}
-
-void CommandHandler::handleHeal(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager)
- return;
-
- if (!args.empty())
- {
- const Being *const being = actorSpriteManager->findBeingByName(
- args, Being::PLAYER);
- if (being)
- actorSpriteManager->heal(being);
- }
- else
- {
- actorSpriteManager->heal(player_node);
- }
-}
-
-void CommandHandler::handleHack(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- Net::getChatHandler()->sendRaw(args);
-}
-
-void CommandHandler::handleMail(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (auctionManager && auctionManager->getEnableAuctionBot())
- auctionManager->sendMail(args);
-}
-
-void CommandHandler::handlePriceLoad(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (shopWindow)
- shopWindow->loadList();
-}
-
-void CommandHandler::handlePriceSave(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (shopWindow)
- shopWindow->saveList();
-}
-
-void CommandHandler::handleDisconnect(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- Net::getGameHandler()->disconnect2();
-}
-
-void CommandHandler::handleUndress(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager)
- return;
-
- Being *const target = actorSpriteManager->findNearestByName(args);
- if (target)
- Net::getBeingHandler()->undress(target);
-}
-
-void CommandHandler::handleAttack(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!player_node || !actorSpriteManager)
- return;
-
- Being *const target = actorSpriteManager->findNearestByName(args);
- if (target)
- player_node->setTarget(target);
- player_node->attack2(player_node->getTarget(), true);
-}
-
-void CommandHandler::handleTrade(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager)
- return;
-
- Being *const being = actorSpriteManager->findBeingByName(
- args, Being::PLAYER);
- if (being)
- {
- Net::getTradeHandler()->request(being);
- tradePartnerName = being->getName();
- if (tradeWindow)
- tradeWindow->clear();
- }
-}
-
-void CommandHandler::handleDirs(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (!player_node || !debugChatTab)
- return;
-
- debugChatTab->chatLog("config directory: "
- + Client::getConfigDirectory());
- debugChatTab->chatLog("logs directory: "
- + Client::getLocalDataDirectory());
- debugChatTab->chatLog("screenshots directory: "
- + Client::getScreenshotDirectory());
- debugChatTab->chatLog("temp directory: "
- + Client::getTempDirectory());
-}
-
-void CommandHandler::handleInfo(const std::string &args A_UNUSED,
- ChatTab *const tab)
-{
- switch (tab->getType())
- {
- case ChatTab::TAB_GUILD:
- {
- if (!player_node)
- return;
- const Guild *const guild = player_node->getGuild();
- if (guild)
- Net::getGuildHandler()->info(guild->getId());
- break;
- }
- default:
- break;
- }
-}
-
-void CommandHandler::handleWait(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (player_node)
- player_node->waitFor(args);
-}
-
-void CommandHandler::handleUptime(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (!debugChatTab)
- return;
-
- if (cur_time < start_time)
- {
- debugChatTab->chatLog(strprintf(_("Client uptime: %s"), "unknown"));
- }
- else
- {
- std::string str;
- int timeDiff = cur_time - start_time;
-
- const int weeks = timeDiff / 60 / 60 / 24 / 7;
- if (weeks > 0)
- {
- str = strprintf(ngettext("%d week", "%d weeks", weeks), weeks);
- timeDiff -= weeks * 60 * 60 * 24 * 7;
- }
-
- const int days = timeDiff / 60 / 60 / 24;
- if (days > 0)
- {
- if (!str.empty())
- str += ", ";
- str += strprintf(ngettext("%d day", "%d days", days), days);
- timeDiff -= days * 60 * 60 * 24;
- }
- const int hours = timeDiff / 60 / 60;
- if (hours > 0)
- {
- if (!str.empty())
- str += ", ";
- str += strprintf(ngettext("%d hour", "%d hours", hours), hours);
- timeDiff -= hours * 60 * 60;
- }
- const int min = timeDiff / 60;
- if (min > 0)
- {
- if (!str.empty())
- str += ", ";
- str += strprintf(ngettext("%d minute", "%d minutes", min), min);
- timeDiff -= min * 60;
- }
-
- if (timeDiff > 0)
- {
- if (!str.empty())
- str += ", ";
- str += strprintf(ngettext("%d second", "%d seconds",
- timeDiff), timeDiff);
- }
- debugChatTab->chatLog(strprintf(_("Client uptime: %s"), str.c_str()));
- }
-}
-
-void CommandHandler::handleAddPriorityAttack(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager
- || actorSpriteManager->isInPriorityAttackList(args))
- {
- return;
- }
-
- actorSpriteManager->removeAttackMob(args);
- actorSpriteManager->addPriorityAttackMob(args);
-
- if (socialWindow)
- socialWindow->updateAttackFilter();
-}
-
-void CommandHandler::handleAddAttack(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager || actorSpriteManager->isInAttackList(args))
- return;
-
- actorSpriteManager->removeAttackMob(args);
- actorSpriteManager->addAttackMob(args);
-
- if (socialWindow)
- socialWindow->updateAttackFilter();
-}
-
-void CommandHandler::handleRemoveAttack(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager || args.empty()
- || !actorSpriteManager->isInAttackList(args))
- {
- return;
- }
-
- actorSpriteManager->removeAttackMob(args);
-
- if (socialWindow)
- socialWindow->updateAttackFilter();
-}
-
-void CommandHandler::handleAddIgnoreAttack(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!actorSpriteManager || actorSpriteManager->isInIgnoreAttackList(args))
- return;
-
- actorSpriteManager->removeAttackMob(args);
- actorSpriteManager->addIgnoreAttackMob(args);
-
- if (socialWindow)
- socialWindow->updateAttackFilter();
-}
-
-void CommandHandler::handleCacheInfo(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- if (!chatWindow || !debugChatTab)
- return;
-
- SDLFont *const font = dynamic_cast<SDLFont *const>(chatWindow->getFont());
- if (!font)
- return;
-
- const std::list<SDLTextChunk> *const cache = font->getCache();
- if (!cache)
- return;
-
- int all = 0;
- debugChatTab->chatLog(_("font cache size"));
- std::string str;
- for (int f = 0; f < 256; f ++)
- {
- if (!cache[f].empty())
- {
- all += static_cast<int>(cache[f].size());
- str += strprintf("%d: %u, ", f,
- static_cast<unsigned int>(cache[f].size()));
- }
- }
- debugChatTab->chatLog(str);
- debugChatTab->chatLog(strprintf("%s %d", _("Cache size:"), all));
-#ifdef DEBUG_FONT_COUNTERS
- debugChatTab->chatLog("");
- debugChatTab->chatLog(strprintf("%s %d",
- _("Created:"), font->getCreateCounter()));
- debugChatTab->chatLog(strprintf("%s %d",
- _("Deleted:"), font->getDeleteCounter()));
-#endif
-}
-
-void CommandHandler::handleServerIgnoreAll(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- Net::getChatHandler()->ignoreAll();
-}
-
-void CommandHandler::handleServerUnIgnoreAll(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- Net::getChatHandler()->unIgnoreAll();
-}
-
-void CommandHandler::handleDumpGraphics(const std::string &args A_UNUSED,
- ChatTab *const tab)
-{
- std::string str;
- str = strprintf ("%s,%s,%dX%dX%d,", PACKAGE_OS, SMALL_VERSION,
- mainGraphics->getWidth(), mainGraphics->getHeight(),
- mainGraphics->getBpp());
-
- if (mainGraphics->getFullScreen())
- str += "F";
- else
- str += "W";
- if (mainGraphics->getHWAccel())
- str += "H";
- else
- str += "S";
-
- if (mainGraphics->getDoubleBuffer())
- str += "D";
- else
- str += "_";
-
-#if defined USE_OPENGL
- str += strprintf(",%d", mainGraphics->getOpenGL());
-#else
- str += ",0";
-#endif
-
- str += strprintf(",%f,", static_cast<double>(Client::getGuiAlpha()));
- str += config.getBoolValue("adjustPerfomance") ? "1" : "0";
- str += config.getBoolValue("alphaCache") ? "1" : "0";
- str += config.getBoolValue("enableMapReduce") ? "1" : "0";
- str += config.getBoolValue("beingopacity") ? "1" : "0";
- str += ",";
- str += config.getBoolValue("enableAlphaFix") ? "1" : "0";
- str += config.getBoolValue("disableAdvBeingCaching") ? "1" : "0";
- str += config.getBoolValue("disableBeingCaching") ? "1" : "0";
- str += config.getBoolValue("particleeffects") ? "1" : "0";
-
- str += strprintf(",%d-%d", fps, config.getIntValue("fpslimit"));
- outStringNormal(tab, str, str);
-}
-
-void CommandHandler::handleDumpTests(const std::string &args A_UNUSED,
- ChatTab *const tab)
-{
- std::string str = config.getStringValue("testInfo");
- outStringNormal(tab, str, str);
-}
-
-void CommandHandler::outStringNormal(ChatTab *const tab,
- const std::string &str,
- const std::string &def)
-{
- if (!player_node)
- return;
-
- if (!tab)
- {
- Net::getChatHandler()->talk(str);
- return;
- }
-
- switch (tab->getType())
- {
- case ChatTab::TAB_PARTY:
- {
- Net::getPartyHandler()->chat(str);
- break;
- }
- case ChatTab::TAB_GUILD:
- {
- if (!player_node)
- return;
- const Guild *const guild = player_node->getGuild();
- if (guild)
- {
- if (guild->getServerGuild())
- Net::getGuildHandler()->chat(guild->getId(), str);
- else if (guildManager)
- guildManager->chat(str);
- }
- break;
- }
- case ChatTab::TAB_WHISPER:
- {
- const WhisperTab *const whisper
- = static_cast<WhisperTab *const>(tab);
- tab->chatLog(player_node->getName(), str);
- Net::getChatHandler()->privateMessage(whisper->getNick(), str);
- break;
- }
- default:
- Net::getChatHandler()->talk(def);
- break;
- }
-}
-
-void CommandHandler::handleSetDrop(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (player_node)
- player_node->setQuickDropCounter(atoi(args.c_str()));
-}
-
-void CommandHandler::handleError(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- int *ptr = nullptr;
- logger->log("test %d", *ptr);
-}
-
-void CommandHandler::handleUrl(const std::string &args,
- ChatTab *const tab)
-{
- if (tab)
- {
- std::string url = args;
- if (!strStartWith(url, "http"))
- url = "http://" + url;
- std::string str = strprintf("[@@%s |%s@@]", url.c_str(), args.c_str());
- outStringNormal(tab, str, str);
- }
-}
-
-void CommandHandler::handleOpen(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- std::string url = args;
- if (!strStartWith(url, "http"))
- url = "http://" + url;
- openBrowser(url);
-}
-
-#ifdef DEBUG_DUMP_LEAKS1
-void showRes(std::string str, ResourceManager::Resources *res);
-
-void showRes(std::string str, ResourceManager::Resources *res)
-{
- if (!res)
- return;
-
- if (debugChatTab)
- debugChatTab->chatLog(str + toString(res->size()));
- logger->log(str + toString(res->size()));
- ResourceManager::ResourceIterator iter = res->begin();
- ResourceManager::ResourceIterator iter_end = res->end();
- while (iter != iter_end)
- {
- if (iter->second && iter->second->getRefCount())
- {
- std::string type = " ";
- std::string isNew = "N";
- if (iter->second->getDumped())
- isNew = "O";
- else
- iter->second->setDumped(true);
-
- SubImage *const subImage = dynamic_cast<SubImage *const>(
- iter->second);
- Image *const image = dynamic_cast<Image *const>(iter->second);
- int id = 0;
- if (subImage)
- type = "S";
- else if (image)
- type = "I";
- if (image)
- id = image->getGLImage();
- logger->log("Resource %s%s: %s (%d) id=%d", type.c_str(),
- isNew.c_str(), iter->second->getIdPath().c_str(),
- iter->second->getRefCount(), id);
- }
- ++ iter;
- }
-}
-
-void CommandHandler::handleDump(const std::string &args,
- ChatTab *const tab A_UNUSED)
-{
- if (!debugChatTab)
- return;
-
- ResourceManager *resman = ResourceManager::getInstance();
-
- if (!args.empty())
- {
- ResourceManager::Resources *res = resman->getResources();
- showRes(_("Resource images:"), res);
- res = resman->getOrphanedResources();
- showRes(_("Resource orphaned images:"), res);
- }
- else
- {
- ResourceManager::Resources *res = resman->getResources();
- debugChatTab->chatLog(_("Resource images:") + toString(res->size()));
- res = resman->getOrphanedResources();
- debugChatTab->chatLog(_("Resource orphaned images:")
- + toString(res->size()));
- }
-}
-
-#elif defined ENABLE_MEM_DEBUG
-void CommandHandler::handleDump(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
- check_leaks();
-}
-#else
-void CommandHandler::handleDump(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
-}
-#endif
-
-void CommandHandler::replaceVars(std::string &str)
-{
- if (!player_node || !actorSpriteManager)
- return;
-
- if (str.find("<PLAYER>") != std::string::npos)
- {
- const Being *target = player_node->getTarget();
- if (!target || target->getType() != ActorSprite::PLAYER)
- {
- target = actorSpriteManager->findNearestLivingBeing(
- player_node, 20, ActorSprite::PLAYER);
- }
- if (target)
- replaceAll(str, "<PLAYER>", target->getName());
- else
- replaceAll(str, "<PLAYER>", "");
- }
- if (str.find("<MONSTER>") != std::string::npos)
- {
- const Being *target = player_node->getTarget();
- if (!target || target->getType() != ActorSprite::MONSTER)
- {
- target = actorSpriteManager->findNearestLivingBeing(
- player_node, 20, ActorSprite::MONSTER);
- }
- if (target)
- replaceAll(str, "<MONSTER>", target->getName());
- else
- replaceAll(str, "<MONSTER>", "");
- }
- if (str.find("<PEOPLE>") != std::string::npos)
- {
- StringVect names;
- std::string newStr = "";
- actorSpriteManager->getPlayerNames(names, false);
- for (StringVectCIter it = names.begin(), it_end = names.end();
- it != it_end; ++ it)
- {
- if (*it != player_node->getName())
- newStr += *it + ",";
- }
- if (newStr[newStr.size() - 1] == ',')
- newStr = newStr.substr(0, newStr.size() - 1);
- if (!newStr.empty())
- replaceAll(str, "<PEOPLE>", newStr);
- else
- replaceAll(str, "<PEOPLE>", "");
- }
- if (str.find("<PARTY>") != std::string::npos)
- {
- StringVect names;
- std::string newStr = "";
- const Party *party = nullptr;
- if (player_node->isInParty() && (party = player_node->getParty()))
- {
- party->getNames(names);
- for (StringVectCIter it = names.begin(), it_end = names.end();
- it != it_end; ++ it)
- {
- if (*it != player_node->getName())
- newStr += *it + ",";
- }
- if (newStr[newStr.size() - 1] == ',')
- newStr = newStr.substr(0, newStr.size() - 1);
- if (!newStr.empty())
- replaceAll(str, "<PARTY>", newStr);
- else
- replaceAll(str, "<PARTY>", "");
- }
- else
- {
- replaceAll(str, "<PARTY>", "");
- }
- }
-}
-
-void CommandHandler::handleDumpOGL(const std::string &args A_UNUSED,
- ChatTab *const tab A_UNUSED)
-{
-#if defined USE_OPENGL && !defined ANDROID
- NormalOpenGLGraphics::dumpSettings();
-#endif
-}
diff --git a/src/commandhandler.h b/src/commandhandler.h
index 507218f01..076c35711 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -23,16 +23,18 @@
#ifndef COMMANDHANDLER_H
#define COMMANDHANDLER_H
-#include "playerrelations.h"
+#include "commands.h"
#include <string>
+#include "localconsts.h"
+
class ChatTab;
extern ChatTab *localChatTab;
-#define BOOLEAN_OPTIONS _("Options to /%s are \"yes\", \"no\", \"true\", "\
-"\"false\", \"1\", \"0\".")
+typedef std::map<std::string, CommandFuncPtr> CommandsMap;
+typedef CommandsMap::const_iterator CommandsMapIter;
/**
* A class to parse and handle user commands
@@ -56,303 +58,16 @@ class CommandHandler final
/**
* Parse and handle the given command.
*/
- static void handleCommand(const std::string &command,
- ChatTab *const tab = localChatTab);
-
- static void handleCommands(const std::string &command,
- ChatTab *const tab = localChatTab);
-
- static void replaceVars(std::string &str);
+ void handleCommand(const std::string &command,
+ ChatTab *const tab = localChatTab);
- static signed char parseBoolean(const std::string &value);
+ void handleCommands(const std::string &command,
+ ChatTab *const tab = localChatTab);
protected:
friend class ChatTab;
friend class WhisperTab;
-
- /**
- * Handle an announce command.
- */
- static void handleAnnounce(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle a help command.
- */
- static void handleHelp(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a where command.
- */
- static void handleWhere(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a who command.
- */
- static void handleWho(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a msg command.
- */
- static void handleMsg(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a msg tab request.
- */
- static void handleQuery(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a join command.
- */
- static void handleJoin(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a listchannels command.
- */
- static void handleListChannels(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle a clear command.
- */
- static void handleClear(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a createparty command.
- */
- static void handleCreateParty(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle a createguild command.
- */
- static void handleCreateGuild(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle a party command.
- */
- static void handleParty(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a me command.
- */
- static void handleMe(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a toggle command.
- */
- static void handleToggle(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle a present command.
- */
- static void handlePresent(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle an ignore command.
- */
- static void handleIgnore(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle an unignore command.
- */
- static void handleUnignore(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle an friend command.
- */
- static void handleFriend(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle an disregard command.
- */
- static void handleDisregard(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle an neutral command.
- */
- static void handleNeutral(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle an blacklist command.
- */
- static void handleBlackList(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle an enemy command.
- */
- static void handleEnemy(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle an erase command.
- */
- static void handleErase(const std::string &args, ChatTab *const tab);
-
- /**
- * Change relation.
- */
- static void changeRelation(const std::string &args,
- const PlayerRelation::Relation relation,
- const std::string &relationText,
- ChatTab *const tab);
-
- /**
- * Handle a quit command.
- */
- static void handleQuit(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle show all command.
- */
- static void handleShowAll(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle move command.
- */
- static void handleMove(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle target command.
- */
- static void handleTarget(const std::string &args, ChatTab *const tab);
- /**
- * Handle atkhuman command.
- */
- static void handleAttackHuman(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle closeall command.
- */
- static void handleCloseAll(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle ignoreall command.
- */
- static void handleIgnoreAll(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle outfit command.
- */
- static void handleOutfit(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle emote command.
- */
- static void handleEmote(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle away command.
- */
- static void handleAway(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle pseudo away command.
- */
- static void handlePseudoAway(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle follow command.
- */
- static void handleFollow(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle imitation command.
- */
- static void handleImitation(const std::string &args,
- ChatTab *const tab);
-
- /**
- * Handle heal command.
- */
- static void handleHeal(const std::string &args, ChatTab *const tab);
-
- /**
- * Handle navigate command.
- */
- static void handleNavigate(const std::string &args,
- ChatTab *const tab);
-
- static void handleMail(const std::string &args, ChatTab *const tab);
-
- static void handleHack(const std::string &args, ChatTab *const tab);
-
- static void handlePriceLoad(const std::string &args,
- ChatTab *const tab);
-
- static void handlePriceSave(const std::string &args,
- ChatTab *const tab);
-
- static void handleTrade(const std::string &args, ChatTab *const tab);
-
- static void handleDisconnect(const std::string &args,
- ChatTab *const tab);
-
- static void handleUndress(const std::string &args, ChatTab *const tab);
-
- static void handleAttack(const std::string &args, ChatTab *const tab);
-
- static void handleDirs(const std::string &args, ChatTab *const tab);
-
- static void handleInfo(const std::string &args, ChatTab *const tab);
-
- static void handleWait(const std::string &args, ChatTab *const tab);
-
- static void handleUptime(const std::string &args, ChatTab *const tab);
-
- static void handleAddAttack(const std::string &args,
- ChatTab *const tab);
-
- static void handleAddPriorityAttack(const std::string &args,
- ChatTab *const tab);
-
- static void handleRemoveAttack(const std::string &args,
- ChatTab *const tab);
-
- static void handleAddIgnoreAttack(const std::string &args,
- ChatTab *const tab);
-
- static void handleServerIgnoreAll(const std::string &args,
- ChatTab *const tab);
-
- static void handleServerUnIgnoreAll(const std::string &args,
- ChatTab *const tab);
-
- static void handleSetDrop(const std::string &args, ChatTab *const tab);
-
- static void handleError(const std::string &args, ChatTab *const tab);
-
- static void handleUrl(const std::string &args, ChatTab *const tab);
-
- static void handleOpen(const std::string &args, ChatTab *const tab);
-
- static void handleDump(const std::string &args, ChatTab *const tab);
-
- static void handleDumpGraphics(const std::string &args,
- ChatTab *const tab);
-
- static void handleDumpTests(const std::string &args,
- ChatTab *const tab);
-
- static void handleDumpOGL(const std::string &args, ChatTab *const tab);
-
- static void outString(ChatTab *const tab, const std::string &str,
- const std::string &def);
-
- static void outStringNormal(ChatTab *const tab, const std::string &str,
- const std::string &def);
-
- static void handleCacheInfo(const std::string &args,
- ChatTab *const tab);
-
- static bool parse2Int(const std::string &args, int &x, int &y);
+ CommandsMap mCommands;
};
extern CommandHandler *commandHandler;
diff --git a/src/commands.cpp b/src/commands.cpp
new file mode 100644
index 000000000..31e3d3fe2
--- /dev/null
+++ b/src/commands.cpp
@@ -0,0 +1,1210 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2008-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "commandhandler.h"
+
+#include "auctionmanager.h"
+#include "actorspritemanager.h"
+#include "channelmanager.h"
+#include "channel.h"
+#include "client.h"
+#include "configuration.h"
+#include "game.h"
+#include "guildmanager.h"
+#include "localplayer.h"
+#include "main.h"
+#include "party.h"
+
+#include "gui/chatwindow.h"
+#include "gui/helpwindow.h"
+#include "gui/gui.h"
+#include "gui/outfitwindow.h"
+#include "gui/shopwindow.h"
+#include "gui/socialwindow.h"
+#include "gui/tradewindow.h"
+#include "gui/sdlfont.h"
+
+#include "gui/widgets/channeltab.h"
+#include "gui/widgets/whispertab.h"
+
+#include "net/adminhandler.h"
+#include "net/beinghandler.h"
+#include "net/chathandler.h"
+#include "net/gamehandler.h"
+#include "net/guildhandler.h"
+#include "net/net.h"
+#include "net/partyhandler.h"
+#include "net/playerhandler.h"
+#include "net/tradehandler.h"
+
+#if defined USE_OPENGL
+#include "normalopenglgraphics.h"
+#endif
+
+#ifdef DEBUG_DUMP_LEAKS1
+#include "resources/image.h"
+#include "resources/resource.h"
+#include "resources/resourcemanager.h"
+#include "resources/subimage.h"
+#endif
+
+#include "utils/gettext.h"
+#include "utils/process.h"
+
+#include "debug.h"
+
+#define impHandler(name) void name(const std::string &args, ChatTab *const tab)
+#define impHandler0(name) void name(const std::string &args A_UNUSED, \
+ ChatTab *const tab A_UNUSED)
+#define impHandler1(name) void name(const std::string &args, \
+ ChatTab *const tab A_UNUSED)
+#define impHandler2(name) void name(const std::string &args A_UNUSED, \
+ ChatTab *const tab)
+
+extern std::string tradePartnerName;
+
+namespace Commands
+{
+
+static void outString(ChatTab *const tab, const std::string &str,
+ const std::string &def)
+{
+ if (!tab)
+ {
+ Net::getChatHandler()->me(def);
+ return;
+ }
+
+ switch (tab->getType())
+ {
+ case ChatTab::TAB_PARTY:
+ {
+ Net::getPartyHandler()->chat(str);
+ break;
+ }
+ case ChatTab::TAB_GUILD:
+ {
+ if (!player_node)
+ return;
+ const Guild *const guild = player_node->getGuild();
+ if (guild)
+ {
+ if (guild->getServerGuild())
+ Net::getGuildHandler()->chat(guild->getId(), str);
+ else if (guildManager)
+ guildManager->chat(str);
+ }
+ break;
+ }
+ default:
+ Net::getChatHandler()->me(def);
+ break;
+ }
+}
+
+static void changeRelation(const std::string &args,
+ const PlayerRelation::Relation relation,
+ const std::string &relationText,
+ ChatTab *const tab)
+{
+ if (args.empty())
+ {
+ if (tab)
+ tab->chatLog(_("Please specify a name."), BY_SERVER);
+ return;
+ }
+
+ if (player_relations.getRelation(args) == relation)
+ {
+ if (tab)
+ {
+ tab->chatLog(strprintf(_("Player already %s!"),
+ relationText.c_str()), BY_SERVER);
+ }
+ return;
+ }
+ else
+ {
+ player_relations.setRelation(args, relation);
+ }
+
+ if (player_relations.getRelation(args) == relation)
+ {
+ if (tab)
+ {
+ tab->chatLog(strprintf(_("Player successfully %s!"),
+ relationText.c_str()), BY_SERVER);
+ }
+ }
+ else
+ {
+ if (tab)
+ {
+ tab->chatLog(strprintf(_("Player could not be %s!"),
+ relationText.c_str()), BY_SERVER);
+ }
+ }
+}
+
+static bool parse2Int(const std::string &args, int &x, int &y)
+{
+ bool isValid = false;
+ const size_t pos = args.find(" ");
+ if (pos != std::string::npos)
+ {
+ if (pos + 1 < args.length())
+ {
+ x = atoi(args.substr(0, pos).c_str());
+ y = atoi(args.substr(pos + 1, args.length()).c_str());
+ isValid = true;
+ }
+ }
+ return isValid;
+}
+
+static void outStringNormal(ChatTab *const tab,
+ const std::string &str,
+ const std::string &def)
+{
+ if (!player_node)
+ return;
+
+ if (!tab)
+ {
+ Net::getChatHandler()->talk(str);
+ return;
+ }
+
+ switch (tab->getType())
+ {
+ case ChatTab::TAB_PARTY:
+ {
+ Net::getPartyHandler()->chat(str);
+ break;
+ }
+ case ChatTab::TAB_GUILD:
+ {
+ if (!player_node)
+ return;
+ const Guild *const guild = player_node->getGuild();
+ if (guild)
+ {
+ if (guild->getServerGuild())
+ Net::getGuildHandler()->chat(guild->getId(), str);
+ else if (guildManager)
+ guildManager->chat(str);
+ }
+ break;
+ }
+ case ChatTab::TAB_WHISPER:
+ {
+ const WhisperTab *const whisper
+ = static_cast<WhisperTab *const>(tab);
+ tab->chatLog(player_node->getName(), str);
+ Net::getChatHandler()->privateMessage(whisper->getNick(), str);
+ break;
+ }
+ default:
+ Net::getChatHandler()->talk(def);
+ break;
+ }
+}
+
+
+impHandler1(announce)
+{
+ Net::getAdminHandler()->announce(args);
+}
+
+impHandler0(help)
+{
+ if (!helpWindow)
+ return;
+
+ if (!tab)
+ {
+ helpWindow->loadHelp("chatcommands");
+ helpWindow->requestMoveToTop();
+ return;
+ }
+ switch (tab->getType())
+ {
+ case ChatTab::TAB_PARTY:
+ {
+ helpWindow->loadHelp("chatparty");
+ break;
+ }
+ case ChatTab::TAB_GUILD:
+ {
+ helpWindow->loadHelp("chatguild");
+ break;
+ }
+ default:
+ helpWindow->loadHelp("chatcommands");
+ break;
+ }
+ helpWindow->requestMoveToTop();
+}
+
+impHandler2(where)
+{
+ std::ostringstream where;
+ where << Game::instance()->getCurrentMapName() << ", coordinates: "
+ << ((player_node->getPixelX() - 16) / 32) << ", "
+ << ((player_node->getPixelY() - 32) / 32);
+
+ tab->chatLog(where.str(), BY_SERVER);
+}
+
+impHandler0(who)
+{
+ Net::getChatHandler()->who();
+}
+
+impHandler(msg)
+{
+ std::string recvnick("");
+ std::string msg("");
+
+ if (args.substr(0, 1) == "\"")
+ {
+ const size_t pos = args.find('"', 1);
+ if (pos != std::string::npos)
+ {
+ recvnick = args.substr(1, pos - 1);
+ if (pos + 2 < args.length())
+ msg = args.substr(pos + 2, args.length());
+ }
+ }
+ else
+ {
+ const size_t pos = args.find(" ");
+ if (pos != std::string::npos)
+ {
+ recvnick = args.substr(0, pos);
+ if (pos + 1 < args.length())
+ msg = args.substr(pos + 1, args.length());
+ }
+ else
+ {
+ recvnick = std::string(args);
+ msg = "";
+ }
+ }
+
+ trim(msg);
+
+ if (msg.length() > 0)
+ {
+ std::string playerName = player_node->getName();
+ std::string tempNick = recvnick;
+
+ toLower(playerName);
+ toLower(tempNick);
+
+ if (tempNick.compare(playerName) == 0 || args.empty())
+ return;
+
+ chatWindow->addWhisper(recvnick, msg, BY_PLAYER);
+ }
+ else
+ tab->chatLog(_("Cannot send empty whispers!"), BY_SERVER);
+}
+
+impHandler(query)
+{
+ if (chatWindow)
+ {
+ if (chatWindow->addWhisperTab(args, true))
+ {
+ chatWindow->saveState();
+ return;
+ }
+ }
+
+ tab->chatLog(strprintf(_("Cannot create a whisper tab for nick \"%s\"! "
+ "It either already exists, or is you."),
+ args.c_str()), BY_SERVER);
+}
+
+impHandler0(clear)
+{
+ if (chatWindow)
+ chatWindow->clearTab();
+}
+
+impHandler(join)
+{
+ if (!tab)
+ return;
+
+ const size_t pos = args.find(' ');
+ const std::string name(args, 0, pos);
+ const std::string password(args, pos + 1);
+ tab->chatLog(strprintf(_("Requesting to join channel %s."), name.c_str()));
+ Net::getChatHandler()->enterChannel(name, password);
+}
+
+impHandler0(listChannels)
+{
+ Net::getChatHandler()->channelList();
+}
+
+impHandler(createParty)
+{
+ if (!tab)
+ return;
+
+ if (args.empty())
+ tab->chatLog(_("Party name is missing."), BY_SERVER);
+ else
+ Net::getPartyHandler()->create(args);
+}
+
+impHandler(createGuild)
+{
+ if (!tab)
+ return;
+
+ if (args.empty())
+ tab->chatLog(_("Guild name is missing."), BY_SERVER);
+ else
+ Net::getGuildHandler()->create(args);
+}
+
+impHandler(party)
+{
+ if (!tab)
+ return;
+
+ if (args != "")
+ Net::getPartyHandler()->invite(args);
+ else
+ tab->chatLog(_("Please specify a name."), BY_SERVER);
+}
+
+impHandler(me)
+{
+ outString(tab, strprintf("*%s*", args.c_str()), args);
+}
+
+impHandler(toggle)
+{
+ if (args.empty())
+ {
+ if (chatWindow && tab)
+ {
+ tab->chatLog(chatWindow->getReturnTogglesChat() ?
+ _("Return toggles chat.") : _("Message closes chat."));
+ }
+ return;
+ }
+
+ switch (parseBoolean(args))
+ {
+ case 1:
+ if (tab)
+ tab->chatLog(_("Return now toggles chat."));
+ if (chatWindow)
+ chatWindow->setReturnTogglesChat(true);
+ return;
+ case 0:
+ if (tab)
+ tab->chatLog(_("Message now closes chat."));
+ if (chatWindow)
+ chatWindow->setReturnTogglesChat(false);
+ return;
+ case -1:
+ if (tab)
+ tab->chatLog(strprintf(BOOLEAN_OPTIONS, "toggle"));
+ return;
+ default:
+ return;
+ }
+}
+
+impHandler0(present)
+{
+ if (chatWindow)
+ chatWindow->doPresent();
+}
+
+impHandler1(ignore)
+{
+ changeRelation(args, PlayerRelation::IGNORED, "ignored", tab);
+}
+
+impHandler(beFriend)
+{
+ changeRelation(args, PlayerRelation::FRIEND, _("friend"), tab);
+}
+
+impHandler(disregard)
+{
+ changeRelation(args, PlayerRelation::DISREGARDED, _("disregarded"), tab);
+}
+
+impHandler(neutral)
+{
+ changeRelation(args, PlayerRelation::NEUTRAL, _("neutral"), tab);
+}
+
+impHandler(unignore)
+{
+ if (args.empty())
+ {
+ if (tab)
+ tab->chatLog(_("Please specify a name."), BY_SERVER);
+ return;
+ }
+
+ if (player_relations.getRelation(args) != PlayerRelation::NEUTRAL
+ && player_relations.getRelation(args) != PlayerRelation::FRIEND)
+ {
+ player_relations.setRelation(args, PlayerRelation::NEUTRAL);
+ }
+ else
+ {
+ if (tab)
+ tab->chatLog(_("Player wasn't ignored!"), BY_SERVER);
+ return;
+ }
+
+ if (tab)
+ {
+ if (player_relations.getRelation(args) == PlayerRelation::NEUTRAL)
+ tab->chatLog(_("Player no longer ignored!"), BY_SERVER);
+ else
+ tab->chatLog(_("Player could not be unignored!"), BY_SERVER);
+ }
+}
+
+impHandler(blackList)
+{
+ changeRelation(args, PlayerRelation::BLACKLISTED, _("blacklisted"), tab);
+}
+
+impHandler(enemy)
+{
+ changeRelation(args, PlayerRelation::ENEMY2, _("enemy"), tab);
+}
+
+impHandler(erase)
+{
+ if (args.empty())
+ {
+ if (tab)
+ tab->chatLog(_("Please specify a name."), BY_SERVER);
+ return;
+ }
+
+ if (player_relations.getRelation(args) == PlayerRelation::ERASED)
+ {
+ if (tab)
+ tab->chatLog(_("Player already erased!"), BY_SERVER);
+ return;
+ }
+ else
+ {
+ player_relations.setRelation(args, PlayerRelation::ERASED);
+ }
+
+ if (tab)
+ {
+ if (player_relations.getRelation(args) == PlayerRelation::ERASED)
+ tab->chatLog(_("Player successfully erased!"), BY_SERVER);
+ else
+ tab->chatLog(_("Player could not be erased!"), BY_SERVER);
+ }
+}
+
+impHandler0(quit)
+{
+// quit();
+}
+
+impHandler0(showAll)
+{
+ if (actorSpriteManager)
+ actorSpriteManager->printAllToChat();
+}
+
+impHandler1(move)
+{
+ int x = 0;
+ int y = 0;
+
+ if (player_node && parse2Int(args, x, y))
+ player_node->moveTo(x, y);
+}
+
+impHandler1(navigate)
+{
+ if (!player_node)
+ return;
+
+ int x = 0;
+ int y = 0;
+
+ if (parse2Int(args, x, y))
+ player_node->navigateTo(x, y);
+ else
+ player_node->navigateClean();
+}
+
+impHandler1(target)
+{
+ if (!actorSpriteManager || !player_node)
+ return;
+
+ Being *const target = actorSpriteManager->findNearestByName(args);
+ if (target)
+ player_node->setTarget(target);
+}
+
+impHandler0(attackHuman)
+{
+ if (!actorSpriteManager || !player_node)
+ return;
+
+ Being *const target = actorSpriteManager->findNearestLivingBeing(
+ player_node, 10, ActorSprite::PLAYER);
+ if (target)
+ {
+ if (player_node->checAttackPermissions(target))
+ {
+ player_node->setTarget(target);
+ player_node->attack2(target, true);
+ }
+ }
+}
+
+
+impHandler0(closeAll)
+{
+ if (chatWindow)
+ {
+ chatWindow->removeAllWhispers();
+ chatWindow->saveState();
+ }
+}
+
+impHandler0(ignoreAll)
+{
+ if (chatWindow)
+ {
+ chatWindow->ignoreAllWhispers();
+ chatWindow->saveState();
+ }
+}
+
+impHandler1(outfit)
+{
+ if (outfitWindow)
+ {
+ if (!args.empty())
+ {
+ const std::string op = args.substr(0, 1);
+ if (op == "n")
+ outfitWindow->wearNextOutfit(true);
+ else if (op == "p")
+ outfitWindow->wearPreviousOutfit(true);
+ else
+ outfitWindow->wearOutfit(atoi(args.c_str()) - 1, false, true);
+ }
+ else
+ {
+ outfitWindow->wearOutfit(atoi(args.c_str()) - 1, false, true);
+ }
+ }
+}
+
+impHandler1(emote)
+{
+ if (player_node)
+ player_node->emote(static_cast<uint8_t>(atoi(args.c_str())));
+}
+
+impHandler1(away)
+{
+ if (player_node)
+ player_node->setAway(args);
+}
+
+impHandler1(pseudoAway)
+{
+ if (player_node)
+ {
+ player_node->setPseudoAway(args);
+ player_node->updateStatus();
+ }
+}
+
+impHandler(follow)
+{
+ if (!player_node)
+ return;
+
+ if (!args.empty())
+ {
+ player_node->setFollow(args);
+ }
+ else if (tab && tab->getType() == ChatTab::TAB_WHISPER)
+ {
+ player_node->setFollow(static_cast<WhisperTab*>(tab)->getNick());
+ }
+}
+
+impHandler(imitation)
+{
+ if (!player_node)
+ return;
+
+ if (!args.empty())
+ player_node->setImitate(args);
+ else if (tab && tab->getType() == ChatTab::TAB_WHISPER)
+ player_node->setImitate(static_cast<WhisperTab*>(tab)->getNick());
+ else
+ player_node->setImitate("");
+}
+
+impHandler1(heal)
+{
+ if (!actorSpriteManager)
+ return;
+
+ if (!args.empty())
+ {
+ const Being *const being = actorSpriteManager->findBeingByName(
+ args, Being::PLAYER);
+ if (being)
+ actorSpriteManager->heal(being);
+ }
+ else
+ {
+ actorSpriteManager->heal(player_node);
+ }
+}
+
+impHandler1(hack)
+{
+ Net::getChatHandler()->sendRaw(args);
+}
+
+impHandler1(mail)
+{
+ if (auctionManager && auctionManager->getEnableAuctionBot())
+ auctionManager->sendMail(args);
+}
+
+impHandler0(priceLoad)
+{
+ if (shopWindow)
+ shopWindow->loadList();
+}
+
+impHandler0(priceSave)
+{
+ if (shopWindow)
+ shopWindow->saveList();
+}
+
+impHandler0(disconnect)
+{
+ Net::getGameHandler()->disconnect2();
+}
+
+impHandler1(undress)
+{
+ if (!actorSpriteManager)
+ return;
+
+ Being *const target = actorSpriteManager->findNearestByName(args);
+ if (target)
+ Net::getBeingHandler()->undress(target);
+}
+
+impHandler1(attack)
+{
+ if (!player_node || !actorSpriteManager)
+ return;
+
+ Being *const target = actorSpriteManager->findNearestByName(args);
+ if (target)
+ player_node->setTarget(target);
+ player_node->attack2(player_node->getTarget(), true);
+}
+
+impHandler1(trade)
+{
+ if (!actorSpriteManager)
+ return;
+
+ Being *const being = actorSpriteManager->findBeingByName(
+ args, Being::PLAYER);
+ if (being)
+ {
+ Net::getTradeHandler()->request(being);
+ tradePartnerName = being->getName();
+ if (tradeWindow)
+ tradeWindow->clear();
+ }
+}
+
+impHandler0(dirs)
+{
+ if (!player_node || !debugChatTab)
+ return;
+
+ debugChatTab->chatLog("config directory: "
+ + Client::getConfigDirectory());
+ debugChatTab->chatLog("logs directory: "
+ + Client::getLocalDataDirectory());
+ debugChatTab->chatLog("screenshots directory: "
+ + Client::getScreenshotDirectory());
+ debugChatTab->chatLog("temp directory: "
+ + Client::getTempDirectory());
+}
+
+impHandler2(info)
+{
+ switch (tab->getType())
+ {
+ case ChatTab::TAB_GUILD:
+ {
+ if (!player_node)
+ return;
+ const Guild *const guild = player_node->getGuild();
+ if (guild)
+ Net::getGuildHandler()->info(guild->getId());
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+impHandler1(wait)
+{
+ if (player_node)
+ player_node->waitFor(args);
+}
+
+impHandler0(uptime)
+{
+ if (!debugChatTab)
+ return;
+
+ if (cur_time < start_time)
+ {
+ debugChatTab->chatLog(strprintf(_("Client uptime: %s"), "unknown"));
+ }
+ else
+ {
+ std::string str;
+ int timeDiff = cur_time - start_time;
+
+ const int weeks = timeDiff / 60 / 60 / 24 / 7;
+ if (weeks > 0)
+ {
+ str = strprintf(ngettext("%d week", "%d weeks", weeks), weeks);
+ timeDiff -= weeks * 60 * 60 * 24 * 7;
+ }
+
+ const int days = timeDiff / 60 / 60 / 24;
+ if (days > 0)
+ {
+ if (!str.empty())
+ str += ", ";
+ str += strprintf(ngettext("%d day", "%d days", days), days);
+ timeDiff -= days * 60 * 60 * 24;
+ }
+ const int hours = timeDiff / 60 / 60;
+ if (hours > 0)
+ {
+ if (!str.empty())
+ str += ", ";
+ str += strprintf(ngettext("%d hour", "%d hours", hours), hours);
+ timeDiff -= hours * 60 * 60;
+ }
+ const int min = timeDiff / 60;
+ if (min > 0)
+ {
+ if (!str.empty())
+ str += ", ";
+ str += strprintf(ngettext("%d minute", "%d minutes", min), min);
+ timeDiff -= min * 60;
+ }
+
+ if (timeDiff > 0)
+ {
+ if (!str.empty())
+ str += ", ";
+ str += strprintf(ngettext("%d second", "%d seconds",
+ timeDiff), timeDiff);
+ }
+ debugChatTab->chatLog(strprintf(_("Client uptime: %s"), str.c_str()));
+ }
+}
+
+impHandler1(addPriorityAttack)
+{
+ if (!actorSpriteManager
+ || actorSpriteManager->isInPriorityAttackList(args))
+ {
+ return;
+ }
+
+ actorSpriteManager->removeAttackMob(args);
+ actorSpriteManager->addPriorityAttackMob(args);
+
+ if (socialWindow)
+ socialWindow->updateAttackFilter();
+}
+
+impHandler1(addAttack)
+{
+ if (!actorSpriteManager || actorSpriteManager->isInAttackList(args))
+ return;
+
+ actorSpriteManager->removeAttackMob(args);
+ actorSpriteManager->addAttackMob(args);
+
+ if (socialWindow)
+ socialWindow->updateAttackFilter();
+}
+
+impHandler1(removeAttack)
+{
+ if (!actorSpriteManager || args.empty()
+ || !actorSpriteManager->isInAttackList(args))
+ {
+ return;
+ }
+
+ actorSpriteManager->removeAttackMob(args);
+
+ if (socialWindow)
+ socialWindow->updateAttackFilter();
+}
+
+impHandler1(addIgnoreAttack)
+{
+ if (!actorSpriteManager || actorSpriteManager->isInIgnoreAttackList(args))
+ return;
+
+ actorSpriteManager->removeAttackMob(args);
+ actorSpriteManager->addIgnoreAttackMob(args);
+
+ if (socialWindow)
+ socialWindow->updateAttackFilter();
+}
+
+impHandler0(cacheInfo)
+{
+ if (!chatWindow || !debugChatTab)
+ return;
+
+ SDLFont *const font = dynamic_cast<SDLFont *const>(chatWindow->getFont());
+ if (!font)
+ return;
+
+ const std::list<SDLTextChunk> *const cache = font->getCache();
+ if (!cache)
+ return;
+
+ int all = 0;
+ debugChatTab->chatLog(_("font cache size"));
+ std::string str;
+ for (int f = 0; f < 256; f ++)
+ {
+ if (!cache[f].empty())
+ {
+ all += static_cast<int>(cache[f].size());
+ str += strprintf("%d: %u, ", f,
+ static_cast<unsigned int>(cache[f].size()));
+ }
+ }
+ debugChatTab->chatLog(str);
+ debugChatTab->chatLog(strprintf("%s %d", _("Cache size:"), all));
+#ifdef DEBUG_FONT_COUNTERS
+ debugChatTab->chatLog("");
+ debugChatTab->chatLog(strprintf("%s %d",
+ _("Created:"), font->getCreateCounter()));
+ debugChatTab->chatLog(strprintf("%s %d",
+ _("Deleted:"), font->getDeleteCounter()));
+#endif
+}
+
+impHandler0(serverIgnoreAll)
+{
+ Net::getChatHandler()->ignoreAll();
+}
+
+impHandler0(serverUnIgnoreAll)
+{
+ Net::getChatHandler()->unIgnoreAll();
+}
+
+impHandler2(dumpGraphics)
+{
+ std::string str;
+ str = strprintf ("%s,%s,%dX%dX%d,", PACKAGE_OS, SMALL_VERSION,
+ mainGraphics->getWidth(), mainGraphics->getHeight(),
+ mainGraphics->getBpp());
+
+ if (mainGraphics->getFullScreen())
+ str += "F";
+ else
+ str += "W";
+ if (mainGraphics->getHWAccel())
+ str += "H";
+ else
+ str += "S";
+
+ if (mainGraphics->getDoubleBuffer())
+ str += "D";
+ else
+ str += "_";
+
+#if defined USE_OPENGL
+ str += strprintf(",%d", mainGraphics->getOpenGL());
+#else
+ str += ",0";
+#endif
+
+ str += strprintf(",%f,", static_cast<double>(Client::getGuiAlpha()));
+ str += config.getBoolValue("adjustPerfomance") ? "1" : "0";
+ str += config.getBoolValue("alphaCache") ? "1" : "0";
+ str += config.getBoolValue("enableMapReduce") ? "1" : "0";
+ str += config.getBoolValue("beingopacity") ? "1" : "0";
+ str += ",";
+ str += config.getBoolValue("enableAlphaFix") ? "1" : "0";
+ str += config.getBoolValue("disableAdvBeingCaching") ? "1" : "0";
+ str += config.getBoolValue("disableBeingCaching") ? "1" : "0";
+ str += config.getBoolValue("particleeffects") ? "1" : "0";
+
+ str += strprintf(",%d-%d", fps, config.getIntValue("fpslimit"));
+ outStringNormal(tab, str, str);
+}
+
+impHandler2(dumpTests)
+{
+ std::string str = config.getStringValue("testInfo");
+ outStringNormal(tab, str, str);
+}
+
+impHandler1(setDrop)
+{
+ if (player_node)
+ player_node->setQuickDropCounter(atoi(args.c_str()));
+}
+
+impHandler0(error)
+{
+ int *ptr = nullptr;
+ logger->log("test %d", *ptr);
+}
+
+impHandler(url)
+{
+ if (tab)
+ {
+ std::string url = args;
+ if (!strStartWith(url, "http"))
+ url = "http://" + url;
+ std::string str = strprintf("[@@%s |%s@@]", url.c_str(), args.c_str());
+ outStringNormal(tab, str, str);
+ }
+}
+
+impHandler1(open)
+{
+ std::string url = args;
+ if (!strStartWith(url, "http"))
+ url = "http://" + url;
+ openBrowser(url);
+}
+
+#ifdef DEBUG_DUMP_LEAKS1
+void showRes(std::string str, ResourceManager::Resources *res);
+
+void showRes(std::string str, ResourceManager::Resources *res)
+{
+ if (!res)
+ return;
+
+ if (debugChatTab)
+ debugChatTab->chatLog(str + toString(res->size()));
+ logger->log(str + toString(res->size()));
+ ResourceManager::ResourceIterator iter = res->begin();
+ ResourceManager::ResourceIterator iter_end = res->end();
+ while (iter != iter_end)
+ {
+ if (iter->second && iter->second->getRefCount())
+ {
+ std::string type = " ";
+ std::string isNew = "N";
+ if (iter->second->getDumped())
+ isNew = "O";
+ else
+ iter->second->setDumped(true);
+
+ SubImage *const subImage = dynamic_cast<SubImage *const>(
+ iter->second);
+ Image *const image = dynamic_cast<Image *const>(iter->second);
+ int id = 0;
+ if (subImage)
+ type = "S";
+ else if (image)
+ type = "I";
+ if (image)
+ id = image->getGLImage();
+ logger->log("Resource %s%s: %s (%d) id=%d", type.c_str(),
+ isNew.c_str(), iter->second->getIdPath().c_str(),
+ iter->second->getRefCount(), id);
+ }
+ ++ iter;
+ }
+}
+
+impHandler1(dump)
+{
+ if (!debugChatTab)
+ return;
+
+ ResourceManager *resman = ResourceManager::getInstance();
+
+ if (!args.empty())
+ {
+ ResourceManager::Resources *res = resman->getResources();
+ showRes(_("Resource images:"), res);
+ res = resman->getOrphanedResources();
+ showRes(_("Resource orphaned images:"), res);
+ }
+ else
+ {
+ ResourceManager::Resources *res = resman->getResources();
+ debugChatTab->chatLog(_("Resource images:") + toString(res->size()));
+ res = resman->getOrphanedResources();
+ debugChatTab->chatLog(_("Resource orphaned images:")
+ + toString(res->size()));
+ }
+}
+
+#elif defined ENABLE_MEM_DEBUG
+impHandler0(dump)
+{
+ check_leaks();
+}
+#else
+impHandler0(dump)
+{
+}
+#endif
+
+
+impHandler0(dumpOGL)
+{
+#if defined USE_OPENGL && !defined ANDROID
+ NormalOpenGLGraphics::dumpSettings();
+#endif
+}
+
+void replaceVars(std::string &str)
+{
+ if (!player_node || !actorSpriteManager)
+ return;
+
+ if (str.find("<PLAYER>") != std::string::npos)
+ {
+ const Being *target = player_node->getTarget();
+ if (!target || target->getType() != ActorSprite::PLAYER)
+ {
+ target = actorSpriteManager->findNearestLivingBeing(
+ player_node, 20, ActorSprite::PLAYER);
+ }
+ if (target)
+ replaceAll(str, "<PLAYER>", target->getName());
+ else
+ replaceAll(str, "<PLAYER>", "");
+ }
+ if (str.find("<MONSTER>") != std::string::npos)
+ {
+ const Being *target = player_node->getTarget();
+ if (!target || target->getType() != ActorSprite::MONSTER)
+ {
+ target = actorSpriteManager->findNearestLivingBeing(
+ player_node, 20, ActorSprite::MONSTER);
+ }
+ if (target)
+ replaceAll(str, "<MONSTER>", target->getName());
+ else
+ replaceAll(str, "<MONSTER>", "");
+ }
+ if (str.find("<PEOPLE>") != std::string::npos)
+ {
+ StringVect names;
+ std::string newStr = "";
+ actorSpriteManager->getPlayerNames(names, false);
+ for (StringVectCIter it = names.begin(), it_end = names.end();
+ it != it_end; ++ it)
+ {
+ if (*it != player_node->getName())
+ newStr += *it + ",";
+ }
+ if (newStr[newStr.size() - 1] == ',')
+ newStr = newStr.substr(0, newStr.size() - 1);
+ if (!newStr.empty())
+ replaceAll(str, "<PEOPLE>", newStr);
+ else
+ replaceAll(str, "<PEOPLE>", "");
+ }
+ if (str.find("<PARTY>") != std::string::npos)
+ {
+ StringVect names;
+ std::string newStr = "";
+ const Party *party = nullptr;
+ if (player_node->isInParty() && (party = player_node->getParty()))
+ {
+ party->getNames(names);
+ for (StringVectCIter it = names.begin(), it_end = names.end();
+ it != it_end; ++ it)
+ {
+ if (*it != player_node->getName())
+ newStr += *it + ",";
+ }
+ if (newStr[newStr.size() - 1] == ',')
+ newStr = newStr.substr(0, newStr.size() - 1);
+ if (!newStr.empty())
+ replaceAll(str, "<PARTY>", newStr);
+ else
+ replaceAll(str, "<PARTY>", "");
+ }
+ else
+ {
+ replaceAll(str, "<PARTY>", "");
+ }
+ }
+}
+
+}
diff --git a/src/commands.h b/src/commands.h
new file mode 100644
index 000000000..33f86d76b
--- /dev/null
+++ b/src/commands.h
@@ -0,0 +1,193 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2008-2009 The Mana World Development Team
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-2012 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef COMMANDS_H
+#define COMMANDS_H
+
+#include "playerrelations.h"
+
+#include <string>
+
+class ChatTab;
+
+extern ChatTab *localChatTab;
+
+#define BOOLEAN_OPTIONS _("Options to /%s are \"yes\", \"no\", \"true\", "\
+"\"false\", \"1\", \"0\".")
+
+#define decHandler(name) void name(const std::string &args, ChatTab *const tab)
+
+typedef void (*CommandFuncPtr) (const std::string &args, ChatTab *const tab);
+
+struct CommandInfo
+{
+ const char *name;
+ CommandFuncPtr func;
+};
+
+namespace Commands
+{
+ decHandler(announce);
+ decHandler(help);
+ decHandler(where);
+ decHandler(who);
+ decHandler(msg);
+ decHandler(query);
+ decHandler(join);
+ decHandler(listChannels);
+ decHandler(clear);
+ decHandler(createParty);
+ decHandler(createGuild);
+ decHandler(party);
+ decHandler(me);
+ decHandler(toggle);
+ decHandler(present);
+ decHandler(ignore);
+ decHandler(unignore);
+ decHandler(beFriend);
+ decHandler(disregard);
+ decHandler(neutral);
+ decHandler(blackList);
+ decHandler(enemy);
+ decHandler(erase);
+ decHandler(quit);
+ decHandler(showAll);
+ decHandler(move);
+ decHandler(target);
+ decHandler(attackHuman);
+ decHandler(closeAll);
+ decHandler(ignoreAll);
+ decHandler(outfit);
+ decHandler(emote);
+ decHandler(away);
+ decHandler(pseudoAway);
+ decHandler(follow);
+ decHandler(imitation);
+ decHandler(heal);
+ decHandler(navigate);
+ decHandler(mail);
+ decHandler(hack);
+ decHandler(priceLoad);
+ decHandler(priceSave);
+ decHandler(trade);
+ decHandler(disconnect);
+ decHandler(undress);
+ decHandler(attack);
+ decHandler(dirs);
+ decHandler(info);
+ decHandler(wait);
+ decHandler(uptime);
+ decHandler(addAttack);
+ decHandler(addPriorityAttack);
+ decHandler(removeAttack);
+ decHandler(addIgnoreAttack);
+ decHandler(serverIgnoreAll);
+ decHandler(serverUnIgnoreAll);
+ decHandler(setDrop);
+ decHandler(error);
+ decHandler(url);
+ decHandler(open);
+ decHandler(dump);
+ decHandler(dumpGraphics);
+ decHandler(dumpTests);
+ decHandler(dumpOGL);
+ decHandler(cacheInfo);
+
+ void replaceVars(std::string &str);
+}
+
+static const CommandInfo commands[] = {
+ {"closeall", &Commands::closeAll},
+ {"ignoreall", &Commands::ignoreAll},
+ {"help", &Commands::help},
+ {"announce", &Commands::announce},
+ {"where", &Commands::where},
+ {"who", &Commands::who},
+ {"msg", Commands::msg},
+ {"whisper", Commands::msg},
+ {"w", &Commands::msg},
+ {"query", Commands::query},
+ {"q", &Commands::query},
+ {"ignore", &Commands::ignore},
+ {"unignore", &Commands::unignore},
+ {"friend", Commands::beFriend},
+ {"befriend", &Commands::beFriend},
+ {"disregard", &Commands::disregard},
+ {"neutral", &Commands::neutral},
+ {"blacklist", &Commands::blackList},
+ {"enemy", &Commands::enemy},
+ {"erase", &Commands::erase},
+ {"join", &Commands::join},
+ {"list", &Commands::listChannels},
+ {"clear", &Commands::clear},
+ {"createparty", &Commands::createParty},
+ {"createguild", &Commands::createGuild},
+ {"party", &Commands::party},
+ {"me", &Commands::me},
+ {"toggle", &Commands::toggle},
+ {"present", &Commands::present},
+ {"quit", &Commands::quit},
+ {"all", &Commands::showAll},
+ {"move", &Commands::move},
+ {"target", &Commands::target},
+ {"atkhuman", &Commands::attackHuman},
+ {"outfit", &Commands::outfit},
+ {"emote", &Commands::emote},
+ {"away", &Commands::away},
+ {"pseudoaway", &Commands::pseudoAway},
+ {"follow", &Commands::follow},
+ {"heal", &Commands::heal},
+ {"navigate", &Commands::navigate},
+ {"imitation", &Commands::imitation},
+ {"mail", &Commands::mail},
+ {"trade", &Commands::trade},
+ {"priceload", &Commands::priceLoad},
+ {"pricesave", &Commands::priceSave},
+ {"cacheinfo", &Commands::cacheInfo},
+ {"disconnect", &Commands::disconnect},
+ {"undress", &Commands::undress},
+ {"attack", &Commands::attack},
+ {"dirs", &Commands::dirs},
+ {"info", &Commands::info},
+ {"wait", &Commands::wait},
+ {"uptime", &Commands::uptime},
+ {"addpriorityattack", &Commands::addPriorityAttack},
+ {"addattack", &Commands::addAttack},
+ {"removeattack", Commands::removeAttack},
+ {"removeignoreattack", &Commands::removeAttack},
+ {"addignoreattack", &Commands::addIgnoreAttack},
+ {"dump", &Commands::dump},
+ {"serverignoreall", &Commands::serverIgnoreAll},
+ {"serverunignoreall", &Commands::serverUnIgnoreAll},
+ {"setdrop", &Commands::setDrop},
+ {"error", &Commands::error},
+ {"dumpg", &Commands::dumpGraphics},
+ {"dumpt", &Commands::dumpTests},
+ {"dumpogl", &Commands::dumpOGL},
+ {"url", &Commands::url},
+ {"open", &Commands::open},
+ {"hack", &Commands::hack}
+};
+
+#undef decHandler
+
+#endif // COMMANDS_H
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 2e78c048c..9ba871575 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -24,7 +24,7 @@
#include "actorspritemanager.h"
#include "client.h"
-#include "commandhandler.h"
+#include "commands.h"
#include "configuration.h"
#include "game.h"
#include "guild.h"
diff --git a/src/gui/widgets/battletab.cpp b/src/gui/widgets/battletab.cpp
index f448dd057..f02a86134 100644
--- a/src/gui/widgets/battletab.cpp
+++ b/src/gui/widgets/battletab.cpp
@@ -23,7 +23,6 @@
#include "gui/widgets/battletab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "localplayer.h"
#include "main.h"
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index e35105692..4e6e7c522 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -375,8 +375,7 @@ void ChatTab::chatInput(const std::string &message)
start = msg.find('[', start + 1);
}
- if (commandHandler)
- commandHandler->replaceVars(msg);
+ Commands::replaceVars(msg);
switch (msg[0])
{
diff --git a/src/gui/widgets/guildchattab.cpp b/src/gui/widgets/guildchattab.cpp
index 7b1ca5bd3..442bb44e2 100644
--- a/src/gui/widgets/guildchattab.cpp
+++ b/src/gui/widgets/guildchattab.cpp
@@ -23,7 +23,6 @@
#include "gui/widgets/guildchattab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "guild.h"
#include "guildmanager.h"
#include "localplayer.h"
diff --git a/src/gui/widgets/tradetab.cpp b/src/gui/widgets/tradetab.cpp
index 78d076e12..47d47c304 100644
--- a/src/gui/widgets/tradetab.cpp
+++ b/src/gui/widgets/tradetab.cpp
@@ -23,7 +23,6 @@
#include "gui/widgets/tradetab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "localplayer.h"
#include "net/net.h"
diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp
index 6079b668c..c22c9d694 100644
--- a/src/gui/widgets/whispertab.cpp
+++ b/src/gui/widgets/whispertab.cpp
@@ -23,7 +23,7 @@
#include "gui/widgets/whispertab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
+#include "commands.h"
#include "localplayer.h"
#include "net/chathandler.h"
@@ -140,13 +140,11 @@ bool WhisperTab::handleCommand(const std::string &type,
}
else if (type == "ignore")
{
- if (commandHandler)
- commandHandler->handleIgnore(mNick, this);
+ Commands::ignore(mNick, this);
}
else if (type == "unignore")
{
- if (commandHandler)
- commandHandler->handleUnignore(mNick, this);
+ Commands::unignore(mNick, this);
}
else
{
diff --git a/src/net/ea/gui/guildtab.cpp b/src/net/ea/gui/guildtab.cpp
index 210db0235..7d7c5119e 100644
--- a/src/net/ea/gui/guildtab.cpp
+++ b/src/net/ea/gui/guildtab.cpp
@@ -23,7 +23,6 @@
#include "net/ea/gui/guildtab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "guild.h"
#include "localplayer.h"
#include "sound.h"
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp
index 4b9cd0488..e5b2c586b 100644
--- a/src/net/ea/gui/partytab.cpp
+++ b/src/net/ea/gui/partytab.cpp
@@ -160,7 +160,7 @@ bool PartyTab::handleCommand(const std::string &type, const std::string &args)
}
}
- const signed char opt = CommandHandler::parseBoolean(args);
+ const signed char opt = parseBoolean(args);
switch (opt)
{
@@ -199,7 +199,7 @@ bool PartyTab::handleCommand(const std::string &type, const std::string &args)
}
}
- const signed char opt = CommandHandler::parseBoolean(args);
+ const signed char opt = parseBoolean(args);
switch (opt)
{
diff --git a/src/net/eathena/gui/guildtab.cpp b/src/net/eathena/gui/guildtab.cpp
index fb7cabc77..049c00186 100644
--- a/src/net/eathena/gui/guildtab.cpp
+++ b/src/net/eathena/gui/guildtab.cpp
@@ -23,7 +23,6 @@
#include "net/eathena/gui/guildtab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "guild.h"
#include "localplayer.h"
diff --git a/src/net/eathena/gui/partytab.cpp b/src/net/eathena/gui/partytab.cpp
index da14226fe..e98642963 100644
--- a/src/net/eathena/gui/partytab.cpp
+++ b/src/net/eathena/gui/partytab.cpp
@@ -23,7 +23,6 @@
#include "net/eathena/gui/partytab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "localplayer.h"
#include "party.h"
diff --git a/src/net/tmwa/gui/guildtab.cpp b/src/net/tmwa/gui/guildtab.cpp
index ebdaea10f..ddf646f84 100644
--- a/src/net/tmwa/gui/guildtab.cpp
+++ b/src/net/tmwa/gui/guildtab.cpp
@@ -23,7 +23,6 @@
#include "net/tmwa/gui/guildtab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "guild.h"
#include "localplayer.h"
diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp
index 6b9440642..09ce35d8a 100644
--- a/src/net/tmwa/gui/partytab.cpp
+++ b/src/net/tmwa/gui/partytab.cpp
@@ -23,7 +23,6 @@
#include "net/tmwa/gui/partytab.h"
#include "chatlogger.h"
-#include "commandhandler.h"
#include "localplayer.h"
#include "party.h"
diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp
index 8c6d88d1c..7c7b76ea6 100644
--- a/src/utils/stringutils.cpp
+++ b/src/utils/stringutils.cpp
@@ -653,3 +653,19 @@ std::string getDateString()
strftime(buffer, 79, "%Y-%m-%d", timeinfo);
return std::string(buffer);
}
+
+signed char parseBoolean(const std::string &value)
+{
+ std::string opt = value.substr(0, 1);
+
+ if (opt == "1" ||
+ opt == "y" || opt == "Y" ||
+ opt == "t" || opt == "T")
+ return 1;
+ else if (opt == "0" ||
+ opt == "n" || opt == "N" ||
+ opt == "f" || opt == "F")
+ return 0;
+ else
+ return -1;
+}
diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h
index cef7a9ccf..819b1a7c6 100644
--- a/src/utils/stringutils.h
+++ b/src/utils/stringutils.h
@@ -221,4 +221,6 @@ bool strStartWith(std::string str, std::string start) A_WARN_UNUSED;
std::string getDateString() A_WARN_UNUSED;
+signed char parseBoolean(const std::string &value);
+
#endif // UTILS_STRINGUTILS_H