diff options
| author | 2026-02-16 16:31:54 -0500 | |
|---|---|---|
| committer | 2026-02-16 16:31:54 -0500 | |
| commit | ca90ebdfa8789654766c5d7969baa7afacd9ebd2 (patch) | |
| tree | 9693e0c7a5af6713f4c5e39372dcf22d05844ec3 /packet/command/delta | |
Diffstat (limited to '')
| -rw-r--r-- | packet/command/delta/delta.go | 26 | ||||
| -rw-r--r-- | packet/command/deltapacketentities/deltapacketentities.go | 43 | ||||
| -rw-r--r-- | packet/command/deltausercommand/deltausercommand.go | 178 |
3 files changed, 247 insertions, 0 deletions
diff --git a/packet/command/delta/delta.go b/packet/command/delta/delta.go new file mode 100644 index 0000000..90fdffe --- /dev/null +++ b/packet/command/delta/delta.go @@ -0,0 +1,26 @@ +package delta + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/protocol" +) + +type Command struct { + Seq byte +} + +func (cmd *Command) Bytes() []byte { + return []byte{protocol.CLCDelta, cmd.Seq} +} + +func Parse(ctx *context.Context, buf *buffer.Buffer) (*Command, error) { + var err error + var cmd Command + + if cmd.Seq, err = buf.ReadByte(); err != nil { + return nil, err + } + + return &cmd, nil +} diff --git a/packet/command/deltapacketentities/deltapacketentities.go b/packet/command/deltapacketentities/deltapacketentities.go new file mode 100644 index 0000000..7a1d415 --- /dev/null +++ b/packet/command/deltapacketentities/deltapacketentities.go @@ -0,0 +1,43 @@ +package deltapacketentities + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/packet/command/packetentity" + "github.com/osm/quake/protocol" +) + +type Command struct { + Index byte + Entities []*packetentity.Command +} + +func (cmd *Command) Bytes() []byte { + buf := buffer.New() + + buf.PutByte(protocol.SVCDeltaPacketEntities) + buf.PutByte(cmd.Index) + + for i := 0; i < len(cmd.Entities); i++ { + buf.PutBytes(cmd.Entities[i].Bytes()) + } + + buf.PutUint16(0x0000) + + return buf.Bytes() +} + +func Parse(ctx *context.Context, buf *buffer.Buffer) (*Command, error) { + var err error + var cmd Command + + if cmd.Index, err = buf.ReadByte(); err != nil { + return nil, err + } + + if cmd.Entities, err = packetentity.Parse(ctx, buf); err != nil { + return nil, err + } + + return &cmd, nil +} diff --git a/packet/command/deltausercommand/deltausercommand.go b/packet/command/deltausercommand/deltausercommand.go new file mode 100644 index 0000000..3a18371 --- /dev/null +++ b/packet/command/deltausercommand/deltausercommand.go @@ -0,0 +1,178 @@ +package deltausercommand + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/protocol" +) + +type Command struct { + ProtocolVersion uint32 + + Bits byte + + CMAngle1 float32 + CMAngle2 float32 + CMAngle3 float32 + CMForward8 byte + CMForward16 uint16 + CMSide8 byte + CMSide16 uint16 + CMUp8 byte + CMUp16 uint16 + CMButtons byte + CMImpulse byte + CMMsec byte +} + +func (cmd *Command) Bytes() []byte { + buf := buffer.New() + + buf.PutByte(cmd.Bits) + + if cmd.Bits&protocol.CMAngle1 != 0 { + buf.PutAngle16(cmd.CMAngle1) + } + + if cmd.Bits&protocol.CMAngle2 != 0 { + buf.PutAngle16(cmd.CMAngle2) + } + + if cmd.Bits&protocol.CMAngle3 != 0 { + buf.PutAngle16(cmd.CMAngle3) + } + + if cmd.ProtocolVersion <= 26 { + if cmd.Bits&protocol.CMForward != 0 { + buf.PutByte(cmd.CMForward8) + } + + if cmd.Bits&protocol.CMSide != 0 { + buf.PutByte(cmd.CMSide8) + } + + if cmd.Bits&protocol.CMUp != 0 { + buf.PutByte(cmd.CMUp8) + } + } else { + if cmd.Bits&protocol.CMForward != 0 { + buf.PutUint16(cmd.CMForward16) + } + + if cmd.Bits&protocol.CMSide != 0 { + buf.PutUint16(cmd.CMSide16) + } + + if cmd.Bits&protocol.CMUp != 0 { + buf.PutUint16(cmd.CMUp16) + } + } + + if cmd.Bits&protocol.CMButtons != 0 { + buf.PutByte(cmd.CMButtons) + } + + if cmd.Bits&protocol.CMImpulse != 0 { + buf.PutByte(cmd.CMImpulse) + } + + if cmd.ProtocolVersion <= 26 && cmd.Bits&protocol.CMMsec != 0 { + buf.PutByte(cmd.CMMsec) + } else if cmd.ProtocolVersion >= 27 { + buf.PutByte(cmd.CMMsec) + } + + return buf.Bytes() +} + +func Parse(ctx *context.Context, buf *buffer.Buffer) (*Command, error) { + var err error + var cmd Command + + cmd.ProtocolVersion = ctx.GetProtocolVersion() + + if cmd.Bits, err = buf.ReadByte(); err != nil { + return nil, err + } + + if cmd.Bits&protocol.CMAngle1 != 0 { + if cmd.CMAngle1, err = buf.GetAngle16(); err != nil { + return nil, err + } + } + + if cmd.Bits&protocol.CMAngle2 != 0 { + if cmd.CMAngle2, err = buf.GetAngle16(); err != nil { + return nil, err + } + } + + if cmd.Bits&protocol.CMAngle3 != 0 { + if cmd.CMAngle3, err = buf.GetAngle16(); err != nil { + return nil, err + } + } + + if cmd.ProtocolVersion <= 26 { + if cmd.Bits&protocol.CMForward != 0 { + if cmd.CMForward8, err = buf.ReadByte(); err != nil { + return nil, err + } + } + + if cmd.Bits&protocol.CMSide != 0 { + if cmd.CMSide8, err = buf.ReadByte(); err != nil { + return nil, err + } + } + + if cmd.Bits&protocol.CMUp != 0 { + if cmd.CMUp8, err = buf.ReadByte(); err != nil { + return nil, err + } + } + } else { + if cmd.Bits&protocol.CMForward != 0 { + if cmd.CMForward16, err = buf.GetUint16(); err != nil { + return nil, err + } + } + + if cmd.Bits&protocol.CMSide != 0 { + if cmd.CMSide16, err = buf.GetUint16(); err != nil { + return nil, err + } + } + + if cmd.Bits&protocol.CMUp != 0 { + if cmd.CMUp16, err = buf.GetUint16(); err != nil { + return nil, err + } + } + + } + + if cmd.Bits&protocol.CMButtons != 0 { + if cmd.CMButtons, err = buf.ReadByte(); err != nil { + return nil, err + } + } + + if cmd.Bits&protocol.CMImpulse != 0 { + if cmd.CMImpulse, err = buf.ReadByte(); err != nil { + return nil, err + } + } + + if cmd.ProtocolVersion <= 26 && cmd.Bits&protocol.CMMsec != 0 { + if cmd.CMMsec, err = buf.ReadByte(); err != nil { + return nil, err + } + } else if cmd.ProtocolVersion >= 27 { + if cmd.CMMsec, err = buf.ReadByte(); err != nil { + return nil, err + } + } + + return &cmd, nil +} |
