MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / savePlayer

Method savePlayer

source/game/StarPlayerStorage.cpp:159–179  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

157
158
159Json PlayerStorage::savePlayer(PlayerPtr const& player) {
160 auto entityFactory = Root::singleton().entityFactory();
161 auto versioningDatabase = Root::singleton().versioningDatabase();
162
163 RecursiveMutexLocker locker(m_mutex);
164
165 auto uuid = player->uuid();
166
167 auto& playerCacheData = m_savedPlayersCache[uuid];
168 if (!m_playerFileNames.hasLeftValue(uuid))
169 m_playerFileNames.insert(uuid, uuid.hex());
170 auto newPlayerData = player->diskStore();
171 if (playerCacheData != newPlayerData) {
172 playerCacheData = newPlayerData;
173 VersionedJson versionedJson = entityFactory->storeVersionedJson(EntityType::Player, playerCacheData);
174 auto fileName = strf("{}.player", uuidFileName(uuid));
175 VersionedJson::writeFile(versionedJson, File::relativeTo(m_storageDirectory, fileName));
176 Logger::debug("Saved player {} to {}", Text::stripEscapeCodes(player->name()), fileName);
177 }
178 return newPlayerData;
179}
180
181Maybe<Json> PlayerStorage::maybeGetPlayerData(Uuid const& uuid) {
182 RecursiveMutexLocker locker(m_mutex);

Callers 5

setMainPlayerMethod · 0.80
updateMethod · 0.80
reloadPlayerMethod · 0.80
resetMethod · 0.80
initCharCreationMenuMethod · 0.80

Calls 12

singletonClass · 0.85
strfFunction · 0.85
stripEscapeCodesFunction · 0.85
entityFactoryMethod · 0.80
versioningDatabaseMethod · 0.80
hasLeftValueMethod · 0.80
hexMethod · 0.80
storeVersionedJsonMethod · 0.80
uuidMethod · 0.45
insertMethod · 0.45
diskStoreMethod · 0.45
nameMethod · 0.45

Tested by

no test coverage detected