go-teeworlds-protocol/messages7/map_change.go

66 lines
1.4 KiB
Go
Raw Normal View History

2024-06-22 02:38:06 +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"
2024-06-22 02:38:06 +00:00
)
type MapChange struct {
ChunkHeader *chunk7.ChunkHeader
Name string
Crc int
Size int
NumResponseChunksPerRequest int
ChunkSize int
Sha256 [32]byte
}
func (msg *MapChange) MsgId() int {
2024-06-22 02:38:06 +00:00
return network7.MsgSysMapChange
}
func (msg *MapChange) MsgType() network7.MsgType {
2024-06-22 02:38:06 +00:00
return network7.TypeNet
}
func (msg *MapChange) System() bool {
2024-06-22 02:38:06 +00:00
return true
}
func (msg *MapChange) Vital() bool {
2024-06-22 02:38:06 +00:00
return true
}
func (msg *MapChange) Pack() []byte {
2024-06-22 02:38:06 +00:00
return slices.Concat(
packer.PackStr(msg.Name),
packer.PackInt(msg.Crc),
packer.PackInt(msg.Size),
packer.PackInt(msg.NumResponseChunksPerRequest),
packer.PackInt(msg.ChunkSize),
msg.Sha256[:],
)
}
func (msg *MapChange) Unpack(u *packer.Unpacker) error {
msg.Name, _ = u.GetString()
2024-06-22 02:38:06 +00:00
msg.Crc = u.GetInt()
msg.Size = u.GetInt()
msg.NumResponseChunksPerRequest = u.GetInt()
msg.ChunkSize = u.GetInt()
msg.Sha256 = [32]byte(u.Rest())
return nil
2024-06-22 02:38:06 +00:00
}
func (msg *MapChange) Header() *chunk7.ChunkHeader {
return msg.ChunkHeader
}
func (msg *MapChange) SetHeader(header *chunk7.ChunkHeader) {
msg.ChunkHeader = header
}