Remove max 80 words limit now we use uint16_t for wide char

This commit is contained in:
Benau 2018-05-01 12:42:59 +08:00
parent eb9f5b3fb3
commit ac54ee8888
4 changed files with 29 additions and 9 deletions

View File

@ -141,6 +141,28 @@ public:
/** Allows to read a buffer from the beginning again. */
void reset() { m_current_offset = 0; }
// ------------------------------------------------------------------------
BareNetworkString& encodeString16(const irr::core::stringw& value)
{
uint8_t str_len = (uint8_t)value.size();
if (value.size() > 255)
str_len = 255;
addUInt8(str_len);
for (unsigned i = 0; i < str_len; i++)
addUInt16((uint16_t)value[i]);
return *this;
}
// ------------------------------------------------------------------------
int decodeString16(irr::core::stringw* out) const
{
unsigned str_len = getUInt8();
for (unsigned i = 0; i < str_len; i++)
{
uint16_t c = getUInt16();
out->append((wchar_t)c);
}
return str_len + 1;
}
// ------------------------------------------------------------------------
BareNetworkString& encodeString(const std::string &value);
BareNetworkString& encodeString(const irr::core::stringw &value);
int decodeString(std::string *out) const;

View File

@ -544,13 +544,12 @@ void ClientLobby::handleChat(Event* event)
if (!UserConfigParams::m_lobby_chat)
return;
SFXManager::get()->quickSound("plopp");
std::string message;
event->data().decodeString(&message);
Log::info("ClientLobby", "%s", message.c_str());
core::stringw message;
event->data().decodeString16(&message);
Log::info("ClientLobby", "%s", StringUtils::wideToUtf8(message).c_str());
if (message.size() > 0)
{
NetworkingLobby::getInstance()->addMoreServerInfo(
StringUtils::utf8ToWide(message));
NetworkingLobby::getInstance()->addMoreServerInfo(message);
}
} // handleChat

View File

@ -169,12 +169,12 @@ void ServerLobby::handleChat(Event* event)
return;
}
core::stringw message;
event->data().decodeStringW(&message);
event->data().decodeString16(&message);
if (message.size() > 0)
{
NetworkString* chat = getNetworkString();
chat->setSynchronous(true);
chat->addUInt8(LE_CHAT).encodeString(message);
chat->addUInt8(LE_CHAT).encodeString16(message);
sendMessageToPeersChangingToken(chat, /*reliable*/true);
delete chat;
}

View File

@ -258,8 +258,7 @@ void NetworkingLobby::sendChat(irr::core::stringw text)
name = PlayerManager::getCurrentOnlineUserName();
else
name = player->getName();
// Max 80 words
chat.encodeString((name + L": " + text).subString(0, 80));
chat.encodeString16(name + L": " + text);
STKHost::get()->sendToServer(&chat, true);
}