summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorEugenio Favalli <elvenprogrammer@gmail.com>2006-01-03 17:54:26 +0000
committerEugenio Favalli <elvenprogrammer@gmail.com>2006-01-03 17:54:26 +0000
commit65ef705d73144167aa6e3eeef87fd55a691fc9e0 (patch)
tree1d4884c74c177a125d444a81554730693695c346 /src/gui
parent08310d2bad4f7d2f00ef506630a350bff2f4a951 (diff)
downloadmana-client-65ef705d73144167aa6e3eeef87fd55a691fc9e0.tar.gz
mana-client-65ef705d73144167aa6e3eeef87fd55a691fc9e0.tar.bz2
mana-client-65ef705d73144167aa6e3eeef87fd55a691fc9e0.tar.xz
mana-client-65ef705d73144167aa6e3eeef87fd55a691fc9e0.zip
Enabled some /commands.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chat.cpp54
-rw-r--r--src/gui/chat.h8
2 files changed, 48 insertions, 14 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 91b6be91..748f4848 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -32,15 +32,16 @@
#include "chatinput.h"
#include "scrollarea.h"
-#include "../playerinfo.h"
-#include "../log.h"
-
+#include "../game.h"
#include "../graphics.h"
-extern Graphics *graphics;
+#include "../log.h"
+#include "../playerinfo.h"
#include "../net/messageout.h"
#include "../net/protocol.h"
+extern Graphics *graphics;
+
ChatWindow::ChatWindow(const std::string &logfile):
Window(""),
mTmpVisible(false)
@@ -194,7 +195,6 @@ ChatWindow::action(const std::string& eventId)
if (eventId == "chatinput")
{
std::string message = chatInput->getText();
- printf("Message: %s\n", message.c_str());
if (message.length() > 0) {
// If message different from previous, put it in the history
@@ -253,20 +253,50 @@ ChatWindow::isFocused()
void
ChatWindow::chatSend(std::string nick, std::string msg)
{
- short packetId = CMSG_CHAT_MESSAGE;
-
- // prepare command
- if (msg.substr(0, 1) == "/") {
- // prepare ordinary message
- chatLog("Sorry but /commands are not available yet", BY_SERVER);
+ // Prepare command
+ if (msg.substr(0, 1) == "/")
+ {
+ /* 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.substr(0, IS_ANNOUNCE_LENGTH) == IS_ANNOUNCE)
+ {
+ msg.erase(0, IS_ANNOUNCE_LENGTH);
+ MessageOut outMsg;
+ outMsg.writeInt16(0x0099);
+ outMsg.writeInt16(msg.length() + 4);
+ outMsg.writeString(msg, msg.length());
+ }
+ else if (msg.substr(0, IS_HELP_LENGTH) == IS_HELP)
+ {
+ chatLog("-- Help --", BY_SERVER);
+ chatLog("/help : Display this help.", BY_SERVER);
+ chatLog("/announce : Global announcement (GM only)", BY_SERVER);
+ chatLog("/where : Display map name", BY_SERVER);
+ chatLog("/who : Display number of online users", BY_SERVER);
+ }
+ else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE)
+ {
+ chatLog(map_path, BY_SERVER);
+ }
+ else if (msg.substr(0, IS_WHO_LENGTH) == IS_WHO)
+ {
+ MessageOut outMsg;
+ outMsg.writeInt16(0x00c1);
+ }
+ else
+ {
+ chatLog("Unknown command", BY_SERVER);
+ }
}
+ // Prepare ordinary message
else {
nick += " : ";
nick += msg;
msg = nick;
MessageOut outMsg;
- outMsg.writeInt16(packetId);
+ outMsg.writeInt16(CMSG_CHAT_MESSAGE);
outMsg.writeInt16(msg.length() + 4);
outMsg.writeString(msg, msg.length());
}
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 80189665..5b470e27 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -48,8 +48,12 @@ class ScrollArea;
#define IS_ANNOUNCE "/announce "
#define IS_ANNOUNCE_LENGTH 10
-#define IS_WHERE "/where "
-#define IS_WHERE_LENGTH 7
+#define IS_HELP "/help"
+#define IS_HELP_LENGTH 5
+#define IS_WHERE "/where"
+#define IS_WHERE_LENGTH 6
+#define IS_WHO "/who"
+#define IS_WHO_LENGTH 4
/**
* gets in between usernick and message text depending on