diff options
Diffstat (limited to 'packet/command/s2cchallenge/s2cchallenge.go')
| -rw-r--r-- | packet/command/s2cchallenge/s2cchallenge.go | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/packet/command/s2cchallenge/s2cchallenge.go b/packet/command/s2cchallenge/s2cchallenge.go new file mode 100644 index 0000000..95cba70 --- /dev/null +++ b/packet/command/s2cchallenge/s2cchallenge.go @@ -0,0 +1,72 @@ +package s2cchallenge + +import ( + "github.com/osm/quake/common/buffer" + "github.com/osm/quake/common/context" + "github.com/osm/quake/protocol" + "github.com/osm/quake/protocol/fte" + "github.com/osm/quake/protocol/mvd" +) + +type Command struct { + ChallengeID string + Extensions []*protocol.Extension +} + +func (cmd *Command) Bytes() []byte { + buf := buffer.New() + + buf.PutByte(byte(protocol.S2CChallenge)) + buf.PutString(cmd.ChallengeID) + + for _, ext := range cmd.Extensions { + buf.PutBytes(ext.Bytes()) + } + + return buf.Bytes() +} + +func Parse(ctx *context.Context, buf *buffer.Buffer) (*Command, error) { + var err error + var cmd Command + + if cmd.ChallengeID, err = buf.GetString(); err != nil { + return nil, err + } + + for buf.Off() < buf.Len() { + version, err := buf.GetUint32() + if err != nil { + return nil, err + } + + extensions, err := buf.GetUint32() + if err != nil { + return nil, err + } + + if ctx.GetIsFTEEnabled() && version == fte.ProtocolVersion { + ctx.SetFTEProtocolExtension(extensions) + + if extensions&fte.ExtensionFloatCoords != 0 { + ctx.SetAngleSize(1) + ctx.SetCoordSize(2) + } + } + + if ctx.GetIsFTE2Enabled() && version == fte.ProtocolVersion2 { + ctx.SetFTE2ProtocolExtension(extensions) + } + + if ctx.GetIsMVDEnabled() && version == mvd.ProtocolVersion { + ctx.SetMVDProtocolExtension(extensions) + } + + cmd.Extensions = append(cmd.Extensions, &protocol.Extension{ + Version: version, + Extensions: extensions, + }) + } + + return &cmd, nil +} |
