summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MCServer/Plugins/APIDump/APIDesc.lua3
-rw-r--r--src/ClientHandle.cpp29
-rw-r--r--src/ClientHandle.h11
3 files changed, 41 insertions, 2 deletions
diff --git a/MCServer/Plugins/APIDump/APIDesc.lua b/MCServer/Plugins/APIDump/APIDesc.lua
index 19ca971e2..06e333cf9 100644
--- a/MCServer/Plugins/APIDump/APIDesc.lua
+++ b/MCServer/Plugins/APIDump/APIDesc.lua
@@ -523,13 +523,16 @@ end
Functions =
{
+ GenerateOfflineUUID = { Params = "Username", Return = "string", Notes = "(STATIC) Generates an UUID based on the player name provided. This is used for the offline (non-auth) mode, when there's no UUID source. Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. Returns a 36-char UUID (with dashes)." },
GetLocale = { Params = "", Return = "Locale", Notes = "Returns the locale string that the client sends as part of the protocol handshake. Can be used to provide localized strings." },
GetPing = { Params = "", Return = "number", Notes = "Returns the ping time, in ms" },
GetPlayer = { Params = "", Return = "{{cPlayer|cPlayer}}", Notes = "Returns the player object connected to this client. Note that this may be nil, for example if the player object is not yet spawned." },
GetUniqueID = { Params = "", Return = "number", Notes = "Returns the UniqueID of the client used to identify the client in the server" },
+ GetUUID = { Params = "", Return = "string", Notes = "Returns the authentication-based UUID of the client. This UUID should be used to identify the player when persisting any player-related data." },
GetUsername = { Params = "", Return = "string", Notes = "Returns the username that the client has provided" },
GetViewDistance = { Params = "", Return = "number", Notes = "Returns the viewdistance (number of chunks loaded for the player in each direction)" },
HasPluginChannel = { Params = "ChannelName", Return = "bool", Notes = "Returns true if the client has registered to receive messages on the specified plugin channel." },
+ IsUUIDOnline = { Params = "UUID", Return = "bool", Notes = "(STATIC) Returns true if the UUID is generated by online auth, false if it is an offline-generated UUID. We use Version-3 UUIDs for offline UUIDs, online UUIDs are Version-4, thus we can tell them apart. Accepts both 32-char and 36-char UUIDs (with and without dashes). If the string given is not a valid UUID, returns false."},
Kick = { Params = "Reason", Return = "", Notes = "Kicks the user with the specified reason" },
SendPluginMessage = { Params = "Channel, Message", Return = "", Notes = "Sends the plugin message on the specified channel." },
SetLocale = { Params = "Locale", Return = "", Notes = "Sets the locale that MCServer keeps on record. Initially the locale is initialized in protocol handshake, this function allows plugins to override the stored value (but only server-side and only until the user disconnects)." },
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index ade7e20ac..46083a8f1 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -232,6 +232,9 @@ AString cClientHandle::FormatMessageType(bool ShouldAppendChatPrefixes, eMessage
AString 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
@@ -254,6 +257,32 @@ AString cClientHandle::GenerateOfflineUUID(const AString & a_Username)
+bool cClientHandle::IsUUIDOnline(const AString & 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;
+}
+
+
+
+
+
void cClientHandle::Kick(const AString & a_Reason)
{
if (m_State >= csAuthenticating) // Don't log pings
diff --git a/src/ClientHandle.h b/src/ClientHandle.h
index 0d883f3af..3e18cbdad 100644
--- a/src/ClientHandle.h
+++ b/src/ClientHandle.h
@@ -63,7 +63,7 @@ public:
const AString & GetIPString(void) const { return m_IPString; }
- cPlayer* GetPlayer() { return m_Player; } // tolua_export
+ cPlayer * GetPlayer(void) { return m_Player; } // tolua_export
const AString & GetUUID(void) const { return m_UUID; } // tolua_export
void SetUUID(const AString & a_UUID) { m_UUID = a_UUID; }
@@ -76,9 +76,16 @@ public:
/** Generates an UUID based on the player name provided.
This is used for the offline (non-auth) mode, when there's no UUID source.
- Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same. */
+ Each username generates a unique and constant UUID, so that when the player reconnects with the same name, their UUID is the same.
+ Returns a 36-char UUID (with dashes). */
static AString GenerateOfflineUUID(const AString & a_Username); // tolua_export
+ /** Returns true if the UUID is generated by online auth, false if it is an offline-generated UUID.
+ We use Version-3 UUIDs for offline UUIDs, online UUIDs are Version-4, thus we can tell them apart.
+ Accepts both 32-char and 36-char UUIDs (with and without dashes).
+ If the string given is not a valid UUID, returns false. */
+ static bool IsUUIDOnline(const AString & a_UUID); // tolua_export
+
/** Formats the type of message with the proper color and prefix for sending to the client. **/
static AString FormatMessageType(bool ShouldAppendChatPrefixes, eMessageType a_ChatPrefix, const AString & a_AdditionalData);