package mt
import (
- "crypto/sha1"
"fmt"
"image/color"
"io"
"math"
+
+ "github.com/dragonfireclient/mt/rudp"
)
type ToCltCmd interface {
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
//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
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"
case Crash:
msg = "server crash"
default:
- msg = fmt.Sprintf("DiscoReason(%d)", cmd.Reason)
+ msg = fmt.Sprintf("KickReason(%d)", cmd.Reason)
}
if cmd.Custom != "" {
// 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
// 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.
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
)
// 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.
// 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.
Pitch, Yaw float32
}
-type ToCltDiscoLegacy struct {
+type ToCltLegacyKick struct {
//mt:utf16
Reason string
}
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
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
//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
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
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
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{} }