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