From ca90ebdfa8789654766c5d7969baa7afacd9ebd2 Mon Sep 17 00:00:00 2001 From: BanceDev Date: Mon, 16 Feb 2026 16:31:54 -0500 Subject: initial commit --- packet/command/damage/damage.go | 61 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 packet/command/damage/damage.go (limited to 'packet/command/damage/damage.go') diff --git a/packet/command/damage/damage.go b/packet/command/damage/damage.go new file mode 100644 index 0000000..93ddb1e --- /dev/null +++ b/packet/command/damage/damage.go @@ -0,0 +1,61 @@ +package damage + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/protocol" +) + +type Command struct { + CoordSize uint8 + + Armor byte + Blood byte + Coord [3]float32 +} + +func (cmd *Command) Bytes() []byte { + buf := buffer.New() + + writeCoord := buf.PutCoord16 + if cmd.CoordSize == 4 { + writeCoord = buf.PutCoord32 + } + + buf.PutByte(byte(protocol.SVCDamage)) + buf.PutByte(cmd.Armor) + buf.PutByte(cmd.Blood) + + for i := 0; i < 3; i++ { + writeCoord(cmd.Coord[i]) + } + + return buf.Bytes() +} + +func Parse(ctx *context.Context, buf *buffer.Buffer) (*Command, error) { + var err error + var cmd Command + + cmd.CoordSize = ctx.GetCoordSize() + readCoord := buf.GetCoord16 + if cmd.CoordSize == 4 { + readCoord = buf.GetCoord32 + } + + if cmd.Armor, err = buf.ReadByte(); err != nil { + return nil, err + } + + if cmd.Blood, err = buf.ReadByte(); err != nil { + return nil, err + } + + for i := 0; i < 3; i++ { + if cmd.Coord[i], err = readCoord(); err != nil { + return nil, err + } + } + + return &cmd, nil +} -- cgit v1.2.3-59-g8ed1b