1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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
This commit is contained in:
Loïc Blot 2017-07-16 10:47:31 +02:00 committed by GitHub
parent ecbc972ea6
commit 7ddf67aa14
16 changed files with 251 additions and 51 deletions

View file

@ -47,6 +47,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "guiscalingfilter.h"
#include "script/scripting_client.h"
#include "game.h"
#include "chatmessage.h"
extern gui::IGUIEnvironment* guienv;
@ -1518,12 +1519,34 @@ u16 Client::getHP()
return player->hp;
}
bool Client::getChatMessage(std::wstring &message)
bool Client::getChatMessage(std::wstring &res)
{
if(m_chat_queue.size() == 0)
if (m_chat_queue.empty())
return false;
message = m_chat_queue.front();
ChatMessage *chatMessage = m_chat_queue.front();
m_chat_queue.pop();
res = L"";
switch (chatMessage->type) {
case CHATMESSAGE_TYPE_RAW:
case CHATMESSAGE_TYPE_ANNOUNCE:
case CHATMESSAGE_TYPE_SYSTEM:
res = chatMessage->message;
break;
case CHATMESSAGE_TYPE_NORMAL: {
if (!chatMessage->sender.empty())
res = L"<" + chatMessage->sender + L"> " + chatMessage->message;
else
res = chatMessage->message;
break;
}
default:
break;
}
delete chatMessage;
return true;
}
@ -1542,14 +1565,13 @@ void Client::typeChatMessage(const std::wstring &message)
sendChatMessage(message);
// Show locally
if (message[0] != L'/')
{
if (message[0] != L'/') {
// compatibility code
if (m_proto_ver < 29) {
LocalPlayer *player = m_env.getLocalPlayer();
assert(player);
std::wstring name = narrow_to_wide(player->getName());
pushToChatQueue((std::wstring)L"<" + name + L"> " + message);
pushToChatQueue(new ChatMessage(CHATMESSAGE_TYPE_NORMAL, message, name));
}
}
}
@ -1806,7 +1828,8 @@ void Client::makeScreenshot()
} else {
sstr << "Failed to save screenshot '" << filename << "'";
}
pushToChatQueue(narrow_to_wide(sstr.str()));
pushToChatQueue(new ChatMessage(CHATMESSAGE_TYPE_SYSTEM,
narrow_to_wide(sstr.str())));
infostream << sstr.str() << std::endl;
image->drop();
}