summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-10 21:41:02 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2008-04-10 21:41:02 +0000
commitc67fa724ddbdc4ef3a98920d7b92816ecd6fc2be (patch)
treeb5c779854531e24a65e284736002aa1a0198c7dc /src
parenta191c063d77dfe5ee7e79e55a7106ad505d8f493 (diff)
downloadmana-c67fa724ddbdc4ef3a98920d7b92816ecd6fc2be.tar.gz
mana-c67fa724ddbdc4ef3a98920d7b92816ecd6fc2be.tar.bz2
mana-c67fa724ddbdc4ef3a98920d7b92816ecd6fc2be.tar.xz
mana-c67fa724ddbdc4ef3a98920d7b92816ecd6fc2be.zip
Implemented support for whispering to other players (patch by peavey).
Diffstat (limited to 'src')
-rw-r--r--src/gui/chat.cpp30
-rw-r--r--src/gui/chat.h2
-rw-r--r--src/net/chathandler.cpp34
-rw-r--r--src/net/protocol.h3
4 files changed, 64 insertions, 5 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 8fe1a67a..179fca2a 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -276,11 +276,12 @@ ChatWindow::chatSend(const std::string &nick, std::string msg)
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);
- chatLog("/clear : Clears this window", 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);
+ chatLog("/clear: Clears this window", BY_SERVER);
+ chatLog("/whisper: Whisper <nick> <message> - sends a private <message> to <nick>", BY_SERVER);
}
else if (msg.substr(0, IS_WHERE_LENGTH) == IS_WHERE)
{
@@ -295,6 +296,25 @@ ChatWindow::chatSend(const std::string &nick, std::string msg)
{
mTextOutput->clearRows();
}
+ else if (msg.substr(0, IS_WHISPER_LENGTH) == IS_WHISPER)
+ {
+ std::string recvnick = "";
+ msg.erase(0, IS_WHISPER_LENGTH + 1);
+
+ const std::string::size_type pos = msg.find(" ");
+ if (pos != std::string::npos) {
+ recvnick = msg.substr(0, pos);
+ msg.erase(0, pos + 1);
+ }
+
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(CMSG_CHAT_WHISPER);
+ outMsg.writeInt16(msg.length() + 28);
+ outMsg.writeString(recvnick, 24);
+ outMsg.writeString(msg, msg.length());
+
+ chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER);
+ }
else
{
chatLog("Unknown command", BY_SERVER);
diff --git a/src/gui/chat.h b/src/gui/chat.h
index cbfc8a63..7dd68604 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -58,6 +58,8 @@ class ScrollArea;
#define IS_WHO_LENGTH 4
#define IS_CLEAR "/clear"
#define IS_CLEAR_LENGTH 6
+#define IS_WHISPER "/whisper"
+#define IS_WHISPER_LENGTH 8
/**
* gets in between usernick and message text depending on
diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp
index dbbb84a5..d2e1361e 100644
--- a/src/net/chathandler.cpp
+++ b/src/net/chathandler.cpp
@@ -45,6 +45,8 @@ ChatHandler::ChatHandler()
static const Uint16 _messages[] = {
SMSG_BEING_CHAT,
SMSG_PLAYER_CHAT,
+ SMSG_WHISPER,
+ SMSG_WHISPER_RESPONSE,
SMSG_GM_CHAT,
SMSG_WHO_ANSWER,
0x10c, // MVP
@@ -57,10 +59,42 @@ void ChatHandler::handleMessage(MessageIn *msg)
{
Being *being;
std::string chatMsg;
+ std::string nick;
Sint16 chatMsgLength;
switch (msg->getId())
{
+ case SMSG_WHISPER_RESPONSE:
+ switch (msg->readInt8())
+ {
+ case 0x00:
+ // comment out since we'll local echo in chat.cpp instead, then only report failures
+ //chatWindow->chatLog("Whisper sent", BY_SERVER);
+ break;
+ case 0x01:
+ chatWindow->chatLog("Whisper could not be sent, user is offline", BY_SERVER);
+ break;
+ case 0x02:
+ chatWindow->chatLog("Whisper could not be sent, ignored by user", BY_SERVER);
+ break;
+ }
+ break;
+
+ // Received whisper
+ case SMSG_WHISPER:
+ chatMsgLength = msg->readInt16() - 28;
+ nick = msg->readString(24);
+
+ if (chatMsgLength <= 0)
+ break;
+
+ chatMsg = msg->readString(chatMsgLength);
+ if (nick != "Server")
+ chatMsg = nick + " : " + chatMsg;
+ chatWindow->chatLog(chatMsg, (nick == "Server") ? BY_SERVER : ACT_WHISPER);
+
+ break;
+
// Received speech from being
case SMSG_BEING_CHAT:
chatMsgLength = msg->readInt16() - 8;
diff --git a/src/net/protocol.h b/src/net/protocol.h
index f755eda4..1e76ce1c 100644
--- a/src/net/protocol.h
+++ b/src/net/protocol.h
@@ -72,6 +72,8 @@
#define SMSG_NPC_BUY_RESPONSE 0x00ca
#define SMSG_NPC_SELL_RESPONSE 0x00cb
#define SMSG_PLAYER_CHAT 0x008e /**< Player talks */
+#define SMSG_WHISPER 0x0097 /**< Whisper Recieved */
+#define SMSG_WHISPER_RESPONSE 0x0098
#define SMSG_GM_CHAT 0x009a /**< GM announce */
#define SMSG_WALK_RESPONSE 0x0087
#define SMSG_TRADE_REQUEST 0x00e5 /**< Receiving a request to trade */
@@ -89,6 +91,7 @@
#define CMSG_NPC_BUY_REQUEST 0x00c8
#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5
#define CMSG_CHAT_MESSAGE 0x008c
+#define CMSG_CHAT_WHISPER 0x0096
#define CMSG_NPC_LIST_CHOICE 0x00b8
#define CMSG_NPC_NEXT_REQUEST 0x00b9
#define CMSG_NPC_SELL_REQUEST 0x00c9