]> git.lizzy.rs Git - mt.git/blobdiff - tocltcmds.go
Add WaitGroup to SerializePkt
[mt.git] / tocltcmds.go
index 5fbe18b8044d8c2106ec0101a0a004807c5a25c1..54ab78853c83df2abd9531d4ad52b042a9d19e9b 100644 (file)
@@ -1,11 +1,12 @@
 package mt
 
 import (
-       "crypto/sha1"
        "fmt"
        "image/color"
        "io"
        "math"
+
+       "github.com/dragonfireclient/mt/rudp"
 )
 
 type ToCltCmd interface {
@@ -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 != "" {
@@ -117,7 +122,9 @@ func (cmd ToCltDisco) String() (msg string) {
 // ToCltBlkData tells the client the contents of a nearby MapBlk.
 type ToCltBlkData struct {
        Blkpos [3]int16
-       Blk    MapBlk
+       //mt:zstd
+       Blk MapBlk
+       //mt:end
 }
 
 // ToCltAddNode tells the client that a nearby node changed
@@ -172,13 +179,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,10 +200,10 @@ type ToCltChatMsg struct {
 type ChatMsgType uint8
 
 const (
-       RawMsg ChatMsgType = iota // raw
-       NormalMsg                 // normal
-       AnnounceMsg               // announce
-       SysMsg                    // sys
+       RawMsg      ChatMsgType = iota // raw
+       NormalMsg                      // normal
+       AnnounceMsg                    // announce
+       SysMsg                         // sys
        maxMsg
 )
 
@@ -209,13 +213,15 @@ const (
 // 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.
@@ -227,6 +233,8 @@ type ToCltAOMsgs struct {
 // ToCltHP updates the player's HP on the client.
 type ToCltHP struct {
        HP uint16
+       //mt:opt
+       DamageEffect bool
 }
 
 // ToCltMovePlayer tells the client that the player has been moved server-side.
@@ -235,7 +243,7 @@ type ToCltMovePlayer struct {
        Pitch, Yaw float32
 }
 
-type ToCltDiscoLegacy struct {
+type ToCltLegacyKick struct {
        //mt:utf16
        Reason string
 }
@@ -409,12 +417,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
@@ -430,6 +433,15 @@ type ToCltAddHUD struct {
        Size     [2]int32
        ZIndex   int16
        Text2    string
+       Style    HUDStyleFlags
+}
+
+type HUDID uint32
+
+// ToCltHUDAdd tells the client to add a HUD.
+type ToCltAddHUD struct {
+       ID HUDID
+       HUD
 }
 
 type HUDType uint8
@@ -503,12 +515,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
@@ -527,11 +543,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
@@ -650,9 +677,9 @@ type ToCltUpdatePlayerList struct {
 type PlayerListUpdateType uint8
 
 const (
-       InitPlayers PlayerListUpdateType = iota // init
-       AddPlayers                              // add
-       RemovePlayers                           // remove
+       InitPlayers   PlayerListUpdateType = iota // init
+       AddPlayers                                // add
+       RemovePlayers                             // remove
 )
 
 //go:generate stringer -linecomment -type PlayerListUpdateType
@@ -731,35 +758,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{} }