diff options
author | Fate <fate-tmw@googlemail.com> | 2008-12-05 23:35:35 -0700 |
---|---|---|
committer | Fate <fate-tmw@googlemail.com> | 2008-12-05 23:35:35 -0700 |
commit | 369e540d6cb78874c4951b66b1668468168f496b (patch) | |
tree | 8545fac5a6b1e0f0858d8fb1c8b12c4eb16f30c6 /src/gui/chat.cpp | |
parent | 9559fdb347054e945940980efdbbe83615ce9733 (diff) | |
download | mana-369e540d6cb78874c4951b66b1668468168f496b.tar.gz mana-369e540d6cb78874c4951b66b1668468168f496b.tar.bz2 mana-369e540d6cb78874c4951b66b1668468168f496b.tar.xz mana-369e540d6cb78874c4951b66b1668468168f496b.zip |
added /w shortcut for whispering
Diffstat (limited to 'src/gui/chat.cpp')
-rw-r--r-- | src/gui/chat.cpp | 64 |
1 files changed, 35 insertions, 29 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); |