summaryrefslogtreecommitdiffstats
path: root/src/WorldStorage
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-12-11 11:17:54 +0100
committerMattes D <github@xoft.cz>2014-12-11 11:17:54 +0100
commit1b1f971752049fba6a00e0aff3e9776327e577d5 (patch)
treea6e78218d586955e2db05d423d8b6c407288c9f8 /src/WorldStorage
parentFixed DungeonRooms edges not generating sometimes. (diff)
parentCheck to see if header write out is required (diff)
downloadcuberite-1b1f971752049fba6a00e0aff3e9776327e577d5.tar
cuberite-1b1f971752049fba6a00e0aff3e9776327e577d5.tar.gz
cuberite-1b1f971752049fba6a00e0aff3e9776327e577d5.tar.bz2
cuberite-1b1f971752049fba6a00e0aff3e9776327e577d5.tar.lz
cuberite-1b1f971752049fba6a00e0aff3e9776327e577d5.tar.xz
cuberite-1b1f971752049fba6a00e0aff3e9776327e577d5.tar.zst
cuberite-1b1f971752049fba6a00e0aff3e9776327e577d5.zip
Diffstat (limited to 'src/WorldStorage')
-rwxr-xr-x[-rw-r--r--]src/WorldStorage/WSSAnvil.cpp35
-rwxr-xr-x[-rw-r--r--]src/WorldStorage/WSSAnvil.h3
2 files changed, 33 insertions, 5 deletions
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index 5a0932bbe..ad875b4cb 100644..100755
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -2923,6 +2923,8 @@ cWSSAnvil::cMCAFile::cMCAFile(const AString & a_FileName, int a_RegionX, int a_R
bool cWSSAnvil::cMCAFile::OpenFile(bool a_IsForReading)
{
+ bool writeOutNeeded = false;
+
if (m_File.IsOpen())
{
// Already open
@@ -2948,12 +2950,26 @@ bool cWSSAnvil::cMCAFile::OpenFile(bool a_IsForReading)
if (m_File.Read(m_Header, sizeof(m_Header)) != sizeof(m_Header))
{
// Cannot read the header - perhaps the file has just been created?
- // Try writing a nullptr header (both chunk offsets and timestamps):
+ // Try writing a nullptr header for chunk offsets:
memset(m_Header, 0, sizeof(m_Header));
+ writeOutNeeded = true;
+ }
+
+ // Load the TimeStamps:
+ if (m_File.Read(m_TimeStamps, sizeof(m_TimeStamps)) != sizeof(m_TimeStamps))
+ {
+ // Cannot read the time stamps - perhaps the file has just been created?
+ // Try writing a nullptr header for timestamps:
+ memset(m_TimeStamps, 0, sizeof(m_TimeStamps));
+ writeOutNeeded = true;
+ }
+
+ if (writeOutNeeded)
+ {
if (
- (m_File.Write(m_Header, sizeof(m_Header)) != sizeof(m_Header)) || // Real header - chunk offsets
- (m_File.Write(m_Header, sizeof(m_Header)) != sizeof(m_Header)) // Bogus data for the chunk timestamps
- )
+ (m_File.Write(m_Header, sizeof(m_Header)) != sizeof(m_Header)) || // Write chunk offsets
+ (m_File.Write(m_TimeStamps, sizeof(m_TimeStamps)) != sizeof(m_TimeStamps)) // Write chunk timestamps
+ )
{
LOGWARNING("Cannot process MCA header in file \"%s\", chunks in that file will be lost", m_FileName.c_str());
m_File.Close();
@@ -3083,7 +3099,13 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri
);
return false;
}
+
+ // Store the header info in the table
m_Header[LocalX + 32 * LocalZ] = htonl((ChunkSector << 8) | ChunkSize);
+
+ // Set the modification time
+ m_TimeStamps[LocalX + 32 * LocalZ] = htonl(time(nullptr));
+
if (m_File.Seek(0) < 0)
{
LOGWARNING("Cannot save chunk [%d, %d], seeking in file \"%s\" failed", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, GetFileName().c_str());
@@ -3094,6 +3116,11 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri
LOGWARNING("Cannot save chunk [%d, %d], writing header to file \"%s\" failed", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, GetFileName().c_str());
return false;
}
+ if (m_File.Write(m_TimeStamps, sizeof(m_TimeStamps)) != sizeof(m_TimeStamps))
+ {
+ LOGWARNING("Cannot save chunk [%d, %d], writing timestamps to file \"%s\" failed", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, GetFileName().c_str());
+ return false;
+ }
return true;
}
diff --git a/src/WorldStorage/WSSAnvil.h b/src/WorldStorage/WSSAnvil.h
index 7a98a9a04..974ba932e 100644..100755
--- a/src/WorldStorage/WSSAnvil.h
+++ b/src/WorldStorage/WSSAnvil.h
@@ -80,7 +80,8 @@ protected:
// First 1024 entries are chunk locations - the 3 + 1 byte sector-offset and sector-count
unsigned m_Header[MCA_MAX_CHUNKS];
- // Chunk timestamps, following the chunk headers, are unused by MCS
+ // Chunk timestamps, following the chunk headers
+ unsigned m_TimeStamps[MCA_MAX_CHUNKS];
/// Finds a free location large enough to hold a_Data. Gets a hint of the chunk coords, places the data there if it fits. Returns the sector number.
unsigned FindFreeLocation(int a_LocalX, int a_LocalZ, const AString & a_Data);