diff options
author | peterbell10 <peterbell10@live.co.uk> | 2018-07-20 01:30:09 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-20 01:30:09 +0200 |
commit | 4fbf04413d68446777832b6c980bfac7879903c1 (patch) | |
tree | 8d2a64e019c4f436c89e56633b9db3d7c6ae9fef /src/Entities | |
parent | cBlockArea: Write all present data types by default (#4252) (diff) | |
download | cuberite-4fbf04413d68446777832b6c980bfac7879903c1.tar cuberite-4fbf04413d68446777832b6c980bfac7879903c1.tar.gz cuberite-4fbf04413d68446777832b6c980bfac7879903c1.tar.bz2 cuberite-4fbf04413d68446777832b6c980bfac7879903c1.tar.lz cuberite-4fbf04413d68446777832b6c980bfac7879903c1.tar.xz cuberite-4fbf04413d68446777832b6c980bfac7879903c1.tar.zst cuberite-4fbf04413d68446777832b6c980bfac7879903c1.zip |
Diffstat (limited to 'src/Entities')
-rw-r--r-- | src/Entities/Player.cpp | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index e984534a5..6ddfeb75c 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -36,6 +36,41 @@ // 1000 = once per second #define PLAYER_LIST_TIME_MS std::chrono::milliseconds(1000) +namespace +{ + +/** Returns the old Offline UUID generated before becoming vanilla compliant. */ +cUUID GetOldStyleOfflineUUID(const AString & a_PlayerName) +{ + // Use lowercase username + auto BaseUUID = cUUID::GenerateVersion3(StrToLower(a_PlayerName)).ToRaw(); + // Clobber a full nibble around the variant bits + BaseUUID[8] = (BaseUUID[8] & 0x0f) | 0x80; + + cUUID Ret; + Ret.FromRaw(BaseUUID); + return Ret; +} + + + + + +/** Returns the folder for the player data based on the UUID given. +This can be used both for online and offline UUIDs. */ +AString GetUUIDFolderName(const cUUID & a_Uuid) +{ + AString UUID = a_Uuid.ToShortString(); + + AString res(FILE_IO_PREFIX "players/"); + res.append(UUID, 0, 2); + res.push_back('/'); + return res; +} + +} // namespace (anonymous) + + @@ -2055,8 +2090,25 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World) return true; } - // Load from the offline UUID file, if allowed: + // Check for old offline UUID filename, if it exists migrate to new filename cUUID OfflineUUID = cClientHandle::GenerateOfflineUUID(GetName()); + auto OldFilename = GetUUIDFileName(GetOldStyleOfflineUUID(GetName())); + auto NewFilename = GetUUIDFileName(m_UUID); + // Only move if there isn't already a new file + if (!cFile::IsFile(NewFilename) && cFile::IsFile(OldFilename)) + { + cFile::CreateFolderRecursive(GetUUIDFolderName(m_UUID)); // Ensure folder exists to move to + if ( + cFile::Rename(OldFilename, NewFilename) && + (m_UUID == OfflineUUID) && + LoadFromFile(NewFilename, a_World) + ) + { + return true; + } + } + + // Load from the offline UUID file, if allowed: const char * OfflineUsage = " (unused)"; if (cRoot::Get()->GetServer()->ShouldLoadOfflinePlayerData()) { @@ -2227,8 +2279,7 @@ void cPlayer::OpenHorseInventory() bool cPlayer::SaveToDisk() { - cFile::CreateFolder(FILE_IO_PREFIX + AString("players/")); // Create the "players" folder, if it doesn't exist yet (#1268) - cFile::CreateFolder(FILE_IO_PREFIX + AString("players/") + m_UUID.ToShortString().substr(0, 2)); + cFile::CreateFolderRecursive(GetUUIDFolderName(m_UUID)); // create the JSON data Json::Value JSON_PlayerPosition; @@ -2864,7 +2915,7 @@ AString cPlayer::GetUUIDFileName(const cUUID & a_UUID) { AString UUID = a_UUID.ToLongString(); - AString res("players/"); + AString res(FILE_IO_PREFIX "players/"); res.append(UUID, 0, 2); res.push_back('/'); res.append(UUID, 2, AString::npos); |