修正代码中的若干拼写错误

This commit is contained in:
Tnze
2019-07-16 23:28:02 +08:00
parent ce9ce6c6f2
commit a7858a2459
8 changed files with 32 additions and 32 deletions

View File

@ -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.

View File

@ -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 {

View File

@ -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

View File

@ -53,9 +53,9 @@ func main() {
}
func getAddr() (string, int) {
const useage = "Useage: mcping <hostname>[:port]"
const usage = "Usage: mcping <hostname>[: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)
}
}

View File

@ -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
}

View File

@ -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 {

View File

@ -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)
}

View File

@ -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
}