diff options
Diffstat (limited to 'packet/command/updateping/updateping.go')
| -rw-r--r-- | packet/command/updateping/updateping.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packet/command/updateping/updateping.go b/packet/command/updateping/updateping.go new file mode 100644 index 0000000..412d9c5 --- /dev/null +++ b/packet/command/updateping/updateping.go @@ -0,0 +1,37 @@ +package updateping + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/protocol" +) + +type Command struct { + PlayerIndex byte + Ping int16 +} + +func (cmd *Command) Bytes() []byte { + buf := buffer.New() + + buf.PutByte(protocol.SVCUpdatePing) + buf.PutByte(cmd.PlayerIndex) + buf.PutInt16(cmd.Ping) + + return buf.Bytes() +} + +func Parse(ctx *context.Context, buf *buffer.Buffer) (*Command, error) { + var err error + var cmd Command + + if cmd.PlayerIndex, err = buf.ReadByte(); err != nil { + return nil, err + } + + if cmd.Ping, err = buf.GetInt16(); err != nil { + return nil, err + } + + return &cmd, nil +} |
