mirror of
https://github.com/cuberite/cuberite.git
synced 2025-01-08 11:57:39 +08:00
Merge branch 'cuberite:master' into Issue5495
This commit is contained in:
commit
1eb0c8b86c
@ -27,6 +27,7 @@ FakeTruth (founder)
|
||||
feyokorenhof
|
||||
Gareth Nelson
|
||||
GefaketHD
|
||||
Griezn (Seppe Degryse)
|
||||
HaoTNN
|
||||
havel06 (Michal Havlíček)
|
||||
hle0
|
||||
|
@ -260,7 +260,7 @@ AString ItemTypeToString(short a_ItemType)
|
||||
|
||||
AString ItemToFullString(const cItem & a_Item)
|
||||
{
|
||||
return fmt::format(FMT_STRING("{}:{} * {}"), ItemToString(a_Item), a_Item.m_ItemDamage, a_Item.m_ItemCount);
|
||||
return fmt::format(FMT_STRING("{}:{} * {:d}"), ItemToString(a_Item), a_Item.m_ItemDamage, a_Item.m_ItemCount);
|
||||
}
|
||||
|
||||
|
||||
|
@ -40,4 +40,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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
AString SerializeSingleValueJsonObject(
|
||||
const AString & a_Key, const AString & a_Value)
|
||||
{
|
||||
Json::Value root;
|
||||
root[a_Key] = a_Value;
|
||||
return JsonUtils::WriteFastString(root);
|
||||
}
|
||||
|
||||
} // namespace JsonUtils
|
||||
|
@ -14,4 +14,7 @@ AString WriteStyledString(const Json::Value & a_Root);
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
@ -229,7 +229,7 @@ void cMultiVersionProtocol::SendDisconnect(cClientHandle & a_Client, const AStri
|
||||
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);
|
||||
cByteBuffer Out(
|
||||
cByteBuffer::GetVarIntSize(PacketID) +
|
||||
|
@ -9,6 +9,7 @@ Implements the 1.14 protocol classes:
|
||||
#include "Globals.h"
|
||||
#include "Protocol_1_14.h"
|
||||
#include "Packetizer.h"
|
||||
#include "JsonUtils.h"
|
||||
#include "../Root.h"
|
||||
#include "../Server.h"
|
||||
#include "../World.h"
|
||||
@ -440,7 +441,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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -313,7 +313,7 @@ void cProtocol_1_8_0::SendChat(const AString & a_Message, eChatType a_Type)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
@ -433,13 +433,13 @@ void cProtocol_1_8_0::SendDisconnect(const AString & a_Reason)
|
||||
case State::Login:
|
||||
{
|
||||
cPacketizer Pkt(*this, pktDisconnectDuringLogin);
|
||||
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), EscapeString(a_Reason)));
|
||||
Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_Reason));
|
||||
break;
|
||||
}
|
||||
case State::Game:
|
||||
{
|
||||
cPacketizer Pkt(*this, pktDisconnectDuringGame);
|
||||
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), EscapeString(a_Reason)));
|
||||
Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_Reason));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
@ -1103,7 +1103,7 @@ void cProtocol_1_8_0::SendPlayerListUpdateDisplayName(const cPlayer & a_Player,
|
||||
else
|
||||
{
|
||||
Pkt.WriteBool(true);
|
||||
Pkt.WriteString(fmt::format(FMT_STRING("{{\"text\":\"{}\"}}"), a_CustomName));
|
||||
Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", a_CustomName));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1659,9 +1659,7 @@ void cProtocol_1_8_0::SendUpdateSign(Vector3i a_BlockPos, const AString & a_Line
|
||||
AString Lines[] = { a_Line1, a_Line2, a_Line3, a_Line4 };
|
||||
for (size_t i = 0; i < ARRAYCOUNT(Lines); i++)
|
||||
{
|
||||
Json::Value RootValue;
|
||||
RootValue["text"] = Lines[i];
|
||||
Pkt.WriteString(JsonUtils::WriteFastString(RootValue));
|
||||
Pkt.WriteString(JsonUtils::SerializeSingleValueJsonObject("text", Lines[i]));
|
||||
}
|
||||
}
|
||||
|
||||
@ -1750,7 +1748,7 @@ void cProtocol_1_8_0::SendWindowOpen(const cWindow & a_Window)
|
||||
cPacketizer Pkt(*this, pktWindowOpen);
|
||||
Pkt.WriteBEUInt8(static_cast<UInt8>(a_Window.GetWindowID()));
|
||||
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())
|
||||
{
|
||||
@ -3138,7 +3136,7 @@ void cProtocol_1_8_0::WriteBlockEntity(cFastNBTWriter & a_Writer, const cBlockEn
|
||||
a_Writer.AddString("CustomName", "@");
|
||||
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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user