diff --git a/bot/client.go b/bot/client.go index 700ec7e..1fa346f 100644 --- a/bot/client.go +++ b/bot/client.go @@ -19,7 +19,7 @@ type Client struct { Wd world.World //the map data // Delegate allows you push a function to let HandleGame run. - // Do not send at the same goroutin! + // Do not send at the same goroutine! Delegate chan func() error Events eventBroker @@ -29,7 +29,7 @@ type Client struct { // NewClient init and return a new Client. // // A new Client has default name "Steve" and zero UUID. -// It is useable for an offline-mode game. +// It is usable for an offline-mode game. // // For online-mode, you need login your Mojang account // and load your Name, UUID and AccessToken to client. diff --git a/bot/mcbot.go b/bot/mcbot.go index 81118e7..22b3913 100644 --- a/bot/mcbot.go +++ b/bot/mcbot.go @@ -1,7 +1,7 @@ // Package bot implements a simple Minecraft client that can join a server // or just ping it for getting information. // -// Runable example could be found at cmd/ . +// Runnable example could be found at cmd/ . package bot import ( @@ -15,10 +15,10 @@ import ( // ProtocolVersion , the protocol version number of minecraft net protocol const ProtocolVersion = 490 -// PingAndList chack server status and list online player. +// PingAndList check server status and list online player. // Returns a JSON data with server status, and the delay. // -// For more infomation for JSON format, see https://wiki.vg/Server_List_Ping#Response +// For more information for JSON format, see https://wiki.vg/Server_List_Ping#Response func PingAndList(addr string, port int) ([]byte, time.Duration, error) { conn, err := net.DialMC(fmt.Sprintf("%s:%d", addr, port)) if err != nil { diff --git a/cmd/autofish/autofish.go b/cmd/autofish/autofish.go index c3ebab3..7755d93 100644 --- a/cmd/autofish/autofish.go +++ b/cmd/autofish/autofish.go @@ -24,7 +24,7 @@ func main() { } log.Println("Login success") - //Regist event handlers + //Register event handlers c.Events.GameStart = onGameStart c.Events.ChatMsg = onChatMsg c.Events.Disconnect = onDisconnect diff --git a/cmd/mcping/mcping.go b/cmd/mcping/mcping.go index 6658329..5686aac 100644 --- a/cmd/mcping/mcping.go +++ b/cmd/mcping/mcping.go @@ -53,9 +53,9 @@ func main() { } func getAddr() (string, int) { - const useage = "Useage: mcping [:port]" + const usage = "Usage: mcping [:port]" if len(os.Args) < 2 { - fmt.Println("no host name.", useage) + fmt.Println("no host name.", usage) os.Exit(1) } @@ -68,7 +68,7 @@ func getAddr() (string, int) { var err error port, err = strconv.Atoi(addr[1]) if err != nil { - fmt.Println(err, useage) + fmt.Println(err, usage) os.Exit(1) } } diff --git a/nbt/marshal.go b/nbt/marshal.go index f13f8bf..d19d336 100644 --- a/nbt/marshal.go +++ b/nbt/marshal.go @@ -107,7 +107,7 @@ func (e *Encoder) marshal(val reflect.Value, tagName string) error { } default: - return errors.New("unknow type " + val.Type().String() + " slice") + return errors.New("unknown type " + val.Type().String() + " slice") } case reflect.String: @@ -167,18 +167,18 @@ func (e *Encoder) writeNamelessTag(tagType byte, tagName string) error { } func (e *Encoder) writeInt16(n int16) error { - e.w.Write([]byte{byte(n >> 8), byte(n)}) - return nil + _, err := e.w.Write([]byte{byte(n >> 8), byte(n)}) + return err } func (e *Encoder) writeInt32(n int32) error { - e.w.Write([]byte{byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)}) - return nil + _, err := e.w.Write([]byte{byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)}) + return err } func (e *Encoder) writeInt64(n int64) error { - e.w.Write([]byte{ + _, err := e.w.Write([]byte{ byte(n >> 56), byte(n >> 48), byte(n >> 40), byte(n >> 32), byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)}) - return nil + return err } diff --git a/nbt/read.go b/nbt/read.go index f4a4f37..af6e20f 100644 --- a/nbt/read.go +++ b/nbt/read.go @@ -169,7 +169,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte, tagName string) err if err != nil { return err } - vt := val.Type() //reciver must be []int or []int32 + vt := val.Type() //receiver must be []int or []int32 if vt.Kind() == reflect.Interface { vt = reflect.TypeOf([]int32{}) // pass } else if vt.Kind() != reflect.Slice { @@ -193,7 +193,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte, tagName string) err if err != nil { return err } - vt := val.Type() //reciver must be []int or []int64 + vt := val.Type() //receiver must be []int or []int64 if vt.Kind() == reflect.Interface { vt = reflect.TypeOf([]int64{}) // pass } else if vt.Kind() != reflect.Slice { diff --git a/nbt/typeinfo.go b/nbt/typeinfo.go index 0d49f56..9903804 100644 --- a/nbt/typeinfo.go +++ b/nbt/typeinfo.go @@ -10,15 +10,15 @@ type typeInfo struct { nameToIndex map[string]int } -var tinfoMap sync.Map +var tInfoMap sync.Map func getTypeInfo(typ reflect.Type) *typeInfo { - if ti, ok := tinfoMap.Load(typ); ok { + if ti, ok := tInfoMap.Load(typ); ok { return ti.(*typeInfo) } - tinfo := new(typeInfo) - tinfo.nameToIndex = make(map[string]int) + tInfo := new(typeInfo) + tInfo.nameToIndex = make(map[string]int) if typ.Kind() == reflect.Struct { n := typ.NumField() for i := 0; i < n; i++ { @@ -28,14 +28,14 @@ func getTypeInfo(typ reflect.Type) *typeInfo { continue // Private field } - tinfo.nameToIndex[tag] = i - if _, ok := tinfo.nameToIndex[f.Name]; !ok { - tinfo.nameToIndex[f.Name] = i + tInfo.nameToIndex[tag] = i + if _, ok := tInfo.nameToIndex[f.Name]; !ok { + tInfo.nameToIndex[f.Name] = i } } } - ti, _ := tinfoMap.LoadOrStore(typ, tinfo) + ti, _ := tInfoMap.LoadOrStore(typ, tInfo) return ti.(*typeInfo) } diff --git a/net/conn.go b/net/conn.go index 5b47eb3..572fddd 100644 --- a/net/conn.go +++ b/net/conn.go @@ -22,7 +22,7 @@ func ListenMC(addr string) (*Listener, error) { return &Listener{l}, nil } -//Accept a miencraft Conn +//Accept a minecraft Conn func (l Listener) Accept() (Conn, error) { conn, err := l.Listener.Accept() return Conn{ @@ -70,21 +70,21 @@ func (c *Conn) WritePacket(p pk.Packet) error { } // SetCipher load the decode/encode stream to this Conn -func (c *Conn) SetCipher(encoStream, decoStream cipher.Stream) { +func (c *Conn) SetCipher(ecoStream, decoStream cipher.Stream) { //加密连接 - c.ByteReader = bufio.NewReader(cipher.StreamReader{ //Set reciver for AES + c.ByteReader = bufio.NewReader(cipher.StreamReader{ //Set receiver for AES S: decoStream, R: c.Socket, }) c.Writer = cipher.StreamWriter{ - S: encoStream, + S: ecoStream, W: c.Socket, } } // SetThreshold set threshold to Conn. -// The data packet with length longger then threshold -// will be compress when sendding. +// The data packet with length longer then threshold +// will be compress when sending. func (c *Conn) SetThreshold(t int) { c.threshold = t }