forked from PretendoNetwork/super-mario-maker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.go
45 lines (31 loc) · 1.27 KB
/
register.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
package main
import (
nex "github.com/PretendoNetwork/nex-go"
nexproto "github.com/PretendoNetwork/nex-protocols-go"
)
func register(err error, client *nex.Client, callID uint32, stationUrls []*nex.StationURL) {
localStation := stationUrls[0]
address := client.Address().IP.String()
port := string(client.Address().Port)
localStation.SetAddress(&address)
localStation.SetPort(&port)
localStationURL := localStation.EncodeToString()
rmcResponseStream := nex.NewStreamOut(nexServer)
rmcResponseStream.WriteUInt32LE(0x10001) // Success
rmcResponseStream.WriteUInt32LE(uint32(secureServer.ConnectionIDCounter.Increment()))
rmcResponseStream.WriteString(localStationURL)
rmcResponseBody := rmcResponseStream.Bytes()
// Build response packet
rmcResponse := nex.NewRMCResponse(nexproto.SecureProtocolID, callID)
rmcResponse.SetSuccess(nexproto.SecureMethodRegisterEx, rmcResponseBody)
rmcResponseBytes := rmcResponse.Bytes()
responsePacket, _ := nex.NewPacketV1(client, nil)
responsePacket.SetVersion(1)
responsePacket.SetSource(0xA1)
responsePacket.SetDestination(0xAF)
responsePacket.SetType(nex.DataPacket)
responsePacket.SetPayload(rmcResponseBytes)
responsePacket.AddFlag(nex.FlagNeedsAck)
responsePacket.AddFlag(nex.FlagReliable)
nexServer.Send(responsePacket)
}