修正代码中的若干拼写错误
This commit is contained in:
@ -19,7 +19,7 @@ type Client struct {
|
|||||||
Wd world.World //the map data
|
Wd world.World //the map data
|
||||||
|
|
||||||
// Delegate allows you push a function to let HandleGame run.
|
// 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
|
Delegate chan func() error
|
||||||
Events eventBroker
|
Events eventBroker
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ type Client struct {
|
|||||||
// NewClient init and return a new Client.
|
// NewClient init and return a new Client.
|
||||||
//
|
//
|
||||||
// A new Client has default name "Steve" and zero UUID.
|
// 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
|
// For online-mode, you need login your Mojang account
|
||||||
// and load your Name, UUID and AccessToken to client.
|
// and load your Name, UUID and AccessToken to client.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
// Package bot implements a simple Minecraft client that can join a server
|
// Package bot implements a simple Minecraft client that can join a server
|
||||||
// or just ping it for getting information.
|
// or just ping it for getting information.
|
||||||
//
|
//
|
||||||
// Runable example could be found at cmd/ .
|
// Runnable example could be found at cmd/ .
|
||||||
package bot
|
package bot
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -15,10 +15,10 @@ import (
|
|||||||
// ProtocolVersion , the protocol version number of minecraft net protocol
|
// ProtocolVersion , the protocol version number of minecraft net protocol
|
||||||
const ProtocolVersion = 490
|
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.
|
// 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) {
|
func PingAndList(addr string, port int) ([]byte, time.Duration, error) {
|
||||||
conn, err := net.DialMC(fmt.Sprintf("%s:%d", addr, port))
|
conn, err := net.DialMC(fmt.Sprintf("%s:%d", addr, port))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -24,7 +24,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Println("Login success")
|
log.Println("Login success")
|
||||||
|
|
||||||
//Regist event handlers
|
//Register event handlers
|
||||||
c.Events.GameStart = onGameStart
|
c.Events.GameStart = onGameStart
|
||||||
c.Events.ChatMsg = onChatMsg
|
c.Events.ChatMsg = onChatMsg
|
||||||
c.Events.Disconnect = onDisconnect
|
c.Events.Disconnect = onDisconnect
|
||||||
|
@ -53,9 +53,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getAddr() (string, int) {
|
func getAddr() (string, int) {
|
||||||
const useage = "Useage: mcping <hostname>[:port]"
|
const usage = "Usage: mcping <hostname>[:port]"
|
||||||
if len(os.Args) < 2 {
|
if len(os.Args) < 2 {
|
||||||
fmt.Println("no host name.", useage)
|
fmt.Println("no host name.", usage)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ func getAddr() (string, int) {
|
|||||||
var err error
|
var err error
|
||||||
port, err = strconv.Atoi(addr[1])
|
port, err = strconv.Atoi(addr[1])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err, useage)
|
fmt.Println(err, usage)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ func (e *Encoder) marshal(val reflect.Value, tagName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return errors.New("unknow type " + val.Type().String() + " slice")
|
return errors.New("unknown type " + val.Type().String() + " slice")
|
||||||
}
|
}
|
||||||
|
|
||||||
case reflect.String:
|
case reflect.String:
|
||||||
@ -167,18 +167,18 @@ func (e *Encoder) writeNamelessTag(tagType byte, tagName string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Encoder) writeInt16(n int16) error {
|
func (e *Encoder) writeInt16(n int16) error {
|
||||||
e.w.Write([]byte{byte(n >> 8), byte(n)})
|
_, err := e.w.Write([]byte{byte(n >> 8), byte(n)})
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Encoder) writeInt32(n int32) error {
|
func (e *Encoder) writeInt32(n int32) error {
|
||||||
e.w.Write([]byte{byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)})
|
_, err := e.w.Write([]byte{byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)})
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *Encoder) writeInt64(n int64) error {
|
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 >> 56), byte(n >> 48), byte(n >> 40), byte(n >> 32),
|
||||||
byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)})
|
byte(n >> 24), byte(n >> 16), byte(n >> 8), byte(n)})
|
||||||
return nil
|
return err
|
||||||
}
|
}
|
||||||
|
@ -169,7 +169,7 @@ func (d *Decoder) unmarshal(val reflect.Value, tagType byte, tagName string) err
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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 {
|
if vt.Kind() == reflect.Interface {
|
||||||
vt = reflect.TypeOf([]int32{}) // pass
|
vt = reflect.TypeOf([]int32{}) // pass
|
||||||
} else if vt.Kind() != reflect.Slice {
|
} 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 {
|
if err != nil {
|
||||||
return err
|
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 {
|
if vt.Kind() == reflect.Interface {
|
||||||
vt = reflect.TypeOf([]int64{}) // pass
|
vt = reflect.TypeOf([]int64{}) // pass
|
||||||
} else if vt.Kind() != reflect.Slice {
|
} else if vt.Kind() != reflect.Slice {
|
||||||
|
@ -10,15 +10,15 @@ type typeInfo struct {
|
|||||||
nameToIndex map[string]int
|
nameToIndex map[string]int
|
||||||
}
|
}
|
||||||
|
|
||||||
var tinfoMap sync.Map
|
var tInfoMap sync.Map
|
||||||
|
|
||||||
func getTypeInfo(typ reflect.Type) *typeInfo {
|
func getTypeInfo(typ reflect.Type) *typeInfo {
|
||||||
if ti, ok := tinfoMap.Load(typ); ok {
|
if ti, ok := tInfoMap.Load(typ); ok {
|
||||||
return ti.(*typeInfo)
|
return ti.(*typeInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
tinfo := new(typeInfo)
|
tInfo := new(typeInfo)
|
||||||
tinfo.nameToIndex = make(map[string]int)
|
tInfo.nameToIndex = make(map[string]int)
|
||||||
if typ.Kind() == reflect.Struct {
|
if typ.Kind() == reflect.Struct {
|
||||||
n := typ.NumField()
|
n := typ.NumField()
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
@ -28,14 +28,14 @@ func getTypeInfo(typ reflect.Type) *typeInfo {
|
|||||||
continue // Private field
|
continue // Private field
|
||||||
}
|
}
|
||||||
|
|
||||||
tinfo.nameToIndex[tag] = i
|
tInfo.nameToIndex[tag] = i
|
||||||
if _, ok := tinfo.nameToIndex[f.Name]; !ok {
|
if _, ok := tInfo.nameToIndex[f.Name]; !ok {
|
||||||
tinfo.nameToIndex[f.Name] = i
|
tInfo.nameToIndex[f.Name] = i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ti, _ := tinfoMap.LoadOrStore(typ, tinfo)
|
ti, _ := tInfoMap.LoadOrStore(typ, tInfo)
|
||||||
return ti.(*typeInfo)
|
return ti.(*typeInfo)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
12
net/conn.go
12
net/conn.go
@ -22,7 +22,7 @@ func ListenMC(addr string) (*Listener, error) {
|
|||||||
return &Listener{l}, nil
|
return &Listener{l}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//Accept a miencraft 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{
|
||||||
@ -70,21 +70,21 @@ func (c *Conn) WritePacket(p pk.Packet) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// SetCipher load the decode/encode stream to this Conn
|
// 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,
|
S: decoStream,
|
||||||
R: c.Socket,
|
R: c.Socket,
|
||||||
})
|
})
|
||||||
c.Writer = cipher.StreamWriter{
|
c.Writer = cipher.StreamWriter{
|
||||||
S: encoStream,
|
S: ecoStream,
|
||||||
W: c.Socket,
|
W: c.Socket,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetThreshold set threshold to Conn.
|
// SetThreshold set threshold to Conn.
|
||||||
// The data packet with length longger then threshold
|
// The data packet with length longer then threshold
|
||||||
// will be compress when sendding.
|
// will be compress when sending.
|
||||||
func (c *Conn) SetThreshold(t int) {
|
func (c *Conn) SetThreshold(t int) {
|
||||||
c.threshold = t
|
c.threshold = t
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user