diff options
author | Jared Adams <jaxad0127@gmail.com> | 2009-03-23 07:02:32 -0600 |
---|---|---|
committer | Jared Adams <jaxad0127@gmail.com> | 2009-03-23 07:02:32 -0600 |
commit | 7c360d2887216099ca8cc767f15a34fcf302803b (patch) | |
tree | 308a8889e1173a27b4c20ef608c0749449c8aa04 /src/commandhandler.cpp | |
parent | d3f315b45bd9055ac7f61082f5af54b863410517 (diff) | |
download | mana-7c360d2887216099ca8cc767f15a34fcf302803b.tar.gz mana-7c360d2887216099ca8cc767f15a34fcf302803b.tar.bz2 mana-7c360d2887216099ca8cc767f15a34fcf302803b.tar.xz mana-7c360d2887216099ca8cc767f15a34fcf302803b.zip |
Merge eA's command handling into CommandHandler
Also drop Aethyra's custom magic code
Diffstat (limited to 'src/commandhandler.cpp')
-rw-r--r-- | src/commandhandler.cpp | 422 |
1 files changed, 339 insertions, 83 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 0f4d0f2f..a86f9f4b 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -25,9 +25,27 @@ #include "channel.h" #include "game.h" #include "localplayer.h" + #include "gui/chat.h" + +#ifdef TMWSERV_SUPPORT #include "net/chatserver/chatserver.h" #include "net/gameserver/player.h" +#else +#include "party.h" +#include "net/messageout.h" +#include "net/ea/protocol.h" +#endif + +#include "utils/gettext.h" +#include "utils/stringutils.h" +#include "utils/strprintf.h" + +#ifdef EATHENA_SUPPORT +CommandHandler::CommandHandler(Network *network): + mNetwork(network) +{} +#endif void CommandHandler::handleCommand(const std::string &command) { @@ -51,10 +69,11 @@ void CommandHandler::handleCommand(const std::string &command) { handleWho(); } - else if (type == "msg") + else if (type == "msg" || type == "whisper" || type == "w") { handleMsg(args); } +#ifdef TMWSERV_SUPPORT else if (type == "join") { handleJoin(args); @@ -79,10 +98,6 @@ void CommandHandler::handleCommand(const std::string &command) { handleClear(); } - else if (type == "party") - { - handleParty(args); - } else if (type == "op") { handleOp(args); @@ -91,6 +106,27 @@ void CommandHandler::handleCommand(const std::string &command) { handleKick(args); } +#endif + else if (type == "party") + { + handleParty(args); + } + else if (type == "me") + { + handleMe(args); + } + else if (type == "record") + { + handleRecord(args); + } + else if (type == "toggle") + { + handleToggle(args); + } + else if (type == "present") + { + handlePresent(args); + } else { chatWindow->chatLog("Unknown command"); @@ -99,142 +135,263 @@ void CommandHandler::handleCommand(const std::string &command) void CommandHandler::handleAnnounce(const std::string &args) { +#ifdef TMWSERV_SUPPORT Net::ChatServer::announce(args); +#else + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x0099); + outMsg.writeInt16(args.length() + 4); + outMsg.writeString(args, args.length()); +#endif } void CommandHandler::handleHelp(const std::string &args) { if (args == "") { - chatWindow->chatLog("-- Help --"); - chatWindow->chatLog("/help > Display this help."); - chatWindow->chatLog("/announce > Global announcement (GM only)"); - chatWindow->chatLog("/where > Display map name"); - chatWindow->chatLog("/who > Display number of online users"); - chatWindow->chatLog("/msg > Send a private message to a user"); - chatWindow->chatLog("/list > Display all public channels"); - chatWindow->chatLog("/users > Lists the users in the current channel"); - chatWindow->chatLog("/join > Join or create a channel"); - chatWindow->chatLog("/topic > Set the topic of the current channel"); - chatWindow->chatLog("/quit > Leave a channel"); - chatWindow->chatLog("/clear > Clears this window"); - chatWindow->chatLog("/party > Invite a user to party"); - chatWindow->chatLog("/op > Make a user a channel operator"); - chatWindow->chatLog("/kick > Kick a user from the channel"); - chatWindow->chatLog("For more information, type /help <command>"); + chatWindow->chatLog(_("-- Help --")); + chatWindow->chatLog(_("/help > Display this help.")); + + chatWindow->chatLog(_("/where > Display map name")); + chatWindow->chatLog(_("/who > Display number of online users")); + chatWindow->chatLog(_("/me > Tell something about yourself")); + + chatWindow->chatLog(_("/msg > Send a private message to a user")); + chatWindow->chatLog(_("/whisper > Alias of msg")); + chatWindow->chatLog(_("/w > Alias of msg")); + +#ifdef TMWSERV_SUPPORT + chatWindow->chatLog(_("/list > Display all public channels")); + chatWindow->chatLog(_("/users > Lists the users in the current channel")); + chatWindow->chatLog(_("/join > Join or create a channel")); + chatWindow->chatLog(_("/topic > Set the topic of the current channel")); + chatWindow->chatLog(_("/quit > Leave a channel")); + chatWindow->chatLog(_("/clear > Clears this window")); + chatWindow->chatLog(_("/op > Make a user a channel operator")); + chatWindow->chatLog(_("/kick > Kick a user from the channel")); + + chatWindow->chatLog(_("/party > Invite a user to party")); +#else + chatWindow->chatLog(_("/party > Party-related commands")); +#endif + + chatWindow->chatLog(_("/record > Start recording the chat to an external file")); + chatWindow->chatLog(_("/toggle > Determine whether <return> toggles the chat log")); + chatWindow->chatLog(_("/present > Get list of players present (sent to chat log, if logging)")); + + chatWindow->chatLog(_("/announce > Global announcement (GM only)")); + + chatWindow->chatLog(_("For more information, type /help <command>")); } else if (args == "announce") { - chatWindow->chatLog("Command: /announce <msg>"); - chatWindow->chatLog("*** only available to a GM ***"); - chatWindow->chatLog("This command sends the message <msg> to " - "all players currently online."); + chatWindow->chatLog(_("Command: /announce <msg>")); + chatWindow->chatLog(_("*** only available to a GM ***")); + chatWindow->chatLog(_("This command sends the message <msg> to " + "all players currently online.")); } else if (args == "clear") { - chatWindow->chatLog("Command: /clear"); - chatWindow->chatLog("This command clears the chat log of previous chat."); + chatWindow->chatLog(_("Command: /clear")); + chatWindow->chatLog(_("This command clears the chat log of previous chat.")); } else if (args == "help") { - chatWindow->chatLog("Command: /help"); - chatWindow->chatLog("This command displays a list of all commands available."); - chatWindow->chatLog("Command: /help <command>"); - chatWindow->chatLog("This command displays help on <command>."); + chatWindow->chatLog(_("Command: /help")); + chatWindow->chatLog(_("This command displays a list of all commands available.")); + chatWindow->chatLog(_("Command: /help <command>")); + chatWindow->chatLog(_("This command displays help on <command>.")); } else if (args == "join") { - chatWindow->chatLog("Command: /join <channel>"); - chatWindow->chatLog("This command makes you enter <channel>."); - chatWindow->chatLog("If <channel> doesn't exist, it's created."); + chatWindow->chatLog(_("Command: /join <channel>")); + chatWindow->chatLog(_("This command makes you enter <channel>.")); + chatWindow->chatLog(_("If <channel> doesn't exist, it's created.")); } else if (args == "kick") { - chatWindow->chatLog("Command: /kick <nick>"); - chatWindow->chatLog("This command makes <nick> leave the channel."); - chatWindow->chatLog("If the <nick> has spaces in it, enclose it in " - "double quotes (\")."); + chatWindow->chatLog(_("Command: /kick <nick>")); + chatWindow->chatLog(_("This command makes <nick> leave the channel.")); + chatWindow->chatLog(_("If the <nick> has spaces in it, enclose it in " + "double quotes (\").")); } else if (args == "list") { - chatWindow->chatLog("Command: /list"); - chatWindow->chatLog("This command shows a list of all channels."); + chatWindow->chatLog(_("Command: /list")); + chatWindow->chatLog(_("This command shows a list of all channels.")); } - else if (args == "msg") + else if (args == "me") { - chatWindow->chatLog("Command: /msg <nick> <message>"); - chatWindow->chatLog("This command sends the text <message> to <nick>."); - chatWindow->chatLog("If the <nick> has spaces in it, enclose it in " - "double quotes (\")."); + chatWindow->chatLog(_("Command: /me <message>")); + chatWindow->chatLog(_("This command tell others you are (doing) <msg>.")); + } + else if (args == "msg" || args == "whisper" || args == "w") + { + chatWindow->chatLog(_("Command: /msg <nick> <message>")); + chatWindow->chatLog(_("Command: /whisper <nick> <message>")); + chatWindow->chatLog(_("Command: /w <nick> <message>")); + chatWindow->chatLog(_("This command sends the text <message> to <nick>.")); + chatWindow->chatLog(_("If the <nick> has spaces in it, enclose it in " + "double quotes (\").")); } else if (args == "op") { - chatWindow->chatLog("Command: /op <nick>"); - chatWindow->chatLog("This command makes <nick> a channel operator."); - chatWindow->chatLog("If the <nick> has spaces in it, enclose it in " - "double quotes (\")."); - chatWindow->chatLog("Channel operators can kick and op other users " - "from the channel."); + chatWindow->chatLog(_("Command: /op <nick>")); + chatWindow->chatLog(_("This command makes <nick> a channel operator.")); + chatWindow->chatLog(_("If the <nick> has spaces in it, enclose it in " + "double quotes (\").")); + chatWindow->chatLog(_("Channel operators can kick and op other users " + "from the channel.")); } +#ifdef TMWSERV_SUPPORT else if (args == "party") { - chatWindow->chatLog("Command: /party <nick>"); - chatWindow->chatLog("This command invites <nick> to party with you."); - chatWindow->chatLog("If the <nick> has spaces in it, enclose it in " - "double quotes (\")."); + chatWindow->chatLog(_("Command: /party <nick>")); + chatWindow->chatLog(_("This command invites <nick> to party with you.")); + chatWindow->chatLog(_("If the <nick> has spaces in it, enclose it in " + "double quotes (\").")); +#else + else if (args.substr(0, 5) == "party") + { + playerParty->help(args); +#endif + } + else if (args == "present") + { + chatWindow->chatLog(_("Command: /present")); + chatWindow->chatLog(_("This command gets a list of players within hearing and " + "sends it to either the record log if recording, or the chat " + "log otherwise.")); } else if (args == "quit") { - chatWindow->chatLog("Command: /quit"); - chatWindow->chatLog("This command leaves the current channel."); - chatWindow->chatLog("If you're the last person in the channel, it will be deleted."); + chatWindow->chatLog(_("Command: /quit")); + chatWindow->chatLog(_("This command leaves the current channel.")); + chatWindow->chatLog(_("If you're the last person in the channel, it will be deleted.")); + } + else if (args == "record") + { + chatWindow->chatLog(_("Command: /record <filename>")); + chatWindow->chatLog(_("This command starts recording the chat log to the file " + "<filename>.")); + chatWindow->chatLog(_("Command: /record")); + chatWindow->chatLog(_("This command finishes a recording session.")); + } + else if (args == "toggle") + { + chatWindow->chatLog(_("Command: /toggle <state>")); + chatWindow->chatLog(_("This command sets whether the return key should toggle the " + "chat log, or whether the chat log turns off automatically.")); + chatWindow->chatLog(_("<state> can be one of \"1\", \"yes\", \"true\" to " + "turn the toggle on, or \"0\", \"no\", \"false\" to turn the " + "toggle off.")); + chatWindow->chatLog(_("Command: /toggle")); + chatWindow->chatLog(_("This command displays the return toggle status.")); } else if (args == "topic") { - chatWindow->chatLog("Command: /topic <message>"); - chatWindow->chatLog("This command sets the topic to <message>."); + chatWindow->chatLog(_("Command: /topic <message>")); + chatWindow->chatLog(_("This command sets the topic to <message>.")); } else if (args == "users") { - chatWindow->chatLog("Command: /users <channel>"); - chatWindow->chatLog("This command shows the users in <channel>."); + chatWindow->chatLog(_("Command: /users <channel>")); + chatWindow->chatLog(_("This command shows the users in <channel>.")); } else if (args == "where") { - chatWindow->chatLog("Command: /where"); - chatWindow->chatLog("This command displays the name of the current map."); + chatWindow->chatLog(_("Command: /where")); + chatWindow->chatLog(_("This command displays the name of the current map.")); } else if (args == "who") { - chatWindow->chatLog("Command: /who"); - chatWindow->chatLog("This command displays the number of players currently " - "online."); + chatWindow->chatLog(_("Command: /who")); + chatWindow->chatLog(_("This command displays the number of players currently " + "online.")); } else { - chatWindow->chatLog("Unknown command."); - chatWindow->chatLog("Type /help for a list of commands."); + chatWindow->chatLog(_("Unknown command.")); + chatWindow->chatLog(_("Type /help for a list of commands.")); } } void CommandHandler::handleWhere() { + // TODO: add position chatWindow->chatLog(map_path, BY_SERVER); } void CommandHandler::handleWho() { - +#ifdef TMWSERV_SUPPORT + //TODO +#else + MessageOut outMsg(mNetwork); + outMsg.writeInt16(0x00c1); +#endif } void CommandHandler::handleMsg(const std::string &args) { +#ifdef TMWSERV_SUPPORT std::string::size_type pos = args.find(' '); std::string recipient(args, 0, pos); std::string text(args, pos+1); Net::ChatServer::privMsg(recipient, text); +#else + std::string recvnick = ""; + std::string msg = ""; + + if (args.substr(0, 1) == "\"") + { + const std::string::size_type pos = args.find('"', 1); + if (pos != std::string::npos) + { + recvnick = args.substr(1, pos - 1); + msg = args.substr(pos + 2, args.length()); + } + } + else + { + const std::string::size_type pos = msg.find(" "); + if (pos != std::string::npos) + { + recvnick = args.substr(0, pos); + msg = args.substr(pos + 1, args.length()); + } + } + + trim(msg); + + std::string playerName = player_node->getName(); + std::string tempNick = recvnick; + + toLower(playerName); + toLower(tempNick); + + if (tempNick.compare(playerName) == 0 || args.empty()) + return; + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CHAT_WHISPER); + outMsg.writeInt16(msg.length() + 28); + outMsg.writeString(recvnick, 24); + outMsg.writeString(msg, msg.length()); + + chatWindow->chatLog(strprintf(_("Whispering to %s: %s"), + recvnick.c_str(), msg.c_str()), + BY_PLAYER); +#endif } +void CommandHandler::handleClear() +{ + chatWindow->clearTab(chatWindow->getFocused()); +} + +#ifdef TMWSERV_SUPPORT + void CommandHandler::handleJoin(const std::string &args) { std::string::size_type pos = args.find(' '); @@ -278,19 +435,6 @@ void CommandHandler::handleQuit() } } -void CommandHandler::handleClear() -{ - chatWindow->clearTab(chatWindow->getFocused()); -} - -void CommandHandler::handleParty(const std::string &args) -{ - if (args != "") - { - player_node->inviteToParty(args); - } -} - void CommandHandler::handleOp(const std::string &args) { if (Channel *channel = channelManager->findByName(chatWindow->getFocused())) @@ -321,3 +465,115 @@ void CommandHandler::handleKick(const std::string &args) chatWindow->chatLog("Unable to kick user", BY_CHANNEL); } } + +#endif + +void CommandHandler::handleParty(const std::string &args) +{ +#ifdef TMWSERV_SUPPORT + if (args != "") + { + player_node->inviteToParty(args); + } +#else + if (args.empty()) + { + chatWindow->chatLog(_("Unknown party command... Type \"/help\" party for more " + "information."), BY_SERVER); + return; + } + + const std::string::size_type space = args.find(" "); + std::string command; + std::string rest; + + if (space == std::string::npos) + { + command = args; + } + else + { + command = args.substr(0, space); + rest = args.substr(space + 1, args.length()); + } + + if (command == "prefix") + { + if (rest.empty()) + { + char temp[2] = "."; + *temp = chatWindow->getPartyPrefix(); + chatWindow->chatLog(_("The current party prefix is ") + std::string(temp)); + } + else if (rest.length() != 1) + { + chatWindow->chatLog(_("Party prefix must be one character long.")); + } + else + { + if (rest == "/") + { + chatWindow->chatLog(_("Cannot use a '/' as the prefix.")); + } + else + { + chatWindow->setPartyPrefix(rest.at(0)); + chatWindow->chatLog(_("Changing prefix to ") + rest); + } + } + } + else + playerParty->respond(command, rest); +#endif +} + +void CommandHandler::handleMe(const std::string &args) +{ + std::string action = strprintf("*%s*", args.c_str()); + chatWindow->chatSend(action); + //std::stringstream actionStr; + //actionStr << "*" << args << "*"; + //chatWindow->chatSend(actionStr.str()); +} + +void CommandHandler::handleRecord(const std::string &args) +{ + chatWindow->setRecordingFile(args); +} + +void CommandHandler::handleToggle(const std::string &args) +{ + if (args.empty()) + { + chatWindow->chatLog(chatWindow->getReturnTogglesChat() ? + _("Return toggles chat.") : _("Message closes chat.")); + return; + } + + std::string opt = args.substr(0, 1); + + if (opt == "1" || + opt == "y" || opt == "Y" || + opt == "t" || opt == "T") + { + chatWindow->chatLog(_("Return now toggles chat.")); + chatWindow->setReturnTogglesChat(true); + return; + } + else if (opt == "0" || + opt == "n" || opt == "N" || + opt == "f" || opt == "F") + { + chatWindow->chatLog(_("Message now closes chat.")); + chatWindow->setReturnTogglesChat(false); + return; + } + else + chatWindow->chatLog(_("Options to /toggle are \"yes\", \"no\", \"true\", " + "\"false\", \"1\", \"0\".")); +} + +void CommandHandler::handlePresent(const std::string &args) +{ + chatWindow->doPresent(); +} |