forked from PretendoNetwork/super-mario-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
connect.go
37 lines (25 loc) · 1.05 KB
/
connect.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
package main
import (
nex "github.com/PretendoNetwork/nex-go"
)
func connect(packet *nex.PacketV1) {
payload := packet.Payload()
stream := nex.NewStreamIn(payload, nexServer)
_, _ = stream.ReadBuffer()
checkData, _ := stream.ReadBuffer()
sessionKey := make([]byte, nexServer.KerberosKeySize())
kerberos := nex.NewKerberosEncryption(sessionKey)
checkDataDecrypted := kerberos.Decrypt(checkData)
checkDataStream := nex.NewStreamIn(checkDataDecrypted, nexServer)
userPID := checkDataStream.ReadUInt32LE() // User PID
packet.Sender().SetPID(userPID)
_ = checkDataStream.ReadUInt32LE() //CID of secure server station url
responseCheck := checkDataStream.ReadUInt32LE()
responseValueStream := nex.NewStreamOut(nexServer)
responseValueStream.WriteUInt32LE(responseCheck + 1)
responseValueBufferStream := nex.NewStreamOut(nexServer)
responseValueBufferStream.WriteBuffer(responseValueStream.Bytes())
nexServer.AcknowledgePacket(packet, responseValueBufferStream.Bytes())
packet.Sender().UpdateRC4Key(sessionKey)
packet.Sender().SetSessionKey(sessionKey)
}