-
Notifications
You must be signed in to change notification settings - Fork 16
/
Packet9BLayer.go
87 lines (77 loc) · 1.83 KB
/
Packet9BLayer.go
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package peer
import (
"fmt"
)
// Packet9BLayer represents ID_LUAU_CHALLENGE
type Packet9BLayer struct {
Int1 uint32
Challenge uint32
Response uint32
Script []byte
}
func (thisStream *extendedReader) DecodePacket9BLayer(reader PacketReader, layers *PacketLayers) (RakNetPacket, error) {
var err error
layer := &Packet9BLayer{}
if !reader.IsClient() {
layer.Int1, err = thisStream.readUint32BE()
if err != nil {
return layer, err
}
layer.Challenge, err = thisStream.readUint32BE()
if err != nil {
return layer, err
}
length, err := thisStream.readUint32BE()
if err != nil {
return layer, err
}
layer.Script, err = thisStream.readString(int(length))
if err != nil {
return layer, err
}
return layer, nil
}
layer.Challenge, err = thisStream.readUint32BE()
if err != nil {
return layer, err
}
layer.Response, err = thisStream.readUint32BE()
if err != nil {
return layer, err
}
return layer, nil
}
// Serialize implements RakNetPacket.Serialize
func (layer *Packet9BLayer) Serialize(writer PacketWriter, stream *extendedWriter) error {
if writer.ToClient() {
err := stream.writeUint32BE(layer.Int1)
if err != nil {
return err
}
err = stream.writeUint32BE(layer.Challenge)
if err != nil {
return err
}
err = stream.writeUint32BE(uint32(len(layer.Script)))
if err != nil {
return err
}
return stream.allBytes(layer.Script)
}
err := stream.writeUint32BE(layer.Challenge)
if err != nil {
return err
}
return stream.writeUint32BE(layer.Response)
}
func (layer *Packet9BLayer) String() string {
return fmt.Sprintf("ID_LUAU_CHALLENGE: %08X", layer.Challenge)
}
// TypeString implements RakNetPacket.TypeString()
func (Packet9BLayer) TypeString() string {
return "ID_LUAU_CHALLENGE"
}
// Type implements RakNetPacket.Type()
func (Packet9BLayer) Type() byte {
return 0x9B
}