summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-04-16 10:10:50 -0600
committerJared Adams <jaxad0127@gmail.com>2009-04-16 10:10:50 -0600
commit736795a624ae5f04b11fa284cb8a4b14579c1766 (patch)
tree6c7c70926959ff23831002a06ea82c17cadc3188
parente8dd52d8264cd0eec1f5d32c1f809a164e2d2f59 (diff)
downloadmana-client-736795a624ae5f04b11fa284cb8a4b14579c1766.tar.gz
mana-client-736795a624ae5f04b11fa284cb8a4b14579c1766.tar.bz2
mana-client-736795a624ae5f04b11fa284cb8a4b14579c1766.tar.xz
mana-client-736795a624ae5f04b11fa284cb8a4b14579c1766.zip
Rehash CommandHandler a bit, it's now fully merged
Tabs can now interract with CommandHandler and define their own commands in a seemless way. Most channel-related commands have been moved into ChannelTab, the close command is now in the WhisperTab, and eAthena's party tab now shows all standard commands.
-rw-r--r--src/commandhandler.cpp165
-rw-r--r--src/commandhandler.h25
-rw-r--r--src/gui/login.cpp2
-rw-r--r--src/gui/widgets/channeltab.cpp87
-rw-r--r--src/gui/widgets/channeltab.h4
-rw-r--r--src/gui/widgets/chattab.h19
-rw-r--r--src/gui/widgets/whispertab.cpp27
-rw-r--r--src/gui/widgets/whispertab.h4
-rw-r--r--src/net/ea/chathandler.cpp16
-rw-r--r--src/net/ea/gui/partytab.cpp42
-rw-r--r--src/net/ea/gui/partytab.h5
11 files changed, 193 insertions, 203 deletions
diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp
index d507048c..2f9969e8 100644
--- a/src/commandhandler.cpp
+++ b/src/commandhandler.cpp
@@ -47,14 +47,18 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
std::string::size_type pos = command.find(' ');
std::string type(command, 0, pos);
std::string args(command, pos == std::string::npos ? command.size() : pos + 1);
-
- if (type == "announce")
+
+ if (type == "help") // Do help before tabs so they can't override it
{
- handleAnnounce(args, tab);
+ handleHelp(args, tab);
}
- else if (type == "help")
+ else if (tab->handleCommand(type, args))
{
- handleHelp(args, tab);
+ // Nothing to do
+ }
+ if (type == "announce")
+ {
+ handleAnnounce(args, tab);
}
else if (type == "where")
{
@@ -80,30 +84,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab)
{
handleListChannels(args, tab);
}
- else if (type == "users")
- {
- handleListUsers(args, tab);
- }
- else if (type == "quit")
- {
- handleQuit(args, tab);
- }
- else if (type == "topic")
- {
- handleTopic(args, tab);
- }
else if (type == "clear")
{
handleClear(args, tab);
}
- else if (type == "op")
- {
- handleOp(args, tab);
- }
- else if (type == "kick")
- {
- handleKick(args, tab);
- }
else if (type == "party")
{
handleParty(args, tab);
@@ -146,23 +130,16 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
tab->chatLog(_("/who > Display number of online users"));
tab->chatLog(_("/me > Tell something about yourself"));
+ tab->chatLog(_("/clear > Clears this window"));
+
tab->chatLog(_("/msg > Send a private message to a user"));
tab->chatLog(_("/whisper > Alias of msg"));
tab->chatLog(_("/w > Alias of msg"));
tab->chatLog(_("/query > Makes a tab for private messages with another user"));
tab->chatLog(_("/q > Alias of query"));
- tab->chatLog(_("/close > Close the whisper tab (only works in whisper tabs)"));
-#ifdef TMWSERV_SUPPORT
tab->chatLog(_("/list > Display all public channels"));
- tab->chatLog(_("/users > Lists the users in the current channel"));
tab->chatLog(_("/join > Join or create a channel"));
- tab->chatLog(_("/topic > Set the topic of the current channel"));
- tab->chatLog(_("/quit > Leave a channel"));
- tab->chatLog(_("/clear > Clears this window"));
- tab->chatLog(_("/op > Make a user a channel operator"));
- tab->chatLog(_("/kick > Kick a user from the channel"));
-#endif
tab->chatLog(_("/party > Invite a user to party"));
@@ -172,8 +149,21 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
tab->chatLog(_("/announce > Global announcement (GM only)"));
+ tab->showHelp(); // Allow the tab to show it's help
+
tab->chatLog(_("For more information, type /help <command>"));
}
+ else if (args == "help") // Do this before tabs so they can't change it
+ {
+ tab->chatLog(_("Command: /help"));
+ tab->chatLog(_("This command displays a list of all commands available."));
+ tab->chatLog(_("Command: /help <command>"));
+ tab->chatLog(_("This command displays help on <command>."));
+ }
+ else if (tab->handleCommand("help", args))
+ {
+ // Nothing to do
+ }
else if (args == "announce")
{
tab->chatLog(_("Command: /announce <msg>"));
@@ -186,26 +176,12 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
tab->chatLog(_("Command: /clear"));
tab->chatLog(_("This command clears the chat log of previous chat."));
}
- else if (args == "help")
- {
- tab->chatLog(_("Command: /help"));
- tab->chatLog(_("This command displays a list of all commands available."));
- tab->chatLog(_("Command: /help <command>"));
- tab->chatLog(_("This command displays help on <command>."));
- }
else if (args == "join")
{
tab->chatLog(_("Command: /join <channel>"));
tab->chatLog(_("This command makes you enter <channel>."));
tab->chatLog(_("If <channel> doesn't exist, it's created."));
}
- else if (args == "kick")
- {
- tab->chatLog(_("Command: /kick <nick>"));
- tab->chatLog(_("This command makes <nick> leave the channel."));
- tab->chatLog(_("If the <nick> has spaces in it, enclose it in "
- "double quotes (\")."));
- }
else if (args == "list")
{
tab->chatLog(_("Command: /list"));
@@ -232,15 +208,6 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
tab->chatLog(_("This command tries to make a tab for whispers between"
"you and <nick>."));
}
- else if (args == "op")
- {
- tab->chatLog(_("Command: /op <nick>"));
- tab->chatLog(_("This command makes <nick> a channel operator."));
- tab->chatLog(_("If the <nick> has spaces in it, enclose it in "
- "double quotes (\")."));
- tab->chatLog(_("Channel operators can kick and op other users "
- "from the channel."));
- }
else if (args == "party")
{
tab->chatLog(_("Command: /party <nick>"));
@@ -255,12 +222,6 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
"sends it to either the record log if recording, or the chat "
"log otherwise."));
}
- else if (args == "quit")
- {
- tab->chatLog(_("Command: /quit"));
- tab->chatLog(_("This command leaves the current channel."));
- tab->chatLog(_("If you're the last person in the channel, it will be deleted."));
- }
else if (args == "record")
{
tab->chatLog(_("Command: /record <filename>"));
@@ -280,16 +241,6 @@ void CommandHandler::handleHelp(const std::string &args, ChatTab *tab)
tab->chatLog(_("Command: /toggle"));
tab->chatLog(_("This command displays the return toggle status."));
}
- else if (args == "topic")
- {
- tab->chatLog(_("Command: /topic <message>"));
- tab->chatLog(_("This command sets the topic to <message>."));
- }
- else if (args == "users")
- {
- tab->chatLog(_("Command: /users <channel>"));
- tab->chatLog(_("This command shows the users in <channel>."));
- }
else if (args == "where")
{
tab->chatLog(_("Command: /where"));
@@ -396,74 +347,6 @@ void CommandHandler::handleListChannels(const std::string &args, ChatTab *tab)
Net::getChatHandler()->channelList();
}
-void CommandHandler::handleListUsers(const std::string &args, ChatTab *tab)
-{
- Net::getChatHandler()->userList(chatWindow->getFocused()->getCaption());
-}
-
-void CommandHandler::handleTopic(const std::string &args, ChatTab *tab)
-{
- ChannelTab *channelTab = dynamic_cast<ChannelTab*>(tab);
- Channel *channel = channelTab ? channelTab->getChannel() : NULL;
- if (channel)
- {
- Net::getChatHandler()->setChannelTopic(channel->getId(), args);
- }
- else
- {
- tab->chatLog("Unable to set this channel's topic", BY_CHANNEL);
- }
-}
-
-void CommandHandler::handleQuit(const std::string &args, ChatTab *tab)
-{
- ChannelTab *channelTab = dynamic_cast<ChannelTab*>(tab);
- Channel *channel = channelTab ? channelTab->getChannel() : NULL;
- if (channel)
- {
- Net::getChatHandler()->quitChannel(channel->getId());
- }
- else
- {
- tab->chatLog("Unable to quit this channel", BY_CHANNEL);
- }
-}
-
-void CommandHandler::handleOp(const std::string &args, ChatTab *tab)
-{
- ChannelTab *channelTab = dynamic_cast<ChannelTab*>(tab);
- Channel *channel = channelTab ? channelTab->getChannel() : NULL;
- if (channel)
- {
- // set the user mode 'o' to op a user
- if (args != "")
- {
- Net::getChatHandler()->setUserMode(channel->getId(), args, 'o');
- }
- }
- else
- {
- tab->chatLog("Unable to set this user's mode", BY_CHANNEL);
- }
-}
-
-void CommandHandler::handleKick(const std::string &args, ChatTab *tab)
-{
- ChannelTab *channelTab = dynamic_cast<ChannelTab*>(tab);
- Channel *channel = channelTab ? channelTab->getChannel() : NULL;
- if (channel)
- {
- if (args != "")
- {
- Net::getChatHandler()->kickUser(channel->getId(), args);
- }
- }
- else
- {
- tab->chatLog("Unable to kick user", BY_CHANNEL);
- }
-}
-
void CommandHandler::handleParty(const std::string &args, ChatTab *tab)
{
if (args != "")
diff --git a/src/commandhandler.h b/src/commandhandler.h
index cc14060b..2969d1a1 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -91,21 +91,6 @@ class CommandHandler
void handleListChannels(const std::string &args, ChatTab *tab);
/**
- * Handle a listusers command.
- */
- void handleListUsers(const std::string &args, ChatTab *tab);
-
- /**
- * Handle a topic command.
- */
- void handleTopic(const std::string &args, ChatTab *tab);
-
- /**
- * Handle a quit command.
- */
- void handleQuit(const std::string &args, ChatTab *tab);
-
- /**
* Handle a clear command.
*/
void handleClear(const std::string &args, ChatTab *tab);
@@ -116,16 +101,6 @@ class CommandHandler
void handleParty(const std::string &args, ChatTab *tab);
/**
- * Handle a op command.
- */
- void handleOp(const std::string &args, ChatTab *tab);
-
- /**
- * Handle a kick command.
- */
- void handleKick(const std::string &args, ChatTab *tab);
-
- /**
* Handle a me command.
*/
void handleMe(const std::string &args, ChatTab *tab);
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index c1ffb658..021f8d4b 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -131,7 +131,9 @@ LoginDialog::LoginDialog(LoginData *loginData):
LoginDialog::~LoginDialog()
{
+#ifdef EATHENA_SUPPORT
delete mServerList;
+#endif
}
void LoginDialog::action(const gcn::ActionEvent &event)
diff --git a/src/gui/widgets/channeltab.cpp b/src/gui/widgets/channeltab.cpp
index edc0473c..0bafc10f 100644
--- a/src/gui/widgets/channeltab.cpp
+++ b/src/gui/widgets/channeltab.cpp
@@ -26,6 +26,8 @@
#include "net/chathandler.h"
#include "net/net.h"
+#include "utils/gettext.h"
+
ChannelTab::ChannelTab(Channel *channel) : ChatTab(channel->getName()),
mChannel(channel)
{
@@ -39,3 +41,88 @@ ChannelTab::~ChannelTab()
void ChannelTab::handleInput(const std::string &msg) {
Net::getChatHandler()->sendToChannel(getChannel()->getId(), msg);
}
+
+void ChannelTab::showHelp()
+{
+ chatLog(_("/users > Lists the users in the current channel"));
+ chatLog(_("/topic > Set the topic of the current channel"));
+ chatLog(_("/quit > Leave a channel"));
+ chatLog(_("/op > Make a user a channel operator"));
+ chatLog(_("/kick > Kick a user from the channel"));
+}
+
+bool ChannelTab::handleCommand(std::string type, std::string args)
+{
+ if (type == "help")
+ {
+ if (args == "users")
+ {
+ chatLog(_("Command: /users"));
+ chatLog(_("This command shows the users in this channel."));
+ }
+ else if (args == "topic")
+ {
+ chatLog(_("Command: /topic <message>"));
+ chatLog(_("This command sets the topic to <message>."));
+ }
+ else if (args == "quit")
+ {
+ chatLog(_("Command: /quit"));
+ chatLog(_("This command leaves the current channel."));
+ chatLog(_("If you're the last person in the channel, it will be deleted."));
+ }
+ else if (args == "op")
+ {
+ chatLog(_("Command: /op <nick>"));
+ chatLog(_("This command makes <nick> a channel operator."));
+ chatLog(_("If the <nick> has spaces in it, enclose it in "
+ "double quotes (\")."));
+ chatLog(_("Channel operators can kick and op other users "
+ "from the channel."));
+ }
+ else if (args == "kick")
+ {
+ chatLog(_("Command: /kick <nick>"));
+ chatLog(_("This command makes <nick> leave the channel."));
+ chatLog(_("If the <nick> has spaces in it, enclose it in "
+ "double quotes (\")."));
+ }
+ else
+ return false;
+ }
+ else if (type == "users")
+ {
+ Net::getChatHandler()->userList(mChannel->getName());
+ }
+ else if (type == "topic")
+ {
+ Net::getChatHandler()->setChannelTopic(mChannel->getId(), args);
+ }
+ else if (type == "topic")
+ {
+ Net::getChatHandler()->setChannelTopic(mChannel->getId(), args);
+ }
+ else if (type == "quit")
+ {
+ Net::getChatHandler()->quitChannel(mChannel->getId());
+ }
+ else if (type == "op")
+ {
+ // set the user mode 'o' to op a user
+ if (args != "")
+ Net::getChatHandler()->setUserMode(mChannel->getId(), args, 'o');
+ else
+ chatLog(_("Need a user to op!"), BY_CHANNEL);
+ }
+ else if (type == "kick")
+ {
+ if (args != "")
+ Net::getChatHandler()->kickUser(mChannel->getId(), args);
+ else
+ chatLog(_("Need a user to kick!"), BY_CHANNEL);
+ }
+ else
+ return false;
+
+ return true;
+}
diff --git a/src/gui/widgets/channeltab.h b/src/gui/widgets/channeltab.h
index 8c98189b..886ae28e 100644
--- a/src/gui/widgets/channeltab.h
+++ b/src/gui/widgets/channeltab.h
@@ -35,6 +35,10 @@ class ChannelTab : public ChatTab
Channel *getChannel() { return mChannel; }
+ void showHelp();
+
+ bool handleCommand(std::string type, std::string args);
+
protected:
friend class Channel;
diff --git a/src/gui/widgets/chattab.h b/src/gui/widgets/chattab.h
index 3d92e57f..ccb85d2a 100644
--- a/src/gui/widgets/chattab.h
+++ b/src/gui/widgets/chattab.h
@@ -95,8 +95,27 @@ class ChatTab : public Tab
*/
void scroll(int amount);
+ /**
+ * Clears the text from the tab
+ */
void clearText();
+ /**
+ * Add any extra help text to the output. Allows tabs to define help
+ * for commands defined by the tab itself.
+ */
+ virtual void showHelp() {}
+
+ /**
+ * Handle special commands. Allows a tab to handle commands it
+ * defines itself.
+ *
+ * @returns true if the command was handled
+ * false if the command was not handled
+ */
+ virtual bool handleCommand(std::string type, std::string args)
+ { return false; }
+
protected:
friend class ChatWindow;
friend class WhisperWindow;
diff --git a/src/gui/widgets/whispertab.cpp b/src/gui/widgets/whispertab.cpp
index d69a495c..975cac94 100644
--- a/src/gui/widgets/whispertab.cpp
+++ b/src/gui/widgets/whispertab.cpp
@@ -62,3 +62,30 @@ void WhisperTab::handleCommand(std::string msg)
else
ChatTab::handleCommand(msg);
}
+
+void WhisperTab::showHelp()
+{
+ chatLog(_("/close > Close the whisper tab"));
+}
+
+bool WhisperTab::handleCommand(std::string type, std::string args)
+{
+ if (type == "help")
+ {
+ if (args == "close")
+ {
+ chatLog(_("Command: /close"));
+ chatLog(_("This command closes the current whisper tab."));
+ }
+ else
+ return false;
+ }
+ else if (type == "close")
+ {
+ delete this;
+ }
+ else
+ return false;
+
+ return true;
+}
diff --git a/src/gui/widgets/whispertab.h b/src/gui/widgets/whispertab.h
index 739ae159..0d39b6ec 100644
--- a/src/gui/widgets/whispertab.h
+++ b/src/gui/widgets/whispertab.h
@@ -34,6 +34,10 @@ class WhisperTab : public ChatTab
public:
const std::string &getNick() const { return mNick; }
+ void showHelp();
+
+ bool handleCommand(std::string type, std::string args);
+
protected:
friend class ChatWindow;
diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp
index 997881f8..626f1048 100644
--- a/src/net/ea/chathandler.cpp
+++ b/src/net/ea/chathandler.cpp
@@ -200,43 +200,43 @@ void ChatHandler::privateMessage(const std::string &recipient,
void ChatHandler::channelList()
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
void ChatHandler::enterChannel(const std::string &channel,
const std::string &password)
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
void ChatHandler::quitChannel(int channelId)
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
void ChatHandler::sendToChannel(int channelId, const std::string &text)
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
void ChatHandler::userList(const std::string &channel)
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
void ChatHandler::setChannelTopic(int channelId, const std::string &text)
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
void ChatHandler::setUserMode(int channelId, const std::string &name, int mode)
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
void ChatHandler::kickUser(int channelId, const std::string &name)
{
- // TODO
+ localChatTab->chatLog(_("Channels are not supported!"), BY_SERVER);
}
} // namespace EAthena
diff --git a/src/net/ea/gui/partytab.cpp b/src/net/ea/gui/partytab.cpp
index 5f6da0f9..e9651af9 100644
--- a/src/net/ea/gui/partytab.cpp
+++ b/src/net/ea/gui/partytab.cpp
@@ -46,24 +46,20 @@ void PartyTab::handleInput(const std::string &msg)
Net::getPartyHandler()->chat(msg);
}
-void PartyTab::handleCommand(std::string msg)
+void PartyTab::showHelp()
{
- std::string::size_type pos = msg.find(' ');
- std::string type(msg, 0, pos);
- std::string args(msg, pos == std::string::npos ? msg.size() : pos + 1);
+ chatLog(_("/help > Display this help."));
+ chatLog(_("/create > Create a new party"));
+ chatLog(_("/new > Alias of create"));
+ chatLog(_("/invite > Invite a player to your party"));
+ chatLog(_("/leave > Leave the party you are in"));
+}
+bool PartyTab::handleCommand(std::string type, std::string args)
+{
if (type == "help")
{
- if (args == "")
- {
- chatLog(_("-- Help --"));
- chatLog(_("/help > Display this help."));
- chatLog(_("/create > Create a new party"));
- chatLog(_("/new > Alias of create"));
- chatLog(_("/invite > Invite a player to your party"));
- chatLog(_("/leave > Leave the party you are in"));
- }
- else if (args == "create" || args == "new")
+ if (args == "create" || args == "new")
{
chatLog(_("Command: /new <party-name>"));
chatLog(_("Command: /create <party-name>"));
@@ -83,18 +79,8 @@ void PartyTab::handleCommand(std::string msg)
chatLog(_("Command: /leave"));
chatLog(_("This command causes the player to leave the party."));
}
- else if (args == "help")
- {
- chatLog(_("Command: /help"));
- chatLog(_("This command displays a list of all commands available."));
- chatLog(_("Command: /help <command>"));
- chatLog(_("This command displays help on <command>."));
- }
else
- {
- chatLog(_("Unknown command."));
- chatLog(_("Type /help for a list of commands."));
- }
+ return false;
}
else if (type == "create" || type == "new")
{
@@ -121,7 +107,7 @@ void PartyTab::handleCommand(std::string msg)
*/
}
else
- {
- chatLog("Unknown command");
- }
+ return false;
+
+ return true;
}
diff --git a/src/net/ea/gui/partytab.h b/src/net/ea/gui/partytab.h
index bf9413d0..fac4061b 100644
--- a/src/net/ea/gui/partytab.h
+++ b/src/net/ea/gui/partytab.h
@@ -33,9 +33,12 @@ class PartyTab : public ChatTab
PartyTab();
~PartyTab();
+ void showHelp();
+
+ bool handleCommand(std::string type, std::string args);
+
protected:
void handleInput(const std::string &msg);
- void handleCommand(std::string msg);
};
extern PartyTab *partyTab;