1
0
mirror of https://github.com/moparisthebest/minetest synced 2024-11-11 03:45:01 -05:00

Fixed a temporary solution of server shutting down to an assert(0) when a too large block metadata is sent to an old client

This commit is contained in:
Perttu Ahola 2011-05-03 17:33:51 +03:00
parent 821d5bb4cc
commit 59c4a342a9
2 changed files with 14 additions and 4 deletions

View File

@ -2109,10 +2109,18 @@ void MapBlock::serialize(std::ostream &os, u8 version)
{
if(version <= 15)
{
try{
std::ostringstream oss(std::ios_base::binary);
m_node_metadata.serialize(oss);
os<<serializeString(oss.str());
}
// This will happen if the string is longer than 65535
catch(SerializationError &e)
{
// Use an empty string
os<<serializeString("");
}
}
else
{
std::ostringstream oss(std::ios_base::binary);

View File

@ -1911,7 +1911,9 @@ inline v3f intToFloat(v3s16 p, f32 d)
// Creates a string with the length as the first two bytes
inline std::string serializeString(const std::string &plain)
{
assert(plain.size() <= 65535);
//assert(plain.size() <= 65535);
if(plain.size() > 65535)
throw SerializationError("String too long for serializeString");
char buf[2];
writeU16((u8*)&buf[0], plain.size());
std::string s;