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