get offline UUID of player from their name!

This commit is contained in:
Tnze
2019-08-29 15:52:54 +08:00
parent d85d31da46
commit d0dbc703cf
4 changed files with 30 additions and 1 deletions

View File

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/aes"
"crypto/cipher"
"crypto/md5"
"crypto/rand"
"crypto/rsa"
"crypto/sha1"
@ -16,6 +17,7 @@ import (
"github.com/Tnze/go-mc/net/CFB8"
pk "github.com/Tnze/go-mc/net/packet"
"github.com/google/uuid"
)
// Auth includes a account
@ -25,6 +27,20 @@ type Auth struct {
AsTk string
}
// OfflineUUID return the UUID from player name in offline mode
func OfflineUUID(name string) uuid.UUID {
var version = 3
h := md5.New()
h.Reset()
h.Write([]byte("OfflinePlayer:" + name))
s := h.Sum(nil)
var uuid uuid.UUID
copy(uuid[:], s)
uuid[6] = (uuid[6] & 0x0f) | uint8((version&0xf)<<4)
uuid[8] = (uuid[8] & 0x3f) | 0x80 // RFC 4122 variant
return uuid
}
// 加密请求
func handleEncryptionRequest(c *Client, pack pk.Packet) error {
//创建AES对称加密密钥