diff options
author | Loïc Blot <nerzhul@users.noreply.github.com> | 2017-07-16 10:47:31 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-16 10:47:31 +0200 |
commit | 7ddf67aa1478813e12a5fcdfb4986b9e5adfe62f (patch) | |
tree | 0bbbee7ed9470e0de149ec9bdaf6a51693ec0e22 /src/network/clientpackethandler.cpp | |
parent | ecbc972ea6a2371d64b1d9c9576d31be36b8ae6a (diff) | |
download | minetest-7ddf67aa1478813e12a5fcdfb4986b9e5adfe62f.tar.gz minetest-7ddf67aa1478813e12a5fcdfb4986b9e5adfe62f.tar.bz2 minetest-7ddf67aa1478813e12a5fcdfb4986b9e5adfe62f.zip |
Chat protocol rewrite (#5117)
* New TOCLIENT_CHAT_MESSAGE packet
* Rename old packet to TOCLIENT_CHAT_MESSAGE_OLD for compat
* Handle TOCLIENT_CHAT_MESSAGE new structure client side
* Client chat queue should use a specific object
* SendChatMessage: use the right packet depending on protocol version (not complete yet)
* Add chatmessage(type) objects and handle them client side (partially)
* Use ChatMessage instead of std::wstring server side
* Update with timestamp support
Diffstat (limited to 'src/network/clientpackethandler.cpp')
-rw-r--r-- | src/network/clientpackethandler.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/network/clientpackethandler.cpp b/src/network/clientpackethandler.cpp index e6f0d7092..bb4db6f47 100644 --- a/src/network/clientpackethandler.cpp +++ b/src/network/clientpackethandler.cpp @@ -20,6 +20,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "client.h" #include "util/base64.h" +#include "chatmessage.h" #include "clientmedia.h" #include "log.h" #include "map.h" @@ -142,7 +143,9 @@ void Client::handleCommand_AcceptSudoMode(NetworkPacket* pkt) } void Client::handleCommand_DenySudoMode(NetworkPacket* pkt) { - pushToChatQueue(L"Password change denied. Password NOT changed."); + ChatMessage *chatMessage = new ChatMessage(CHATMESSAGE_TYPE_SYSTEM, + L"Password change denied. Password NOT changed."); + pushToChatQueue(chatMessage); // reset everything and be sad deleteAuthData(); } @@ -395,7 +398,7 @@ void Client::handleCommand_TimeOfDay(NetworkPacket* pkt) << " dr=" << dr << std::endl; } -void Client::handleCommand_ChatMessage(NetworkPacket* pkt) +void Client::handleCommand_ChatMessageOld(NetworkPacket *pkt) { /* u16 command @@ -413,8 +416,43 @@ void Client::handleCommand_ChatMessage(NetworkPacket* pkt) } // If chat message not consummed by client lua API + // @TODO send this to CSM using ChatMessage object if (!moddingEnabled() || !m_script->on_receiving_message(wide_to_utf8(message))) { - pushToChatQueue(message); + pushToChatQueue(new ChatMessage(message)); + } +} + +void Client::handleCommand_ChatMessage(NetworkPacket *pkt) +{ + /* + u8 version + u8 message_type + u16 sendername length + wstring sendername + u16 length + wstring message + */ + + ChatMessage *chatMessage = new ChatMessage(); + u8 version, message_type; + *pkt >> version >> message_type; + + if (version != 1 || message_type >= CHATMESSAGE_TYPE_MAX) { + delete chatMessage; + return; + } + + *pkt >> chatMessage->sender >> chatMessage->message >> chatMessage->timestamp; + + chatMessage->type = (ChatMessageType) message_type; + + // @TODO send this to CSM using ChatMessage object + if (!moddingEnabled() || !m_script->on_receiving_message( + wide_to_utf8(chatMessage->message))) { + pushToChatQueue(chatMessage); + } else { + // Message was consumed by CSM and should not handled by client, destroying + delete chatMessage; } } |