From f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Fri, 25 Aug 2017 13:43:18 +0100 Subject: Add cUUID class (#3871) --- src/Entities/Player.cpp | 13 ++++++------- src/Entities/Player.h | 16 +++++++++------- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'src/Entities') diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 60da8c758..fb2274cad 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -84,7 +84,7 @@ cPlayer::cPlayer(cClientHandlePtr a_Client, const AString & a_PlayerName) : m_bIsInBed(false), m_TicksUntilNextSave(PLAYER_INVENTORY_SAVE_INTERVAL), m_bIsTeleporting(false), - m_UUID((a_Client != nullptr) ? a_Client->GetUUID() : ""), + m_UUID((a_Client != nullptr) ? a_Client->GetUUID() : cUUID{}), m_CustomName(""), m_SkinParts(0), m_MainHand(mhRight) @@ -2077,7 +2077,7 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World) } // Load from the offline UUID file, if allowed: - AString OfflineUUID = cClientHandle::GenerateOfflineUUID(GetName()); + cUUID OfflineUUID = cClientHandle::GenerateOfflineUUID(GetName()); const char * OfflineUsage = " (unused)"; if (cRoot::Get()->GetServer()->ShouldLoadOfflinePlayerData()) { @@ -2105,7 +2105,7 @@ bool cPlayer::LoadFromDisk(cWorldPtr & a_World) // None of the files loaded successfully LOG("Player data file not found for %s (%s, offline %s%s), will be reset to defaults.", - GetName().c_str(), m_UUID.c_str(), OfflineUUID.c_str(), OfflineUsage + GetName().c_str(), m_UUID.ToShortString().c_str(), OfflineUUID.ToShortString().c_str(), OfflineUsage ); if (a_World == nullptr) @@ -2220,7 +2220,7 @@ bool cPlayer::LoadFromFile(const AString & a_FileName, cWorldPtr & a_World) 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.substr(0, 2)); + cFile::CreateFolder(FILE_IO_PREFIX + AString("players/") + m_UUID.ToShortString().substr(0, 2)); // create the JSON data Json::Value JSON_PlayerPosition; @@ -2879,10 +2879,9 @@ void cPlayer::RemoveClientHandle(void) -AString cPlayer::GetUUIDFileName(const AString & a_UUID) +AString cPlayer::GetUUIDFileName(const cUUID & a_UUID) { - AString UUID = cMojangAPI::MakeUUIDDashed(a_UUID); - ASSERT(UUID.length() == 36); + AString UUID = a_UUID.ToLongString(); AString res("players/"); res.append(UUID, 0, 2); diff --git a/src/Entities/Player.h b/src/Entities/Player.h index 5b0aa84a8..5c08151c8 100644 --- a/src/Entities/Player.h +++ b/src/Entities/Player.h @@ -8,6 +8,8 @@ #include "../Statistics.h" +#include "../UUID.h" + @@ -488,14 +490,14 @@ public: /** Whether placing the given blocks would intersect any entitiy */ bool DoesPlacingBlocksIntersectEntity(const sSetBlockVector & a_Blocks); + /** Returns the UUID that has been read from the client, or nil if not available. */ + const cUUID & GetUUID(void) const { return m_UUID; } // Exported in ManualBindings.cpp + // tolua_begin /** Returns wheter the player can fly or not. */ virtual bool CanFly(void) const { return m_CanFly; } - /** Returns the UUID (short format) that has been read from the client, or empty string if not available. */ - const AString & GetUUID(void) const { return m_UUID; } - /** (Re)loads the rank and permissions from the cRankManager. Expects the m_UUID member to be valid. Loads the m_Rank, m_Permissions, m_MsgPrefix, m_MsgSuffix and m_MsgNameColorCode members. */ @@ -694,9 +696,9 @@ protected: */ bool m_bIsTeleporting; - /** The short UUID (no dashes) of the player, as read from the ClientHandle. - If no ClientHandle is given, the UUID is initialized to empty. */ - AString m_UUID; + /** The UUID of the player, as read from the ClientHandle. + If no ClientHandle is given, the UUID is nil. */ + cUUID m_UUID; AString m_CustomName; @@ -731,7 +733,7 @@ protected: /** Returns the filename for the player data based on the UUID given. This can be used both for online and offline UUIDs. */ - AString GetUUIDFileName(const AString & a_UUID); + AString GetUUIDFileName(const cUUID & a_UUID); private: -- cgit v1.2.3