Skip to content

Commit

Permalink
Merge branch 'cuberite:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtakingithard committed May 26, 2023
2 parents e3d4d6a + 17d5278 commit 55ed387
Show file tree
Hide file tree
Showing 87 changed files with 1,261 additions and 1,056 deletions.
18 changes: 11 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,6 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# The need for speed (in Release):
if(WHOLE_PROGRAM_OPTIMISATION)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE ${IPO_SUPPORTED})
endif()

# Static CRT:
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

Expand Down Expand Up @@ -99,6 +92,17 @@ if(SELF_TEST)
add_subdirectory(tests)
endif()

# The need for speed (in Release):
if(WHOLE_PROGRAM_OPTIMISATION)
include(CheckIPOSupported)
check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_CHECK_OUTPUT)
if(IPO_SUPPORTED)
set_property(TARGET ${CMAKE_PROJECT_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "IPO is not supported: ${IPO_CHECK_OUTPUT}")
endif()
endif()

emit_fixups()
group_sources()
enable_bindings_generation()
7 changes: 6 additions & 1 deletion Server/Plugins/APIDump/Classes/Network.lua
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,10 @@ g_Server = nil
Name = "OwnPrivateKeyPassword",
Type = "string",
},
{
Name = "TrustedRootCAs",
Type = "string",
},
},
Returns =
{
Expand All @@ -541,7 +545,7 @@ g_Server = nil
IsOptional = true,
},
},
Notes = "Starts a TLS handshake on the link, as a client side of the TLS. The Own___ parameters specify the client certificate and its corresponding private key and password; all three parameters are optional and no client certificate is presented to the remote peer if they are not used or all empty. Once the TLS handshake is started by this call, all incoming data is first decrypted before being sent to the OnReceivedData callback, and all outgoing data is queued until the TLS handshake completes, and then sent encrypted over the link. Returns true on success, nil and optional error message on immediate failure.<br/><b>NOTE:</b> The TLS support in the API is currently experimental and shouldn't be considered safe - there's no peer certificate verification and the error reporting is only basic.",
Notes = "Starts a TLS handshake on the link, as a client side of the TLS. The Own___ parameters specify the client certificate and its corresponding private key and password; all three parameters are optional and no client certificate is presented to the remote peer if they are not used or all empty. Once the TLS handshake is started by this call, all incoming data is first decrypted before being sent to the OnReceivedData callback, and all outgoing data is queued until the TLS handshake completes, and then sent encrypted over the link. Returns true on success, nil and optional error message on immediate failure.<br/>The TrustedRootCAs is a string containing all certificates that should be trusted, in PEM format, concatenated and separated by a newline.<b>NOTE:</b> If TrustedRootCAs is empty or nil, the server's certificate will NOT be verified, which is UNSAFE!",
},
StartTLSServer =
{
Expand Down Expand Up @@ -1123,6 +1127,7 @@ end
<tr><td>OwnCert</td><td>The client certificate to use, if requested by the server. A string containing a PEM- or DER-encoded cert is expected.</td></tr>
<tr><td>OwnPrivKey</td><td>The private key appropriate for OwnCert. A string containing a PEM- or DER-encoded private key is expected.</td></tr>
<tr><td>OwnPrivKeyPassword</td><td>The password for OwnPrivKey. If not present or empty, no password is assumed.</td></tr>
<tr><td>TrustedRootCAs</td><td>The certificates of the Root CAs that are to be trusted, encoded in PEM format. Multiple certificates can be used by concatenating the certificates, separating them by newlines. If this option is not present or empty, the request will NOT check the server's certificate, which is UNSAFE!</td></tr>
</table>
<p>
Redirection:
Expand Down
10 changes: 4 additions & 6 deletions Tools/GrownBiomeGenVisualiser/GrownBiomeGenVisualiser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ void generateExamples(int a_Seed);




/** Color palette used for algorithm examples.
No relevance to biomes whatsoever. */
static const Color spectrumColors[] =
Expand Down Expand Up @@ -82,8 +81,7 @@ static const struct
{
EMCSBiome biome;
Color color;
}
biomeColorMap[] =
} biomeColorMap[] =
{
{ biOcean, { 0x00, 0x00, 0x70 }, },
{ biPlains, { 0x8d, 0xb3, 0x60 }, },
Expand Down Expand Up @@ -271,7 +269,7 @@ void generateZoomLevels(int a_Seed)
gen->GetInts(0, 0, arrSize, arrSize, workspace);

// Output to a bitmap file:
AString fnam = Printf("zoomedgrown_%u.pbm", i);
AString fnam = fmt::format(FMT_STRING("zoomedgrown_{}.pbm"), i);
outputBitmapFile(fnam, 257, 257, workspace, arrSize, arrSize, spectrumColors, ARRAYCOUNT(spectrumColors));
log(" zoom level %u complete", i);
} // for i - Image
Expand Down Expand Up @@ -309,7 +307,7 @@ void generateSmoothLevels(int a_Seed)
gen->GetInts(static_cast<int>(i), static_cast<int>(i), arrSize, arrSize, workspace);

// Output to a bitmap file:
AString fnam = Printf("smoothedgrown_%u.ppm", i);
AString fnam = fmt::format(FMT_STRING("smoothedgrown_{}.ppm"), i);
outputBitmapFile(fnam, 257, 257, workspace, arrSize, arrSize, spectrumColors, ARRAYCOUNT(spectrumColors));
log(" smooth level %u complete", i);
} // for i - Image
Expand Down Expand Up @@ -404,7 +402,7 @@ void generateExamples(int a_Seed)
for (const auto & gen: gens)
{
gen.gen->GetInts(gen.offset, gen.offset, gen.size, gen.size, workspace);
AString fnam = Printf("grownexample_%s.ppm", gen.name);
AString fnam = fmt::format(FMT_STRING("grownexample_{}.ppm"), gen.name);
outputBitmapFile(fnam, 256, 256, workspace, gen.size, gen.size, gen.colormap.colors, gen.colormap.count);
log(" Created example \"%s\"", gen.name);
} // for gen - gens[]
Expand Down
40 changes: 20 additions & 20 deletions Tools/ProtoProxy/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
{ \
return false; \
} \
} while(false)
} while (false)

#define HANDLE_SERVER_PACKET_READ(Proc, Type, Var) \
Type Var; \
Expand All @@ -52,7 +52,7 @@
{ \
return false; \
} \
} while(false)
} while (false)

#define CLIENTSEND(...) SendData(m_ClientSocket, __VA_ARGS__, "Client")
#define SERVERSEND(...) SendData(m_ServerSocket, __VA_ARGS__, "Server")
Expand Down Expand Up @@ -151,7 +151,8 @@ AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor = 32)

AString PrintableAbsIntTriplet(int a_X, int a_Y, int a_Z, double a_Divisor)
{
return Printf("<%d, %d, %d> ~ {%.02f, %.02f, %.02f}",
return fmt::format(
FMT_STRING("<{}, {}, {}> ~ {{{}, {}, {}}}"),
a_X, a_Y, a_Z,
static_cast<double>(a_X) / a_Divisor, static_cast<double>(a_Y) / a_Divisor, static_cast<double>(a_Z) / a_Divisor
);
Expand Down Expand Up @@ -214,7 +215,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) :
mkdir("Logs", 0777);
#endif

Printf(m_LogNameBase, "Logs/Log_%d_%d", static_cast<int>(time(nullptr)), static_cast<int>(a_ClientSocket));
m_LogNameBase = fmt::format(FMT_STRING("Logs/Log_{}_{}"), time(nullptr), a_ClientSocket);
AString fnam(m_LogNameBase);
fnam.append(".log");
#ifdef _WIN32
Expand All @@ -223,7 +224,7 @@ cConnection::cConnection(SOCKET a_ClientSocket, cServer & a_Server) :
m_LogFile = fopen(fnam.c_str(), "w");
#endif
Log("Log file created");
printf("Connection is logged to file \"%s\"\n", fnam.c_str());
fmt::print(FMT_STRING("Connection is logged to file \"{}\"\n"), fnam);
}


Expand Down Expand Up @@ -1795,12 +1796,12 @@ bool cConnection::HandleServerKick(void)

if (Split.size() == 6)
{
Log(" Preamble: \"%s\"", Split[0].c_str());
Log(" Protocol version: \"%s\"", Split[1].c_str());
Log(" Server version: \"%s\"", Split[2].c_str());
Log(" MOTD: \"%s\"", Split[3].c_str());
Log(" Cur players: \"%s\"", Split[4].c_str());
Log(" Max players: \"%s\"", Split[5].c_str());
Log(" Preamble: \"%s\"", Split[0]);
Log(" Protocol version: \"%s\"", Split[1]);
Log(" Server version: \"%s\"", Split[2]);
Log(" MOTD: \"%s\"", Split[3]);
Log(" Cur players: \"%s\"", Split[4]);
Log(" Max players: \"%s\"", Split[5]);

// Modify the MOTD to show that it's being ProtoProxied:
Reason.assign(Split[0]);
Expand All @@ -1809,7 +1810,7 @@ bool cConnection::HandleServerKick(void)
Reason.push_back(0);
Reason.append(Split[2]);
Reason.push_back(0);
Reason.append(Printf("ProtoProxy: %s", Split[3].c_str()));
Reason.append(fmt::format(FMT_STRING("ProtoProxy: {}"), Split[3]));
Reason.push_back(0);
Reason.append(Split[4]);
Reason.push_back(0);
Expand All @@ -1829,7 +1830,7 @@ bool cConnection::HandleServerKick(void)
}
else
{
Log(" Reason = \"%s\"", Reason.c_str());
Log(" Reason = \"%s\"", Reason);
}
COPY_TO_CLIENT();
return true;
Expand Down Expand Up @@ -2407,6 +2408,7 @@ bool cConnection::HandleServerStatistics(void)




bool cConnection::HandleServerStatusPing(void)
{
HANDLE_SERVER_PACKET_READ(ReadBEInt64, Int64, Time);
Expand Down Expand Up @@ -2548,8 +2550,7 @@ bool cConnection::HandleServerUpdateTileEntity(void)
DataLog(Data.data(), Data.size(), " Data (%u bytes)", DataLength);

// Save metadata to a file:
AString fnam;
Printf(fnam, "%s_tile_%08x.nbt", m_LogNameBase.c_str(), m_ItemIdx++);
auto fnam = fmt::format(FMT_STRING("{}_tile_{:08x}.nbt"), m_LogNameBase, m_ItemIdx++);
FILE * f = fopen(fnam.c_str(), "wb");
if (f != nullptr)
{
Expand Down Expand Up @@ -2691,7 +2692,7 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
a_Buffer.ReadBEInt8(ItemCount); // We already know we can read these bytes - we checked before.
a_Buffer.ReadBEInt16(ItemDamage);
a_Buffer.ReadBEUInt16(MetadataLength);
Printf(a_ItemDesc, "%d:%d * %d", ItemType, ItemDamage, ItemCount);
a_ItemDesc = fmt::format(FMT_STRING("{}:{} * {}"), ItemType, ItemDamage, ItemCount);
if (MetadataLength <= 0)
{
return true;
Expand All @@ -2704,17 +2705,16 @@ bool cConnection::ParseSlot(cByteBuffer & a_Buffer, AString & a_ItemDesc)
}
AString MetaHex;
CreateHexDump(MetaHex, Metadata.data(), Metadata.size(), 16);
AppendPrintf(a_ItemDesc, "; %u bytes of meta:\n%s", MetadataLength, MetaHex.c_str());
a_ItemDesc.append(fmt::format(FMT_STRING("; {} bytes of meta:\n{}"), MetadataLength, MetaHex));

// Save metadata to a file:
AString fnam;
Printf(fnam, "%s_item_%08x.nbt", m_LogNameBase.c_str(), m_ItemIdx++);
auto fnam = fmt::format(FMT_STRING("{}_item_{:08x}.nbt"), m_LogNameBase, m_ItemIdx++);
FILE * f = fopen(fnam.c_str(), "wb");
if (f != nullptr)
{
fwrite(Metadata.data(), 1, Metadata.size(), f);
fclose(f);
AppendPrintf(a_ItemDesc, "\n (saved to file \"%s\")", fnam.c_str());
a_ItemDesc.append(fmt::format(FMT_STRING("\n (saved to file \"{}\")"), fnam));
}

return true;
Expand Down
26 changes: 13 additions & 13 deletions src/Bindings/BlockTypePalette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void BlockTypePalette::loadFromJsonString(const AString & aJsonPalette)
const auto & states = (*itr)["states"];
if (states == Json::Value())
{
throw LoadFailedException(Printf("Missing \"states\" for block type \"%s\"", blockTypeName));
throw LoadFailedException(fmt::format(FMT_STRING("Missing \"states\" for block type \"{}\""), blockTypeName));
}
for (const auto & state: states)
{
Expand All @@ -200,7 +200,7 @@ void BlockTypePalette::loadFromJsonString(const AString & aJsonPalette)
const auto & properties = state["properties"];
if (!properties.isObject())
{
throw LoadFailedException(Printf("Member \"properties\" is not a JSON object (block type \"%s\", id %u).", blockTypeName, id));
throw LoadFailedException(fmt::format(FMT_STRING("Member \"properties\" is not a JSON object (block type \"{}\", id {})."), blockTypeName, id));
}
for (const auto & key: properties.getMemberNames())
{
Expand Down Expand Up @@ -249,7 +249,7 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade)
auto keyEnd = findNextSeparator(aTsvPalette, idx + 1);
if (keyEnd == AString::npos)
{
throw LoadFailedException(Printf("Invalid header key format on line %u", line));
throw LoadFailedException(fmt::format(FMT_STRING("Invalid header key format on line {}"), line));
}
if (keyEnd == idx + 1) // Empty line, end of headers
{
Expand All @@ -264,7 +264,7 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade)
auto valueEnd = findNextSeparator(aTsvPalette, keyEnd + 1);
if ((valueEnd == AString::npos) || (aTsvPalette[valueEnd] == '\t'))
{
throw LoadFailedException(Printf("Invalid header value format on line %u", line));
throw LoadFailedException(fmt::format(FMT_STRING("Invalid header value format on line {}"), line));
}
auto key = aTsvPalette.substr(keyStart, keyEnd - keyStart);
if (key == "FileVersion")
Expand All @@ -277,7 +277,7 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade)
}
else if (version != 1)
{
throw LoadFailedException(Printf("Unknown FileVersion: %u. Only version 1 is supported.", version));
throw LoadFailedException(fmt::format(FMT_STRING("Unknown FileVersion: {}. Only version 1 is supported."), version));
}
hasHadVersion = true;
}
Expand All @@ -304,36 +304,36 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade)
auto idEnd = findNextSeparator(aTsvPalette, lineStart);
if ((idEnd == AString::npos) || (aTsvPalette[idEnd] != '\t'))
{
throw LoadFailedException(Printf("Incomplete data on line %u (id)", line));
throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (id)"), line));
}
UInt32 id;
if (!StringToInteger(aTsvPalette.substr(lineStart, idEnd - lineStart), id))
{
throw LoadFailedException(Printf("Failed to parse id on line %u", line));
throw LoadFailedException(fmt::format(FMT_STRING("Failed to parse id on line {}"), line));
}
size_t metaEnd = idEnd;
if (isUpgrade)
{
metaEnd = findNextSeparator(aTsvPalette, idEnd + 1);
if ((metaEnd == AString::npos) || (aTsvPalette[metaEnd] != '\t'))
{
throw LoadFailedException(Printf("Incomplete data on line %u (meta)", line));
throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (meta)"), line));
}
UInt32 meta = 0;
if (!StringToInteger(aTsvPalette.substr(idEnd + 1, metaEnd - idEnd - 1), meta))
{
throw LoadFailedException(Printf("Failed to parse meta on line %u", line));
throw LoadFailedException(fmt::format(FMT_STRING("Failed to parse meta on line {}"), line));
}
if (meta > 15)
{
throw LoadFailedException(Printf("Invalid meta value on line %u: %u", line, meta));
throw LoadFailedException(fmt::format(FMT_STRING("Invalid meta value on line {}: {}"), line, meta));
}
id = (id * 16) | meta;
}
auto blockTypeEnd = findNextSeparator(aTsvPalette, metaEnd + 1);
if (blockTypeEnd == AString::npos)
{
throw LoadFailedException(Printf("Incomplete data on line %u (blockTypeName)", line));
throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (blockTypeName)"), line));
}
auto blockTypeName = aTsvPalette.substr(metaEnd + 1, blockTypeEnd - metaEnd - 1);
auto blockStateEnd = blockTypeEnd;
Expand All @@ -343,12 +343,12 @@ void BlockTypePalette::loadFromTsv(const AString & aTsvPalette, bool aIsUpgrade)
auto keyEnd = findNextSeparator(aTsvPalette, blockStateEnd + 1);
if ((keyEnd == AString::npos) || (aTsvPalette[keyEnd] != '\t'))
{
throw LoadFailedException(Printf("Incomplete data on line %u (blockState key)", line));
throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (blockState key)"), line));
}
auto valueEnd = findNextSeparator(aTsvPalette, keyEnd + 1);
if (valueEnd == AString::npos)
{
throw LoadFailedException(Printf("Incomplete data on line %u (blockState value)", line));
throw LoadFailedException(fmt::format(FMT_STRING("Incomplete data on line {} (blockState value)"), line));
}
auto key = aTsvPalette.substr(blockStateEnd + 1, keyEnd - blockStateEnd - 1);
auto value = aTsvPalette.substr(keyEnd + 1, valueEnd - keyEnd - 1);
Expand Down
2 changes: 1 addition & 1 deletion src/Bindings/BlockTypePalette.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class BlockTypePalette

public:
NoSuchIndexException(UInt32 aIndex):
Super(Printf("No such palette index: %u", aIndex))
Super(fmt::format(FMT_STRING("No such palette index: {}"), aIndex))
{
}
};
Expand Down
19 changes: 10 additions & 9 deletions src/Bindings/BlockTypeRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ AString BlockTypeRegistry::AlreadyRegisteredException::message(
const std::shared_ptr<BlockInfo> & aNewRegistration
)
{
return Printf("Attempting to register BlockTypeName %s from plugin %s, while it is already registered in plugin %s",
aNewRegistration->blockTypeName().c_str(),
aNewRegistration->pluginName().c_str(),
aPreviousRegistration->pluginName().c_str()
return fmt::format(
FMT_STRING("Attempting to register BlockTypeName {} from plugin {}, while it is already registered in plugin {}"),
aNewRegistration->blockTypeName(),
aNewRegistration->pluginName(),
aPreviousRegistration->pluginName()
);
}

Expand All @@ -230,11 +231,11 @@ BlockTypeRegistry::NotRegisteredException::NotRegisteredException(
const AString & aHintKey,
const AString & aHintValue
):
Super(Printf(
"Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = %s\n\tHintKey = %s\n\tHintValue = %s",
aBlockTypeName.c_str(),
aHintKey.c_str(),
aHintValue.c_str()
Super(fmt::format(
FMT_STRING("Attempting to set a hint of nonexistent BlockTypeName.\n\tBlockTypeName = {}\n\tHintKey = {}\n\tHintValue = {}"),
aBlockTypeName,
aHintKey,
aHintValue
))
{
}

0 comments on commit 55ed387

Please sign in to comment.