diff options
Diffstat (limited to 'packet/command/setinfo/setinfo.go')
| -rw-r--r-- | packet/command/setinfo/setinfo.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/packet/command/setinfo/setinfo.go b/packet/command/setinfo/setinfo.go new file mode 100644 index 0000000..6262ab8 --- /dev/null +++ b/packet/command/setinfo/setinfo.go @@ -0,0 +1,43 @@ +package setinfo + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/protocol" +) + +type Command struct { + PlayerIndex byte + Key string + Value string +} + +func (cmd *Command) Bytes() []byte { + buf := buffer.New() + + buf.PutByte(protocol.SVCSetInfo) + buf.PutByte(cmd.PlayerIndex) + buf.PutString(cmd.Key) + buf.PutString(cmd.Value) + + 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.Key, err = buf.GetString(); err != nil { + return nil, err + } + + if cmd.Value, err = buf.GetString(); err != nil { + return nil, err + } + + return &cmd, nil +} |
