mirror of
https://github.com/PretendoNetwork/friends.git
synced 2025-04-02 11:01:46 -04:00
43 lines
1.6 KiB
Go
43 lines
1.6 KiB
Go
package nex_friends_3ds
|
|
|
|
import (
|
|
database_3ds "github.com/PretendoNetwork/friends/database/3ds"
|
|
"github.com/PretendoNetwork/friends/globals"
|
|
notifications_3ds "github.com/PretendoNetwork/friends/notifications/3ds"
|
|
nex "github.com/PretendoNetwork/nex-go/v2"
|
|
"github.com/PretendoNetwork/nex-go/v2/types"
|
|
friends_3ds "github.com/PretendoNetwork/nex-protocols-go/v2/friends-3ds"
|
|
)
|
|
|
|
func AddFriendByPrincipalID(err error, packet nex.PacketInterface, callID uint32, lfc types.UInt64, pid types.PID) (*nex.RMCMessage, *nex.Error) {
|
|
if err != nil {
|
|
globals.Logger.Error(err.Error())
|
|
return nil, nex.NewError(nex.ResultCodes.FPD.InvalidArgument, "") // TODO - Add error message
|
|
}
|
|
|
|
connection := packet.Sender().(*nex.PRUDPConnection)
|
|
|
|
friendRelationship, err := database_3ds.SaveFriendship(uint32(connection.PID()), uint32(pid))
|
|
if err != nil {
|
|
globals.Logger.Critical(err.Error())
|
|
return nil, nex.NewError(nex.ResultCodes.FPD.Unknown, "") // TODO - Add error message
|
|
}
|
|
|
|
connectedUser, ok := globals.ConnectedUsers.Get(uint32(pid))
|
|
if ok && connectedUser != nil {
|
|
go notifications_3ds.SendFriendshipCompleted(connectedUser.Connection, connection.PID())
|
|
}
|
|
|
|
rmcResponseStream := nex.NewByteStreamOut(globals.SecureEndpoint.LibraryVersions(), globals.SecureEndpoint.ByteStreamSettings())
|
|
|
|
friendRelationship.WriteTo(rmcResponseStream)
|
|
|
|
rmcResponseBody := rmcResponseStream.Bytes()
|
|
|
|
rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseBody)
|
|
rmcResponse.ProtocolID = friends_3ds.ProtocolID
|
|
rmcResponse.MethodID = friends_3ds.MethodAddFriendByPrincipalID
|
|
rmcResponse.CallID = callID
|
|
|
|
return rmcResponse, nil
|
|
}
|