-
Notifications
You must be signed in to change notification settings - Fork 58
/
server_login_encrypt_response.go
122 lines (118 loc) · 3.49 KB
/
server_login_encrypt_response.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
package v119
import (
"errors"
"fmt"
"github.com/LilyPad/GoLilyPad/packet"
minecraft "github.com/LilyPad/GoLilyPad/packet/minecraft"
"io"
)
type CodecServerLoginEncryptResponse struct {
IdMap *minecraft.IdMap
}
func (this *CodecServerLoginEncryptResponse) Decode(reader io.Reader) (decode packet.Packet, err error) {
packetServerLoginEncryptResponse := new(minecraft.PacketServerLoginEncryptResponse)
packetServerLoginEncryptResponse.IdFrom(this.IdMap)
sharedSecretLength, err := packet.ReadVarInt(reader)
if err != nil {
return
}
if sharedSecretLength < 0 {
err = errors.New(fmt.Sprintf("Decode, Shared secret length is below zero: %d", sharedSecretLength))
return
}
if sharedSecretLength > 65535 {
err = errors.New(fmt.Sprintf("Decode, Shared secret length is above maximum: %d", sharedSecretLength))
return
}
packetServerLoginEncryptResponse.SharedSecret = make([]byte, sharedSecretLength)
_, err = reader.Read(packetServerLoginEncryptResponse.SharedSecret)
if err != nil {
return
}
verifyTokenPresent, err := packet.ReadBool(reader)
if err != nil {
return
}
if verifyTokenPresent {
var verifyTokenLength int
verifyTokenLength, err = packet.ReadVarInt(reader)
if err != nil {
return
}
if verifyTokenLength < 0 {
err = errors.New(fmt.Sprintf("Decode, Verify token length is below zero: %d", verifyTokenLength))
return
}
if verifyTokenLength > 65535 {
err = errors.New(fmt.Sprintf("Decode, Verify token length is above maximum: %d", verifyTokenLength))
return
}
packetServerLoginEncryptResponse.VerifyToken = make([]byte, verifyTokenLength)
_, err = reader.Read(packetServerLoginEncryptResponse.VerifyToken)
if err != nil {
return
}
} else {
packetServerLoginEncryptResponse.Salt, err = packet.ReadInt64(reader)
if err != nil {
return
}
var signatureLength int
signatureLength, err = packet.ReadVarInt(reader)
if err != nil {
return
}
if signatureLength < 0 {
err = errors.New(fmt.Sprintf("Decode, Salt signature length is below zero: %d", signatureLength))
return
}
if signatureLength > 65535 {
err = errors.New(fmt.Sprintf("Decode, Salt signature length is above maximum: %d", signatureLength))
return
}
packetServerLoginEncryptResponse.Signature = make([]byte, signatureLength)
_, err = reader.Read(packetServerLoginEncryptResponse.Signature)
if err != nil {
return
}
}
decode = packetServerLoginEncryptResponse
return
}
func (this *CodecServerLoginEncryptResponse) Encode(writer io.Writer, encode packet.Packet) (err error) {
packetServerLoginEncryptResponse := encode.(*minecraft.PacketServerLoginEncryptResponse)
err = packet.WriteVarInt(writer, len(packetServerLoginEncryptResponse.SharedSecret))
if err != nil {
return
}
_, err = writer.Write(packetServerLoginEncryptResponse.SharedSecret)
if err != nil {
return
}
if packetServerLoginEncryptResponse.VerifyToken == nil {
err = packet.WriteBool(writer, false)
if err != nil {
return
}
err = packet.WriteInt64(writer, packetServerLoginEncryptResponse.Salt)
if err != nil {
return
}
err = packet.WriteVarInt(writer, len(packetServerLoginEncryptResponse.Signature))
if err != nil {
return
}
_, err = writer.Write(packetServerLoginEncryptResponse.Signature)
} else {
err = packet.WriteBool(writer, true)
if err != nil {
return
}
err = packet.WriteVarInt(writer, len(packetServerLoginEncryptResponse.VerifyToken))
if err != nil {
return
}
_, err = writer.Write(packetServerLoginEncryptResponse.VerifyToken)
}
return
}