aboutsummaryrefslogtreecommitdiffstats
path: root/packet/command/qtvconnect/qtvconnect.go
blob: 86adab3e68b00fbe60e154f93b77a12bce35e056 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package qtvconnect

import (
	"fmt"

	"github.com/osm/quake/common/buffer"
	"github.com/osm/quake/common/infostring"
)

type Command struct {
	Version    byte
	Extensions uint32
	Source     string
	UserInfo   *infostring.InfoString
}

func (cmd *Command) Bytes() []byte {
	buf := buffer.New()

	buf.PutBytes([]byte("QTV\n"))
	buf.PutBytes([]byte(fmt.Sprintf("VERSION: %d\n", cmd.Version)))
	buf.PutBytes([]byte(fmt.Sprintf("QTV_EZQUAKE_EXT: %d\n", cmd.Extensions)))
	buf.PutBytes([]byte(fmt.Sprintf("SOURCE: %s\n", cmd.Source)))

	if cmd.UserInfo != nil {
		buf.PutBytes([]byte(fmt.Sprintf("USERINFO: %s\n", string(cmd.UserInfo.Bytes()))))
	}

	buf.PutBytes([]byte("\n"))

	return buf.Bytes()
}