Cuberite Forum
Question on offline UUIDs - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Question on offline UUIDs (/thread-2924.html)



Question on offline UUIDs - Zee1234 - 03-22-2017

Let's say I have an 'offline' server. Will a username always map directly to a UUID? Obviously this is NOT a Mojang UUID and should not be expected to be the same if the server is ever put into online mode (or was taken off online mode). 

So if username 'BlueSky' logs into the offline server from home, they get assigned #UUID1#.

Assume that 'BlueSky' logs in again two months later from school. Will they still get assigned #UUID1# ? Is there any chance that someone with a username OTHER THAN 'BlueSky' gets this offline UUID?


Related note: I did a search for things about UUIDs on the forum. Didn't notice this topic come up, but I saw it mentioned a few times that there might be a callback based async MojangAPI thing written so that plugins could query it without blocking the server. Did that ever happen?


RE: Question on offline UUIDs - xoft - 03-22-2017

Yes, the offline UUID is generated based on their username, so it stays the same. The chance of a collision is rather low, it is assumed safe for identification. Internally, MD5 of the lowercased username is used for the offline UUIDs.

The non-blocking MojangAPI has not been implemented yet. There's even no issue for it on GitHub, I just created it:
https://github.com/cuberite/cuberite/issues/3640

Anyway, if you only query UUIDs of players who have already connected to your server, even the synchronous API is kinda safe, because the UUIDs are cached, so it returns the UUID from cache, rather than making a network request.

Theoretically, you could even implement the MojangAPI requests in your plugin using cNetwork or cUrlClient functions, but it's like "preinventing" the wheel Smile


RE: Question on offline UUIDs - Zee1234 - 03-23-2017

Thanks much. Much nicer to store things by UUID.

Yes, at this time I plan to only query previously online users.

I can't say I'd look forward to 'preinventing' the wheel, as you put it. I don't think I'd even need the functionality just yet, it was mostly a curiosity.


RE: Question on offline UUIDs - Zee1234 - 03-28-2017

Just to verify, if I wanted to create the offline UUID for a player while the server was in online mode, I could do such with:

Code:
cCryptoHash.md5(cPlayer:GetName():lower())

correct?


RE: Question on offline UUIDs - NiLSPACE - 03-28-2017

No, you'll want to do something like this:
cMojangAPI:GetUUIDFromPlayerName(playerName, true);



RE: Question on offline UUIDs - Seadragon91 - 03-28-2017

The problem currently with cMojangAPI is, that it blocks the server. There is a open issue on github.
For now I think cUrlClient could be used. The requests are done asynchronous and this won't block the server.
cUrlClient:Get("https://api.mojang.com/users/profiles/minecraft/<username>",
 function (a_Body, a_Data)
 if (a_Body) then
 -- Response received correctly, a_Body contains the entire response body,
 -- a_Data is a dictionary-table of the response\'s HTTP headers
 local tbUUIDName = cJson:Parse(a_Body)
 LOG(tbUUIDName.id)
 LOG(tbUUIDName.name)
 else
 -- There was an error, a_Data is the error message string
 LOG(a_Data)
 end
 end
)

LOG("Request sent.")

Result for my username:
4fd9f50b6b6143f7a99b8b5be71b52c3
Seadragon91

Source:
http://wiki.vg/Mojang_API#Username_-.3E_UUID_at_time
https://api.cuberite.org/cUrlClient.html


RE: Question on offline UUIDs - xoft - 03-28-2017

The easiest way to get the offline UUIDs is to use the API function cClientHandle:GenerateOfflineUUID("playername")
https://api.cuberite.org/cClientHandle.html#GenerateOfflineUUID_1