2024-06-22 04:25:29 +00:00
|
|
|
package messages7
|
|
|
|
|
|
|
|
import (
|
|
|
|
"slices"
|
|
|
|
|
2024-06-22 05:59:27 +00:00
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/chunk7"
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/network7"
|
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/packer"
|
2024-06-24 09:03:13 +00:00
|
|
|
"github.com/teeworlds-go/go-teeworlds-protocol/snapshot7"
|
2024-06-22 04:25:29 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type SnapSingle struct {
|
|
|
|
ChunkHeader *chunk7.ChunkHeader
|
|
|
|
|
|
|
|
GameTick int
|
|
|
|
DeltaTick int
|
|
|
|
Crc int
|
|
|
|
PartSize int
|
2024-06-24 09:03:13 +00:00
|
|
|
|
|
|
|
// TODO: remove data when snapshot packing works
|
|
|
|
// as of right now Data and Snapshot are the same thing
|
|
|
|
Data []byte
|
|
|
|
Snapshot snapshot7.Snapshot
|
2024-06-22 04:25:29 +00:00
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *SnapSingle) MsgId() int {
|
2024-06-22 04:25:29 +00:00
|
|
|
return network7.MsgSysSnapSingle
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *SnapSingle) MsgType() network7.MsgType {
|
2024-06-22 04:25:29 +00:00
|
|
|
return network7.TypeNet
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *SnapSingle) System() bool {
|
2024-06-22 04:25:29 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *SnapSingle) Vital() bool {
|
2024-06-22 04:25:29 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *SnapSingle) Pack() []byte {
|
2024-06-22 04:25:29 +00:00
|
|
|
return slices.Concat(
|
|
|
|
packer.PackInt(msg.GameTick),
|
|
|
|
packer.PackInt(msg.DeltaTick),
|
|
|
|
packer.PackInt(msg.Crc),
|
|
|
|
packer.PackInt(msg.PartSize),
|
2024-06-23 19:18:54 +00:00
|
|
|
msg.Data,
|
2024-06-22 04:25:29 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
func (msg *SnapSingle) Unpack(u *packer.Unpacker) error {
|
2024-06-22 04:25:29 +00:00
|
|
|
msg.GameTick = u.GetInt()
|
|
|
|
msg.DeltaTick = u.GetInt()
|
|
|
|
msg.Crc = u.GetInt()
|
|
|
|
msg.PartSize = u.GetInt()
|
|
|
|
msg.Data = u.Rest()
|
2024-06-24 09:03:13 +00:00
|
|
|
|
|
|
|
// genius
|
|
|
|
u.Reset(msg.Data)
|
|
|
|
err := msg.Snapshot.Unpack(u)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2024-06-23 19:18:54 +00:00
|
|
|
return nil
|
2024-06-22 04:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *SnapSingle) Header() *chunk7.ChunkHeader {
|
|
|
|
return msg.ChunkHeader
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *SnapSingle) SetHeader(header *chunk7.ChunkHeader) {
|
|
|
|
msg.ChunkHeader = header
|
|
|
|
}
|