2024-02-25 14:46:47 +00:00
|
|
|
#pragma once
|
2023-06-20 04:33:09 +00:00
|
|
|
|
|
|
|
#include "StarOrderedMap.hpp"
|
|
|
|
#include "StarUuid.hpp"
|
|
|
|
#include "StarPlayerFactory.hpp"
|
|
|
|
#include "StarThread.hpp"
|
|
|
|
#include "StarWorldStorage.hpp"
|
|
|
|
#include "StarStatistics.hpp"
|
|
|
|
|
|
|
|
namespace Star {
|
|
|
|
|
|
|
|
class PlayerStorage {
|
|
|
|
public:
|
|
|
|
PlayerStorage(String const& storageDir);
|
|
|
|
~PlayerStorage();
|
|
|
|
|
|
|
|
size_t playerCount() const;
|
|
|
|
// Returns nothing if index is out of bounds.
|
|
|
|
Maybe<Uuid> playerUuidAt(size_t index);
|
2023-07-22 12:31:04 +00:00
|
|
|
// Returns nothing if name doesn't match a player.
|
2023-07-24 07:54:31 +00:00
|
|
|
Maybe<Uuid> playerUuidByName(String const& name, Maybe<Uuid> except = {});
|
2023-06-20 04:33:09 +00:00
|
|
|
|
2023-07-22 12:31:04 +00:00
|
|
|
// Also returns the diskStore Json if needed.
|
|
|
|
Json savePlayer(PlayerPtr const& player);
|
|
|
|
|
|
|
|
Maybe<Json> maybeGetPlayerData(Uuid const& uuid);
|
|
|
|
Json getPlayerData(Uuid const& uuid);
|
2023-06-20 04:33:09 +00:00
|
|
|
PlayerPtr loadPlayer(Uuid const& uuid);
|
|
|
|
void deletePlayer(Uuid const& uuid);
|
|
|
|
|
|
|
|
WorldChunks loadShipData(Uuid const& uuid);
|
|
|
|
void applyShipUpdates(Uuid const& uuid, WorldChunks const& updates);
|
|
|
|
|
|
|
|
// Move the given player to the top of the player ordering.
|
|
|
|
void moveToFront(Uuid const& uuid);
|
|
|
|
|
|
|
|
// Copy all the player relevant files for this uuid into .bak1 .bak2 etc
|
|
|
|
// files for however many backups are configured
|
|
|
|
void backupCycle(Uuid const& uuid);
|
|
|
|
|
|
|
|
// Get / Set PlayerStorage global metadata
|
|
|
|
void setMetadata(String key, Json value);
|
|
|
|
Json getMetadata(String const& key);
|
|
|
|
|
|
|
|
private:
|
2023-11-24 09:35:21 +00:00
|
|
|
String const& uuidFileName(Uuid const& uuid);
|
2023-06-20 04:33:09 +00:00
|
|
|
void writeMetadata();
|
|
|
|
|
|
|
|
mutable RecursiveMutex m_mutex;
|
|
|
|
String m_storageDirectory;
|
2023-08-02 12:56:36 +00:00
|
|
|
String m_backupDirectory;
|
2023-06-20 04:33:09 +00:00
|
|
|
OrderedHashMap<Uuid, Json> m_savedPlayersCache;
|
2023-08-02 12:25:20 +00:00
|
|
|
BiMap<Uuid, String> m_playerFileNames;
|
2023-06-20 04:33:09 +00:00
|
|
|
JsonObject m_metadata;
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|