get offline UUID of player from their name!
This commit is contained in:
@ -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)
|
||||
|
16
bot/login.go
16
bot/login.go
@ -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对称加密密钥
|
||||
|
Reference in New Issue
Block a user