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