/
update_presence.go
62 lines (46 loc) · 1.85 KB
/
update_presence.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
package nex_friends_3ds
import (
"github.com/PretendoNetwork/friends/globals"
notifications_3ds "github.com/PretendoNetwork/friends/notifications/3ds"
"github.com/PretendoNetwork/friends/types"
nex "github.com/PretendoNetwork/nex-go"
friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds"
friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types"
)
func UpdatePresence(err error, client *nex.Client, callID uint32, presence *friends_3ds_types.NintendoPresence, showGame bool) uint32 {
if err != nil {
globals.Logger.Error(err.Error())
return nex.Errors.FPD.InvalidArgument
}
currentPresence := presence
// Send an entirely empty status, with every flag set to update
if !showGame {
currentPresence = friends_3ds_types.NewNintendoPresence()
currentPresence.GameKey = friends_3ds_types.NewGameKey()
currentPresence.ChangedFlags = 0xFFFFFFFF // All flags
}
go notifications_3ds.SendPresenceUpdate(client, currentPresence)
pid := client.PID()
if globals.ConnectedUsers[pid] == nil {
// TODO - Figure out why this is getting removed
connectedUser := types.NewConnectedUser()
connectedUser.PID = pid
connectedUser.Platform = types.CTR
connectedUser.Client = client
globals.ConnectedUsers[pid] = connectedUser
}
globals.ConnectedUsers[pid].Presence = currentPresence
rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID)
rmcResponse.SetSuccess(friends_3ds.MethodUpdatePresence, nil)
rmcResponseBytes := rmcResponse.Bytes()
responsePacket, _ := nex.NewPacketV0(client, nil)
responsePacket.SetVersion(0)
responsePacket.SetSource(0xA1)
responsePacket.SetDestination(0xAF)
responsePacket.SetType(nex.DataPacket)
responsePacket.SetPayload(rmcResponseBytes)
responsePacket.AddFlag(nex.FlagNeedsAck)
responsePacket.AddFlag(nex.FlagReliable)
globals.SecureServer.Send(responsePacket)
return 0
}