Merge commit '4fe144de352434ff6e98a4269777b82e8b03f4d0' into pullstream

This commit is contained in:
Rebekah 2024-02-14 06:32:59 -05:00
commit cbe7385a3b
Signed by: oneechanhax
GPG Key ID: 183EB7902964DAE5
6 changed files with 26 additions and 11 deletions

View File

@ -27,6 +27,7 @@ FakeTruth (founder)
feyokorenhof feyokorenhof
Gareth Nelson Gareth Nelson
GefaketHD GefaketHD
Griezn (Seppe Degryse)
HaoTNN HaoTNN
havel06 (Michal Havlíček) havel06 (Michal Havlíček)
hle0 hle0

View File

@ -56,4 +56,16 @@ bool ParseString(const AString & a_JsonStr, Json::Value & a_Root, AString * a_Er
return Reader->parse(Doc, Doc + a_JsonStr.size(), &a_Root, a_ErrorMsg); return Reader->parse(Doc, Doc + a_JsonStr.size(), &a_Root, a_ErrorMsg);
} }
AString SerializeSingleValueJsonObject(
const AString & a_Key, const AString & a_Value)
{
Json::Value root;
root[a_Key] = a_Value;
return JsonUtils::WriteFastString(root);
}
} // namespace JsonUtils } // namespace JsonUtils

View File

@ -30,4 +30,7 @@ AString WriteStyledString(const Json::Value & a_Root);
bool ParseString(const AString & a_JsonStr, Json::Value & a_Root, AString * a_ErrorMsg = nullptr); bool ParseString(const AString & a_JsonStr, Json::Value & a_Root, AString * a_ErrorMsg = nullptr);
/** Creates a Json string representing an object with the specified single value. */
extern AString SerializeSingleValueJsonObject(const AString & a_Key, const AString & a_Value);
} }

View File

@ -245,7 +245,7 @@ void cMultiVersionProtocol::SendDisconnect(cClientHandle & a_Client, const AStri
return; return;
} }
const AString Message = fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), EscapeString(a_Reason)); const AString Message = JsonUtils::SerializeSingleValueJsonObject("text", a_Reason);
const auto PacketID = GetPacketID(cProtocol::ePacketType::pktDisconnectDuringLogin); const auto PacketID = GetPacketID(cProtocol::ePacketType::pktDisconnectDuringLogin);
cByteBuffer Out( cByteBuffer Out(
cByteBuffer::GetVarIntSize(PacketID) + cByteBuffer::GetVarIntSize(PacketID) +

View File

@ -25,6 +25,7 @@ Implements the 1.14 protocol classes:
#include "Globals.h" #include "Globals.h"
#include "Protocol_1_14.h" #include "Protocol_1_14.h"
#include "Packetizer.h" #include "Packetizer.h"
#include "JsonUtils.h"
#include "../Root.h" #include "../Root.h"
#include "../Server.h" #include "../Server.h"
#include "../World.h" #include "../World.h"
@ -456,7 +457,7 @@ void cProtocol_1_14::SendWindowOpen(const cWindow & a_Window)
} }
} }
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), a_Window.GetWindowTitle())); Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_Window.GetWindowTitle()));
} }
} }

View File

@ -329,7 +329,7 @@ void cProtocol_1_8_0::SendChat(const AString & a_Message, eChatType a_Type)
{ {
ASSERT(m_State == 3); // In game mode? ASSERT(m_State == 3); // In game mode?
SendChatRaw(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), EscapeString(a_Message)), a_Type); SendChatRaw(JsonUtils::SerializeSingleValueJsonObject("text", a_Message), a_Type);
} }
@ -449,13 +449,13 @@ void cProtocol_1_8_0::SendDisconnect(const AString & a_Reason)
case State::Login: case State::Login:
{ {
cPacketizer Pkt(*this, pktDisconnectDuringLogin); cPacketizer Pkt(*this, pktDisconnectDuringLogin);
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), EscapeString(a_Reason))); Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_Reason));
break; break;
} }
case State::Game: case State::Game:
{ {
cPacketizer Pkt(*this, pktDisconnectDuringGame); cPacketizer Pkt(*this, pktDisconnectDuringGame);
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), EscapeString(a_Reason))); Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_Reason));
break; break;
} }
default: default:
@ -1119,7 +1119,7 @@ void cProtocol_1_8_0::SendPlayerListUpdateDisplayName(const cPlayer & a_Player,
else else
{ {
Pkt.WriteBool(true); Pkt.WriteBool(true);
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), a_CustomName)); Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_CustomName));
} }
} }
@ -1675,9 +1675,7 @@ void cProtocol_1_8_0::SendUpdateSign(Vector3i a_BlockPos, const AString & a_Line
AString Lines[] = { a_Line1, a_Line2, a_Line3, a_Line4 }; AString Lines[] = { a_Line1, a_Line2, a_Line3, a_Line4 };
for (size_t i = 0; i < ARRAYCOUNT(Lines); i++) for (size_t i = 0; i < ARRAYCOUNT(Lines); i++)
{ {
Json::Value RootValue; Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", Lines[i]));
RootValue["text"] = Lines[i];
Pkt.WriteString(JsonUtils::WriteFastString(RootValue));
} }
} }
@ -1766,7 +1764,7 @@ void cProtocol_1_8_0::SendWindowOpen(const cWindow & a_Window)
cPacketizer Pkt(*this, pktWindowOpen); cPacketizer Pkt(*this, pktWindowOpen);
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Window.GetWindowID())); Pkt.WriteBEUInt8(static_cast<UInt8>(a_Window.GetWindowID()));
Pkt.WriteString(a_Window.GetWindowTypeName()); Pkt.WriteString(a_Window.GetWindowTypeName());
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), a_Window.GetWindowTitle())); Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_Window.GetWindowTitle()));
switch (a_Window.GetWindowType()) switch (a_Window.GetWindowType())
{ {
@ -3154,7 +3152,7 @@ void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEn
a_Writer.AddString("CustomName", "@"); a_Writer.AddString("CustomName", "@");
if (!CommandBlockEntity.GetLastOutput().empty()) if (!CommandBlockEntity.GetLastOutput().empty())
{ {
a_Writer.AddString("LastOutput", fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), CommandBlockEntity.GetLastOutput())); a_Writer.AddString("LastOutput", JsonUtils::SerializeSingleValueJsonObject("text", CommandBlockEntity.GetLastOutput()));
} }
break; break;
} }