Add ctrl close

This commit is contained in:
ChillerDragon 2024-06-21 11:21:48 +08:00
parent 4d05818f15
commit 88a312abc4

48
messages7/ctrl_close.go Normal file
View file

@ -0,0 +1,48 @@
package messages7
import (
"slices"
"github.com/teeworlds-go/teeworlds/chunk7"
"github.com/teeworlds-go/teeworlds/network7"
"github.com/teeworlds-go/teeworlds/packer"
)
type CtrlClose struct {
Reason string
}
func (msg CtrlClose) MsgId() int {
return network7.MsgCtrlClose
}
func (msg CtrlClose) MsgType() network7.MsgType {
return network7.TypeControl
}
func (msg CtrlClose) System() bool {
return false
}
func (msg CtrlClose) Vital() bool {
return false
}
func (msg CtrlClose) Pack() []byte {
return slices.Concat(
[]byte{network7.MsgCtrlClose},
packer.PackStr(msg.Reason),
)
}
func (msg *CtrlClose) Unpack(u *packer.Unpacker) {
// TODO: sanitize
msg.Reason = u.GetString()
}
func (msg *CtrlClose) Header() *chunk7.ChunkHeader {
return nil
}
func (msg *CtrlClose) SetHeader(header *chunk7.ChunkHeader) {
}