From 64667826d0eecb534d7006e84a1a50eb46b236e5 Mon Sep 17 00:00:00 2001 From: Tnze Date: Wed, 16 Nov 2022 23:32:33 +0800 Subject: [PATCH] go fmt --- bot/basic/settings.go | 2 +- bot/client.go | 2 +- chat/message.go | 2 +- level/block/block.go | 1 + nbt/encode.go | 1 - nbt/nbt.go | 2 +- net/conn.go | 9 +++++---- net/packet/packet.go | 4 ++-- net/packet/types.go | 2 +- realms/mco.go | 7 ++++--- server/auth/auth.go | 11 +++++------ 11 files changed, 22 insertions(+), 21 deletions(-) diff --git a/bot/basic/settings.go b/bot/basic/settings.go index 105a819..c5f5cb0 100644 --- a/bot/basic/settings.go +++ b/bot/basic/settings.go @@ -30,7 +30,7 @@ const ( Hat ) -//DefaultSettings are the default settings of client +// DefaultSettings are the default settings of client var DefaultSettings = Settings{ Locale: "zh_CN", // ^_^ ViewDistance: 15, diff --git a/bot/client.go b/bot/client.go index 17db3b8..a790a1b 100644 --- a/bot/client.go +++ b/bot/client.go @@ -37,7 +37,7 @@ func NewClient() *Client { } } -//Position is a 3D vector. +// Position is a 3D vector. type Position struct { X, Y, Z int } diff --git a/chat/message.go b/chat/message.go index bec4d59..c4770af 100644 --- a/chat/message.go +++ b/chat/message.go @@ -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) { if len(raw) == 0 { return io.EOF diff --git a/level/block/block.go b/level/block/block.go index 1a2e68d..e8d786b 100644 --- a/level/block/block.go +++ b/level/block/block.go @@ -15,6 +15,7 @@ type Block interface { } // This file stores all possible block states into a TAG_List with gzip compressed. +// //go:embed block_states.nbt var blockStates []byte diff --git a/nbt/encode.go b/nbt/encode.go index b2ae079..b942d8d 100644 --- a/nbt/encode.go +++ b/nbt/encode.go @@ -39,7 +39,6 @@ func NewEncoder(w io.Writer) *Encoder { // expect `[]int8`, `[]int32`, `[]int64`, `[]uint8`, `[]uint32` and `[]uint64`, // which TagByteArray, TagIntArray and TagLongArray. // To force encode them as TagList, add a struct field tag. -// func (e *Encoder) Encode(v interface{}, tagName string) error { t, val := getTagType(reflect.ValueOf(v)) return e.marshal(val, t, tagName) diff --git a/nbt/nbt.go b/nbt/nbt.go index e807010..983b088 100644 --- a/nbt/nbt.go +++ b/nbt/nbt.go @@ -6,7 +6,7 @@ import ( "io" ) -//Tag type IDs +// Tag type IDs const ( TagEnd byte = iota TagByte diff --git a/net/conn.go b/net/conn.go index f4dec81..f243ad0 100644 --- a/net/conn.go +++ b/net/conn.go @@ -18,7 +18,7 @@ const DefaultPort = 25565 // A Listener is a minecraft 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) { l, err := net.Listen("tcp", addr) if err != nil { @@ -27,7 +27,7 @@ func ListenMC(addr string) (*Listener, error) { return &Listener{l}, nil } -//Accept a minecraft Conn +// Accept a minecraft Conn func (l Listener) Accept() (Conn, error) { conn, err := l.Listener.Accept() return Conn{ @@ -38,7 +38,7 @@ func (l Listener) Accept() (Conn, error) { }, err } -//Conn is a minecraft Connection +// Conn is a minecraft Connection type Conn struct { Socket net.Conn io.Reader @@ -136,6 +136,7 @@ func (d *Dialer) DialMCContext(ctx context.Context, addr string) (*Conn, error) // - now+Timeout // - d.Deadline // - the context's deadline +// // Or zero, if none of Timeout, Deadline, or context's deadline is set. // // 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() } // ReadPacket read a Packet from Conn. diff --git a/net/packet/packet.go b/net/packet/packet.go index e929258..9f72163 100644 --- a/net/packet/packet.go +++ b/net/packet/packet.go @@ -16,7 +16,7 @@ type Packet struct { 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) { var pb Builder for _, v := range fields { @@ -25,7 +25,7 @@ func Marshal(id int32, fields ...FieldEncoder) (pk Packet) { 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 { r := bytes.NewReader(p.Data) for _, v := range fields { diff --git a/net/packet/types.go b/net/packet/types.go index 71c7b0b..5057a47 100644 --- a/net/packet/types.go +++ b/net/packet/types.go @@ -404,7 +404,7 @@ func (d *Double) ReadFrom(r io.Reader) (n int64, err error) { return } -//NBT encode a value as Named Binary Tag +// NBT encode a value as Named Binary Tag func NBT(v interface{}, optionalTagName ...string) Field { if len(optionalTagName) > 0 { return nbtField{V: v, FieldName: optionalTagName[0]} diff --git a/realms/mco.go b/realms/mco.go index adf071d..a2e628f 100644 --- a/realms/mco.go +++ b/realms/mco.go @@ -9,9 +9,10 @@ func (r *Realms) Available() (ok bool, err error) { } // 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, -// else it returns COMPATIBLE. +// +// if the client is outdated, it returns OUTDATED, +// if the client is running a snapshot, it returns OTHER, +// else it returns COMPATIBLE. func (r *Realms) Compatible() (string, error) { resp, err := r.c.Get(Domain + "/mco/client/compatible") if err != nil { diff --git a/server/auth/auth.go b/server/auth/auth.go index a1bd733..290cebd 100644 --- a/server/auth/auth.go +++ b/server/auth/auth.go @@ -14,7 +14,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "net/http" "strings" @@ -27,7 +26,7 @@ import ( 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) { //generate keys key, err := rsa.GenerateKey(rand.Reader, 1024) @@ -153,7 +152,7 @@ func authentication(name, hash string) (*Resp, error) { } defer resp.Body.Close() - body, err := ioutil.ReadAll(resp.Body) + body, err := io.ReadAll(resp.Body) if err != nil { return nil, err } @@ -205,7 +204,7 @@ func twosComplement(p []byte) []byte { return p } -//Resp is the response of authentication +// Resp is the response of authentication type Resp struct { Name string ID uuid.UUID @@ -229,7 +228,7 @@ func (p Property) WriteTo(w io.Writer) (n int64, err error) { }.WriteTo(w) } -//Texture includes player's skin and cape +// Texture includes player's skin and cape type Texture struct { TimeStamp int64 `json:"timestamp"` ID uuid.UUID `json:"profileId"` @@ -241,7 +240,7 @@ type Texture struct { } `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) { var texture []byte texture, err = base64.StdEncoding.DecodeString(r.Properties[0].Value)