diff options
author | peterbell10 <peterbell10@live.co.uk> | 2020-05-09 16:51:15 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-09 16:51:15 +0200 |
commit | e6634ed26c50e99f6ccd285235fe477cb4168b06 (patch) | |
tree | b533a69db545835a886bcd8c5b05609b4c830d11 /src/Protocol | |
parent | Upgrade to C++17 [CI] (#4716) (diff) | |
download | cuberite-e6634ed26c50e99f6ccd285235fe477cb4168b06.tar cuberite-e6634ed26c50e99f6ccd285235fe477cb4168b06.tar.gz cuberite-e6634ed26c50e99f6ccd285235fe477cb4168b06.tar.bz2 cuberite-e6634ed26c50e99f6ccd285235fe477cb4168b06.tar.lz cuberite-e6634ed26c50e99f6ccd285235fe477cb4168b06.tar.xz cuberite-e6634ed26c50e99f6ccd285235fe477cb4168b06.tar.zst cuberite-e6634ed26c50e99f6ccd285235fe477cb4168b06.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Protocol/Authenticator.cpp | 4 | ||||
-rw-r--r-- | src/Protocol/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/Protocol/MojangAPI.cpp | 22 | ||||
-rw-r--r-- | src/Protocol/ProtocolRecognizer.cpp | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_10.cpp | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_11.cpp | 7 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_12.cpp | 10 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_13.cpp | 4 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_8.cpp | 13 | ||||
-rw-r--r-- | src/Protocol/Protocol_1_9.cpp | 23 |
10 files changed, 41 insertions, 52 deletions
diff --git a/src/Protocol/Authenticator.cpp b/src/Protocol/Authenticator.cpp index 85c5c920a..995ba1394 100644 --- a/src/Protocol/Authenticator.cpp +++ b/src/Protocol/Authenticator.cpp @@ -9,6 +9,7 @@ #include "../UUID.h" #include "../IniFile.h" +#include "../JsonUtils.h" #include "json/json.h" #include "../mbedTLS++/BlockingSslClientSocket.h" @@ -185,8 +186,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S return false; } Json::Value root; - Json::Reader reader; - if (!reader.parse(Response, root, false)) + if (!JsonUtils::ParseString(Response, root)) { LOGWARNING("cAuthenticator: Cannot parse received data (authentication) to JSON!"); return false; diff --git a/src/Protocol/CMakeLists.txt b/src/Protocol/CMakeLists.txt index f2169ce86..0f22e531f 100644 --- a/src/Protocol/CMakeLists.txt +++ b/src/Protocol/CMakeLists.txt @@ -35,5 +35,5 @@ SET (HDRS if (NOT MSVC) add_library(Protocol ${SRCS} ${HDRS}) - target_link_libraries(Protocol fmt::fmt) + target_link_libraries(Protocol fmt::fmt SQLiteCpp) endif() diff --git a/src/Protocol/MojangAPI.cpp b/src/Protocol/MojangAPI.cpp index be6ee35e2..8a3868ecc 100644 --- a/src/Protocol/MojangAPI.cpp +++ b/src/Protocol/MojangAPI.cpp @@ -8,6 +8,7 @@ #include "SQLiteCpp/Database.h" #include "SQLiteCpp/Statement.h" #include "../IniFile.h" +#include "../JsonUtils.h" #include "json/json.h" #include "../mbedTLS++/BlockingSslClientSocket.h" #include "../mbedTLS++/SslConfig.h" @@ -514,7 +515,7 @@ void cMojangAPI::LoadCachesFromDisk(void) try { // Open up the SQLite DB: - SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); + SQLite::Database db("MojangAPI.sqlite", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); @@ -572,7 +573,7 @@ void cMojangAPI::SaveCachesToDisk(void) try { // Open up the SQLite DB: - SQLite::Database db("MojangAPI.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE); + SQLite::Database db("MojangAPI.sqlite", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE); db.exec("CREATE TABLE IF NOT EXISTS PlayerNameToUUID (PlayerName, UUID, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); @@ -670,8 +671,7 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery) root.append(req); } // for itr - a_PlayerNames[] a_NamesToQuery.erase(a_NamesToQuery.begin(), itr); - Json::FastWriter Writer; - AString RequestBody = Writer.write(root); + auto RequestBody = JsonUtils::WriteFastString(root); // Create the HTTP request: AString Request; @@ -712,11 +712,11 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery) Response.erase(0, idxHeadersEnd + 4); // Parse the returned string into Json: - Json::Reader reader; - if (!reader.parse(Response, root, false) || !root.isArray()) + AString ParseError; + if (!JsonUtils::ParseString(Response, root, &ParseError) || !root.isArray()) { - LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __FUNCTION__, reader.getFormattedErrorMessages().c_str()); - LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); + LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __FUNCTION__, ParseError); + LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16)); continue; } @@ -822,11 +822,11 @@ void cMojangAPI::QueryUUIDToProfile(const cUUID & a_UUID) Response.erase(0, idxHeadersEnd + 4); // Parse the returned string into Json: - Json::Reader reader; Json::Value root; - if (!reader.parse(Response, root, false) || !root.isObject()) + AString ParseError; + if (!JsonUtils::ParseString(Response, root, &ParseError) || !root.isObject()) { - LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __FUNCTION__, reader.getFormattedErrorMessages().c_str()); + LOGWARNING("%s failed: Cannot parse received data (NameToUUID) to JSON: \"%s\"", __FUNCTION__, ParseError); LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str()); return; } diff --git a/src/Protocol/ProtocolRecognizer.cpp b/src/Protocol/ProtocolRecognizer.cpp index ddc1aaf93..73f8e0ff1 100644 --- a/src/Protocol/ProtocolRecognizer.cpp +++ b/src/Protocol/ProtocolRecognizer.cpp @@ -19,6 +19,7 @@ #include "../Server.h" #include "../World.h" #include "../ChatColor.h" +#include "../JsonUtils.h" #include "../Bindings/PluginManager.h" @@ -1222,8 +1223,7 @@ void cProtocolRecognizer::HandlePacketStatusRequest(void) ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); } - Json::FastWriter Writer; - AString Response = Writer.write(ResponseValue); + AString Response = JsonUtils::WriteFastString(ResponseValue); cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp index 83df39a6c..1ab412839 100644 --- a/src/Protocol/Protocol_1_10.cpp +++ b/src/Protocol/Protocol_1_10.cpp @@ -16,6 +16,7 @@ Implements the 1.10 protocol classes: #include "../Root.h" #include "../Server.h" #include "../ClientHandle.h" +#include "../JsonUtils.h" #include "../WorldStorage/FastNBT.h" @@ -375,8 +376,7 @@ void cProtocol_1_10_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); } - Json::FastWriter Writer; - AString Response = Writer.write(ResponseValue); + AString Response = JsonUtils::WriteFastString(ResponseValue); cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp index b12b45814..785b8f271 100644 --- a/src/Protocol/Protocol_1_11.cpp +++ b/src/Protocol/Protocol_1_11.cpp @@ -41,6 +41,7 @@ Implements the 1.11 protocol classes: #include "../Server.h" #include "../ClientHandle.h" #include "../CompositeChat.h" +#include "../JsonUtils.h" #include "../Bindings/PluginManager.h" @@ -642,9 +643,8 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) } // Serialize the response into a packet: - Json::FastWriter Writer; cPacketizer Pkt(*this, pktStatusResponse); - Pkt.WriteString(Writer.write(ResponseValue)); + Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue)); } @@ -1265,7 +1265,6 @@ void cProtocol_1_11_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) } // Serialize the response into a packet: - Json::FastWriter Writer; cPacketizer Pkt(*this, pktStatusResponse); - Pkt.WriteString(Writer.write(ResponseValue)); + Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue)); } diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp index d2e7b2071..dba85435b 100644 --- a/src/Protocol/Protocol_1_12.cpp +++ b/src/Protocol/Protocol_1_12.cpp @@ -26,6 +26,7 @@ Implements the 1.12 protocol classes: #include "../Server.h" #include "../ClientHandle.h" #include "../Bindings/PluginManager.h" +#include "../JsonUtils.h" @@ -361,9 +362,8 @@ void cProtocol_1_12::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) } // Serialize the response into a packet: - Json::FastWriter Writer; cPacketizer Pkt(*this, pktStatusResponse); - Pkt.WriteString(Writer.write(ResponseValue)); + Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue)); } @@ -1220,9 +1220,8 @@ void cProtocol_1_12_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) } // Serialize the response into a packet: - Json::FastWriter Writer; cPacketizer Pkt(*this, pktStatusResponse); - Pkt.WriteString(Writer.write(ResponseValue)); + Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue)); } @@ -1378,9 +1377,8 @@ void cProtocol_1_12_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) } // Serialize the response into a packet: - Json::FastWriter Writer; cPacketizer Pkt(*this, pktStatusResponse); - Pkt.WriteString(Writer.write(ResponseValue)); + Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue)); } diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp index e7de8158d..fc048fe70 100644 --- a/src/Protocol/Protocol_1_13.cpp +++ b/src/Protocol/Protocol_1_13.cpp @@ -27,6 +27,7 @@ Implements the 1.13 protocol classes: #include "../Root.h" #include "../Server.h" #include "../World.h" +#include "../JsonUtils.h" #include "../Bindings/PluginManager.h" @@ -253,9 +254,8 @@ void cProtocol_1_13::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) } // Serialize the response into a packet: - Json::FastWriter Writer; cPacketizer Pkt(*this, pktStatusResponse); - Pkt.WriteString(Writer.write(ResponseValue)); + Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue)); } diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp index cc108fb69..9f149f643 100644 --- a/src/Protocol/Protocol_1_8.cpp +++ b/src/Protocol/Protocol_1_8.cpp @@ -24,6 +24,7 @@ Implements the 1.8 protocol classes: #include "../Statistics.h" #include "../UUID.h" #include "../World.h" +#include "../JsonUtils.h" #include "../WorldStorage/FastNBT.h" #include "../WorldStorage/EnchantmentSerializer.h" @@ -138,8 +139,7 @@ cProtocol_1_8_0::cProtocol_1_8_0(cClientHandle * a_Client, const AString & a_Ser m_Client->SetUUID(UUID); Json::Value root; - Json::Reader reader; - if (!reader.parse(Params[3], root)) + if (!JsonUtils::ParseString(Params[3], root)) { LOGERROR("Unable to parse player properties: '%s'", Params[3]); } @@ -1561,13 +1561,12 @@ void cProtocol_1_8_0::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c cPacketizer Pkt(*this, pktUpdateSign); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); - Json::StyledWriter JsonWriter; 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(JsonWriter.write(RootValue).c_str()); + Pkt.WriteString(JsonUtils::WriteFastString(RootValue)); } } @@ -2275,8 +2274,7 @@ void cProtocol_1_8_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); } - Json::FastWriter Writer; - AString Response = Writer.write(ResponseValue); + auto Response = JsonUtils::WriteFastString(ResponseValue); cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); @@ -2741,11 +2739,10 @@ void cProtocol_1_8_0::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer) AString Lines[4]; Json::Value root; - Json::Reader reader; for (int i = 0; i < 4; i++) { HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line); - if (reader.parse(Line, root, false)) + if (JsonUtils::ParseString(Line, root)) { Lines[i] = root.asString(); } diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp index ff62df242..49d5e876b 100644 --- a/src/Protocol/Protocol_1_9.cpp +++ b/src/Protocol/Protocol_1_9.cpp @@ -27,7 +27,7 @@ Implements the 1.9 protocol classes: #include "../StringCompression.h" #include "../CompositeChat.h" #include "../Statistics.h" -#include "../World.h" +#include "../JsonUtils.h" #include "../WorldStorage/FastNBT.h" @@ -702,8 +702,7 @@ void cProtocol_1_9_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); } - Json::FastWriter Writer; - AString Response = Writer.write(ResponseValue); + auto Response = JsonUtils::WriteFastString(ResponseValue); cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); @@ -2281,8 +2280,7 @@ void cProtocol_1_9_1::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); } - Json::FastWriter Writer; - AString Response = Writer.write(ResponseValue); + AString Response = JsonUtils::WriteFastString(ResponseValue); cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); @@ -2339,8 +2337,7 @@ void cProtocol_1_9_2::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); } - Json::FastWriter Writer; - AString Response = Writer.write(ResponseValue); + AString Response = JsonUtils::WriteFastString(ResponseValue); cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); @@ -2397,8 +2394,7 @@ void cProtocol_1_9_4::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer) ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); } - Json::FastWriter Writer; - AString Response = Writer.write(ResponseValue); + AString Response = JsonUtils::WriteFastString(ResponseValue); cPacketizer Pkt(*this, pktStatusResponse); Pkt.WriteString(Response); @@ -2439,19 +2435,18 @@ void cProtocol_1_9_4::SendUpdateSign(int a_BlockX, int a_BlockY, int a_BlockZ, c Writer.AddInt("z", a_BlockZ); Writer.AddString("id", "Sign"); - Json::StyledWriter JsonWriter; Json::Value Line1; Line1["text"] = a_Line1; - Writer.AddString("Text1", JsonWriter.write(Line1)); + Writer.AddString("Text1", JsonUtils::WriteFastString(Line1)); Json::Value Line2; Line2["text"] = a_Line2; - Writer.AddString("Text2", JsonWriter.write(Line2)); + Writer.AddString("Text2", JsonUtils::WriteFastString(Line2)); Json::Value Line3; Line3["text"] = a_Line3; - Writer.AddString("Text3", JsonWriter.write(Line3)); + Writer.AddString("Text3", JsonUtils::WriteFastString(Line3)); Json::Value Line4; Line4["text"] = a_Line4; - Writer.AddString("Text4", JsonWriter.write(Line4)); + Writer.AddString("Text4", JsonUtils::WriteFastString(Line4)); Writer.Finish(); Pkt.WriteBuf(Writer.GetResult().data(), Writer.GetResult().size()); |