Add input timing and dont error on snap empty

This commit is contained in:
ChillerDragon 2024-06-22 13:15:25 +08:00
parent e1fc8a94f5
commit 1cf0184d60
4 changed files with 68 additions and 7 deletions

52
messages7/input_timing.go Normal file
View file

@ -0,0 +1,52 @@
package messages7
import (
"slices"
"github.com/teeworlds-go/teeworlds/chunk7"
"github.com/teeworlds-go/teeworlds/network7"
"github.com/teeworlds-go/teeworlds/packer"
)
type InputTiming struct {
ChunkHeader *chunk7.ChunkHeader
IntendedPredTick int
TimeLeft int
}
func (msg InputTiming) MsgId() int {
return network7.MsgSysInputTiming
}
func (msg InputTiming) MsgType() network7.MsgType {
return network7.TypeNet
}
func (msg InputTiming) System() bool {
return true
}
func (msg InputTiming) Vital() bool {
return false
}
func (msg InputTiming) Pack() []byte {
return slices.Concat(
packer.PackInt(msg.IntendedPredTick),
packer.PackInt(msg.TimeLeft),
)
}
func (msg *InputTiming) Unpack(u *packer.Unpacker) {
msg.IntendedPredTick = u.GetInt()
msg.TimeLeft = u.GetInt()
}
func (msg *InputTiming) Header() *chunk7.ChunkHeader {
return msg.ChunkHeader
}
func (msg *InputTiming) SetHeader(header *chunk7.ChunkHeader) {
msg.ChunkHeader = header
}

View file

@ -14,6 +14,7 @@ const (
MsgSysConReady = 5
MsgSysSnapEmpty = 7
MsgSysSnapSingle = 8
MsgSysInputTiming = 10
MsgSysReady = 18
MsgSysEnterGame = 19

View file

@ -104,6 +104,10 @@ func (connection *Connection) OnSystemMsg(msg messages7.NetMessage, response *Pa
case *messages7.SnapSingle:
// fmt.Printf("got snap single tick=%d\n", msg.GameTick)
response.Messages = append(response.Messages, &messages7.CtrlKeepAlive{})
case *messages7.SnapEmpty:
// fmt.Printf("got snap empty tick=%d\n", msg.GameTick)
case *messages7.InputTiming:
// fmt.Printf("timing time left=%d\n", msg.TimeLeft)
default:
fmt.Printf("unknown system message id=%d payload=%x\n", msg.MsgId(), msg.Pack())
return false

View file

@ -97,6 +97,10 @@ func (packet *Packet) unpackSystem(msgId int, chunk chunk7.Chunk, u *packer.Unpa
msg := &messages7.SnapEmpty{ChunkHeader: &chunk.Header}
msg.Unpack(u)
packet.Messages = append(packet.Messages, msg)
} else if msgId == network7.MsgSysInputTiming {
msg := &messages7.InputTiming{ChunkHeader: &chunk.Header}
msg.Unpack(u)
packet.Messages = append(packet.Messages, msg)
} else {
return false
}