1
0
Fork 0

Update submodules (#4727)

Closes #4708

This updates jsoncpp, mbedtls, TCLAP and SQLiteCpp to their latest stable release. A few additional changes were needed:

* jsoncpp deprecated Reader, FastWriter and StyledWriter which I've replaced
  with some helper functions in JsonUtils.cpp

* SQLiteCpp changed how it builds with external sqlite libraries, now expecting
  them to be installed. The simplest path was to remove sqlite from cuberite's
  submodule and just use SQLiteCpp's internal version.
This commit is contained in:
peterbell10 2020-05-09 15:51:15 +01:00 committed by GitHub
parent 804c3ba6e9
commit e6634ed26c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
39 changed files with 160 additions and 110 deletions

View File

@ -188,7 +188,7 @@ set(SQLITECPP_RUN_CPPCHECK OFF CACHE BOOL "Run cppcheck C++ static analysis t
set(SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool." FORCE) set(SQLITECPP_RUN_DOXYGEN OFF CACHE BOOL "Run Doxygen C++ documentation tool." FORCE)
set(SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples." FORCE) set(SQLITECPP_BUILD_EXAMPLES OFF CACHE BOOL "Build examples." FORCE)
set(SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests." FORCE) set(SQLITECPP_BUILD_TESTS OFF CACHE BOOL "Build and run tests." FORCE)
set(SQLITECPP_INTERNAL_SQLITE OFF CACHE BOOL "Add the internal SQLite3 source to the project." FORCE) set(SQLITECPP_INTERNAL_SQLITE ON CACHE BOOL "Add the internal SQLite3 source to the project." FORCE)
set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "" FORCE) set(SQLITE_ENABLE_COLUMN_METADATA OFF CACHE BOOL "" FORCE)
# Set options for LibEvent, disable all their tests and benchmarks: # Set options for LibEvent, disable all their tests and benchmarks:
@ -251,29 +251,26 @@ endif()
# Include all the libraries: # Include all the libraries:
add_subdirectory(lib/jsoncpp/) add_subdirectory(lib/jsoncpp/ EXCLUDE_FROM_ALL)
add_subdirectory(lib/zlib/) add_subdirectory(lib/zlib/)
add_subdirectory(lib/lua/) add_subdirectory(lib/lua/)
add_subdirectory(lib/tolua++/ EXCLUDE_FROM_ALL) add_subdirectory(lib/tolua++/ EXCLUDE_FROM_ALL)
add_subdirectory(lib/sqlite/)
add_subdirectory(lib/SQLiteCpp/) add_subdirectory(lib/SQLiteCpp/)
add_subdirectory(lib/sqlite/)
add_subdirectory(lib/expat/) add_subdirectory(lib/expat/)
add_subdirectory(lib/luaexpat/) add_subdirectory(lib/luaexpat/)
add_subdirectory(lib/libevent/ EXCLUDE_FROM_ALL) add_subdirectory(lib/libevent/ EXCLUDE_FROM_ALL)
add_subdirectory(lib/fmt) add_subdirectory(lib/fmt)
# Add proper include directories so that SQLiteCpp can find SQLite3:
get_property(SQLITECPP_INCLUDES DIRECTORY "lib/SQLiteCpp/" PROPERTY INCLUDE_DIRECTORIES)
set(SQLITECPP_INCLUDES "${SQLITECPP_INCLUDES}" "${CMAKE_CURRENT_SOURCE_DIR}/lib/sqlite/")
set_property(DIRECTORY lib/SQLiteCpp/ PROPERTY INCLUDE_DIRECTORIES "${SQLITECPP_INCLUDES}")
set_property(TARGET SQLiteCpp PROPERTY INCLUDE_DIRECTORIES "${SQLITECPP_INCLUDES}")
# Add proper includes for LibEvent's event-config.h header: # Add proper includes for LibEvent's event-config.h header:
include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS}) include_directories(SYSTEM ${LIBEVENT_INCLUDE_DIRS})
# Prettify jsoncpp_lib_static name in VS solution explorer # Prettify jsoncpp_lib name in VS solution explorer
set_property(TARGET jsoncpp_lib_static PROPERTY PROJECT_LABEL "jsoncpp") set_property(TARGET jsoncpp_lib PROPERTY PROJECT_LABEL "jsoncpp")
# jsoncpp uses these for ccache support, clashing with our method
set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "")
set_property(GLOBAL PROPERTY RULE_LAUNCH_LINK "")
if (WIN32) if (WIN32)
add_subdirectory(lib/luaproxy/) add_subdirectory(lib/luaproxy/)
@ -306,13 +303,13 @@ if (MSVC)
event_extra_static event_extra_static
expat expat
fmt fmt
jsoncpp_lib_static jsoncpp_lib
lua lua
luaexpat luaexpat
mbedcrypto mbedcrypto
mbedtls mbedtls
mbedx509 mbedx509
sqlite lsqlite
SQLiteCpp SQLiteCpp
tolualib tolualib
zlib zlib

@ -1 +1 @@
Subproject commit 1c83894db9deeea32418089e2ffd0c5d3af85b8b Subproject commit 829d549af3a11e24fcb0b99090837dac9a9aae4f

@ -1 +1 @@
Subproject commit 12cee38782897cfe60a1611615c200c45cd99eaf Subproject commit ec3ddcfe41b0544a4551a57439b6b3682fe31479

@ -1 +1 @@
Subproject commit d5ba7e7332ca05aa0a9740b497f914be27181774 Subproject commit d2e6a971f4544c55b8e3b25cf96db266971b778f

@ -1 +1 @@
Subproject commit b4e10cdc437bea82cec9a5da3056ac209bf2386f Subproject commit 6d57f1c3c4face973f0405b2a3c0fb8471a79d92

@ -1 +1 @@
Subproject commit f2a597fa3dd1c7b15e0fee62f6932b253295803d Subproject commit ac15f842a5bb8d4cbceb7175c5d7ab50d96173c0

@ -1 +1 @@
Subproject commit 3ca24a24687eb82c576838ba783c838006004ef2 Subproject commit 9a17fd73198c645c924996c0aee7836f51bcf7bb

View File

@ -169,5 +169,5 @@ endif()
if(NOT MSVC) if(NOT MSVC)
add_library(Bindings ${SRCS} ${HDRS}) add_library(Bindings ${SRCS} ${HDRS})
target_link_libraries(Bindings fmt::fmt lua sqlite tolualib mbedtls HTTPServer) target_link_libraries(Bindings fmt::fmt lua lsqlite tolualib mbedtls HTTPServer SQLiteCpp)
endif() endif()

View File

@ -9,6 +9,7 @@
#include "LuaState.h" #include "LuaState.h"
#include "tolua++/include/tolua++.h" #include "tolua++/include/tolua++.h"
#include "json/json.h" #include "json/json.h"
#include "../JsonUtils.h"
@ -295,10 +296,10 @@ static int tolua_cJson_Parse(lua_State * a_LuaState)
// Parse the string: // Parse the string:
Json::Value root; Json::Value root;
Json::Reader reader; AString ParseError;
if (!reader.parse(input, root, false)) if (!JsonUtils::ParseString(input, root, &ParseError))
{ {
L.Push(cLuaState::Nil, Printf("Parsing Json failed: %s", reader.getFormattedErrorMessages().c_str())); L.Push(cLuaState::Nil, Printf("Parsing Json failed: %s", ParseError));
return 2; return 2;
} }

View File

@ -45,5 +45,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(BlockEntities ${SRCS} ${HDRS}) add_library(BlockEntities ${SRCS} ${HDRS})
target_link_libraries(BlockEntities fmt::fmt) target_link_libraries(BlockEntities fmt::fmt SQLiteCpp)
endif() endif()

View File

@ -1,7 +1,7 @@
#include "Globals.h" #include "Globals.h"
#include "BlockTypePalette.h" #include "BlockTypePalette.h"
#include "json/value.h" #include "json/value.h"
#include "json/reader.h" #include "JsonUtils.h"
@ -170,10 +170,8 @@ void BlockTypePalette::loadFromJsonString(const AString & aJsonPalette)
{ {
// Parse the string into JSON object: // Parse the string into JSON object:
Json::Value root; Json::Value root;
Json::CharReaderBuilder builder;
std::unique_ptr<Json::CharReader> reader(builder.newCharReader());
std::string errs; std::string errs;
if (!reader->parse(aJsonPalette.data(), aJsonPalette.data() + aJsonPalette.size(), &root, &errs)) if (!JsonUtils::ParseString(aJsonPalette, root, &errs))
{ {
throw LoadFailedException(errs); throw LoadFailedException(errs);
} }

View File

@ -108,5 +108,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(Blocks ${SRCS} ${HDRS}) add_library(Blocks ${SRCS} ${HDRS})
target_link_libraries(Blocks fmt::fmt) target_link_libraries(Blocks fmt::fmt SQLiteCpp)
endif() endif()

View File

@ -47,6 +47,7 @@ SET (SRCS
Inventory.cpp Inventory.cpp
Item.cpp Item.cpp
ItemGrid.cpp ItemGrid.cpp
JsonUtils.cpp
LightingThread.cpp LightingThread.cpp
LineBlockTracer.cpp LineBlockTracer.cpp
LinearInterpolation.cpp LinearInterpolation.cpp
@ -126,6 +127,7 @@ SET (HDRS
Item.h Item.h
ItemGrid.h ItemGrid.h
LazyArray.h LazyArray.h
JsonUtils.h
LightingThread.h LightingThread.h
LineBlockTracer.h LineBlockTracer.h
LinearInterpolation.h LinearInterpolation.h
@ -171,8 +173,6 @@ file(WRITE "${CMAKE_BINARY_DIR}/include/Globals.h"
"/* This file allows Globals.h to be included with an absolute path */\n#include \"${PROJECT_SOURCE_DIR}/Globals.h\"\n") "/* This file allows Globals.h to be included with an absolute path */\n#include \"${PROJECT_SOURCE_DIR}/Globals.h\"\n")
include_directories("${CMAKE_BINARY_DIR}/include") include_directories("${CMAKE_BINARY_DIR}/include")
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/sqlite")
include_directories ("${CMAKE_CURRENT_SOURCE_DIR}/../lib/SQLiteCpp/include")
include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/TCLAP/include") include_directories (SYSTEM "${CMAKE_CURRENT_SOURCE_DIR}/../lib/TCLAP/include")
configure_file("BuildInfo.h.cmake" "${CMAKE_BINARY_DIR}/include/BuildInfo.h") configure_file("BuildInfo.h.cmake" "${CMAKE_BINARY_DIR}/include/BuildInfo.h")
@ -439,7 +439,7 @@ if (${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD")
add_flags_lnk(-L/usr/ports/devel) add_flags_lnk(-L/usr/ports/devel)
endif() endif()
target_link_libraries(${CMAKE_PROJECT_NAME} luaexpat jsoncpp_lib_static mbedtls zlib sqlite lua SQLiteCpp event_core event_extra fmt::fmt) target_link_libraries(${CMAKE_PROJECT_NAME} luaexpat jsoncpp_lib mbedtls zlib lsqlite lua SQLiteCpp event_core event_extra fmt::fmt)
# Create a folder for Bindings' documentation: # Create a folder for Bindings' documentation:
FILE(MAKE_DIRECTORY "Bindings/docs") FILE(MAKE_DIRECTORY "Bindings/docs")

View File

@ -6,6 +6,7 @@
#include "Globals.h" #include "Globals.h"
#include "CompositeChat.h" #include "CompositeChat.h"
#include "ClientHandle.h" #include "ClientHandle.h"
#include "JsonUtils.h"
@ -408,11 +409,10 @@ AString cCompositeChat::CreateJsonString(bool a_ShouldUseChatPrefixes) const
#if 1 #if 1
// Serialize as machine-readable string (no whitespace): // Serialize as machine-readable string (no whitespace):
Json::FastWriter writer; return JsonUtils::WriteFastString(msg);
return writer.write(msg);
#else #else
// Serialize as human-readable string (pretty-printed): // Serialize as human-readable string (pretty-printed):
return msg.toStyledString(); return JsonUtils::WriteStyledString(msg);
#endif #endif
} }

View File

@ -59,5 +59,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(Entities ${SRCS} ${HDRS}) add_library(Entities ${SRCS} ${HDRS})
target_link_libraries(Entities fmt::fmt WorldStorage) target_link_libraries(Entities fmt::fmt WorldStorage SQLiteCpp)
endif() endif()

View File

@ -28,6 +28,7 @@
#include "../Blocks/ChunkInterface.h" #include "../Blocks/ChunkInterface.h"
#include "../IniFile.h" #include "../IniFile.h"
#include "../JsonUtils.h"
#include "json/json.h" #include "json/json.h"
// 6000 ticks or 5 minutes // 6000 ticks or 5 minutes
@ -2196,10 +2197,13 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World)
// Parse the JSON format: // Parse the JSON format:
Json::Value root; Json::Value root;
Json::Reader reader; AString ParseError;
if (!reader.parse(buffer, root, false)) if (!JsonUtils::ParseString(buffer, root, &ParseError))
{ {
LOGWARNING("Cannot parse player data in file \"%s\"", a_FileName.c_str()); FLOGWARNING(
"Cannot parse player data in file \"{0}\":\n {1}",
a_FileName, ParseError
);
return false; return false;
} }
@ -2369,9 +2373,7 @@ bool cPlayer::SaveToDisk()
root["gamemode"] = static_cast<int>(eGameMode_NotSet); root["gamemode"] = static_cast<int>(eGameMode_NotSet);
} }
Json::StyledWriter writer; auto JsonData = JsonUtils::WriteStyledString(root);
std::string JsonData = writer.write(root);
AString SourceFile = GetUUIDFileName(m_UUID); AString SourceFile = GetUUIDFileName(m_UUID);
cFile f; cFile f;

View File

@ -65,5 +65,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(Items ${SRCS} ${HDRS}) add_library(Items ${SRCS} ${HDRS})
target_link_libraries(Items fmt::fmt) target_link_libraries(Items fmt::fmt SQLiteCpp)
endif() endif()

43
src/JsonUtils.cpp Normal file
View File

@ -0,0 +1,43 @@
#include "Globals.h"
#include "JsonUtils.h"
#include "json/json.h"
#include <sstream>
namespace JsonUtils
{
AString WriteFastString(const Json::Value & a_Root)
{
Json::StreamWriterBuilder Builder;
Builder["commentStyle"] = "None";
Builder["indentation"] = "";
return Json::writeString(Builder, a_Root);
}
AString WriteStyledString(const Json::Value & a_Root)
{
Json::StreamWriterBuilder Builder;
return Json::writeString(Builder, a_Root);
}
bool ParseString(const AString & a_JsonStr, Json::Value & a_Root, AString * a_ErrorMsg)
{
Json::CharReaderBuilder Builder;
std::unique_ptr<Json::CharReader> Reader(Builder.newCharReader());
const char * Doc = a_JsonStr.data();
return Reader->parse(Doc, Doc + a_JsonStr.size(), &a_Root, a_ErrorMsg);
}
} // namespace JsonUtils

17
src/JsonUtils.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
// fwd:
namespace Json
{
class Value;
}
namespace JsonUtils
{
AString WriteFastString(const Json::Value & a_Root);
AString WriteStyledString(const Json::Value & a_Root);
bool ParseString(const AString & a_JsonStr, Json::Value & a_Root, AString * a_ErrorMsg = nullptr);
}

View File

@ -84,5 +84,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(Mobs ${SRCS} ${HDRS}) add_library(Mobs ${SRCS} ${HDRS})
target_link_libraries(Mobs fmt::fmt) target_link_libraries(Mobs fmt::fmt SQLiteCpp)
endif() endif()

View File

@ -9,6 +9,7 @@
#include "../UUID.h" #include "../UUID.h"
#include "../IniFile.h" #include "../IniFile.h"
#include "../JsonUtils.h"
#include "json/json.h" #include "json/json.h"
#include "../mbedTLS++/BlockingSslClientSocket.h" #include "../mbedTLS++/BlockingSslClientSocket.h"
@ -185,8 +186,7 @@ bool cAuthenticator::AuthWithYggdrasil(AString & a_UserName, const AString & a_S
return false; return false;
} }
Json::Value root; Json::Value root;
Json::Reader reader; if (!JsonUtils::ParseString(Response, root))
if (!reader.parse(Response, root, false))
{ {
LOGWARNING("cAuthenticator: Cannot parse received data (authentication) to JSON!"); LOGWARNING("cAuthenticator: Cannot parse received data (authentication) to JSON!");
return false; return false;

View File

@ -35,5 +35,5 @@ SET (HDRS
if (NOT MSVC) if (NOT MSVC)
add_library(Protocol ${SRCS} ${HDRS}) add_library(Protocol ${SRCS} ${HDRS})
target_link_libraries(Protocol fmt::fmt) target_link_libraries(Protocol fmt::fmt SQLiteCpp)
endif() endif()

View File

@ -8,6 +8,7 @@
#include "SQLiteCpp/Database.h" #include "SQLiteCpp/Database.h"
#include "SQLiteCpp/Statement.h" #include "SQLiteCpp/Statement.h"
#include "../IniFile.h" #include "../IniFile.h"
#include "../JsonUtils.h"
#include "json/json.h" #include "json/json.h"
#include "../mbedTLS++/BlockingSslClientSocket.h" #include "../mbedTLS++/BlockingSslClientSocket.h"
#include "../mbedTLS++/SslConfig.h" #include "../mbedTLS++/SslConfig.h"
@ -514,7 +515,7 @@ void cMojangAPI::LoadCachesFromDisk(void)
try try
{ {
// Open up the SQLite DB: // 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 PlayerNameToUUID (PlayerName, UUID, DateTime)");
db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)"); db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, DateTime)");
@ -572,7 +573,7 @@ void cMojangAPI::SaveCachesToDisk(void)
try try
{ {
// Open up the SQLite DB: // 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 PlayerNameToUUID (PlayerName, UUID, DateTime)");
db.exec("CREATE TABLE IF NOT EXISTS UUIDToProfile (UUID, PlayerName, Textures, TexturesSignature, 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); root.append(req);
} // for itr - a_PlayerNames[] } // for itr - a_PlayerNames[]
a_NamesToQuery.erase(a_NamesToQuery.begin(), itr); a_NamesToQuery.erase(a_NamesToQuery.begin(), itr);
Json::FastWriter Writer; auto RequestBody = JsonUtils::WriteFastString(root);
AString RequestBody = Writer.write(root);
// Create the HTTP request: // Create the HTTP request:
AString Request; AString Request;
@ -712,11 +712,11 @@ void cMojangAPI::QueryNamesToUUIDs(AStringVector & a_NamesToQuery)
Response.erase(0, idxHeadersEnd + 4); Response.erase(0, idxHeadersEnd + 4);
// Parse the returned string into Json: // Parse the returned string into Json:
Json::Reader reader; AString ParseError;
if (!reader.parse(Response, root, false) || !root.isArray()) if (!JsonUtils::ParseString(Response, root, &ParseError) || !root.isArray())
{ {
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()); LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16));
continue; continue;
} }
@ -822,11 +822,11 @@ void cMojangAPI::QueryUUIDToProfile(const cUUID & a_UUID)
Response.erase(0, idxHeadersEnd + 4); Response.erase(0, idxHeadersEnd + 4);
// Parse the returned string into Json: // Parse the returned string into Json:
Json::Reader reader;
Json::Value root; 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()); LOGD("Response body:\n%s", CreateHexDump(HexDump, Response.data(), Response.size(), 16).c_str());
return; return;
} }

View File

@ -19,6 +19,7 @@
#include "../Server.h" #include "../Server.h"
#include "../World.h" #include "../World.h"
#include "../ChatColor.h" #include "../ChatColor.h"
#include "../JsonUtils.h"
#include "../Bindings/PluginManager.h" #include "../Bindings/PluginManager.h"
@ -1222,8 +1223,7 @@ void cProtocolRecognizer::HandlePacketStatusRequest(void)
ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str()); ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
} }
Json::FastWriter Writer; AString Response = JsonUtils::WriteFastString(ResponseValue);
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Response); Pkt.WriteString(Response);

View File

@ -16,6 +16,7 @@ Implements the 1.10 protocol classes:
#include "../Root.h" #include "../Root.h"
#include "../Server.h" #include "../Server.h"
#include "../ClientHandle.h" #include "../ClientHandle.h"
#include "../JsonUtils.h"
#include "../WorldStorage/FastNBT.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()); ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
} }
Json::FastWriter Writer; AString Response = JsonUtils::WriteFastString(ResponseValue);
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Response); Pkt.WriteString(Response);

View File

@ -41,6 +41,7 @@ Implements the 1.11 protocol classes:
#include "../Server.h" #include "../Server.h"
#include "../ClientHandle.h" #include "../ClientHandle.h"
#include "../CompositeChat.h" #include "../CompositeChat.h"
#include "../JsonUtils.h"
#include "../Bindings/PluginManager.h" #include "../Bindings/PluginManager.h"
@ -642,9 +643,8 @@ void cProtocol_1_11_0::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
} }
// Serialize the response into a packet: // Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, pktStatusResponse); 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: // Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Writer.write(ResponseValue)); Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue));
} }

View File

@ -26,6 +26,7 @@ Implements the 1.12 protocol classes:
#include "../Server.h" #include "../Server.h"
#include "../ClientHandle.h" #include "../ClientHandle.h"
#include "../Bindings/PluginManager.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: // Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, pktStatusResponse); 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: // Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, pktStatusResponse); 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: // Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Writer.write(ResponseValue)); Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue));
} }

View File

@ -27,6 +27,7 @@ Implements the 1.13 protocol classes:
#include "../Root.h" #include "../Root.h"
#include "../Server.h" #include "../Server.h"
#include "../World.h" #include "../World.h"
#include "../JsonUtils.h"
#include "../Bindings/PluginManager.h" #include "../Bindings/PluginManager.h"
@ -253,9 +254,8 @@ void cProtocol_1_13::HandlePacketStatusRequest(cByteBuffer & a_ByteBuffer)
} }
// Serialize the response into a packet: // Serialize the response into a packet:
Json::FastWriter Writer;
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Writer.write(ResponseValue)); Pkt.WriteString(JsonUtils::WriteFastString(ResponseValue));
} }

View File

@ -24,6 +24,7 @@ Implements the 1.8 protocol classes:
#include "../Statistics.h" #include "../Statistics.h"
#include "../UUID.h" #include "../UUID.h"
#include "../World.h" #include "../World.h"
#include "../JsonUtils.h"
#include "../WorldStorage/FastNBT.h" #include "../WorldStorage/FastNBT.h"
#include "../WorldStorage/EnchantmentSerializer.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); m_Client->SetUUID(UUID);
Json::Value root; Json::Value root;
Json::Reader reader; if (!JsonUtils::ParseString(Params[3], root))
if (!reader.parse(Params[3], root))
{ {
LOGERROR("Unable to parse player properties: '%s'", Params[3]); 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); cPacketizer Pkt(*this, pktUpdateSign);
Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ); Pkt.WritePosition64(a_BlockX, a_BlockY, a_BlockZ);
Json::StyledWriter JsonWriter;
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; Json::Value RootValue;
RootValue["text"] = Lines[i]; 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()); ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
} }
Json::FastWriter Writer; auto Response = JsonUtils::WriteFastString(ResponseValue);
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Response); Pkt.WriteString(Response);
@ -2741,11 +2739,10 @@ void cProtocol_1_8_0::HandlePacketUpdateSign(cByteBuffer & a_ByteBuffer)
AString Lines[4]; AString Lines[4];
Json::Value root; Json::Value root;
Json::Reader reader;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line); HANDLE_READ(a_ByteBuffer, ReadVarUTF8String, AString, Line);
if (reader.parse(Line, root, false)) if (JsonUtils::ParseString(Line, root))
{ {
Lines[i] = root.asString(); Lines[i] = root.asString();
} }

View File

@ -27,7 +27,7 @@ Implements the 1.9 protocol classes:
#include "../StringCompression.h" #include "../StringCompression.h"
#include "../CompositeChat.h" #include "../CompositeChat.h"
#include "../Statistics.h" #include "../Statistics.h"
#include "../World.h" #include "../JsonUtils.h"
#include "../WorldStorage/FastNBT.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()); ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
} }
Json::FastWriter Writer; auto Response = JsonUtils::WriteFastString(ResponseValue);
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Response); 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()); ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
} }
Json::FastWriter Writer; AString Response = JsonUtils::WriteFastString(ResponseValue);
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Response); 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()); ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
} }
Json::FastWriter Writer; AString Response = JsonUtils::WriteFastString(ResponseValue);
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Response); 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()); ResponseValue["favicon"] = Printf("data:image/png;base64,%s", Favicon.c_str());
} }
Json::FastWriter Writer; AString Response = JsonUtils::WriteFastString(ResponseValue);
AString Response = Writer.write(ResponseValue);
cPacketizer Pkt(*this, pktStatusResponse); cPacketizer Pkt(*this, pktStatusResponse);
Pkt.WriteString(Response); 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.AddInt("z", a_BlockZ);
Writer.AddString("id", "Sign"); Writer.AddString("id", "Sign");
Json::StyledWriter JsonWriter;
Json::Value Line1; Json::Value Line1;
Line1["text"] = a_Line1; Line1["text"] = a_Line1;
Writer.AddString("Text1", JsonWriter.write(Line1)); Writer.AddString("Text1", JsonUtils::WriteFastString(Line1));
Json::Value Line2; Json::Value Line2;
Line2["text"] = a_Line2; Line2["text"] = a_Line2;
Writer.AddString("Text2", JsonWriter.write(Line2)); Writer.AddString("Text2", JsonUtils::WriteFastString(Line2));
Json::Value Line3; Json::Value Line3;
Line3["text"] = a_Line3; Line3["text"] = a_Line3;
Writer.AddString("Text3", JsonWriter.write(Line3)); Writer.AddString("Text3", JsonUtils::WriteFastString(Line3));
Json::Value Line4; Json::Value Line4;
Line4["text"] = a_Line4; Line4["text"] = a_Line4;
Writer.AddString("Text4", JsonWriter.write(Line4)); Writer.AddString("Text4", JsonUtils::WriteFastString(Line4));
Writer.Finish(); Writer.Finish();
Pkt.WriteBuf(Writer.GetResult().data(), Writer.GetResult().size()); Pkt.WriteBuf(Writer.GetResult().data(), Writer.GetResult().size());

View File

@ -16,7 +16,7 @@
// cRankManager: // cRankManager:
cRankManager::cRankManager(void) : cRankManager::cRankManager(void) :
m_DB("Ranks.sqlite", SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE), m_DB("Ranks.sqlite", SQLite::OPEN_READWRITE | SQLite::OPEN_CREATE),
m_IsInitialized(false), m_IsInitialized(false),
m_MojangAPI(nullptr) m_MojangAPI(nullptr)
{ {

View File

@ -28,5 +28,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(Simulator ${SRCS} ${HDRS}) add_library(Simulator ${SRCS} ${HDRS})
target_link_libraries(Simulator fmt::fmt) target_link_libraries(Simulator fmt::fmt SQLiteCpp)
endif() endif()

View File

@ -35,5 +35,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(UI ${SRCS} ${HDRS}) add_library(UI ${SRCS} ${HDRS})
target_link_libraries(UI fmt::fmt) target_link_libraries(UI fmt::fmt SQLiteCpp)
endif() endif()

View File

@ -27,5 +27,5 @@ SET (HDRS
if(NOT MSVC) if(NOT MSVC)
add_library(WorldStorage ${SRCS} ${HDRS}) add_library(WorldStorage ${SRCS} ${HDRS})
target_link_libraries(WorldStorage fmt::fmt OSSupport) target_link_libraries(WorldStorage fmt::fmt OSSupport SQLiteCpp)
endif() endif()

View File

@ -6,6 +6,7 @@
#include "StatSerializer.h" #include "StatSerializer.h"
#include "../Statistics.h" #include "../Statistics.h"
#include "../JsonUtils.h"
@ -44,9 +45,8 @@ bool cStatSerializer::Load(void)
} }
Json::Value Root; Json::Value Root;
Json::Reader Reader;
if (Reader.parse(Data, Root, false)) if (JsonUtils::ParseString(Data, Root))
{ {
return LoadStatFromJSON(Root); return LoadStatFromJSON(Root);
} }
@ -69,8 +69,7 @@ bool cStatSerializer::Save(void)
return false; return false;
} }
Json::StyledWriter Writer; AString JsonData = JsonUtils::WriteStyledString(Root);
AString JsonData = Writer.write(Root);
File.Write(JsonData.data(), JsonData.size()); File.Write(JsonData.data(), JsonData.size());
File.Close(); File.Close();

View File

@ -16,6 +16,7 @@
#include "../SetChunkData.h" #include "../SetChunkData.h"
#include "../Root.h" #include "../Root.h"
#include "../BlockType.h" #include "../BlockType.h"
#include "../JsonUtils.h"
#include "../BlockEntities/BeaconEntity.h" #include "../BlockEntities/BeaconEntity.h"
#include "../BlockEntities/BedEntity.h" #include "../BlockEntities/BedEntity.h"
@ -830,8 +831,7 @@ AString cWSSAnvil::DecodeSignLine(const AString & a_Line)
// Try to parse the JSON: // Try to parse the JSON:
Json::Value root; Json::Value root;
Json::Reader reader; if (!JsonUtils::ParseString(a_Line, root) || !root.isObject())
if (!reader.parse(a_Line, root, false) || !root.isObject())
{ {
return a_Line; return a_Line;
} }

View File

@ -26,11 +26,12 @@ add_executable(BlockTypePaletteTest
../TestHelpers.h ../TestHelpers.h
${CMAKE_SOURCE_DIR}/src/BlockState.cpp ${CMAKE_SOURCE_DIR}/src/BlockState.cpp
${CMAKE_SOURCE_DIR}/src/BlockTypePalette.cpp ${CMAKE_SOURCE_DIR}/src/BlockTypePalette.cpp
${CMAKE_SOURCE_DIR}/src/JsonUtils.cpp
${CMAKE_SOURCE_DIR}/src/StringUtils.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/File.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/File.cpp
) )
target_link_libraries(BlockTypePaletteTest fmt::fmt jsoncpp_lib_static) target_link_libraries(BlockTypePaletteTest fmt::fmt jsoncpp_lib)
# BlockTypeRegistryTest: Verify that the BlockTypeRegistry class works as intended: # BlockTypeRegistryTest: Verify that the BlockTypeRegistry class works as intended:
add_executable(BlockTypeRegistryTest add_executable(BlockTypeRegistryTest
@ -50,11 +51,12 @@ add_executable(PalettedBlockAreaTest
${CMAKE_SOURCE_DIR}/src/BlockTypeRegistry.cpp ${CMAKE_SOURCE_DIR}/src/BlockTypeRegistry.cpp
${CMAKE_SOURCE_DIR}/src/BlockTypePalette.cpp ${CMAKE_SOURCE_DIR}/src/BlockTypePalette.cpp
${CMAKE_SOURCE_DIR}/src/Cuboid.cpp ${CMAKE_SOURCE_DIR}/src/Cuboid.cpp
${CMAKE_SOURCE_DIR}/src/JsonUtils.cpp
${CMAKE_SOURCE_DIR}/src/PalettedBlockArea.cpp ${CMAKE_SOURCE_DIR}/src/PalettedBlockArea.cpp
${CMAKE_SOURCE_DIR}/src/StringUtils.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp
${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/CriticalSection.cpp
) )
target_link_libraries(PalettedBlockAreaTest fmt::fmt jsoncpp_lib_static) target_link_libraries(PalettedBlockAreaTest fmt::fmt jsoncpp_lib)
# Extra files for BlockTypePalette test: # Extra files for BlockTypePalette test:
file (COPY file (COPY

View File

@ -10,12 +10,14 @@ add_definitions(-DTEST_GLOBALS=1)
set (SHARED_SRCS set (SHARED_SRCS
${CMAKE_SOURCE_DIR}/src/CompositeChat.cpp ${CMAKE_SOURCE_DIR}/src/CompositeChat.cpp
${CMAKE_SOURCE_DIR}/src/JsonUtils.cpp
${CMAKE_SOURCE_DIR}/src/StringUtils.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp
) )
set (SHARED_HDRS set (SHARED_HDRS
../TestHelpers.h ../TestHelpers.h
${CMAKE_SOURCE_DIR}/src/CompositeChat.h ${CMAKE_SOURCE_DIR}/src/CompositeChat.h
${CMAKE_SOURCE_DIR}/src/JsonUtils.h
${CMAKE_SOURCE_DIR}/src/StringUtils.h ${CMAKE_SOURCE_DIR}/src/StringUtils.h
) )
@ -28,7 +30,7 @@ set (SRCS
source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS}) source_group("Shared" FILES ${SHARED_SRCS} ${SHARED_HDRS})
source_group("Sources" FILES ${SRCS}) source_group("Sources" FILES ${SRCS})
add_executable(CompositeChat-exe ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS}) add_executable(CompositeChat-exe ${SRCS} ${SHARED_SRCS} ${SHARED_HDRS})
target_link_libraries(CompositeChat-exe jsoncpp_lib_static fmt::fmt) target_link_libraries(CompositeChat-exe jsoncpp_lib fmt::fmt)
add_test(NAME CompositeChat-test COMMAND CompositeChat-exe) add_test(NAME CompositeChat-test COMMAND CompositeChat-exe)

View File

@ -161,7 +161,7 @@ add_library(GeneratorTestingSupport STATIC
${GENERATING_HDRS} ${GENERATING_HDRS}
${STUBS} ${STUBS}
) )
target_link_libraries(GeneratorTestingSupport tolualib zlib fmt::fmt jsoncpp_lib_static) target_link_libraries(GeneratorTestingSupport tolualib zlib fmt::fmt jsoncpp_lib)
source_group("Stubs" FILES ${STUBS}) source_group("Stubs" FILES ${STUBS})
source_group("Generating" FILES ${GENERATING_HDRS} ${GENERATING_SRCS}) source_group("Generating" FILES ${GENERATING_HDRS} ${GENERATING_SRCS})