2024-06-23 04:19:27 +00:00
|
|
|
package messages7
|
|
|
|
|
|
|
|
import (
|
|
|
|
"slices"
|
|
|
|
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/chunk7"
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/network7"
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/packer"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Snap struct {
|
|
|
|
ChunkHeader *chunk7.ChunkHeader
|
|
|
|
|
|
|
|
GameTick int
|
|
|
|
DeltaTick int
|
|
|
|
NumParts int
|
|
|
|
Part int
|
|
|
|
Crc int
|
|
|
|
PartSize int
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *Snap) MsgId() int {
|
2024-06-23 04:19:27 +00:00
|
|
|
return network7.MsgSysSnap
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *Snap) MsgType() network7.MsgType {
|
2024-06-23 04:19:27 +00:00
|
|
|
return network7.TypeNet
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *Snap) System() bool {
|
2024-06-23 04:19:27 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *Snap) Vital() bool {
|
2024-06-23 04:19:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *Snap) Pack() []byte {
|
2024-06-23 04:19:27 +00:00
|
|
|
return slices.Concat(
|
|
|
|
packer.PackInt(msg.GameTick),
|
|
|
|
packer.PackInt(msg.DeltaTick),
|
|
|
|
packer.PackInt(msg.NumParts),
|
|
|
|
packer.PackInt(msg.Part),
|
|
|
|
packer.PackInt(msg.Crc),
|
|
|
|
packer.PackInt(msg.PartSize),
|
2024-06-23 19:18:54 +00:00
|
|
|
msg.Data,
|
2024-06-23 04:19:27 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *Snap) Unpack(u *packer.Unpacker) error {
|
2024-06-23 04:19:27 +00:00
|
|
|
msg.GameTick = u.GetInt()
|
|
|
|
msg.DeltaTick = u.GetInt()
|
|
|
|
msg.NumParts = u.GetInt()
|
|
|
|
msg.Part = u.GetInt()
|
|
|
|
msg.Crc = u.GetInt()
|
|
|
|
msg.PartSize = u.GetInt()
|
|
|
|
msg.Data = u.Rest()
|
2024-06-23 19:18:54 +00:00
|
|
|
return nil
|
2024-06-23 04:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *Snap) Header() *chunk7.ChunkHeader {
|
|
|
|
return msg.ChunkHeader
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *Snap) SetHeader(header *chunk7.ChunkHeader) {
|
|
|
|
msg.ChunkHeader = header
|
|
|
|
}
|