go fmt
This commit is contained in:
@ -30,7 +30,7 @@ const (
|
|||||||
Hat
|
Hat
|
||||||
)
|
)
|
||||||
|
|
||||||
//DefaultSettings are the default settings of client
|
// DefaultSettings are the default settings of client
|
||||||
var DefaultSettings = Settings{
|
var DefaultSettings = Settings{
|
||||||
Locale: "zh_CN", // ^_^
|
Locale: "zh_CN", // ^_^
|
||||||
ViewDistance: 15,
|
ViewDistance: 15,
|
||||||
|
@ -37,7 +37,7 @@ func NewClient() *Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Position is a 3D vector.
|
// Position is a 3D vector.
|
||||||
type Position struct {
|
type Position struct {
|
||||||
X, Y, Z int
|
X, Y, Z int
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func (m Message) MarshalJSON() ([]byte, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//UnmarshalJSON decode json to Message
|
// UnmarshalJSON decode json to Message
|
||||||
func (m *Message) UnmarshalJSON(raw []byte) (err error) {
|
func (m *Message) UnmarshalJSON(raw []byte) (err error) {
|
||||||
if len(raw) == 0 {
|
if len(raw) == 0 {
|
||||||
return io.EOF
|
return io.EOF
|
||||||
|
@ -15,6 +15,7 @@ type Block interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This file stores all possible block states into a TAG_List with gzip compressed.
|
// This file stores all possible block states into a TAG_List with gzip compressed.
|
||||||
|
//
|
||||||
//go:embed block_states.nbt
|
//go:embed block_states.nbt
|
||||||
var blockStates []byte
|
var blockStates []byte
|
||||||
|
|
||||||
|
@ -39,7 +39,6 @@ func NewEncoder(w io.Writer) *Encoder {
|
|||||||
// expect `[]int8`, `[]int32`, `[]int64`, `[]uint8`, `[]uint32` and `[]uint64`,
|
// expect `[]int8`, `[]int32`, `[]int64`, `[]uint8`, `[]uint32` and `[]uint64`,
|
||||||
// which TagByteArray, TagIntArray and TagLongArray.
|
// which TagByteArray, TagIntArray and TagLongArray.
|
||||||
// To force encode them as TagList, add a struct field tag.
|
// To force encode them as TagList, add a struct field tag.
|
||||||
//
|
|
||||||
func (e *Encoder) Encode(v interface{}, tagName string) error {
|
func (e *Encoder) Encode(v interface{}, tagName string) error {
|
||||||
t, val := getTagType(reflect.ValueOf(v))
|
t, val := getTagType(reflect.ValueOf(v))
|
||||||
return e.marshal(val, t, tagName)
|
return e.marshal(val, t, tagName)
|
||||||
|
@ -6,7 +6,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
//Tag type IDs
|
// Tag type IDs
|
||||||
const (
|
const (
|
||||||
TagEnd byte = iota
|
TagEnd byte = iota
|
||||||
TagByte
|
TagByte
|
||||||
|
@ -18,7 +18,7 @@ const DefaultPort = 25565
|
|||||||
// A Listener is a minecraft Listener
|
// A Listener is a minecraft Listener
|
||||||
type Listener struct{ net.Listener }
|
type Listener struct{ net.Listener }
|
||||||
|
|
||||||
//ListenMC listen as TCP but Accept a mc Conn
|
// ListenMC listen as TCP but Accept a mc Conn
|
||||||
func ListenMC(addr string) (*Listener, error) {
|
func ListenMC(addr string) (*Listener, error) {
|
||||||
l, err := net.Listen("tcp", addr)
|
l, err := net.Listen("tcp", addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -27,7 +27,7 @@ func ListenMC(addr string) (*Listener, error) {
|
|||||||
return &Listener{l}, nil
|
return &Listener{l}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Accept a minecraft Conn
|
// Accept a minecraft Conn
|
||||||
func (l Listener) Accept() (Conn, error) {
|
func (l Listener) Accept() (Conn, error) {
|
||||||
conn, err := l.Listener.Accept()
|
conn, err := l.Listener.Accept()
|
||||||
return Conn{
|
return Conn{
|
||||||
@ -38,7 +38,7 @@ func (l Listener) Accept() (Conn, error) {
|
|||||||
}, err
|
}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
//Conn is a minecraft Connection
|
// Conn is a minecraft Connection
|
||||||
type Conn struct {
|
type Conn struct {
|
||||||
Socket net.Conn
|
Socket net.Conn
|
||||||
io.Reader
|
io.Reader
|
||||||
@ -136,6 +136,7 @@ func (d *Dialer) DialMCContext(ctx context.Context, addr string) (*Conn, error)
|
|||||||
// - now+Timeout
|
// - now+Timeout
|
||||||
// - d.Deadline
|
// - d.Deadline
|
||||||
// - the context's deadline
|
// - the context's deadline
|
||||||
|
//
|
||||||
// Or zero, if none of Timeout, Deadline, or context's deadline is set.
|
// Or zero, if none of Timeout, Deadline, or context's deadline is set.
|
||||||
//
|
//
|
||||||
// Copied from net/dial.go
|
// Copied from net/dial.go
|
||||||
@ -197,7 +198,7 @@ func WrapConn(conn net.Conn) *Conn {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Close the connection
|
// Close the connection
|
||||||
func (c *Conn) Close() error { return c.Socket.Close() }
|
func (c *Conn) Close() error { return c.Socket.Close() }
|
||||||
|
|
||||||
// ReadPacket read a Packet from Conn.
|
// ReadPacket read a Packet from Conn.
|
||||||
|
@ -16,7 +16,7 @@ type Packet struct {
|
|||||||
Data []byte
|
Data []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
//Marshal generate Packet with the ID and Fields
|
// Marshal generate Packet with the ID and Fields
|
||||||
func Marshal(id int32, fields ...FieldEncoder) (pk Packet) {
|
func Marshal(id int32, fields ...FieldEncoder) (pk Packet) {
|
||||||
var pb Builder
|
var pb Builder
|
||||||
for _, v := range fields {
|
for _, v := range fields {
|
||||||
@ -25,7 +25,7 @@ func Marshal(id int32, fields ...FieldEncoder) (pk Packet) {
|
|||||||
return pb.Packet(id)
|
return pb.Packet(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Scan decode the packet and fill data into fields
|
// Scan decode the packet and fill data into fields
|
||||||
func (p Packet) Scan(fields ...FieldDecoder) error {
|
func (p Packet) Scan(fields ...FieldDecoder) error {
|
||||||
r := bytes.NewReader(p.Data)
|
r := bytes.NewReader(p.Data)
|
||||||
for _, v := range fields {
|
for _, v := range fields {
|
||||||
|
@ -404,7 +404,7 @@ func (d *Double) ReadFrom(r io.Reader) (n int64, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//NBT encode a value as Named Binary Tag
|
// NBT encode a value as Named Binary Tag
|
||||||
func NBT(v interface{}, optionalTagName ...string) Field {
|
func NBT(v interface{}, optionalTagName ...string) Field {
|
||||||
if len(optionalTagName) > 0 {
|
if len(optionalTagName) > 0 {
|
||||||
return nbtField{V: v, FieldName: optionalTagName[0]}
|
return nbtField{V: v, FieldName: optionalTagName[0]}
|
||||||
|
@ -9,9 +9,10 @@ func (r *Realms) Available() (ok bool, err error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Compatible returns whether the clients version is up to date with Realms.
|
// Compatible returns whether the clients version is up to date with Realms.
|
||||||
// if the client is outdated, it returns OUTDATED,
|
//
|
||||||
// if the client is running a snapshot, it returns OTHER,
|
// if the client is outdated, it returns OUTDATED,
|
||||||
// else it returns COMPATIBLE.
|
// if the client is running a snapshot, it returns OTHER,
|
||||||
|
// else it returns COMPATIBLE.
|
||||||
func (r *Realms) Compatible() (string, error) {
|
func (r *Realms) Compatible() (string, error) {
|
||||||
resp, err := r.c.Get(Domain + "/mco/client/compatible")
|
resp, err := r.c.Get(Domain + "/mco/client/compatible")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -14,7 +14,6 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -27,7 +26,7 @@ import (
|
|||||||
|
|
||||||
const verifyTokenLen = 16
|
const verifyTokenLen = 16
|
||||||
|
|
||||||
//Encrypt a connection, with authentication
|
// Encrypt a connection, with authentication
|
||||||
func Encrypt(conn *net.Conn, name string, profilePubKey *rsa.PublicKey) (*Resp, error) {
|
func Encrypt(conn *net.Conn, name string, profilePubKey *rsa.PublicKey) (*Resp, error) {
|
||||||
//generate keys
|
//generate keys
|
||||||
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
||||||
@ -153,7 +152,7 @@ func authentication(name, hash string) (*Resp, error) {
|
|||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -205,7 +204,7 @@ func twosComplement(p []byte) []byte {
|
|||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
//Resp is the response of authentication
|
// Resp is the response of authentication
|
||||||
type Resp struct {
|
type Resp struct {
|
||||||
Name string
|
Name string
|
||||||
ID uuid.UUID
|
ID uuid.UUID
|
||||||
@ -229,7 +228,7 @@ func (p Property) WriteTo(w io.Writer) (n int64, err error) {
|
|||||||
}.WriteTo(w)
|
}.WriteTo(w)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Texture includes player's skin and cape
|
// Texture includes player's skin and cape
|
||||||
type Texture struct {
|
type Texture struct {
|
||||||
TimeStamp int64 `json:"timestamp"`
|
TimeStamp int64 `json:"timestamp"`
|
||||||
ID uuid.UUID `json:"profileId"`
|
ID uuid.UUID `json:"profileId"`
|
||||||
@ -241,7 +240,7 @@ type Texture struct {
|
|||||||
} `json:"textures"`
|
} `json:"textures"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//Texture unmarshal the base64 encoded texture of Resp
|
// Texture unmarshal the base64 encoded texture of Resp
|
||||||
func (r *Resp) Texture() (t Texture, err error) {
|
func (r *Resp) Texture() (t Texture, err error) {
|
||||||
var texture []byte
|
var texture []byte
|
||||||
texture, err = base64.StdEncoding.DecodeString(r.Properties[0].Value)
|
texture, err = base64.StdEncoding.DecodeString(r.Properties[0].Value)
|
||||||
|
Reference in New Issue
Block a user