]> git.lizzy.rs Git - mt.git/blobdiff - tocltcmds.go
Support HUD font style
[mt.git] / tocltcmds.go
index 6af4f09b4c4003f0581299c9b51cc7153f82e391..7c287491593c0fd7ca38120f86672b07eba483d8 100644 (file)
@@ -1,13 +1,12 @@
-//go:generate ./cmdno.sh tocltcmds ToClt toClt uint16 Cmd newToCltCmd
-
 package mt
 
 import (
-       "crypto/sha1"
        "fmt"
        "image/color"
        "io"
        "math"
+
+       "github.com/Minetest-j45/mt/rudp"
 )
 
 type ToCltCmd interface {
@@ -15,6 +14,8 @@ type ToCltCmd interface {
        toCltCmdNo() uint16
 }
 
+//go:generate ./cmdno.sh tocltcmds ToClt toClt uint16 Cmd newToCltCmd
+
 // ToCltHello is sent as a response to ToSrvInit.
 // The client responds to ToCltHello by authenticating.
 type ToCltHello struct {
@@ -38,14 +39,17 @@ type ToCltAcceptAuth struct {
        SudoAuthMethods AuthMethods
 }
 
-type ToCltAcceptSudoMode struct{}
+type ToCltAcceptSudoMode struct {
+       SudoAuthMethods AuthMethods
+       //mt:const [15]byte{}
+}
 
 type ToCltDenySudoMode struct{}
 
-// ToCltDisco tells that the client that it has been disconnected by the server.
-type ToCltDisco struct {
-       Reason DiscoReason
-       //mt:assert %s.Reason < maxDiscoReason
+// ToCltKick tells that the client that it has been kicked by the server.
+type ToCltKick struct {
+       Reason KickReason
+       //mt:assert %s.Reason < maxKickReason
 
        //mt:if dr := %s.Reason; dr == Custom || dr == Shutdown || dr == Crash
        Custom string
@@ -56,10 +60,11 @@ type ToCltDisco struct {
        //mt:end
 }
 
-type DiscoReason uint8
+// A KickReason is the reason a ToCltKick has been sent.
+type KickReason uint8
 
 const (
-       WrongPasswd DiscoReason = iota
+       WrongPasswd KickReason = iota
        UnexpectedData
        SrvIsSingleplayer
        UnsupportedVer
@@ -72,10 +77,10 @@ const (
        Custom
        Shutdown
        Crash
-       maxDiscoReason
+       maxKickReason
 )
 
-func (cmd ToCltDisco) String() (msg string) {
+func (cmd ToCltKick) String() (msg string) {
        switch cmd.Reason {
        case WrongPasswd:
                return "wrong password"
@@ -104,7 +109,7 @@ func (cmd ToCltDisco) String() (msg string) {
        case Crash:
                msg = "server crash"
        default:
-               msg = fmt.Sprintf("DiscoReason(%d)", cmd.Reason)
+               msg = fmt.Sprintf("KickReason(%d)", cmd.Reason)
        }
 
        if cmd.Custom != "" {
@@ -172,13 +177,10 @@ type ToCltAddPlayerVel struct {
 
 // ToCltMediaPush is sent when a media file is dynamically added.
 type ToCltMediaPush struct {
-       //mt:const uint16(sha1.Size)
-       SHA1        [sha1.Size]byte
-       Filename    string
-       ShouldCache bool
-
-       //mt:len32
-       Data []byte
+       RawHash       string
+       Filename      string
+       CallbackToken uint32
+       ShouldCache   bool
 }
 
 // ToCltChatMsg tells the client that is has received a chat message.
@@ -196,37 +198,28 @@ type ToCltChatMsg struct {
 type ChatMsgType uint8
 
 const (
-       RawMsg ChatMsgType = iota
-       NormalMsg
-       AnnounceMsg
-       SysMsg
+       RawMsg      ChatMsgType = iota // raw
+       NormalMsg                      // normal
+       AnnounceMsg                    // announce
+       SysMsg                         // sys
        maxMsg
 )
 
-func (t ChatMsgType) String() string {
-       if t >= maxMsg {
-               return fmt.Sprintf("ChatMsgType(%d)", t)
-       }
-
-       return [...]string{
-               "raw",
-               "normal",
-               "announce",
-               "sys",
-       }[t]
-}
+//go:generate stringer -linecomment -type ChatMsgType
 
 // ToCltAORmAdd tells the client that AOs have been removed from and/or added to
 // the AOs that it can see.
 type ToCltAORmAdd struct {
        Remove []AOID
-       Add    []struct {
-               ID AOID
-               //mt:const genericCAO
-               //mt:lenhdr 32
-               InitData AOInitData
-               //mt:end
-       }
+       Add    []AOAdd
+}
+
+type AOAdd struct {
+       ID AOID
+       //mt:const genericCAO
+       //mt:lenhdr 32
+       InitData AOInitData
+       //mt:end
 }
 
 // ToCltAOMsgs updates the client about nearby AOs.
@@ -246,7 +239,7 @@ type ToCltMovePlayer struct {
        Pitch, Yaw float32
 }
 
-type ToCltDiscoLegacy struct {
+type ToCltLegacyKick struct {
        //mt:utf16
        Reason string
 }
@@ -420,12 +413,7 @@ type ToCltAddParticleSpawner struct {
        NodeTile     uint8
 }
 
-type HUDID uint32
-
-// ToCltHUDAdd tells the client to add a HUD.
-type ToCltAddHUD struct {
-       ID HUDID
-
+type HUD struct {
        Type HUDType
 
        Pos      [2]float32
@@ -441,6 +429,15 @@ type ToCltAddHUD struct {
        Size     [2]int32
        ZIndex   int16
        Text2    string
+       Style uint32
+}
+
+type HUDID uint32
+
+// ToCltHUDAdd tells the client to add a HUD.
+type ToCltAddHUD struct {
+       ID HUDID
+       HUD
 }
 
 type HUDType uint8
@@ -454,6 +451,8 @@ const (
        ImgWaypointHUD
 )
 
+//go:generate stringer -type HUDType
+
 // ToCltRmHUD tells the client to remove a HUD.
 type ToCltRmHUD struct {
        ID HUDID
@@ -512,12 +511,16 @@ type ToCltChangeHUD struct {
        //mt:end
 
        //mt:if %s.Field == HUDZIndex
-       ZIndex uint32
+       ZIndex int32
        //mt:end
 
        //mt:if %s.Field == HUDText2
        Text2 string
        //mt:end
+
+       //mt:if %s.Field == HUDStyle
+       Style HUDStyleFlags
+       //mt:end
 }
 
 type HUDField uint8
@@ -536,9 +539,22 @@ const (
        HUDSize
        HUDZIndex
        HUDText2
+       HUDStyle
        hudMax
 )
 
+//go:generate stringer -trimprefix HUD -type HUDField
+
+type HUDStyleFlags uint32
+
+const (
+       StyleBold HUDStyleFlags = 1 << iota
+       StyleItalic
+       StyleMono
+)
+
+//go:generate stringer -trimprefix Style -type HUDStyleFlags
+
 // ToCltHUDFlags tells the client to update its HUD flags.
 type ToCltHUDFlags struct {
        // &^= Mask
@@ -580,6 +596,8 @@ const (
        HotbarSelImg
 )
 
+//go:generate stringer -trimprefix Hotbar -type HotbarParam
+
 // ToCltBreath tells the client how much breath it has.
 type ToCltBreath struct {
        Breath uint16
@@ -655,11 +673,13 @@ type ToCltUpdatePlayerList struct {
 type PlayerListUpdateType uint8
 
 const (
-       InitPlayers PlayerListUpdateType = iota
-       AddPlayers
-       RemovePlayers
+       InitPlayers   PlayerListUpdateType = iota // init
+       AddPlayers                                // add
+       RemovePlayers                             // remove
 )
 
+//go:generate stringer -linecomment -type PlayerListUpdateType
+
 // ToCltModChanMsg tells the client it has been sent a message on a mod channel.
 type ToCltModChanMsg struct {
        Channel string
@@ -684,6 +704,8 @@ const (
        SetState
 )
 
+//go:generate stringer -type ModChanSig
+
 // ToCltModChanMsg is sent when node metadata near the client changes.
 type ToCltNodeMetasChanged struct {
        //mt:lenhdr 32
@@ -732,35 +754,37 @@ type ToCltMinimapModes struct {
        Modes   []MinimapMode
 }
 
-func (cmd *ToCltMinimapModes) serialize(w io.Writer) error {
+var _ serializer = (*ToCltMinimapModes)(nil)
+
+func (cmd *ToCltMinimapModes) serialize(w io.Writer) {
        buf := make([]byte, 4)
        if len(cmd.Modes) > math.MaxUint16 {
-               return ErrTooLong
+               chk(ErrTooLong)
        }
        be.PutUint16(buf[0:2], uint16(len(cmd.Modes)))
        be.PutUint16(buf[2:4], cmd.Current)
-       if _, err := w.Write(buf); err != nil {
-               return err
-       }
+       _, err := w.Write(buf)
+       chk(err)
        for i := range cmd.Modes {
-               if err := serialize(w, &cmd.Modes[i]); err != nil {
-                       return err
-               }
+               chk(serialize(w, &cmd.Modes[i]))
        }
-       return nil
 }
 
-func (cmd *ToCltMinimapModes) deserialize(r io.Reader) error {
+var _ deserializer = (*ToCltMinimapModes)(nil)
+
+func (cmd *ToCltMinimapModes) deserialize(r io.Reader) {
        buf := make([]byte, 4)
-       if _, err := io.ReadFull(r, buf); err != nil {
-               return err
-       }
+       _, err := io.ReadFull(r, buf)
+       chk(err)
        cmd.Modes = make([]MinimapMode, be.Uint16(buf[0:2]))
        cmd.Current = be.Uint16(buf[2:4])
        for i := range cmd.Modes {
-               if err := deserialize(r, &cmd.Modes[i]); err != nil {
-                       return err
-               }
+               chk(deserialize(r, &cmd.Modes[i]))
        }
-       return nil
 }
+
+type ToCltDisco struct{}
+
+func (*ToCltDisco) cmd()                         {}
+func (*ToCltDisco) toCltCmdNo() uint16           { return 0xffff }
+func (*ToCltDisco) DefaultPktInfo() rudp.PktInfo { return rudp.PktInfo{} }