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