summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorRoderic Morris <roderic@ccs.neu.edu>2008-06-10 00:45:21 +0000
committerRoderic Morris <roderic@ccs.neu.edu>2008-06-10 00:45:21 +0000
commitf6f031fa4db6fa0ccd6e0b433f61479e9fd85477 (patch)
treef68634271d7e7f315c122ed7a3a08ad1d05b58b6 /src/gui
parent2cf38d37f86c5e5d82d77713afd093735db0598a (diff)
downloadmana-f6f031fa4db6fa0ccd6e0b433f61479e9fd85477.tar.gz
mana-f6f031fa4db6fa0ccd6e0b433f61479e9fd85477.tar.bz2
mana-f6f031fa4db6fa0ccd6e0b433f61479e9fd85477.tar.xz
mana-f6f031fa4db6fa0ccd6e0b433f61479e9fd85477.zip
add commandhandler class and fix / add some commands
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp134
-rw-r--r--src/gui/chat.h51
2 files changed, 51 insertions, 134 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index e7b82621..ba9ef8ee 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -37,6 +37,7 @@
#include "widgets/tab.h"
#include "widgets/tabbedarea.h"
+#include "../commandhandler.h"
#include "../channelmanager.h"
#include "../channel.h"
#include "../configuration.h"
@@ -96,6 +97,18 @@ ChatWindow::~ChatWindow()
delete mChatTabs;
}
+const std::string& ChatWindow::getFocused() const
+{
+ return mChatTabs->getSelectedTab()->getCaption();
+}
+
+void ChatWindow::clearTab(const std::string &tab)
+{
+ ChannelMap::const_iterator chan = mChannels.find(tab);
+ if (chan != mChannels.end())
+ chan->second.browser->clearRows();
+}
+
void ChatWindow::widgetResized(const gcn::Event &event)
{
Window::widgetResized(event);
@@ -122,8 +135,11 @@ void ChatWindow::widgetResized(const gcn::Event &event)
}
void
-ChatWindow::chatLog(std::string line, int own, const std::string &channelName)
+ChatWindow::chatLog(std::string line, int own, std::string channelName)
{
+ if(channelName == "getFocused\"")
+ channelName = getFocused();
+
ChannelMap::const_iterator chan = mChannels.find(channelName);
if (chan == mChannels.end())
return;
@@ -164,6 +180,10 @@ ChatWindow::chatLog(std::string line, int own, const std::string &channelName)
tmp.text = line;
lineColor = "##7"; // Equiv. to BrowserBox::PINK
break;
+ case BY_CHANNEL:
+ tmp.nick = "";
+ lineColor = "##2"; // Equiv. to BrowserBox::GREEN
+ break;
case BY_LOGGER:
tmp.nick = "";
tmp.text = line;
@@ -220,8 +240,7 @@ ChatWindow::action(const gcn::ActionEvent &event)
mCurHist = mHistory.end();
// Send the message to the server
- gcn::Tab *tab = mChatTabs->getSelectedTab();
- chatSend(player_node->getName(), message, tab->getCaption());
+ chatSend(message);
// Clear the text from the chat input
mChatInput->setText("");
@@ -265,115 +284,29 @@ ChatWindow::isFocused()
return mChatInput->isFocused();
}
-void ChatWindow::chatSend(std::string const &nick, std::string const &msg,
- std::string const &channelName)
+void ChatWindow::chatSend(std::string const &msg)
{
- /* Some messages are managed client side, while others
- * require server handling by proper packet. Probably
- * those if elses should be replaced by protocol calls */
-
if (msg.empty()) return;
// Prepare ordinary message
- if (msg[0] != '/') {
- gcn::Tab *tab = mChatTabs->getSelectedTab();
- if (tab->getCaption() == "General")
+ if (msg[0] != '/')
+ {
+ if (getFocused() == "General")
{
Net::GameServer::Player::say(msg);
}
else
{
- Channel *channel = channelManager->findByName(channelName);
+ Channel *channel = channelManager->findByName(getFocused());
if (channel)
{
- int channelId = channel->getId();
- Net::ChatServer::chat(channelId, msg);
+ Net::ChatServer::chat(channel->getId(), msg);
}
}
- return;
- }
-
- std::string::size_type pos = msg.find(' ', 1);
- std::string command(msg, 1, pos == std::string::npos ? pos : pos - 1);
- std::string arg(msg, pos == std::string::npos ? msg.size() : pos + 1);
-
- if (command == "announce")
- {
- Net::ChatServer::announce(arg);
- }
- else if (command == "help")
- {
- chatLog("-- Help --", BY_SERVER, channelName);
- chatLog("/help > Display this help.", BY_SERVER, channelName);
- chatLog("/announce > Global announcement (GM only)", BY_SERVER, channelName);
- chatLog("/where > Display map name", BY_SERVER, channelName);
- chatLog("/who > Display number of online users", BY_SERVER, channelName);
- chatLog("/msg > Send a private message to a user", BY_SERVER, channelName);
- chatLog("/list > Display all public channels", BY_SERVER, channelName);
- chatLog("/register > Register a new channel", BY_SERVER, channelName);
- chatLog("/join > Join an already registered channel", BY_SERVER, channelName);
- chatLog("/quit > Leave a channel", BY_SERVER, channelName);
- chatLog("/admin > Send a command to the server (GM only)", BY_SERVER, channelName);
- chatLog("/clear > Clears this window", BY_SERVER);
- }
- else if (command == "where")
- {
- chatLog(map_path, BY_SERVER);
- }
- else if (command == "who")
- {
- // XXX Convert for new server
- /*
- MessageOut outMsg(0x00c1);
- */
- }
- else if (command == "msg")
- {
- std::string::size_type pos = arg.find(' ', 1);
- std::string recipient(arg, 0, pos);
- std::string text(arg, pos+1);
- Net::ChatServer::privMsg(recipient, text);
- }
- else if (command == "register")
- {
- // TODO: Parse the announcement and password
- chatLog("Requesting to register channel " + arg, BY_SERVER);
- Net::ChatServer::registerChannel(arg, "", "");
- }
- else if (command == "join")
- {
- //TODO: have passwords too
- chatLog("Requesting to join channel " + arg, BY_SERVER);
- enterChannel(arg, "None");
- }
- else if (command == "list")
- {
- Net::ChatServer::getChannelList();
- }
- else if (command == "quit")
- {
- if (Channel *channel = channelManager->findByName(channelName))
- {
- Net::ChatServer::quitChannel(channel->getId());
- }
- else
- {
- chatLog("Unable to quit this channel", BY_SERVER);
- }
- }
- else if (command == "admin")
- {
- Net::GameServer::Player::say("/" + arg);
- }
- else if (command == "clear")
- {
- ChannelMap::const_iterator chan = mChannels.find(channelName);
- if (chan != mChannels.end())
- chan->second.browser->clearRows();
}
else
{
- chatLog("Unknown command", BY_SERVER, channelName);
+ commandHandler->handleCommand(std::string(msg, 1));
}
}
@@ -429,20 +362,11 @@ ChatWindow::createNewChannelTab(const std::string &channelName)
mChannels.insert(
std::make_pair(channelName, ChatArea(textOutput, scrollArea)));
- // Ask for channel users
- Net::ChatServer::getUserList(channelName);
-
// Update UI
logic();
}
void
-ChatWindow::enterChannel(const std::string &channel, const std::string &password)
-{
- Net::ChatServer::enterChannel(channel, password);
-}
-
-void
ChatWindow::sendToChannel(short channelId, const std::string &user, const std::string &msg)
{
Channel *channel = channelManager->findById(channelId);
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 148feb7e..a999f8fc 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -46,6 +46,7 @@ enum
BY_PLAYER = 1,
BY_OTHER = 2,
BY_SERVER = 3,
+ BY_CHANNEL = 4,
BY_LOGGER
};
@@ -74,14 +75,27 @@ class ChatWindow : public Window,
* the tabbed area.
*/
void widgetResized(const gcn::Event &event);
+
+ /**
+ * Gets the focused tab's name
+ */
+ const std::string& getFocused() const;
+
+ /**
+ * Clear the tab with the given name
+ */
+ void clearTab(const std::string &tab);
/**
* Adds a line of text to our message list. Parameters:
*
* @param line Text message.
- * @parem own Type of message (usually the owner-type).
+ * @param own Type of message (usually the owner-type).
+ * @param channelName which channel to send the message to.
*/
- void chatLog(std::string line, int own, const std::string &channelName = "General");
+ void chatLog(std::string line,
+ int own = BY_SERVER,
+ std::string channelName = "getFocused\"");
/**
* Performs action.
@@ -99,31 +113,14 @@ class ChatWindow : public Window,
bool isFocused();
/**
- * Determines whether to send a command or an ordinary message, then
- * contructs packets & sends them.
+ * Determines whether the message is a command or message, then
+ * sends the given message to the game server to be said, or to the
+ * command handler
+ *
+ * @param msg The message text which is to be sent.
*
- * @param nick The character's name to display in front.
- * @param msg The message text which is to be send.
- *
- * NOTE:
- * The nickname is required by the server, if not specified
- * the message may not be sent unless a command was intended
- * which requires another packet to be constructed! you can
- * achieve this by putting a slash ("/") infront of the
- * message followed by the command name and the message.
- * of course all slash-commands need implemented handler-
- * routines. ;-)
- * remember, a line starting with "@" is not a command that needs
- * to be parsed rather is sent using the normal chat-packet.
- *
- * EXAMPLE:
- * // for an global announcement /- command
- * chatlog.chat_send("", "/announce Hello to all logged in users!");
- * // for simple message by a user /- message
- * chatlog.chat_send("Zaeiru", "Hello to all users on the screen!");
*/
- void chatSend(std::string const &nick, std::string const &msg,
- std::string const &channelName);
+ void chatSend(std::string const &msg);
/** Called to remove the channel from the channel manager */
void
@@ -139,10 +136,6 @@ class ChatWindow : public Window,
void
createNewChannelTab(const std::string &channelName);
- /** Called to join channel */
- void
- enterChannel(const std::string &channel, const std::string &password = "None");
-
/** Called to output text to a specific channel */
void
sendToChannel(short channel, const std::string &user, const std::string &msg);