go-teeworlds-protocol/messages7/unknown.go

65 lines
1.3 KiB
Go
Raw Permalink Normal View History

2024-06-21 05:14:01 +00:00
package messages7
import (
"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-21 05:14:01 +00:00
)
type Unknown struct {
ChunkHeader *chunk7.ChunkHeader
// contains entire raw message
// including message id and chunk header
// can either be a control message or a game/system message
Data []byte
Type network7.MsgType
msgId int // TODO: is that supposed to be exported?
2024-06-21 05:14:01 +00:00
}
func (msg *Unknown) MsgId() int {
2024-06-21 05:14:01 +00:00
if msg.Type == network7.TypeControl {
return msg.msgId
2024-06-21 05:14:01 +00:00
}
return msg.msgId >> 1
2024-06-21 05:14:01 +00:00
}
func (msg *Unknown) MsgType() network7.MsgType {
2024-06-21 05:14:01 +00:00
return msg.Type
}
func (msg *Unknown) System() bool {
2024-06-21 05:14:01 +00:00
if msg.Type == network7.TypeControl {
return false
}
sys := msg.msgId&1 != 0
2024-06-21 05:14:01 +00:00
return sys
}
func (msg *Unknown) Vital() bool {
panic("You are not mean't to pack unknown messages. Use msg.Header().Vital instead.")
2024-06-21 05:14:01 +00:00
}
func (msg *Unknown) Pack() []byte {
2024-06-21 05:14:01 +00:00
return msg.Data
}
func (msg *Unknown) Unpack(u *packer.Unpacker) error {
2024-06-21 05:14:01 +00:00
msg.Data = u.Rest()
msgId := packer.UnpackInt(msg.Data)
msg.msgId = msgId
return nil
2024-06-21 05:14:01 +00:00
}
func (msg *Unknown) Header() *chunk7.ChunkHeader {
if msg.Type == network7.TypeControl {
return nil
}
return msg.ChunkHeader
2024-06-21 05:14:01 +00:00
}
func (msg *Unknown) SetHeader(header *chunk7.ChunkHeader) {
msg.ChunkHeader = header
}