add Pilz.Gaming.Minecraft (generate offline player uuid)
This commit is contained in:
15
Pilz.Gaming.Minecraft/Pilz.Gaming.Minecraft.csproj
Normal file
15
Pilz.Gaming.Minecraft/Pilz.Gaming.Minecraft.csproj
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||||
|
<IncrementVersionOnBuild>1.yyyy.Mdd.Hmm</IncrementVersionOnBuild>
|
||||||
|
<Version>1.2023.1120.1110</Version>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
43
Pilz.Gaming.Minecraft/Utils.cs
Normal file
43
Pilz.Gaming.Minecraft/Utils.cs
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
using System.Security.Cryptography;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Pilz.Gaming.Minecraft
|
||||||
|
{
|
||||||
|
public static class Utils
|
||||||
|
{
|
||||||
|
public static string GetUUID(string value)
|
||||||
|
{
|
||||||
|
using var md5 = MD5.Create();
|
||||||
|
|
||||||
|
//extracted from the java code:
|
||||||
|
//new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name));
|
||||||
|
byte[] data = md5.ComputeHash(Encoding.ASCII.GetBytes(value));
|
||||||
|
//set the version to 3 -> Name based md5 hash
|
||||||
|
data[6] = Convert.ToByte(data[6] & 0x0f | 0x30);
|
||||||
|
//IETF variant
|
||||||
|
data[8] = Convert.ToByte(data[8] & 0x3f | 0x80);
|
||||||
|
|
||||||
|
//example: 069a79f4-44e9-4726-a5be-fca90e38aaf5
|
||||||
|
var striped = Convert.ToHexString(data);
|
||||||
|
var components = new string[] {
|
||||||
|
striped[..].Remove(8),
|
||||||
|
striped[8..].Remove(4),
|
||||||
|
striped[12..].Remove(4),
|
||||||
|
striped[16..].Remove(4),
|
||||||
|
striped[20..]
|
||||||
|
};
|
||||||
|
|
||||||
|
return string.Join('-', components).ToLower();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string GetPlayerUUID(string username, bool offlineMode)
|
||||||
|
{
|
||||||
|
using var md5 = MD5.Create();
|
||||||
|
|
||||||
|
if (!offlineMode)
|
||||||
|
throw new NotSupportedException("Getting player's online UUID via the Mojang API is not supported at this time.");
|
||||||
|
|
||||||
|
return GetUUID("OfflinePlayer:" + username);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Pilz.sln
14
Pilz.sln
@@ -37,9 +37,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.UI.Telerik", "Pilz.UI.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Networking.CloudProviders.Nextcloud", "Pilz.Networking.CloudProviders.Nextcloud\Pilz.Networking.CloudProviders.Nextcloud.csproj", "{A91E966B-3A82-4F32-A703-2FC1C7654FD1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Networking.CloudProviders.Nextcloud", "Pilz.Networking.CloudProviders.Nextcloud\Pilz.Networking.CloudProviders.Nextcloud.csproj", "{A91E966B-3A82-4F32-A703-2FC1C7654FD1}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Plugins", "Pilz.Plugins\Pilz.Plugins.csproj", "{1170FCA6-192D-42FE-A79F-49EE03035554}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins", "Pilz.Plugins\Pilz.Plugins.csproj", "{1170FCA6-192D-42FE-A79F-49EE03035554}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Plugins.Advanced", "Pilz.Plugins.Advanced\Pilz.Plugins.Advanced.csproj", "{72153EC8-B297-4A94-80AA-3574544BE8CF}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Pilz.Plugins.Advanced", "Pilz.Plugins.Advanced\Pilz.Plugins.Advanced.csproj", "{72153EC8-B297-4A94-80AA-3574544BE8CF}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Pilz.Gaming.Minecraft", "Pilz.Gaming.Minecraft\Pilz.Gaming.Minecraft.csproj", "{B285DA24-39C9-4BA2-AF3D-A1A05737268B}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -201,6 +203,14 @@ Global
|
|||||||
{72153EC8-B297-4A94-80AA-3574544BE8CF}.Release|Any CPU.Build.0 = Release|Any CPU
|
{72153EC8-B297-4A94-80AA-3574544BE8CF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{72153EC8-B297-4A94-80AA-3574544BE8CF}.Release|x86.ActiveCfg = Release|Any CPU
|
{72153EC8-B297-4A94-80AA-3574544BE8CF}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
{72153EC8-B297-4A94-80AA-3574544BE8CF}.Release|x86.Build.0 = Release|Any CPU
|
{72153EC8-B297-4A94-80AA-3574544BE8CF}.Release|x86.Build.0 = Release|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Debug|x86.Build.0 = Debug|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Release|x86.ActiveCfg = Release|Any CPU
|
||||||
|
{B285DA24-39C9-4BA2-AF3D-A1A05737268B}.Release|x86.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
Reference in New Issue
Block a user