summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
Diffstat (limited to 'src/WorldStorage')
-rw-r--r--src/WorldStorage/ScoreboardSerializer.cpp76
-rw-r--r--src/WorldStorage/WSSAnvil.cpp9
2 files changed, 39 insertions, 46 deletions
diff --git a/src/WorldStorage/ScoreboardSerializer.cpp b/src/WorldStorage/ScoreboardSerializer.cpp
index dabc5e2e1..c65e13f98 100644
--- a/src/WorldStorage/ScoreboardSerializer.cpp
+++ b/src/WorldStorage/ScoreboardSerializer.cpp
@@ -13,11 +13,6 @@
-#define SCOREBOARD_INFLATE_MAX 16 KiB
-
-
-
-
cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScoreboard* a_ScoreBoard)
: m_ScoreBoard(a_ScoreBoard)
@@ -36,38 +31,22 @@ cScoreboardSerializer::cScoreboardSerializer(const AString & a_WorldName, cScore
bool cScoreboardSerializer::Load(void)
{
- cFile File;
-
- if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmReadWrite))
+ AString Data = cFile::ReadWholeFile(FILE_IO_PREFIX + m_Path);
+ if (Data.empty())
{
return false;
}
- AString Data;
-
- File.ReadRestOfFile(Data);
+ AString Uncompressed;
+ int res = UncompressStringGZIP(Data.data(), Data.size(), Uncompressed);
- File.Close();
-
- char Uncompressed[SCOREBOARD_INFLATE_MAX];
- z_stream strm;
- strm.zalloc = (alloc_func)NULL;
- strm.zfree = (free_func)NULL;
- strm.opaque = NULL;
- inflateInit(&strm);
- strm.next_out = (Bytef *)Uncompressed;
- strm.avail_out = sizeof(Uncompressed);
- strm.next_in = (Bytef *)Data.data();
- strm.avail_in = Data.size();
- int res = inflate(&strm, Z_FINISH);
- inflateEnd(&strm);
- if (res != Z_STREAM_END)
+ if (res != Z_OK)
{
return false;
}
// Parse the NBT data:
- cParsedNBT NBT(Uncompressed, strm.total_out);
+ cParsedNBT NBT(Uncompressed.data(), Uncompressed.size());
if (!NBT.IsValid())
{
// NBT Parsing failed
@@ -85,11 +64,8 @@ bool cScoreboardSerializer::Save(void)
{
cFastNBTWriter Writer;
- Writer.BeginCompound("");
- m_ScoreBoard->RegisterObjective("test","test",cObjective::E_TYPE_DUMMY)->AddScore("dot", 2);
SaveScoreboardToNBT(Writer);
- Writer.EndCompound();
Writer.Finish();
#ifdef _DEBUG
@@ -97,12 +73,22 @@ bool cScoreboardSerializer::Save(void)
ASSERT(TestParse.IsValid());
#endif // _DEBUG
- gzFile gz = gzopen((FILE_IO_PREFIX + m_Path).c_str(), "wb");
- if (gz != NULL)
+ cFile File;
+ if (!File.Open(FILE_IO_PREFIX + m_Path, cFile::fmWrite))
+ {
+ return false;
+ }
+
+ AString Compressed;
+ int res = CompressStringGZIP(Writer.GetResult().data(), Writer.GetResult().size(), Compressed);
+
+ if (res != Z_OK)
{
- gzwrite(gz, Writer.GetResult().data(), Writer.GetResult().size());
+ return false;
}
- gzclose(gz);
+
+ File.Write(Compressed.data(), Compressed.size());
+ File.Close();
return true;
}
@@ -113,7 +99,8 @@ bool cScoreboardSerializer::Save(void)
void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
{
- a_Writer.BeginCompound("Data");
+ a_Writer.BeginCompound("data");
+
a_Writer.BeginList("Objectives", TAG_Compound);
for (cScoreboard::cObjectiveMap::const_iterator it = m_ScoreBoard->m_Objectives.begin(); it != m_ScoreBoard->m_Objectives.end(); ++it)
@@ -130,7 +117,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
a_Writer.EndCompound();
}
- a_Writer.EndList();
+ a_Writer.EndList(); // Objectives
a_Writer.BeginList("PlayerScores", TAG_Compound);
@@ -151,7 +138,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
}
}
- a_Writer.EndList();
+ a_Writer.EndList(); // PlayerScores
a_Writer.BeginList("Teams", TAG_Compound);
@@ -182,8 +169,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
a_Writer.EndCompound();
}
- a_Writer.EndList();
- a_Writer.EndCompound();
+ a_Writer.EndList(); // Teams
a_Writer.BeginCompound("DisplaySlots");
@@ -196,7 +182,9 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
Objective = m_ScoreBoard->GetObjectiveIn(cScoreboard::E_DISPLAY_SLOT_NAME);
a_Writer.AddString("slot_2", (Objective == NULL) ? "" : Objective->GetName());
- a_Writer.EndCompound();
+ a_Writer.EndCompound(); // DisplaySlots
+
+ a_Writer.EndCompound(); // Data
}
@@ -205,7 +193,7 @@ void cScoreboardSerializer::SaveScoreboardToNBT(cFastNBTWriter & a_Writer)
bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
{
- int Data = a_NBT.FindChildByName(0, "Data");
+ int Data = a_NBT.FindChildByName(0, "data");
if (Data < 0)
{
return false;
@@ -321,13 +309,13 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
CurrLine = a_NBT.FindChildByName(Child, "AllowFriendlyFire");
if (CurrLine >= 0)
{
- AllowsFriendlyFire = a_NBT.GetInt(CurrLine);
+ AllowsFriendlyFire = (a_NBT.GetInt(CurrLine) != 0);
}
CurrLine = a_NBT.FindChildByName(Child, "SeeFriendlyInvisibles");
if (CurrLine >= 0)
{
- CanSeeFriendlyInvisible = a_NBT.GetInt(CurrLine);
+ CanSeeFriendlyInvisible = (a_NBT.GetInt(CurrLine) != 0);
}
cTeam * Team = m_ScoreBoard->RegisterTeam(Name, DisplayName, Prefix, Suffix);
@@ -347,7 +335,7 @@ bool cScoreboardSerializer::LoadScoreboardFromNBT(const cParsedNBT & a_NBT)
}
}
- int DisplaySlots = a_NBT.FindChildByName(0, "DisplaySlots");
+ int DisplaySlots = a_NBT.FindChildByName(Data, "DisplaySlots");
if (DisplaySlots < 0)
{
return false;
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 8be6372e2..e2a882f65 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -1926,14 +1926,19 @@ bool cWSSAnvil::LoadEntityBaseFromNBT(cEntity & a_Entity, const cParsedNBT & a_N
double Speed[3];
if (!LoadDoublesListFromNBT(Speed, 3, a_NBT, a_NBT.FindChildByName(a_TagIdx, "Motion")))
{
- return false;
+ // Provide default speed:
+ Speed[0] = 0;
+ Speed[1] = 0;
+ Speed[2] = 0;
}
a_Entity.SetSpeed(Speed[0], Speed[1], Speed[2]);
double Rotation[3];
if (!LoadDoublesListFromNBT(Rotation, 2, a_NBT, a_NBT.FindChildByName(a_TagIdx, "Rotation")))
{
- return false;
+ // Provide default rotation:
+ Rotation[0] = 0;
+ Rotation[1] = 0;
}
a_Entity.SetYaw(Rotation[0]);
a_Entity.SetRoll(Rotation[1]);