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

@ -1,6 +1,7 @@
package bot
import (
"encoding/hex"
"github.com/Tnze/go-mc/yggdrasil"
"log"
)
@ -17,7 +18,10 @@ func ExamplePingAndList() {
func ExampleClient_JoinServer_offline() {
c := NewClient()
c.Name = "Tnze" // set it's name before login.
c.Auth.Name = "Tnze" // set it's name before login.
id := OfflineUUID(c.Auth.Name) // optional, get uuid of offline mode game
c.Auth.UUID = hex.EncodeToString(id[:])
//Login
err := c.JoinServer("localhost", 25565)

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对称加密密钥

2
go.mod
View File

@ -4,5 +4,7 @@ go 1.12
require (
github.com/google/uuid v1.1.1
github.com/kr/pretty v0.1.0 // indirect
github.com/satori/go.uuid v1.2.0
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)

7
go.sum
View File

@ -1,4 +1,11 @@
github.com/google/uuid v1.1.1 h1:Gkbcsh/GbpXz7lPftLA3P6TYMwjCLYm83jiFQZF/3gY=
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=