summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-03-23 07:02:32 -0600
committerJared Adams <jaxad0127@gmail.com>2009-03-23 07:02:32 -0600
commit7c360d2887216099ca8cc767f15a34fcf302803b (patch)
tree308a8889e1173a27b4c20ef608c0749449c8aa04 /src
parentd3f315b45bd9055ac7f61082f5af54b863410517 (diff)
downloadMana-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')
-rw-r--r--src/Makefile.am4
-rw-r--r--src/commandhandler.cpp422
-rw-r--r--src/commandhandler.h33
-rw-r--r--src/game.cpp21
-rw-r--r--src/gui/chat.cpp501
-rw-r--r--src/gui/chat.h52
-rw-r--r--src/gui/recorder.cpp4
-rw-r--r--src/gui/recorder.h12
-rw-r--r--src/party.cpp74
-rw-r--r--src/party.h7
10 files changed, 503 insertions, 627 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ce51b12d..17059a72 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -239,6 +239,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \
channel.h \
channelmanager.cpp \
channelmanager.h \
+ commandhandler.cpp \
+ commandhandler.h \
configlistener.h \
configuration.cpp \
configuration.h \
@@ -409,8 +411,6 @@ tmw_SOURCES += \
net/tradehandler.h \
resources/buddylist.cpp \
resources/buddylist.h \
- commandhandler.cpp \
- commandhandler.h \
guild.cpp \
guild.h
endif
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();
+}
diff --git a/src/commandhandler.h b/src/commandhandler.h
index eab0f077..e8da51d7 100644
--- a/src/commandhandler.h
+++ b/src/commandhandler.h
@@ -24,6 +24,10 @@
#include <string>
+#ifdef EATHENA_SUPPORT
+class Network;
+#endif
+
/**
* A class to parse and handle user commands
*/
@@ -33,7 +37,11 @@ class CommandHandler
/**
* Constructor
*/
- CommandHandler() {}
+#ifdef TMWSERV_SUPPORT
+ CommandHandler();
+#else
+ CommandHandler(Network *network);
+#endif
/**
* Destructor
@@ -116,6 +124,29 @@ class CommandHandler
*/
void handleKick(const std::string &args);
+ /**
+ * Handle a me command.
+ */
+ void handleMe(const std::string &args);
+
+ /**
+ * Handle a record command.
+ */
+ void handleRecord(const std::string &args);
+
+ /**
+ * Handle a toggle command.
+ */
+ void handleToggle(const std::string &args);
+
+ /**
+ * Handle a present command.
+ */
+ void handlePresent(const std::string &args);
+
+#ifdef EATHENA_SUPPORT
+ Network *mNetwork;
+#endif
};
extern CommandHandler *commandHandler;
diff --git a/src/game.cpp b/src/game.cpp
index ac18b7ce..aefefd29 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -28,9 +28,7 @@
#include "beingmanager.h"
#include "channelmanager.h"
-#ifdef TMWSERV_SUPPORT
#include "commandhandler.h"
-#endif
#include "configuration.h"
#include "effectmanager.h"
#include "emoteshortcut.h"
@@ -45,6 +43,9 @@
#include "log.h"
#include "npc.h"
#include "particle.h"
+#ifdef EATHENA_SUPPORT
+#include "party.h"
+#endif
#include "player_relations.h"
#include "gui/buy.h"
@@ -165,12 +166,14 @@ ShortcutWindow *emoteShortcutWindow;
BeingManager *beingManager = NULL;
FloorItemManager *floorItemManager = NULL;
ChannelManager *channelManager = NULL;
-#ifdef TMWSERV_SUPPORT
CommandHandler *commandHandler = NULL;
-#endif
Particle* particleEngine = NULL;
EffectManager *effectManager = NULL;
+#ifdef EATHENA_SUPPORT
+Party *playerParty = NULL;
+#endif
+
const int MAX_TIME = 10000;
/**
@@ -362,18 +365,17 @@ Game::Game(Network *network):
engine = new Engine;
beingManager = new BeingManager;
+ commandHandler = new CommandHandler();
#else
createGuiWindows(network);
engine = new Engine(network);
beingManager = new BeingManager(network);
+ commandHandler = new CommandHandler(network);
#endif
floorItemManager = new FloorItemManager;
channelManager = new ChannelManager();
-#ifdef TMWSERV_SUPPORT
- commandHandler = new CommandHandler();
-#endif
effectManager = new EffectManager;
particleEngine = new Particle(NULL);
@@ -392,6 +394,7 @@ Game::Game(Network *network):
beingManager->setPlayer(player_node);
#ifdef EATHENA_SUPPORT
player_node->setNetwork(network);
+ playerParty = new Party(network);
#endif
Joystick::init();
@@ -445,6 +448,8 @@ Game::~Game()
{
#ifdef TMWSERV_SUPPORT
Net::clearHandlers();
+#else
+ delete playerParty;
#endif
delete player_node;
@@ -453,9 +458,7 @@ Game::~Game()
delete beingManager;
delete floorItemManager;
delete channelManager;
-#ifdef TMWSERV_SUPPORT
delete commandHandler;
-#endif
delete joystick;
delete particleEngine;
delete engine;
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index c0d6ed77..f2651a02 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -35,9 +35,7 @@
#include "widgets/tabbedarea.h"
#include "../beingmanager.h"
-#ifdef TMWSERV_SUPPORT
#include "../commandhandler.h"
-#endif
#include "../channelmanager.h"
#include "../channel.h"
#include "../configuration.h"
@@ -105,12 +103,13 @@ ChatWindow::ChatWindow(Network * network):
mPartyPrefix = (partyPrefix.empty() ? '$' : partyPrefix.at(0));
mReturnToggles = config.getValue("ReturnToggles", "0") == "1";
mRecorder = new Recorder(this);
- mParty = new Party(this, mNetwork);
// If the player had @assert on in the last session, ask the server to
// run the @assert command for the player again. Convenience for GMs.
- if (config.getValue(player_node->getName() + "GMassert", 0))
- chatSend(player_node->getName(), "@assert");
+ if (config.getValue(player_node->getName() + "GMassert", 0)) {
+ std::string cmd = "@assert";
+ chatSend(cmd);
+ }
#endif
}
@@ -352,11 +351,7 @@ void ChatWindow::action(const gcn::ActionEvent &event)
mCurHist = mHistory.end();
// Send the message to the server
-#ifdef TMWSERV_SUPPORT
chatSend(message);
-#else
- chatSend(player_node->getName(), message);
-#endif
// Clear the text from the chat input
mChatInput->setText("");
@@ -400,54 +395,6 @@ bool ChatWindow::isInputFocused()
return mChatInput->isFocused();
}
-void ChatWindow::whisper(const std::string &nick, std::string msg)
-{
- std::string recvnick = "";
-
- if (msg.substr(0, 1) == "\"")
- {
- const std::string::size_type pos = msg.find('"', 1);
- if (pos != std::string::npos)
- {
- recvnick = msg.substr(1, pos - 1);
- msg.erase(0, pos + 2);
- }
- }
- else
- {
- const std::string::size_type pos = msg.find(" ");
- if (pos != std::string::npos)
- {
- recvnick = msg.substr(0, pos);
- msg.erase(0, pos + 1);
- }
- }
-
- trim(msg);
-
- std::string playerName = player_node->getName();
- std::string tempNick = recvnick;
-
- toLower(playerName);
- toLower(tempNick);
-
- if (tempNick.compare(playerName) == 0 || msg.empty())
- return;
-
- // TODO: Implement whispering on tmwserv
-#ifdef EATHENA_SUPPORT
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(CMSG_CHAT_WHISPER);
- outMsg.writeInt16(msg.length() + 28);
- outMsg.writeString(recvnick, 24);
- outMsg.writeString(msg, msg.length());
-
- chatLog(strprintf(_("Whispering to %s: %s"),
- recvnick.c_str(), msg.c_str()),
- BY_PLAYER);
-#endif
-}
-
void ChatWindow::removeChannel(short channelId)
{
removeChannel(channelManager->findById(channelId));
@@ -514,65 +461,13 @@ void ChatWindow::sendToChannel(short channelId,
}
}
-#ifdef TMWSERV_SUPPORT
-
void ChatWindow::chatSend(std::string &msg)
{
- if (msg.empty()) return;
-
- // check for item link
- std::string::size_type start = msg.find('[');
- if (start != std::string::npos && msg[start+1] != '@')
- {
- std::string::size_type end = msg.find(']', start);
- if (end != std::string::npos)
- {
- std::string temp = msg.substr(start+1, end-1);
- ItemInfo itemInfo = ItemDB::get(temp);
- msg.insert(end, "@@");
- msg.insert(start+1, "|");
- msg.insert(start+1, toString(itemInfo.getId()));
- msg.insert(start+1, "@@");
-
- }
- }
-
-
- // Prepare ordinary message
- if (msg[0] != '/')
- {
- if (getFocused() == "General")
- {
- Net::GameServer::Player::say(msg);
- }
- else
- {
- Channel *channel = channelManager->findByName(getFocused());
- if (channel)
- {
- Net::ChatServer::chat(channel->getId(), msg);
- }
- }
- }
- else
- {
- commandHandler->handleCommand(std::string(msg, 1));
- }
-}
-
-#else
-
-void ChatWindow::chatSend(const std::string &nick, std::string 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 */
-
trim(msg);
- if (msg.compare("") == 0)
- return;
+ if (msg.empty()) return;
+#ifdef EATHENA_SUPPORT
// Send party message
if (msg.at(0) == mPartyPrefix)
{
@@ -591,6 +486,7 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg)
outMsg.writeString(msg, length);
return;
}
+#endif
// Check for item link
std::string::size_type start = msg.find('[');
@@ -623,10 +519,25 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg)
start = msg.find('[', start + 1);
}
+
// Prepare ordinary message
- if (msg.substr(0, 1) != "/")
+ if (msg[0] != '/')
{
- msg = nick + " : " + msg;
+#ifdef TMWSERV_SUPPORT
+ if (getFocused() == "General")
+ {
+ Net::GameServer::Player::say(msg);
+ }
+ else
+ {
+ Channel *channel = channelManager->findByName(getFocused());
+ if (channel)
+ {
+ Net::ChatServer::chat(channel->getId(), msg);
+ }
+ }
+#else
+ msg = player_node->getName() + " : " + msg;
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_CHAT_MESSAGE);
@@ -634,209 +545,56 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg)
outMsg.writeInt16(msg.length() + 4 + 1);
outMsg.writeString(msg, msg.length() + 1);
return;
- }
-
- msg.erase(0, 1);
- trim(msg);
-
- std::size_t space = msg.find(" ");
- std::string command = msg.substr(0, space);
-
- if (space == std::string::npos)
- {
- msg = "";
+#endif
}
else
{
- msg = msg.substr(space);
- trim(msg);
- }
-
- if (command == "announce")
- {
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(0x0099);
- outMsg.writeInt16(msg.length() + 4);
- outMsg.writeString(msg, msg.length());
- }
- else if (command == "help")
- {
- trim(msg);
- std::size_t space = msg.find(" ");
- std::string msg1;
-
- if (space == std::string::npos)
- {
- msg1 = "";
- }
- else
- {
- msg1 = msg.substr(space + 1, msg.length());
- msg = msg.substr(0, space);
- }
-
- if (!msg.empty() && msg.at(0) == '/')
- {
- msg.erase(0, 1);
- }
-
- trim(msg1);
- help(msg, msg1);
- }
- else if (command == "where")
- {
- // Display the current map, X, and Y
- std::ostringstream where;
- where << map_path << " " << player_node->mX << "," << player_node->mY;
- chatLog(where.str(), BY_SERVER);
- }
- else if (command == "who")
- {
- MessageOut outMsg(mNetwork);
- outMsg.writeInt16(0x00c1);
- }
- else if (command == "clear")
- clearTab(getFocused());
- else if (command == "whisper" || command == "msg" || command == "w")
- whisper(nick, msg);
- else if (command == "record")
- mRecorder->changeRecordingStatus(msg);
- else if (command == "toggle")
- {
- if (msg.empty())
- {
- chatLog(mReturnToggles ? _("Return toggles chat.")
- : _("Message closes chat."), BY_SERVER);
- return;
- }
-
- msg = msg.substr(0, 1);
-
- if (msg == "1" ||
- msg == "y" || msg == "Y" ||
- msg == "t" || msg == "T")
- {
- chatLog(_("Return now toggles chat."), BY_SERVER);
- mReturnToggles = true;
- return;
- }
- else if (msg == "0" ||
- msg == "n" || msg == "N" ||
- msg == "f" || msg == "F")
- {
- chatLog(_("Message now closes chat."), BY_SERVER);
- mReturnToggles = false;
- return;
- }
- else
- chatLog(_("Options to /toggle are \"yes\", \"no\", \"true\", "
- "\"false\", \"1\", \"0\"."), BY_SERVER);
+ commandHandler->handleCommand(std::string(msg, 1));
}
- else if (command == "party")
- {
- if (msg.empty())
- {
- chatLog(_("Unknown party command... Type \"/help\" party for more "
- "information."), BY_SERVER);
- return;
- }
-
- const std::string::size_type space = msg.find(" ");
- std::string rest = (space == std::string::npos ? ""
- : msg.substr(space + 1, msg.length()));
+}
- if (!rest.empty())
- {
- msg = msg.substr(0, space);
- trim(msg);
- }
+void ChatWindow::doPresent()
+{
+ Beings & beings = beingManager->getAll();
+ std::string response = "";
- party(msg, rest);
- return;
- }
- else if (command == "cast")
+ for (BeingIterator bi = beings.begin(), be = beings.end();
+ bi != be; ++bi)
{
- /*
- * This will eventually be replaced by a GUI, so
- * we don't need to get too sophisticated
- */
- MessageOut outMsg(mNetwork);
- if (msg == "heal")
+ if ((*bi)->getType() == Being::PLAYER)
{
- outMsg.writeInt16(0x03f3);
- outMsg.writeInt16(0x01);
- outMsg.writeInt32(0);
- outMsg.writeInt8(0);
- outMsg.writeInt8(0);
- outMsg.writeString("", 24);
- }
- else if (msg == "gather")
- {
- outMsg.writeInt16(0x03f3);
- outMsg.writeInt16(0x02);
- outMsg.writeInt32(0);
- outMsg.writeInt8(0);
- outMsg.writeInt8(0);
- outMsg.writeString("", 24);
- }
- else
- chatLog(_("No such spell!"), BY_SERVER);
- }
- else if (command == "present")
- {
- Beings & beings = beingManager->getAll();
- std::string response = "";
-
- for (BeingIterator bi = beings.begin(), be = beings.end();
- bi != be; ++bi)
- {
- if ((*bi)->getType() == Being::PLAYER)
+ if (!response.empty())
{
- if (!response.empty())
- {
- response += ", ";
- }
- response += (*bi)->getName();
+ response += ", ";
}
+ response += (*bi)->getName();
}
+ }
- if (mRecorder->isRecording())
- {
- // Get the current system time
- time_t t;
- time(&t);
+ if (mRecorder->isRecording())
+ {
+ // Get the current system time
+ time_t t;
+ time(&t);
- // Format the time string properly
- std::stringstream timeStr;
- timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
- << (int) (((t / 60) / 60) % 24)
- << ":" << (((t / 60) % 60 < 10) ? "0" : "")
- << (int) ((t / 60) % 60)
- << "] ";
+ // Format the time string properly
+ std::stringstream timeStr;
+ timeStr << "[" << ((((t / 60) / 60) % 24 < 10) ? "0" : "")
+ << (int) (((t / 60) / 60) % 24)
+ << ":" << (((t / 60) % 60 < 10) ? "0" : "")
+ << (int) ((t / 60) % 60)
+ << "] ";
- mRecorder->record(timeStr.str() + _("Present: ") + response + ".");
- chatLog(_("Attendance written to record log."), BY_SERVER, std::string(), true);
- }
- else
- {
- chatLog(_("Present: ") + response, BY_SERVER);
- }
- }
- else if (command == "me")
- {
- std::stringstream actionStr;
- actionStr << "*" << msg << "*";
- chatSend(player_node->getName(), actionStr.str());
+ mRecorder->record(timeStr.str() + _("Present: ") + response + ".");
+ chatLog(_("Attendance written to record log."), BY_SERVER, std::string(), true);
}
else
{
- chatLog(_("Unknown command"), BY_SERVER);
+ chatLog(_("Present: ") + response, BY_SERVER);
}
}
-#endif
-
void ChatWindow::scroll(int amount)
{
if (!isVisible())
@@ -909,156 +667,13 @@ void ChatWindow::setVisible(bool isVisible)
mTmpVisible = false;
}
-#ifdef EATHENA_SUPPORT
-void ChatWindow::party(const std::string & command, const std::string & rest)
-{
- if (command == "prefix")
- {
- if (rest.empty())
- {
- char temp[2] = ".";
- *temp = mPartyPrefix;
- chatLog(_("The current party prefix is ") + std::string(temp),
- BY_SERVER);
- }
- else if (rest.length() != 1)
- {
- chatLog(_("Party prefix must be one character long."), BY_SERVER);
- }
- else
- {
- if (rest == "/")
- {
- chatLog(_("Cannot use a '/' as the prefix."), BY_SERVER);
- }
- else
- {
- mPartyPrefix = rest.at(0);
- chatLog(_("Changing prefix to ") + rest, BY_SERVER);
- }
- }
- }
- else
- mParty->respond(command, rest);
-}
-#endif
-
-void ChatWindow::help(const std::string & msg1, const std::string & msg2)
-{
- chatLog(_("-- Help --"), BY_SERVER);
- if (msg1.empty())
- {
- chatLog(_("/announce: Global announcement (GM only)"), BY_SERVER);
- chatLog(_("/clear: Clears this window"), BY_SERVER);
- chatLog(_("/help: Display this help"), BY_SERVER);
- chatLog(_("/me <message>: Tell something about yourself"), BY_SERVER);
- chatLog(_("/msg <nick> <message>: Alternate form for /whisper"),
- BY_SERVER);
- chatLog(_("/party <command> <params>: Party commands"), BY_SERVER);
- chatLog(_("/present: Get list of players present"), BY_SERVER);
- chatLog(_("/record <filename>: Start recording the chat to an "
- "external file"), BY_SERVER);
- chatLog(_("/toggle: Determine whether <return> toggles the chat log"),
- BY_SERVER);
- chatLog(_("/w <nick> <message>: Short form for /whisper"), BY_SERVER);
- chatLog(_("/where: Display map name"), BY_SERVER);
- chatLog(_("/whisper <nick> <message>: Sends a private <message> "
- "to <nick>"), BY_SERVER);
- chatLog(_("/who: Display number of online users"), BY_SERVER);
- chatLog(_("For more information, type /help <command>"), BY_SERVER);
- }
- else if (msg1 == "announce")
- {
- chatLog(_("Command: /announce <msg>"), BY_SERVER);
- chatLog(_("*** only available to a GM ***"), BY_SERVER);
- chatLog(_("This command sends the message <msg> to "
- "all players currently online."), BY_SERVER);
- }
- else if (msg1 == "clear")
- {
- chatLog(_("Command: /clear"), BY_SERVER);
- chatLog(_("This command clears the chat log of previous chat."),
- BY_SERVER);
- }
- else if (msg1 == "help")
- {
- chatLog(_("Command: /help"), BY_SERVER);
- chatLog(_("This command displays a list of all commands available."),
- BY_SERVER);
- chatLog(_("Command: /help <command>"), BY_SERVER);
- chatLog(_("This command displays help on <command>."), BY_SERVER);
- }
- else if (msg1 == "me")
- {
- chatLog(_("Command: /me <msg>"), BY_SERVER);
- chatLog(_("This command tell others you are (doing) <msg>."),
- BY_SERVER);
- }
-#ifdef EATHENA_SUPPORT
- else if (msg1 == "party")
- {
- mParty->help(msg2);
- }
-#endif
- else if (msg1 == "present")
- {
- chatLog(_("Command: /present"), BY_SERVER);
- 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."), BY_SERVER);
- }
- else if (msg1 == "record")
- {
- chatLog(_("Command: /record <filename>"), BY_SERVER);
- chatLog(_("This command starts recording the chat log to the file "
- "<filename>."), BY_SERVER);
- chatLog(_("Command: /record"), BY_SERVER);
- chatLog(_("This command finishes a recording session."), BY_SERVER);
- }
- else if (msg1 == "toggle")
- {
- chatLog(_("Command: /toggle <state>"), BY_SERVER);
- chatLog(_("This command sets whether the return key should toggle the "
- "chat log, or whether the chat log turns off automatically."),
- BY_SERVER);
- chatLog(_("<state> can be one of \"1\", \"yes\", \"true\" to "
- "turn the toggle on, or \"0\", \"no\", \"false\" to turn the "
- "toggle off."), BY_SERVER);
- chatLog(_("Command: /toggle"), BY_SERVER);
- chatLog(_("This command displays the return toggle status."),
- BY_SERVER);
- }
- else if (msg1 == "where")
- {
- chatLog(_("Command: /where"), BY_SERVER);
- chatLog(_("This command displays the name of the current map."),
- BY_SERVER);
- }
- else if (msg1 == "whisper" || msg1 == "msg" || msg1 == "w")
- {
- chatLog(_("Command: /msg <nick> <msg>"), BY_SERVER);
- chatLog(_("Command: /whisper <nick> <msg>"), BY_SERVER);
- chatLog(_("Command: /w <nick> <msg>"), BY_SERVER);
- chatLog(_("This command sends the message <msg> to <nick>."),
- BY_SERVER);
- chatLog(_("If the <nick> has spaces in it, enclose it in "
- "double quotes (\")."), BY_SERVER);
- }
- else if (msg1 == "who")
- {
- chatLog(_("Command: /who"), BY_SERVER);
- chatLog(_("This command displays the number of players currently "
- "online."), BY_SERVER);
- }
- else
- {
- chatLog(_("Unknown command."), BY_SERVER);
- chatLog(_("Type /help for a list of commands."), BY_SERVER);
- }
-}
-
bool ChatWindow::tabExists(const std::string &tabName)
{
Tab *tab = mChatTabs->getTab(tabName);
return tab != 0;
}
+
+void ChatWindow::setRecordingFile(const std::string &msg)
+{
+ mRecorder->setRecordingFile(msg);
+}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index a05a2577..a64f24cd 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -152,7 +152,6 @@ class ChatWindow : public Window,
const std::string &user,
const std::string &msg);
-#ifdef TMWSERV_SUPPORT
/**
* Determines whether the message is a command or message, then
* sends the given message to the game server to be said, or to the
@@ -162,33 +161,6 @@ class ChatWindow : public Window,
*
*/
void chatSend(std::string &msg);
-#else
- /**
- * Determines whether to send a command or an ordinary message, then
- * contructs packets & sends them.
- *
- * @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(const std::string &nick, std::string msg);
-#endif
/** Called when key is pressed */
void keyPressed(gcn::KeyEvent &event);
@@ -215,22 +187,21 @@ class ChatWindow : public Window,
void scroll(int amount);
#ifdef EATHENA_SUPPORT
- /**
- * party implements the partying chat commands
- *
- * @param command is the party command to perform
- * @param msg is the remainder of the message
- */
- void party(const std::string &command, const std::string &msg);
+ char getPartyPrefix() { return mPartyPrefix; }
+ void setPartyPrefix(char prefix) { mPartyPrefix = prefix; }
#endif
/**
- * help implements the /help command
+ * Sets the file being recorded to
*
- * @param msg1 is the command that the player needs help on
- * @param msg2 is the sub-command relating to the command
+ * @param msg The file to write out to. If null, then stop recording.
*/
- void help(const std::string &msg1, const std::string &msg2);
+ void setRecordingFile(const std::string &msg);
+
+ bool getReturnTogglesChat() { return mReturnToggles; }
+ void setReturnTogglesChat(bool toggles) { mReturnToggles = toggles; }
+
+ void doPresent();
private:
#ifdef EATHENA_SUPPORT
@@ -241,8 +212,6 @@ class ChatWindow : public Window,
int mItems;
int mItemsKeep;
- void whisper(const std::string &nick, std::string msg);
-
/** One item in the chat log */
struct CHATLOG
{
@@ -287,7 +256,6 @@ class ChatWindow : public Window,
#ifdef EATHENA_SUPPORT
char mPartyPrefix; /**< Messages beginning with the prefix are sent to
the party */
- Party *mParty;
#endif
};
diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp
index ce097db2..a94af4cc 100644
--- a/src/gui/recorder.cpp
+++ b/src/gui/recorder.cpp
@@ -64,7 +64,7 @@ void Recorder::record(const std::string &msg)
}
}
-void Recorder::changeRecordingStatus(const std::string &msg)
+void Recorder::setRecordingFile(const std::string &msg)
{
std::string msgCopy = msg;
trim(msgCopy);
@@ -112,5 +112,5 @@ void Recorder::changeRecordingStatus(const std::string &msg)
void Recorder::action(const gcn::ActionEvent &event)
{
- changeRecordingStatus("");
+ setRecordingFile("");
}
diff --git a/src/gui/recorder.h b/src/gui/recorder.h
index 0bbab012..2a47b5c4 100644
--- a/src/gui/recorder.h
+++ b/src/gui/recorder.h
@@ -41,26 +41,26 @@ class Recorder : public Window, public gcn::ActionListener
virtual ~Recorder();
- /*
+ /**
* Outputs the message to the recorder file
*
* @param msg the line to write to the recorded file.
*/
void record(const std::string &msg);
- /*
- * Outputs the message to the recorder file
+ /**
+ * Sets the file being recorded to
*
* @param msg The file to write out to. If null, then stop recording.
*/
- void changeRecordingStatus(const std::string &msg);
+ void setRecordingFile(const std::string &msg);
- /*
+ /**
* Whether or not the recorder is in use.
*/
bool isRecording() {return (bool) mStream.is_open();}
- /*
+ /**
* called when the button is pressed
*
* @param event is the event that is generated
diff --git a/src/party.cpp b/src/party.cpp
index d22db55f..33336eb8 100644
--- a/src/party.cpp
+++ b/src/party.cpp
@@ -32,8 +32,7 @@
#include "utils/gettext.h"
#include "utils/strprintf.h"
-Party::Party(ChatWindow *chat, Network *network) :
- mChat(chat),
+Party::Party(Network *network) :
mNetwork(network),
mInviteListener(network, &mInParty)
{
@@ -53,7 +52,7 @@ void Party::respond(const std::string &command, const std::string &args)
}
if (command == "settings")
{
- mChat->chatLog(_("Not yet implemented!"), BY_SERVER);
+ chatWindow->chatLog(_("Not yet implemented!"), BY_SERVER);
return;
/*
MessageOut outMsg(mNetwork);
@@ -62,14 +61,14 @@ void Party::respond(const std::string &command, const std::string &args)
outMsg.writeInt16(0); // Item
*/
}
- mChat->chatLog(_("Party command not known."), BY_SERVER);
+ chatWindow->chatLog(_("Party command not known."), BY_SERVER);
}
void Party::create(const std::string &party)
{
if (party.empty())
{
- mChat->chatLog(_("Party name is missing."), BY_SERVER);
+ chatWindow->chatLog(_("Party name is missing."), BY_SERVER);
return;
}
MessageOut outMsg(mNetwork);
@@ -82,7 +81,7 @@ void Party::leave(const std::string &args)
{
MessageOut outMsg(mNetwork);
outMsg.writeInt16(CMSG_PARTY_LEAVE);
- mChat->chatLog(_("Left party."), BY_SERVER);
+ chatWindow->chatLog(_("Left party."), BY_SERVER);
mInParty = false;
}
@@ -90,12 +89,12 @@ void Party::createResponse(bool ok)
{
if (ok)
{
- mChat->chatLog(_("Party successfully created."), BY_SERVER);
+ chatWindow->chatLog(_("Party successfully created."), BY_SERVER);
mInParty = true;
}
else
{
- mChat->chatLog(_("Could not create party."), BY_SERVER);
+ chatWindow->chatLog(_("Could not create party."), BY_SERVER);
}
}
@@ -104,15 +103,15 @@ void Party::inviteResponse(const std::string &nick, int status)
switch (status)
{
case 0:
- mChat->chatLog(strprintf(_("%s is already a member of a party."),
+ chatWindow->chatLog(strprintf(_("%s is already a member of a party."),
nick.c_str()), BY_SERVER);
break;
case 1:
- mChat->chatLog(strprintf(_("%s refused your invitation."),
+ chatWindow->chatLog(strprintf(_("%s refused your invitation."),
nick.c_str()), BY_SERVER);
break;
case 2:
- mChat->chatLog(strprintf(_("%s is now a member of your party."),
+ chatWindow->chatLog(strprintf(_("%s is now a member of your party."),
nick.c_str()), BY_SERVER);
break;
}
@@ -124,7 +123,7 @@ void Party::invitedAsk(const std::string &nick, int gender,
mPartyName = partyName; /* Quick and nasty - needs redoing */
if (nick.empty())
{
- mChat->chatLog(_("You can\'t have a blank party name!"), BY_SERVER);
+ chatWindow->chatLog(_("You can\'t have a blank party name!"), BY_SERVER);
return;
}
mCreating = false;
@@ -147,7 +146,7 @@ void Party::InviteListener::action(const gcn::ActionEvent &event)
void Party::leftResponse(const std::string &nick)
{
- mChat->chatLog(strprintf(_("%s has left your party."), nick.c_str()),
+ chatWindow->chatLog(strprintf(_("%s has left your party."), nick.c_str()),
BY_SERVER);
}
@@ -159,47 +158,50 @@ void Party::receiveChat(Being *being, const std::string &msg)
}
if (being->getType() != Being::PLAYER)
{
- mChat->chatLog(_("Party chat received, but being is not a player"),
+ chatWindow->chatLog(_("Party chat received, but being is not a player"),
BY_SERVER);
return;
}
being->setSpeech(msg, SPEECH_TIME);
- mChat->chatLog(being->getName() + " : " + msg, BY_PARTY);
+ chatWindow->chatLog(being->getName() + " : " + msg, BY_PARTY);
}
-void Party::help(const std::string &msg)
+void Party::help(const std::string &args)
{
+ // Strip "party " from the front
+ std::string msg = args.substr(6, args.length());
+
if (msg.empty())
{
- mChat->chatLog(_("Command: /party <command> <args>"), BY_SERVER);
- mChat->chatLog(_("where <command> can be one of:"), BY_SERVER);
- mChat->chatLog(_(" /new"), BY_SERVER);
- mChat->chatLog(_(" /create"), BY_SERVER);
- mChat->chatLog(_(" /prefix"), BY_SERVER);
- mChat->chatLog(_(" /leave"), BY_SERVER);
- mChat->chatLog(_("This command implements the partying function."),
+ chatWindow->chatLog(_("Command: /party <command> <args>"), BY_SERVER);
+ chatWindow->chatLog(_("where <command> can be one of:"), BY_SERVER);
+ chatWindow->chatLog(_(" /new"), BY_SERVER);
+ chatWindow->chatLog(_(" /create"), BY_SERVER);
+ chatWindow->chatLog(_(" /prefix"), BY_SERVER);
+ chatWindow->chatLog(_(" /leave"), BY_SERVER);
+ chatWindow->chatLog(_("This command implements the partying function."),
BY_SERVER);
- mChat->chatLog(_("Type /help party <command> for further help."),
+ chatWindow->chatLog(_("Type /help party <command> for further help."),
BY_SERVER);
return;
}
if (msg == "new" || msg == "create")
{
- mChat->chatLog(_("Command: /party new <party-name>"), BY_SERVER);
- mChat->chatLog(_("Command: /party create <party-name>"), BY_SERVER);
- mChat->chatLog(_("These commands create a new party <party-name."),
+ chatWindow->chatLog(_("Command: /party new <party-name>"), BY_SERVER);
+ chatWindow->chatLog(_("Command: /party create <party-name>"), BY_SERVER);
+ chatWindow->chatLog(_("These commands create a new party <party-name."),
BY_SERVER);
return;
}
if (msg == "prefix")
{
- mChat->chatLog(_("Command: /party prefix <prefix-char>"), BY_SERVER);
- mChat->chatLog(_("This command sets the party prefix character."),
+ chatWindow->chatLog(_("Command: /party prefix <prefix-char>"), BY_SERVER);
+ chatWindow->chatLog(_("This command sets the party prefix character."),
BY_SERVER);
- mChat->chatLog(_("Any message preceded by <prefix-char> is sent to "
+ chatWindow->chatLog(_("Any message preceded by <prefix-char> is sent to "
"the party instead of everyone."), BY_SERVER);
- mChat->chatLog(_("Command: /party prefix"), BY_SERVER);
- mChat->chatLog(_("This command reports the current party prefix "
+ chatWindow->chatLog(_("Command: /party prefix"), BY_SERVER);
+ chatWindow->chatLog(_("This command reports the current party prefix "
"character."), BY_SERVER);
return;
}
@@ -207,11 +209,11 @@ void Party::help(const std::string &msg)
//if (msg == "info")
if (msg == "leave")
{
- mChat->chatLog(_("Command: /party leave"), BY_SERVER);
- mChat->chatLog(_("This command causes the player to leave the party."),
+ chatWindow->chatLog(_("Command: /party leave"), BY_SERVER);
+ chatWindow->chatLog(_("This command causes the player to leave the party."),
BY_SERVER);
return;
}
- mChat->chatLog(_("Unknown /party command."), BY_SERVER);
- mChat->chatLog(_("Type /help party for a list of options."), BY_SERVER);
+ chatWindow->chatLog(_("Unknown /party command."), BY_SERVER);
+ chatWindow->chatLog(_("Type /help party for a list of options."), BY_SERVER);
}
diff --git a/src/party.h b/src/party.h
index 0f58b14b..d73b4a0f 100644
--- a/src/party.h
+++ b/src/party.h
@@ -34,7 +34,7 @@ class Network;
class Party
{
public:
- Party(ChatWindow *chat, Network *network);
+ Party(Network *network);
void respond(const std::string &command, const std::string &args);
void create(const std::string &party);
@@ -47,10 +47,9 @@ class Party
void leftResponse(const std::string &nick);
void receiveChat(Being *being, const std::string &msg);
- void help(const std::string &msg);
+ void help(const std::string &args);
private:
- ChatWindow *mChat;
std::string mPartyName;
Network *mNetwork;
bool mInParty;
@@ -73,4 +72,6 @@ class Party
InviteListener mInviteListener;
};
+extern Party *playerParty;
+
#endif