Add snap empty msg

This commit is contained in:
ChillerDragon 2024-06-22 13:07:47 +08:00
parent 9ea7a3735c
commit e1fc8a94f5
3 changed files with 57 additions and 0 deletions

52
messages7/snap_empty.go Normal file
View file

@ -0,0 +1,52 @@
package messages7
import (
"slices"
"github.com/teeworlds-go/teeworlds/chunk7"
"github.com/teeworlds-go/teeworlds/network7"
"github.com/teeworlds-go/teeworlds/packer"
)
type SnapEmpty struct {
ChunkHeader *chunk7.ChunkHeader
GameTick int
DeltaTick int
}
func (msg SnapEmpty) MsgId() int {
return network7.MsgSysSnapEmpty
}
func (msg SnapEmpty) MsgType() network7.MsgType {
return network7.TypeNet
}
func (msg SnapEmpty) System() bool {
return true
}
func (msg SnapEmpty) Vital() bool {
return false
}
func (msg SnapEmpty) Pack() []byte {
return slices.Concat(
packer.PackInt(msg.GameTick),
packer.PackInt(msg.DeltaTick),
)
}
func (msg *SnapEmpty) Unpack(u *packer.Unpacker) {
msg.GameTick = u.GetInt()
msg.DeltaTick = u.GetInt()
}
func (msg *SnapEmpty) Header() *chunk7.ChunkHeader {
return msg.ChunkHeader
}
func (msg *SnapEmpty) SetHeader(header *chunk7.ChunkHeader) {
msg.ChunkHeader = header
}

View file

@ -12,6 +12,7 @@ const (
MsgSysInfo = 1 MsgSysInfo = 1
MsgSysMapChange = 2 MsgSysMapChange = 2
MsgSysConReady = 5 MsgSysConReady = 5
MsgSysSnapEmpty = 7
MsgSysSnapSingle = 8 MsgSysSnapSingle = 8
MsgSysReady = 18 MsgSysReady = 18
MsgSysEnterGame = 19 MsgSysEnterGame = 19

View file

@ -93,6 +93,10 @@ func (packet *Packet) unpackSystem(msgId int, chunk chunk7.Chunk, u *packer.Unpa
msg := &messages7.SnapSingle{ChunkHeader: &chunk.Header} msg := &messages7.SnapSingle{ChunkHeader: &chunk.Header}
msg.Unpack(u) msg.Unpack(u)
packet.Messages = append(packet.Messages, msg) packet.Messages = append(packet.Messages, msg)
} else if msgId == network7.MsgSysSnapEmpty {
msg := &messages7.SnapEmpty{ChunkHeader: &chunk.Header}
msg.Unpack(u)
packet.Messages = append(packet.Messages, msg)
} else { } else {
return false return false
} }