QcWorldStorage Class
Reads and writes the files of one world directory besides its chunks: world.json, players (players/<name>-<hash>.qcp) and pending neighbour updates (blockupdates.qce). More...
| Header: | #include <server/storage/QcWorldStorage.h> |
Public Functions
| const QString & | directory() const |
| QcPlayerStorage::Result | parsePlayer(const QString &playerName, const std::optional<QByteArray> &file) const |
| QByteArray | playerBytes(const QcPlayerData &player) const |
| QcResult<QList<QcBlockPos>> | readBlockUpdates() const |
| QcResult<QcWorldInfo> | readInfo() const |
| QcPlayerStorage::Result | readPlayer(const QString &playerName) const |
| QcResult<QList<QcVillage>> | readVillages(const QcVillage::ReadLimits &limits) const |
| int | storedFormatVersion() const |
| QcStatus | writeInfo(const QcWorldInfo &info) const |
| QcStatus | writePlayer(const QString &playerName, const QcPlayerData &player) const |
Static Public Members
| QcResult<std::optional<QByteArray>> | blockUpdatesBytes(const QList<QcBlockPos> &positions) |
| const char *const | blockUpdatesFileName |
| QByteArray | infoBytes(const QcWorldInfo &info) |
| const char *const | infoFileName |
| const quint32 | maxStoredBlockUpdates |
| QString | playerFileName(const QString &playerName) |
| QcChunkPos | regionOf(QcChunkPos chunk) |
| const int | regionSize |
| QByteArray | villagesBytes(const QList<QcVillage> &villages) |
| const char *const | villagesFileName |
Detailed Description
The chunks (blocks, block entities and entities in indexed region files) are QcChunkStore's; a save writes world.json and blockupdates.qce together with the chunks through its journal (infoBytes, blockUpdatesBytes). Blocks and items are stored by name, so content changes between sessions do not scramble a world. Every binary file carries a magic number, a format version and a CRC; damaged files make loading fail with a message instead of crashing.
Member Function Documentation
[static] QcResult<std::optional<QByteArray>> QcWorldStorage::blockUpdatesBytes(const QList<QcBlockPos> &positions)
Returns the contents of blockupdates.qce for positions (none: no file).
const QString &QcWorldStorage::directory() const
Returns the world directory.
[static] QByteArray QcWorldStorage::infoBytes(const QcWorldInfo &info)
Returns the contents of world.json for info.
QcPlayerStorage::Result QcWorldStorage::parsePlayer(const QString &playerName, const std::optional<QByteArray> &file) const
Returns the player playerName read from the contents file of his file (QcPlayerStorage::parse).
QByteArray QcWorldStorage::playerBytes(const QcPlayerData &player) const
Returns the contents of the file of player (QcPlayerStorage::bytes).
[static] QString QcWorldStorage::playerFileName(const QString &playerName)
Returns the file name of the player playerName (QcPlayerStorage::fileName).
QcResult<QList<QcBlockPos>> QcWorldStorage::readBlockUpdates() const
Returns the positions waiting for a neighbour update (blockupdates.qce); empty without error when nothing was saved yet.
QcResult<QcWorldInfo> QcWorldStorage::readInfo() const
Returns the world's info read from world.json, or the error.
QcPlayerStorage::Result QcWorldStorage::readPlayer(const QString &playerName) const
Returns the player playerName read from his file (QcPlayerStorage::read).
QcResult<QList<QcVillage>> QcWorldStorage::readVillages(const QcVillage::ReadLimits &limits) const
Returns the villages of the world (villages.json, decision E-403); empty without error when none was saved yet; an error when the file cannot be read or is no JSON object. Entries that are not plausible are left out, spot lists cut to limits (QcVillage::fromJson).
[static] QcChunkPos QcWorldStorage::regionOf(QcChunkPos chunk)
Returns the region that holds chunk.
int QcWorldStorage::storedFormatVersion() const
Returns the format version world.json names; 0 when it cannot be read.
[static] QByteArray QcWorldStorage::villagesBytes(const QList<QcVillage> &villages)
Returns the contents of villages.json for villages.
QcStatus QcWorldStorage::writeInfo(const QcWorldInfo &info) const
Writes info to world.json (creating the directory). Returns an error when it cannot be written.
QcStatus QcWorldStorage::writePlayer(const QString &playerName, const QcPlayerData &player) const
Writes player to the file of playerName (QcPlayerStorage::write). Returns an error when it cannot be written.
Member Variable Documentation
const quint32 QcWorldStorage::maxStoredBlockUpdates
Positions waiting for a neighbour update (blockupdates.qce). Empty without error when nothing was saved yet. At most maxStoredBlockUpdates are written; the rest is reported as an error.
const int QcWorldStorage::regionSize
The side of a region in chunks (QcRegionFile::regionSize).