diff --git a/conn.go b/conn.go index 866d5cd..49b4885 100644 --- a/conn.go +++ b/conn.go @@ -18,7 +18,8 @@ var connectedConnsMu sync.RWMutex type Conn struct { *rudp.Conn - protoVer uint16 + protoVer uint16 + formspecVer uint16 username string srp_s []byte @@ -46,18 +47,18 @@ type Conn struct { noClt bool modChs map[string]bool - huds map[uint32]bool - + huds map[uint32]bool sounds map[int32]bool - blocks [][3]int16 - - inv *mt.Inv + inv *mt.Inv } // ProtoVer returns the protocol version of the Conn func (c *Conn) ProtoVer() uint16 { return c.protoVer } +// FormspecVer returns the formspec API version of the Conn +func (c *Conn) FormspecVer() uint16 { return c.formspecVer + 1 } + // Addr returns the remote address of the Conn func (c *Conn) Addr() net.Addr { return c.Conn.RemoteAddr() diff --git a/init.go b/init.go index 7f7484c..6d52a60 100644 --- a/init.go +++ b/init.go @@ -209,11 +209,14 @@ func Init(c, c2 *Conn, ignMedia, noAccessDenied bool, fin chan *Conn) { continue } - v := []byte("5.4.0-dev-dd5a732fa") + v := []byte("5.5.0-dev-83a7b48bb") w := bytes.NewBuffer([]byte{0x00, ToServerClientReady}) w.Write([]byte{5, 4, 0, 0}) WriteBytes16(w, v) + if c.FormspecVer() != 1 { + WriteUint16(w, c.FormspecVer()) + } _, err := c2.Send(rudp.Pkt{ Reader: w, @@ -535,6 +538,12 @@ func Init(c, c2 *Conn, ignMedia, noAccessDenied bool, fin chan *Conn) { return } + r.Seek(4, io.SeekCurrent) + ReadBytes16(r) + if r.Len() >= 2 { + c2.formspecVer = ReadUint16(r) - 1 + } + defaultSrv := ConfKey("default_server").(string) defSrv := func() *Conn {