mirror of
https://github.com/PretendoNetwork/friends.git
synced 2026-04-26 07:46:54 -05:00
104 lines
3.4 KiB
Go
104 lines
3.4 KiB
Go
package friends_wiiu
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
database_wiiu "github.com/PretendoNetwork/friends-secure/database/wiiu"
|
|
"github.com/PretendoNetwork/friends-secure/globals"
|
|
nex "github.com/PretendoNetwork/nex-go"
|
|
nexproto "github.com/PretendoNetwork/nex-protocols-go"
|
|
)
|
|
|
|
func UpdatePresence(err error, client *nex.Client, callID uint32, presence *nexproto.NintendoPresenceV2) {
|
|
pid := client.PID()
|
|
|
|
presence.Online = true // Force online status. I have no idea why this is always false
|
|
presence.PID = client.PID() // WHY IS THIS SET TO 0 BY DEFAULT??
|
|
|
|
globals.ConnectedUsers[pid].PresenceV2 = presence
|
|
sendUpdatePresenceWiiUNotifications(presence)
|
|
|
|
rmcResponse := nex.NewRMCResponse(nexproto.FriendsWiiUProtocolID, callID)
|
|
rmcResponse.SetSuccess(nexproto.FriendsWiiUMethodUpdatePresence, 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.NEXServer.Send(responsePacket)
|
|
}
|
|
|
|
func sendUpdatePresenceWiiUNotifications(presence *nexproto.NintendoPresenceV2) {
|
|
eventObject := nexproto.NewNintendoNotificationEvent()
|
|
eventObject.Type = 24
|
|
eventObject.SenderPID = presence.PID
|
|
eventObject.DataHolder = nex.NewDataHolder()
|
|
eventObject.DataHolder.SetTypeName("NintendoPresenceV2")
|
|
eventObject.DataHolder.SetObjectData(presence)
|
|
|
|
stream := nex.NewStreamOut(globals.NEXServer)
|
|
eventObjectBytes := eventObject.Bytes(stream)
|
|
|
|
rmcRequest := nex.NewRMCRequest()
|
|
rmcRequest.SetProtocolID(nexproto.NintendoNotificationsProtocolID)
|
|
rmcRequest.SetCallID(3810693103)
|
|
rmcRequest.SetMethodID(nexproto.NintendoNotificationsMethodProcessNintendoNotificationEvent2)
|
|
rmcRequest.SetParameters(eventObjectBytes)
|
|
|
|
rmcRequestBytes := rmcRequest.Bytes()
|
|
|
|
friendList := database_wiiu.GetUserFriendList(presence.PID)
|
|
|
|
for i := 0; i < len(friendList); i++ {
|
|
if friendList[i] == nil || friendList[i].NNAInfo == nil || friendList[i].NNAInfo.PrincipalBasicInfo == nil {
|
|
// TODO: Fix this
|
|
pid := presence.PID
|
|
var friendPID uint32 = 0
|
|
|
|
if friendList[i] != nil && friendList[i].Presence != nil {
|
|
// TODO: Better track the bad users PID
|
|
friendPID = friendList[i].Presence.PID
|
|
}
|
|
|
|
globals.Logger.Error(fmt.Sprintf("User %d has friend %d with bad presence data", pid, friendPID))
|
|
|
|
if friendList[i] == nil {
|
|
globals.Logger.Error(fmt.Sprintf("%d friendList[i] nil", friendPID))
|
|
} else if friendList[i].NNAInfo == nil {
|
|
globals.Logger.Error(fmt.Sprintf("%d friendList[i].NNAInfo is nil", friendPID))
|
|
} else if friendList[i].NNAInfo.PrincipalBasicInfo == nil {
|
|
globals.Logger.Error(fmt.Sprintf("%d friendList[i].NNAInfo.PrincipalBasicInfo is nil", friendPID))
|
|
}
|
|
|
|
continue
|
|
}
|
|
|
|
friendPID := friendList[i].NNAInfo.PrincipalBasicInfo.PID
|
|
connectedUser := globals.ConnectedUsers[friendPID]
|
|
|
|
if connectedUser != nil {
|
|
requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil)
|
|
|
|
requestPacket.SetVersion(0)
|
|
requestPacket.SetSource(0xA1)
|
|
requestPacket.SetDestination(0xAF)
|
|
requestPacket.SetType(nex.DataPacket)
|
|
requestPacket.SetPayload(rmcRequestBytes)
|
|
|
|
requestPacket.AddFlag(nex.FlagNeedsAck)
|
|
requestPacket.AddFlag(nex.FlagReliable)
|
|
|
|
globals.NEXServer.Send(requestPacket)
|
|
}
|
|
}
|
|
}
|