summaryrefslogtreecommitdiffstats
path: root/src/ClientHandle.cpp
diff options
context:
space:
mode:
authorpeterbell10 <peterbell10@live.co.uk>2017-08-25 14:43:18 +0200
committerAlexander Harkness <me@bearbin.net>2017-08-25 14:43:18 +0200
commitf4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7 (patch)
tree70139b1ad7ed221e4b75c3a9e247b337de68eb07 /src/ClientHandle.cpp
parentcompile.sh update. Fixed -d and -n, intelligent thread choice (#3960) (diff)
downloadcuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.gz
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.bz2
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.lz
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.xz
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.tar.zst
cuberite-f4f2fc7c3d76eb3dc5a91c5eefb36c10597d6cb7.zip
Diffstat (limited to 'src/ClientHandle.cpp')
-rw-r--r--src/ClientHandle.cpp41
1 files changed, 7 insertions, 34 deletions
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 5fc659fe1..caa2d8fd8 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -274,55 +274,28 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage
-AString cClientHandle::GenerateOfflineUUID(const AString & a_Username)
+cUUID cClientHandle::GenerateOfflineUUID(const AString & a_Username)
{
// Online UUIDs are always version 4 (random)
// We use Version 3 (MD5 hash) UUIDs for the offline UUIDs
// This guarantees that they will never collide with an online UUID and can be distinguished.
- // Proper format for a version 3 UUID is:
- // xxxxxxxx-xxxx-3xxx-yxxx-xxxxxxxxxxxx where x is any hexadecimal digit and y is one of 8, 9, A, or B
- // Note that we generate a short UUID (without the dashes)
// First make the username lowercase:
AString lcUsername = StrToLower(a_Username);
- // Generate an md5 checksum, and use it as base for the ID:
- unsigned char MD5[16];
- md5(reinterpret_cast<const unsigned char *>(lcUsername.c_str()), lcUsername.length(), MD5);
- MD5[6] &= 0x0f; // Need to trim to 4 bits only...
- MD5[8] &= 0x0f; // ... otherwise %01x overflows into two chars
- return Printf("%02x%02x%02x%02x%02x%02x3%01x%02x8%01x%02x%02x%02x%02x%02x%02x%02x",
- MD5[0], MD5[1], MD5[2], MD5[3],
- MD5[4], MD5[5], MD5[6], MD5[7],
- MD5[8], MD5[9], MD5[10], MD5[11],
- MD5[12], MD5[13], MD5[14], MD5[15]
- );
+ return cUUID::GenerateVersion3(lcUsername);
}
-bool cClientHandle::IsUUIDOnline(const AString & a_UUID)
+bool cClientHandle::IsUUIDOnline(const cUUID & a_UUID)
{
// Online UUIDs are always version 4 (random)
// We use Version 3 (MD5 hash) UUIDs for the offline UUIDs
// This guarantees that they will never collide with an online UUID and can be distinguished.
- // The version-specifying char is at pos #12 of raw UUID, pos #14 in dashed-UUID.
- switch (a_UUID.size())
- {
- case 32:
- {
- // This is the UUID format without dashes, the version char is at pos #12:
- return (a_UUID[12] == '4');
- }
- case 36:
- {
- // This is the UUID format with dashes, the version char is at pos #14:
- return (a_UUID[14] == '4');
- }
- }
- return false;
+ return (a_UUID.Version() == 4);
}
@@ -342,7 +315,7 @@ void cClientHandle::Kick(const AString & a_Reason)
-void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID, const Json::Value & a_Properties)
+void cClientHandle::Authenticate(const AString & a_Name, const cUUID & a_UUID, const Json::Value & a_Properties)
{
// Atomically increment player count (in server thread)
cRoot::Get()->GetServer()->PlayerCreated();
@@ -366,7 +339,7 @@ void cClientHandle::Authenticate(const AString & a_Name, const AString & a_UUID,
m_Username = a_Name;
// Only assign UUID and properties if not already pre-assigned (BungeeCord sends those in the Handshake packet):
- if (m_UUID.empty())
+ if (m_UUID.IsNil())
{
m_UUID = a_UUID;
}
@@ -1661,7 +1634,7 @@ void cClientHandle::HandleSlotSelected(Int16 a_SlotNum)
-void cClientHandle::HandleSpectate(const AString & a_PlayerUUID)
+void cClientHandle::HandleSpectate(const cUUID & a_PlayerUUID)
{
m_Player->GetWorld()->DoWithPlayerByUUID(a_PlayerUUID, [=](cPlayer * a_ToSpectate)
{