summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/chat.cpp64
-rw-r--r--src/gui/chat.h29
2 files changed, 52 insertions, 41 deletions
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index 71d36e97..5817adbd 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -247,6 +247,38 @@ ChatWindow::isInputFocused()
}
void
+ChatWindow::whisper(const std::string &nick, std::string msg, int prefixlen)
+{
+ std::string recvnick = "";
+ msg.erase(0, prefixlen + 1);
+
+ 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);
+ }
+ }
+
+ 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);
+}
+
+void
ChatWindow::chatSend(const std::string &nick, std::string msg)
{
/* Some messages are managed client side, while others
@@ -307,35 +339,9 @@ 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);
-
- 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);
- }
- }
-
- 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);
- }
+ whisper(nick, msg, IS_WHISPER_LENGTH + 1);
+ else if (msg.substr(0, IS_SHORT_WHISPER_LENGTH) == IS_SHORT_WHISPER)
+ whisper(nick, msg, IS_SHORT_WHISPER_LENGTH + 1);
else
{
chatLog("Unknown command", BY_SERVER);
diff --git a/src/gui/chat.h b/src/gui/chat.h
index 6e412bf6..76a8146c 100644
--- a/src/gui/chat.h
+++ b/src/gui/chat.h
@@ -46,18 +46,20 @@ class ScrollArea;
#define BY_LOGGER 6
-#define IS_ANNOUNCE "/announce "
-#define IS_ANNOUNCE_LENGTH 10
-#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
-#define IS_CLEAR "/clear"
-#define IS_CLEAR_LENGTH 6
-#define IS_WHISPER "/whisper"
-#define IS_WHISPER_LENGTH 8
+#define IS_ANNOUNCE "/announce "
+#define IS_ANNOUNCE_LENGTH 10
+#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
+#define IS_CLEAR "/clear"
+#define IS_CLEAR_LENGTH 6
+#define IS_WHISPER "/whisper"
+#define IS_WHISPER_LENGTH 8
+#define IS_SHORT_WHISPER "/w"
+#define IS_SHORT_WHISPER_LENGTH 2
/**
* gets in between usernick and message text depending on
@@ -219,6 +221,9 @@ class ChatWindow : public Window, public gcn::ActionListener,
Network *mNetwork;
bool mTmpVisible;
+ void
+ whisper(const std::string &nick, std::string msg, int prefixlen);
+
/** One item in the chat log */
struct CHATLOG
{