From 91b13c31a49e17f944fc368e178eebf76efad180 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Sun, 12 Nov 2023 06:48:13 -0500 Subject: [PATCH] work with new nex-go --- globals/globals.go | 4 +- go.mod | 4 +- go.sum | 8 +- grpc/send_user_notification_wiiu.go | 20 ++-- .../nintendo_create_account.go | 23 ++-- nex/authentication.go | 25 ++-- nex/connect.go | 73 ------------ nex/friends-3ds/add_friendship_by_pid.go | 22 ++-- nex/friends-3ds/get_all_friends.go | 22 ++-- nex/friends-3ds/get_friend_mii.go | 22 ++-- nex/friends-3ds/get_friend_persistent_info.go | 22 ++-- nex/friends-3ds/get_friend_presence.go | 22 ++-- nex/friends-3ds/get_pid_by_lfc.go | 6 +- nex/friends-3ds/remove_friend_by_lfc.go | 6 +- nex/friends-3ds/remove_friend_by_pid.go | 22 ++-- nex/friends-3ds/sync_friend.go | 22 ++-- nex/friends-3ds/update_comment.go | 23 ++-- nex/friends-3ds/update_favorite_game_key.go | 22 ++-- nex/friends-3ds/update_mii.go | 22 ++-- nex/friends-3ds/update_preference.go | 22 ++-- nex/friends-3ds/update_presence.go | 22 ++-- nex/friends-3ds/update_profile.go | 22 ++-- nex/friends-wiiu/accept_friend_request.go | 23 ++-- nex/friends-wiiu/add_blacklist.go | 23 ++-- nex/friends-wiiu/add_friend_request.go | 27 +++-- nex/friends-wiiu/cancel_friend_request.go | 22 ++-- nex/friends-wiiu/check_setting_status.go | 23 ++-- nex/friends-wiiu/delete_friend_request.go | 22 ++-- .../delete_persistent_notification.go | 22 ++-- nex/friends-wiiu/deny_friend_request.go | 23 ++-- nex/friends-wiiu/get_basic_info.go | 23 ++-- .../get_request_block_settings.go | 23 ++-- .../mark_friend_requests_as_received.go | 22 ++-- nex/friends-wiiu/remove_blacklist.go | 22 ++-- nex/friends-wiiu/remove_friend.go | 22 ++-- .../update_and_get_all_information.go | 110 +++++++++++++++--- nex/friends-wiiu/update_comment.go | 22 ++-- nex/friends-wiiu/update_preference.go | 22 ++-- nex/friends-wiiu/update_presence.go | 22 ++-- ..._common_authentication_server_protocols.go | 2 +- nex/secure-connection/register_ex.go | 39 ++++--- nex/secure.go | 41 +++---- notifications/3ds/send_comment_update.go | 22 ++-- notifications/3ds/send_favorite_update.go | 22 ++-- .../3ds/send_friendship_completed.go | 22 ++-- notifications/3ds/send_mii_notification.go | 22 ++-- notifications/3ds/send_presence_update.go | 23 ++-- notifications/3ds/send_user_went_offline.go | 32 ++--- notifications/wiiu/send_friend_request.go | 22 ++-- .../wiiu/send_friend_request_accepted.go | 22 ++-- notifications/wiiu/send_friendship_removed.go | 22 ++-- notifications/wiiu/send_presence_update.go | 20 ++-- notifications/wiiu/send_user_went_offline.go | 24 ++-- types/connected_user.go | 2 +- 54 files changed, 692 insertions(+), 574 deletions(-) delete mode 100644 nex/connect.go diff --git a/globals/globals.go b/globals/globals.go index 4f23424..af05fbf 100644 --- a/globals/globals.go +++ b/globals/globals.go @@ -11,8 +11,8 @@ import ( var Logger *plogger.Logger var KerberosPassword = "password" // * Default password -var AuthenticationServer *nex.Server -var SecureServer *nex.Server +var AuthenticationServer *nex.PRUDPServer +var SecureServer *nex.PRUDPServer var ConnectedUsers map[uint32]*types.ConnectedUser var AESKey []byte var GRPCAccountClientConnection *grpc.ClientConn diff --git a/go.mod b/go.mod index f5c2d08..f69ee70 100644 --- a/go.mod +++ b/go.mod @@ -19,13 +19,13 @@ require ( github.com/fatih/color v1.15.0 // indirect github.com/jwalton/go-supportscolor v1.2.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/superwhiskers/crunch/v3 v3.5.7 // indirect golang.org/x/mod v0.13.0 // indirect golang.org/x/net v0.17.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/term v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 // indirect google.golang.org/protobuf v1.31.0 // indirect ) diff --git a/go.sum b/go.sum index 5a3e142..60e97ab 100644 --- a/go.sum +++ b/go.sum @@ -24,8 +24,8 @@ github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2bawbKNqg= github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA= golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI= @@ -46,8 +46,8 @@ golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a h1:a2MQQVoTo96JC9PMGtGBymLp7+/RzpFc2yX/9WfFg1c= -google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:4cYg8o5yUbm77w8ZX00LhMVNl/YVBFJRYWDc0uYWMs0= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405 h1:AB/lmRny7e2pLhFEYIbl5qkDAUt2h0ZRO4wGPhZf+ik= +google.golang.org/genproto/googleapis/rpc v0.0.0-20231030173426-d783a09b4405/go.mod h1:67X1fPuzjcrkymZzZV1vvkFeTn2Rvc6lYF9MYFGCcwE= google.golang.org/grpc v1.58.3 h1:BjnpXut1btbtgN/6sp+brB2Kbm2LjNXnidYujAVbSoQ= google.golang.org/grpc v1.58.3/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= diff --git a/grpc/send_user_notification_wiiu.go b/grpc/send_user_notification_wiiu.go index 24fef84..5e1ed5f 100644 --- a/grpc/send_user_notification_wiiu.go +++ b/grpc/send_user_notification_wiiu.go @@ -16,23 +16,23 @@ func (s *gRPCFriendsServer) SendUserNotificationWiiU(ctx context.Context, in *pb if connectedUser != nil { rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent2) - rmcRequest.SetParameters(in.GetNotificationData()) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent2 + rmcRequest.Parameters = in.GetNotificationData() rmcRequestBytes := rmcRequest.Bytes() - requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/nex/account-management/nintendo_create_account.go b/nex/account-management/nintendo_create_account.go index ce4e7a6..5dfc64a 100644 --- a/nex/account-management/nintendo_create_account.go +++ b/nex/account-management/nintendo_create_account.go @@ -15,12 +15,14 @@ import ( account_management_types "github.com/PretendoNetwork/nex-protocols-go/account-management/types" ) -func NintendoCreateAccount(err error, client *nex.Client, callID uint32, strPrincipalName string, strKey string, uiGroups uint32, strEmail string, oAuthData *nex.DataHolder) uint32 { +func NintendoCreateAccount(err error, packet nex.PacketInterface, callID uint32, strPrincipalName string, strKey string, uiGroups uint32, strEmail string, oAuthData *nex.DataHolder) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.Core.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + var tokenBase64 string oAuthDataType := oAuthData.TypeName() @@ -68,8 +70,6 @@ func NintendoCreateAccount(err error, client *nex.Client, callID uint32, strPrin pidHmac := hex.EncodeToString(mac.Sum(nil)) - rmcResponse := nex.NewRMCResponse(account_management.ProtocolID, callID) - rmcResponseStream := nex.NewStreamOut(globals.SecureServer) rmcResponseStream.WriteUInt32LE(pid) @@ -77,20 +77,23 @@ func NintendoCreateAccount(err error, client *nex.Client, callID uint32, strPrin rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse.SetSuccess(account_management.MethodNintendoCreateAccount, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = account_management.ProtocolID + rmcResponse.MethodID = account_management.MethodNintendoCreateAccount + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/authentication.go b/nex/authentication.go index fa1dd11..672ff67 100644 --- a/nex/authentication.go +++ b/nex/authentication.go @@ -3,6 +3,7 @@ package nex import ( "fmt" "os" + "strconv" "github.com/PretendoNetwork/friends/globals" "github.com/PretendoNetwork/nex-go" @@ -11,28 +12,24 @@ import ( var serverBuildString string func StartAuthenticationServer() { - globals.AuthenticationServer = nex.NewServer() - globals.AuthenticationServer.SetPRUDPVersion(0) - globals.AuthenticationServer.SetPRUDPProtocolMinorVersion(0) // TODO: Figure out what to put here - globals.AuthenticationServer.SetDefaultNEXVersion(&nex.NEXVersion{ - Major: 1, - Minor: 1, - Patch: 0, - }) + globals.AuthenticationServer = nex.NewPRUDPServer() + globals.AuthenticationServer.SetFragmentSize(962) + globals.AuthenticationServer.SetDefaultLibraryVersion(nex.NewLibraryVersion(1, 1, 0)) + globals.AuthenticationServer.SetKerberosPassword([]byte(globals.KerberosPassword)) globals.AuthenticationServer.SetKerberosKeySize(16) - globals.AuthenticationServer.SetKerberosPassword(globals.KerberosPassword) globals.AuthenticationServer.SetAccessKey("ridfebb9") - globals.AuthenticationServer.On("Data", func(packet *nex.PacketV0) { - request := packet.RMCRequest() + globals.AuthenticationServer.OnData(func(packet nex.PacketInterface) { + request := packet.RMCMessage() fmt.Println("==Friends - Auth==") - fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) - fmt.Printf("Method ID: %#v\n", request.MethodID()) + fmt.Printf("Protocol ID: %#v\n", request.ProtocolID) + fmt.Printf("Method ID: %#v\n", request.MethodID) fmt.Println("===============") }) registerCommonAuthenticationServerProtocols() - globals.AuthenticationServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_FRIENDS_AUTHENTICATION_SERVER_PORT"))) + port, _ := strconv.Atoi(os.Getenv("PN_FRIENDS_AUTHENTICATION_SERVER_PORT")) + globals.AuthenticationServer.Listen(port) } diff --git a/nex/connect.go b/nex/connect.go deleted file mode 100644 index b5b8fe9..0000000 --- a/nex/connect.go +++ /dev/null @@ -1,73 +0,0 @@ -package nex - -import ( - "time" - - "github.com/PretendoNetwork/friends/globals" - "github.com/PretendoNetwork/friends/types" - nex "github.com/PretendoNetwork/nex-go" -) - -func connect(packet *nex.PacketV0) { - // * We aren't making any replies here because the common Secure Protocol already does that - // * - // * We only want to check that the data given is right so that we don't register a client - // * with an invalid request - payload := packet.Payload() - stream := nex.NewStreamIn(payload, globals.SecureServer) - - ticketData, err := stream.ReadBuffer() - if err != nil { - return - } - - requestData, err := stream.ReadBuffer() - if err != nil { - return - } - - serverKey := nex.DeriveKerberosKey(2, []byte(globals.SecureServer.KerberosPassword())) - - ticket := nex.NewKerberosTicketInternalData() - err = ticket.Decrypt(nex.NewStreamIn(ticketData, globals.SecureServer), serverKey) - if err != nil { - return - } - - ticketTime := ticket.Timestamp().Standard() - serverTime := time.Now().UTC() - - timeLimit := ticketTime.Add(time.Minute * 2) - if serverTime.After(timeLimit) { - return - } - - sessionKey := ticket.SessionKey() - kerberos, err := nex.NewKerberosEncryption(sessionKey) - if err != nil { - return - } - - decryptedRequestData := kerberos.Decrypt(requestData) - checkDataStream := nex.NewStreamIn(decryptedRequestData, globals.SecureServer) - - userPID, err := checkDataStream.ReadUInt32LE() - if err != nil { - return - } - - _, err = checkDataStream.ReadUInt32LE() // CID of secure server station url - if err != nil { - return - } - - _, err = checkDataStream.ReadUInt32LE() // Response check - if err != nil { - return - } - - connectedUser := types.NewConnectedUser() - connectedUser.PID = userPID - connectedUser.Client = packet.Sender() - globals.ConnectedUsers[userPID] = connectedUser -} diff --git a/nex/friends-3ds/add_friendship_by_pid.go b/nex/friends-3ds/add_friendship_by_pid.go index 6638b08..61ec7d3 100644 --- a/nex/friends-3ds/add_friendship_by_pid.go +++ b/nex/friends-3ds/add_friendship_by_pid.go @@ -8,12 +8,14 @@ import ( friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func AddFriendshipByPrincipalID(err error, client *nex.Client, callID uint32, lfc uint64, pid uint32) uint32 { +func AddFriendshipByPrincipalID(err error, packet nex.PacketInterface, callID uint32, lfc uint64, pid uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + friendRelationship, err := database_3ds.SaveFriendship(client.PID(), pid) if err != nil { globals.Logger.Critical(err.Error()) @@ -31,21 +33,23 @@ func AddFriendshipByPrincipalID(err error, client *nex.Client, callID uint32, lf rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodAddFriendByPrincipalID, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodAddFriendByPrincipalID + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/get_all_friends.go b/nex/friends-3ds/get_all_friends.go index 5be1fb8..8bbe983 100644 --- a/nex/friends-3ds/get_all_friends.go +++ b/nex/friends-3ds/get_all_friends.go @@ -9,12 +9,14 @@ import ( friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func GetAllFriends(err error, client *nex.Client, callID uint32) uint32 { +func GetAllFriends(err error, packet nex.PacketInterface, callID uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.Unknown } + client := packet.Sender().(*nex.PRUDPClient) + friendRelationships, err := database_3ds.GetUserFriends(client.PID()) if err != nil && err != sql.ErrNoRows { globals.Logger.Critical(err.Error()) @@ -27,21 +29,23 @@ func GetAllFriends(err error, client *nex.Client, callID uint32) uint32 { rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodGetAllFriends, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodGetAllFriends + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/get_friend_mii.go b/nex/friends-3ds/get_friend_mii.go index 4768dc9..0984c3c 100644 --- a/nex/friends-3ds/get_friend_mii.go +++ b/nex/friends-3ds/get_friend_mii.go @@ -9,12 +9,14 @@ import ( friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func GetFriendMii(err error, client *nex.Client, callID uint32, pids []uint32) uint32 { +func GetFriendMii(err error, packet nex.PacketInterface, callID uint32, pids []uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + miiList, err := database_3ds.GetFriendMiis(pids) if err != nil && err != sql.ErrNoRows { globals.Logger.Critical(err.Error()) @@ -27,21 +29,23 @@ func GetFriendMii(err error, client *nex.Client, callID uint32, pids []uint32) u rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodGetFriendMii, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodGetFriendMii + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/get_friend_persistent_info.go b/nex/friends-3ds/get_friend_persistent_info.go index 6cc63ff..0a14109 100644 --- a/nex/friends-3ds/get_friend_persistent_info.go +++ b/nex/friends-3ds/get_friend_persistent_info.go @@ -9,12 +9,14 @@ import ( friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func GetFriendPersistentInfo(err error, client *nex.Client, callID uint32, pids []uint32) uint32 { +func GetFriendPersistentInfo(err error, packet nex.PacketInterface, callID uint32, pids []uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.Unknown } + client := packet.Sender().(*nex.PRUDPClient) + infoList, err := database_3ds.GetFriendPersistentInfos(client.PID(), pids) if err != nil && err != sql.ErrNoRows { globals.Logger.Critical(err.Error()) @@ -27,21 +29,23 @@ func GetFriendPersistentInfo(err error, client *nex.Client, callID uint32, pids rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodGetFriendPersistentInfo, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodGetFriendPersistentInfo + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/get_friend_presence.go b/nex/friends-3ds/get_friend_presence.go index c16e8a0..3cd7597 100644 --- a/nex/friends-3ds/get_friend_presence.go +++ b/nex/friends-3ds/get_friend_presence.go @@ -7,12 +7,14 @@ import ( friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types" ) -func GetFriendPresence(err error, client *nex.Client, callID uint32, pids []uint32) uint32 { +func GetFriendPresence(err error, packet nex.PacketInterface, callID uint32, pids []uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.Unknown } + client := packet.Sender().(*nex.PRUDPClient) + presenceList := make([]*friends_3ds_types.FriendPresence, 0) for i := 0; i < len(pids); i++ { @@ -33,21 +35,23 @@ func GetFriendPresence(err error, client *nex.Client, callID uint32, pids []uint rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodGetFriendPresence, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodGetFriendPresence + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/get_pid_by_lfc.go b/nex/friends-3ds/get_pid_by_lfc.go index 16f47db..7d32ee3 100644 --- a/nex/friends-3ds/get_pid_by_lfc.go +++ b/nex/friends-3ds/get_pid_by_lfc.go @@ -6,7 +6,7 @@ import ( // friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func GetPrincipalIDByLocalFriendCode(err error, client *nex.Client, callID uint32, lfc uint64, lfcList []uint64) uint32 { +func GetPrincipalIDByLocalFriendCode(err error, packet nex.PacketInterface, callID uint32, lfc uint64, lfcList []uint64) uint32 { // Respond with unimplemented, waiting for gRPC to retrieve PID from account server // rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) @@ -14,9 +14,9 @@ func GetPrincipalIDByLocalFriendCode(err error, client *nex.Client, callID uint3 // rmcResponseBytes := rmcResponse.Bytes() - // responsePacket, _ := nex.NewPacketV0(client, nil) + // responsePacket, _ := nex.NewPRUDPPacketV0(client, nil) - // responsePacket.SetVersion(0) + // // responsePacket.SetSource(0xA1) // responsePacket.SetDestination(0xAF) // responsePacket.SetType(nex.DataPacket) diff --git a/nex/friends-3ds/remove_friend_by_lfc.go b/nex/friends-3ds/remove_friend_by_lfc.go index bb60fd1..89f2798 100644 --- a/nex/friends-3ds/remove_friend_by_lfc.go +++ b/nex/friends-3ds/remove_friend_by_lfc.go @@ -6,7 +6,7 @@ import ( // friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func RemoveFriendByLocalFriendCode(err error, client *nex.Client, callID uint32, friendLFC uint64) uint32 { +func RemoveFriendByLocalFriendCode(err error, packet nex.PacketInterface, callID uint32, friendLFC uint64) uint32 { // Respond with unimplemented, waiting for gRPC to retrieve PID from account server // rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) @@ -14,9 +14,9 @@ func RemoveFriendByLocalFriendCode(err error, client *nex.Client, callID uint32, // rmcResponseBytes := rmcResponse.Bytes() - // responsePacket, _ := nex.NewPacketV0(client, nil) + // responsePacket, _ := nex.NewPRUDPPacketV0(client, nil) - // responsePacket.SetVersion(0) + // // responsePacket.SetSource(0xA1) // responsePacket.SetDestination(0xAF) // responsePacket.SetType(nex.DataPacket) diff --git a/nex/friends-3ds/remove_friend_by_pid.go b/nex/friends-3ds/remove_friend_by_pid.go index c2a8de3..3f9e94c 100644 --- a/nex/friends-3ds/remove_friend_by_pid.go +++ b/nex/friends-3ds/remove_friend_by_pid.go @@ -9,12 +9,14 @@ import ( friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func RemoveFriendByPrincipalID(err error, client *nex.Client, callID uint32, pid uint32) uint32 { +func RemoveFriendByPrincipalID(err error, packet nex.PacketInterface, callID uint32, pid uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_3ds.RemoveFriendship(client.PID(), pid) if err != nil { if err == database.ErrFriendshipNotFound { @@ -29,21 +31,23 @@ func RemoveFriendByPrincipalID(err error, client *nex.Client, callID uint32, pid go notifications_3ds.SendUserWentOffline(client, pid) - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodRemoveFriendByPrincipalID, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodRemoveFriendByPrincipalID + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/sync_friend.go b/nex/friends-3ds/sync_friend.go index 97de7dc..a738338 100644 --- a/nex/friends-3ds/sync_friend.go +++ b/nex/friends-3ds/sync_friend.go @@ -13,12 +13,14 @@ import ( "golang.org/x/exp/slices" ) -func SyncFriend(err error, client *nex.Client, callID uint32, lfc uint64, pids []uint32, lfcList []uint64) uint32 { +func SyncFriend(err error, packet nex.PacketInterface, callID uint32, lfc uint64, pids []uint32, lfcList []uint64) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + friendRelationships, err := database_3ds.GetUserFriends(client.PID()) if err != nil && err != sql.ErrNoRows { globals.Logger.Critical(err.Error()) @@ -59,21 +61,23 @@ func SyncFriend(err error, client *nex.Client, callID uint32, lfc uint64, pids [ rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodSyncFriend, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodSyncFriend + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/update_comment.go b/nex/friends-3ds/update_comment.go index a921b31..d176a54 100644 --- a/nex/friends-3ds/update_comment.go +++ b/nex/friends-3ds/update_comment.go @@ -8,12 +8,14 @@ import ( friends_3ds "github.com/PretendoNetwork/nex-protocols-go/friends-3ds" ) -func UpdateComment(err error, client *nex.Client, callID uint32, comment string) uint32 { +func UpdateComment(err error, packet nex.PacketInterface, callID uint32, comment string) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_3ds.UpdateUserComment(client.PID(), comment) if err != nil { globals.Logger.Critical(err.Error()) @@ -22,22 +24,23 @@ func UpdateComment(err error, client *nex.Client, callID uint32, comment string) go notifications_3ds.SendCommentUpdate(client, comment) - - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodUpdateComment, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodUpdateComment + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/update_favorite_game_key.go b/nex/friends-3ds/update_favorite_game_key.go index 96964f7..734a216 100644 --- a/nex/friends-3ds/update_favorite_game_key.go +++ b/nex/friends-3ds/update_favorite_game_key.go @@ -9,12 +9,14 @@ import ( friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types" ) -func UpdateFavoriteGameKey(err error, client *nex.Client, callID uint32, gameKey *friends_3ds_types.GameKey) uint32 { +func UpdateFavoriteGameKey(err error, packet nex.PacketInterface, callID uint32, gameKey *friends_3ds_types.GameKey) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_3ds.UpdateUserFavoriteGame(client.PID(), gameKey) if err != nil { globals.Logger.Critical(err.Error()) @@ -23,21 +25,23 @@ func UpdateFavoriteGameKey(err error, client *nex.Client, callID uint32, gameKey go notifications_3ds.SendFavoriteUpdate(client, gameKey) - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodUpdateFavoriteGameKey, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodUpdateFavoriteGameKey + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/update_mii.go b/nex/friends-3ds/update_mii.go index 5130fb4..94bd395 100644 --- a/nex/friends-3ds/update_mii.go +++ b/nex/friends-3ds/update_mii.go @@ -9,12 +9,14 @@ import ( friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types" ) -func UpdateMii(err error, client *nex.Client, callID uint32, mii *friends_3ds_types.Mii) uint32 { +func UpdateMii(err error, packet nex.PacketInterface, callID uint32, mii *friends_3ds_types.Mii) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_3ds.UpdateUserMii(client.PID(), mii) if err != nil { globals.Logger.Critical(err.Error()) @@ -23,21 +25,23 @@ func UpdateMii(err error, client *nex.Client, callID uint32, mii *friends_3ds_ty go notifications_3ds.SendMiiUpdateNotification(client) - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodUpdateMii, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodUpdateMii + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/update_preference.go b/nex/friends-3ds/update_preference.go index 2e4b5d7..c1b66d3 100644 --- a/nex/friends-3ds/update_preference.go +++ b/nex/friends-3ds/update_preference.go @@ -9,12 +9,14 @@ import ( friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types" ) -func UpdatePreference(err error, client *nex.Client, callID uint32, showOnline bool, showCurrentGame bool, showPlayedGame bool) uint32 { +func UpdatePreference(err error, packet nex.PacketInterface, callID uint32, showOnline bool, showCurrentGame bool, showPlayedGame bool) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_3ds.UpdateUserPreferences(client.PID(), showOnline, showCurrentGame) if err != nil { globals.Logger.Critical(err.Error()) @@ -31,21 +33,23 @@ func UpdatePreference(err error, client *nex.Client, callID uint32, showOnline b notifications_3ds.SendUserWentOfflineGlobally(client) } - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodUpdatePreference, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodUpdatePreference + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/update_presence.go b/nex/friends-3ds/update_presence.go index 94e9ff2..f8a60ae 100644 --- a/nex/friends-3ds/update_presence.go +++ b/nex/friends-3ds/update_presence.go @@ -9,12 +9,14 @@ import ( 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 { +func UpdatePresence(err error, packet nex.PacketInterface, callID uint32, presence *friends_3ds_types.NintendoPresence, showGame bool) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + currentPresence := presence // Send an entirely empty status, with every flag set to update @@ -40,21 +42,23 @@ func UpdatePresence(err error, client *nex.Client, callID uint32, presence *frie globals.ConnectedUsers[pid].Presence = currentPresence - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodUpdatePresence, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodUpdatePresence + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-3ds/update_profile.go b/nex/friends-3ds/update_profile.go index 5eb06cc..7918e6c 100644 --- a/nex/friends-3ds/update_profile.go +++ b/nex/friends-3ds/update_profile.go @@ -8,33 +8,37 @@ import ( friends_3ds_types "github.com/PretendoNetwork/nex-protocols-go/friends-3ds/types" ) -func UpdateProfile(err error, client *nex.Client, callID uint32, profileData *friends_3ds_types.MyProfile) uint32 { +func UpdateProfile(err error, packet nex.PacketInterface, callID uint32, profileData *friends_3ds_types.MyProfile) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_3ds.UpdateUserProfile(client.PID(), profileData) if err != nil { globals.Logger.Critical(err.Error()) return nex.Errors.FPD.Unknown } - rmcResponse := nex.NewRMCResponse(friends_3ds.ProtocolID, callID) - rmcResponse.SetSuccess(friends_3ds.MethodUpdateProfile, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_3ds.ProtocolID + rmcResponse.MethodID = friends_3ds.MethodUpdateProfile + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/accept_friend_request.go b/nex/friends-wiiu/accept_friend_request.go index d6459ef..7d94e81 100644 --- a/nex/friends-wiiu/accept_friend_request.go +++ b/nex/friends-wiiu/accept_friend_request.go @@ -10,12 +10,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func AcceptFriendRequest(err error, client *nex.Client, callID uint32, id uint64) uint32 { +func AcceptFriendRequest(err error, packet nex.PacketInterface, callID uint32, id uint64) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + friendInfo, err := database_wiiu.AcceptFriendRequestAndReturnFriendInfo(id) if err != nil { if err == database.ErrFriendRequestNotFound { @@ -59,22 +61,23 @@ func AcceptFriendRequest(err error, client *nex.Client, callID uint32, id uint64 rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodAcceptFriendRequest, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodAcceptFriendRequest + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/add_blacklist.go b/nex/friends-wiiu/add_blacklist.go index d09e9fe..e5de50e 100644 --- a/nex/friends-wiiu/add_blacklist.go +++ b/nex/friends-wiiu/add_blacklist.go @@ -12,12 +12,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func AddBlacklist(err error, client *nex.Client, callID uint32, blacklistPrincipal *friends_wiiu_types.BlacklistedPrincipal) uint32 { +func AddBlacklist(err error, packet nex.PacketInterface, callID uint32, blacklistPrincipal *friends_wiiu_types.BlacklistedPrincipal) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + currentBlacklistPrincipal := blacklistPrincipal senderPID := currentBlacklistPrincipal.PrincipalBasicInfo.PID @@ -52,22 +54,23 @@ func AddBlacklist(err error, client *nex.Client, callID uint32, blacklistPrincip rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodAddBlackList, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodAddBlackList + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/add_friend_request.go b/nex/friends-wiiu/add_friend_request.go index 8c30c44..5fbeb35 100644 --- a/nex/friends-wiiu/add_friend_request.go +++ b/nex/friends-wiiu/add_friend_request.go @@ -13,12 +13,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32, unknown2 uint8, message string, unknown4 uint8, unknown5 string, gameKey *friends_wiiu_types.GameKey, unknown6 *nex.DateTime) uint32 { +func AddFriendRequest(err error, packet nex.PacketInterface, callID uint32, pid uint32, unknown2 uint8, message string, unknown4 uint8, unknown5 string, gameKey *friends_wiiu_types.GameKey, unknown6 *nex.DateTime) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + senderPID := client.PID() recipientPID := pid @@ -113,7 +115,7 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32, friendInfo.LastOnline = nex.NewDateTime(0) friendInfo.Unknown = 0 - recipientClient := client.Server().FindClientFromPID(recipientPID) + recipientClient := globals.ConnectedUsers[recipientPID] if recipientClient != nil { @@ -133,7 +135,7 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32, friendRequestNotificationData.Message.ExpiresOn = expireTime // no idea why this is set as the sent time friendRequestNotificationData.SentOn = sentTime - go notifications_wiiu.SendFriendRequest(recipientClient, friendRequestNotificationData) + go notifications_wiiu.SendFriendRequest(recipientClient.Client, friendRequestNotificationData) } rmcResponseStream := nex.NewStreamOut(globals.SecureServer) @@ -143,22 +145,23 @@ func AddFriendRequest(err error, client *nex.Client, callID uint32, pid uint32, rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodAddFriendRequest, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodAddFriendRequest + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/cancel_friend_request.go b/nex/friends-wiiu/cancel_friend_request.go index 1f011f6..8f60ae5 100644 --- a/nex/friends-wiiu/cancel_friend_request.go +++ b/nex/friends-wiiu/cancel_friend_request.go @@ -9,12 +9,14 @@ import ( friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu" ) -func CancelFriendRequest(err error, client *nex.Client, callID uint32, id uint64) uint32 { +func CancelFriendRequest(err error, packet nex.PacketInterface, callID uint32, id uint64) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + pid, err := database_wiiu.DeleteFriendRequestAndReturnFriendPID(id) if err != nil { if err == database.ErrFriendRequestNotFound { @@ -31,21 +33,23 @@ func CancelFriendRequest(err error, client *nex.Client, callID uint32, id uint64 go notifications_wiiu.SendFriendshipRemoved(connectedUser.Client, client.PID()) } - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodCancelFriendRequest, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodCancelFriendRequest + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/check_setting_status.go b/nex/friends-wiiu/check_setting_status.go index 4eca5ff..4181ce0 100644 --- a/nex/friends-wiiu/check_setting_status.go +++ b/nex/friends-wiiu/check_setting_status.go @@ -6,34 +6,37 @@ import ( friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu" ) -func CheckSettingStatus(err error, client *nex.Client, callID uint32) uint32 { +func CheckSettingStatus(err error, packet nex.PacketInterface, callID uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.Unknown } + client := packet.Sender().(*nex.PRUDPClient) + rmcResponseStream := nex.NewStreamOut(globals.SecureServer) rmcResponseStream.WriteUInt8(0xFF) rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodCheckSettingStatus, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodCheckSettingStatus + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/delete_friend_request.go b/nex/friends-wiiu/delete_friend_request.go index c60aa87..3a61434 100644 --- a/nex/friends-wiiu/delete_friend_request.go +++ b/nex/friends-wiiu/delete_friend_request.go @@ -8,12 +8,14 @@ import ( friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu" ) -func DeleteFriendRequest(err error, client *nex.Client, callID uint32, id uint64) uint32 { +func DeleteFriendRequest(err error, packet nex.PacketInterface, callID uint32, id uint64) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_wiiu.SetFriendRequestDenied(id) if err != nil { if err == database.ErrFriendRequestNotFound { @@ -24,21 +26,23 @@ func DeleteFriendRequest(err error, client *nex.Client, callID uint32, id uint64 } } - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodDeleteFriendRequest, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodDeleteFriendRequest + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/delete_persistent_notification.go b/nex/friends-wiiu/delete_persistent_notification.go index c00c006..af7fdaa 100644 --- a/nex/friends-wiiu/delete_persistent_notification.go +++ b/nex/friends-wiiu/delete_persistent_notification.go @@ -7,29 +7,33 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func DeletePersistentNotification(err error, client *nex.Client, callID uint32, notifications []*friends_wiiu_types.PersistentNotification) uint32 { +func DeletePersistentNotification(err error, packet nex.PacketInterface, callID uint32, notifications []*friends_wiiu_types.PersistentNotification) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + // TODO: Do something here - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodDeletePersistentNotification, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodDeletePersistentNotification + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/deny_friend_request.go b/nex/friends-wiiu/deny_friend_request.go index 974b491..bc49de5 100644 --- a/nex/friends-wiiu/deny_friend_request.go +++ b/nex/friends-wiiu/deny_friend_request.go @@ -12,12 +12,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func DenyFriendRequest(err error, client *nex.Client, callID uint32, id uint64) uint32 { +func DenyFriendRequest(err error, packet nex.PacketInterface, callID uint32, id uint64) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_wiiu.SetFriendRequestDenied(id) if err != nil { globals.Logger.Critical(err.Error()) @@ -62,22 +64,23 @@ func DenyFriendRequest(err error, client *nex.Client, callID uint32, id uint64) rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodDenyFriendRequest, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodDenyFriendRequest + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/get_basic_info.go b/nex/friends-wiiu/get_basic_info.go index cad0bd2..0f214c9 100644 --- a/nex/friends-wiiu/get_basic_info.go +++ b/nex/friends-wiiu/get_basic_info.go @@ -8,12 +8,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func GetBasicInfo(err error, client *nex.Client, callID uint32, pids []uint32) uint32 { +func GetBasicInfo(err error, packet nex.PacketInterface, callID uint32, pids []uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + infos := make([]*friends_wiiu_types.PrincipalBasicInfo, 0) for i := 0; i < len(pids); i++ { @@ -36,22 +38,23 @@ func GetBasicInfo(err error, client *nex.Client, callID uint32, pids []uint32) u rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodGetBasicInfo, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodGetBasicInfo + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/get_request_block_settings.go b/nex/friends-wiiu/get_request_block_settings.go index b2a5fc9..bc97a8b 100644 --- a/nex/friends-wiiu/get_request_block_settings.go +++ b/nex/friends-wiiu/get_request_block_settings.go @@ -8,12 +8,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func GetRequestBlockSettings(err error, client *nex.Client, callID uint32, pids []uint32) uint32 { +func GetRequestBlockSettings(err error, packet nex.PacketInterface, callID uint32, pids []uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + settings := make([]*friends_wiiu_types.PrincipalRequestBlockSetting, 0) // TODO: @@ -40,22 +42,23 @@ func GetRequestBlockSettings(err error, client *nex.Client, callID uint32, pids rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodGetRequestBlockSettings, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodGetRequestBlockSettings + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/mark_friend_requests_as_received.go b/nex/friends-wiiu/mark_friend_requests_as_received.go index 73a9947..db96d72 100644 --- a/nex/friends-wiiu/mark_friend_requests_as_received.go +++ b/nex/friends-wiiu/mark_friend_requests_as_received.go @@ -7,12 +7,14 @@ import ( friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu" ) -func MarkFriendRequestsAsReceived(err error, client *nex.Client, callID uint32, ids []uint64) uint32 { +func MarkFriendRequestsAsReceived(err error, packet nex.PacketInterface, callID uint32, ids []uint64) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + for i := 0; i < len(ids); i++ { id := ids[i] err = database_wiiu.SetFriendRequestReceived(id) @@ -22,21 +24,23 @@ func MarkFriendRequestsAsReceived(err error, client *nex.Client, callID uint32, } } - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodMarkFriendRequestsAsReceived, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodMarkFriendRequestsAsReceived + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/remove_blacklist.go b/nex/friends-wiiu/remove_blacklist.go index 711ecdc..2b741ec 100644 --- a/nex/friends-wiiu/remove_blacklist.go +++ b/nex/friends-wiiu/remove_blacklist.go @@ -8,12 +8,14 @@ import ( friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu" ) -func RemoveBlacklist(err error, client *nex.Client, callID uint32, blockedPID uint32) uint32 { +func RemoveBlacklist(err error, packet nex.PacketInterface, callID uint32, blockedPID uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_wiiu.UnsetUserBlocked(client.PID(), blockedPID) if err != nil { if err == database.ErrPIDNotFound { @@ -24,21 +26,23 @@ func RemoveBlacklist(err error, client *nex.Client, callID uint32, blockedPID ui } } - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodRemoveBlackList, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodRemoveBlackList + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/remove_friend.go b/nex/friends-wiiu/remove_friend.go index c7ebbf0..3d7dca7 100644 --- a/nex/friends-wiiu/remove_friend.go +++ b/nex/friends-wiiu/remove_friend.go @@ -9,12 +9,14 @@ import ( friends_wiiu "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu" ) -func RemoveFriend(err error, client *nex.Client, callID uint32, pid uint32) uint32 { +func RemoveFriend(err error, packet nex.PacketInterface, callID uint32, pid uint32) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_wiiu.RemoveFriendship(client.PID(), pid) if err != nil { if err == database.ErrFriendshipNotFound { @@ -30,21 +32,23 @@ func RemoveFriend(err error, client *nex.Client, callID uint32, pid uint32) uint go notifications_wiiu.SendFriendshipRemoved(connectedUser.Client, pid) } - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodRemoveFriend, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodRemoveFriend + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/update_and_get_all_information.go b/nex/friends-wiiu/update_and_get_all_information.go index 5ac428d..e916494 100644 --- a/nex/friends-wiiu/update_and_get_all_information.go +++ b/nex/friends-wiiu/update_and_get_all_information.go @@ -1,6 +1,7 @@ package nex_friends_wiiu import ( + "fmt" "os" "github.com/PretendoNetwork/friends/database" @@ -13,12 +14,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func UpdateAndGetAllInformation(err error, client *nex.Client, callID uint32, nnaInfo *friends_wiiu_types.NNAInfo, presence *friends_wiiu_types.NintendoPresenceV2, birthday *nex.DateTime) uint32 { +func UpdateAndGetAllInformation(err error, packet nex.PacketInterface, callID uint32, nnaInfo *friends_wiiu_types.NNAInfo, presence *friends_wiiu_types.NintendoPresenceV2, birthday *nex.DateTime) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + // Get user information pid := client.PID() @@ -160,6 +163,84 @@ func UpdateAndGetAllInformation(err error, client *nex.Client, callID uint32, nn friendList = append(friendList, bella) } + // * Force 100 friends + + fmt.Println(len(friendList)) + fmt.Println(100 - len(friendList)) + + for i := 0; i < 100-len(friendList); i++ { + var pid uint32 = 1750000000 + uint32(i) + friend := friends_wiiu_types.NewFriendInfo() + + friend.NNAInfo = friends_wiiu_types.NewNNAInfo() + friend.Presence = friends_wiiu_types.NewNintendoPresenceV2() + friend.Status = friends_wiiu_types.NewComment() + friend.BecameFriend = nex.NewDateTime(0) + friend.LastOnline = nex.NewDateTime(0) + friend.Unknown = 0 + + friend.NNAInfo.PrincipalBasicInfo = friends_wiiu_types.NewPrincipalBasicInfo() + friend.NNAInfo.Unknown1 = 0 + friend.NNAInfo.Unknown2 = 0 + + friend.NNAInfo.PrincipalBasicInfo.PID = pid + friend.NNAInfo.PrincipalBasicInfo.NNID = fmt.Sprint(pid) + friend.NNAInfo.PrincipalBasicInfo.Mii = friends_wiiu_types.NewMiiV2() + friend.NNAInfo.PrincipalBasicInfo.Unknown = 0 + + friend.NNAInfo.PrincipalBasicInfo.Mii.Name = fmt.Sprint(pid) + friend.NNAInfo.PrincipalBasicInfo.Mii.Unknown1 = 0 + friend.NNAInfo.PrincipalBasicInfo.Mii.Unknown2 = 0 + friend.NNAInfo.PrincipalBasicInfo.Mii.MiiData = []byte{ + 0x03, 0x00, 0x00, 0x40, 0xE9, 0x55, 0xA2, 0x09, + 0xE7, 0xC7, 0x41, 0x82, 0xD9, 0x7D, 0x0B, 0x2D, + 0x03, 0xB3, 0xB8, 0x8D, 0x27, 0xD9, 0x00, 0x00, + 0x01, 0x40, 0x62, 0x00, 0x65, 0x00, 0x6C, 0x00, + 0x6C, 0x00, 0x61, 0x00, 0x00, 0x00, 0x45, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x40, + 0x12, 0x00, 0x81, 0x01, 0x04, 0x68, 0x43, 0x18, + 0x20, 0x34, 0x46, 0x14, 0x81, 0x12, 0x17, 0x68, + 0x0D, 0x00, 0x00, 0x29, 0x03, 0x52, 0x48, 0x50, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFE, 0x86, + } + friend.NNAInfo.PrincipalBasicInfo.Mii.Datetime = nex.NewDateTime(0) + + friend.Presence.ChangedFlags = 0x1EE + friend.Presence.Online = true + friend.Presence.GameKey = friends_wiiu_types.NewGameKey() + friend.Presence.Unknown1 = 0 + friend.Presence.Message = "Testing" + //bella.Presence.Unknown2 = 2 + friend.Presence.Unknown2 = 0 + //bella.Presence.Unknown3 = 2 + friend.Presence.Unknown3 = 0 + //bella.Presence.GameServerID = 0x1010EB00 + friend.Presence.GameServerID = 0 + //bella.Presence.Unknown4 = 3 + friend.Presence.Unknown4 = 0 + friend.Presence.PID = pid + //bella.Presence.GatheringID = 1743126339 // test fake ID + friend.Presence.GatheringID = 0 + //bella.Presence.ApplicationData, _ = hex.DecodeString("0000200300000000000000001843ffe567000000") + friend.Presence.ApplicationData = []byte{0x0} + friend.Presence.Unknown5 = 0 + friend.Presence.Unknown6 = 0 + friend.Presence.Unknown7 = 0 + + //bella.Presence.GameKey.TitleID = 0x000500001010EC00 + friend.Presence.GameKey.TitleID = 0 + //bella.Presence.GameKey.TitleVersion = 64 + friend.Presence.GameKey.TitleVersion = 0 + + friend.Status.Unknown = 0 + friend.Status.Contents = "test" + friend.Status.LastChanged = nex.NewDateTime(0) + + friendList = append(friendList, friend) + } + rmcResponseStream := nex.NewStreamOut(globals.SecureServer) rmcResponseStream.WriteStructure(principalPreference) @@ -168,30 +249,31 @@ func UpdateAndGetAllInformation(err error, client *nex.Client, callID uint32, nn rmcResponseStream.WriteListStructure(friendRequestsOut) rmcResponseStream.WriteListStructure(friendRequestsIn) rmcResponseStream.WriteListStructure(blockList) - rmcResponseStream.WriteBool(false) // Unknown + rmcResponseStream.WriteBool(false) // * Unknown rmcResponseStream.WriteListStructure(notifications) - - //Unknown Bool - rmcResponseStream.WriteUInt8(0) + rmcResponseStream.WriteBool(false) // * Unknown rmcResponseBody := rmcResponseStream.Bytes() - // Build response packet - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodUpdateAndGetAllInformation, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodUpdateAndGetAllInformation + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) + + responsePacket.SetRMCMessage(rmcResponse) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/update_comment.go b/nex/friends-wiiu/update_comment.go index c28a846..398db68 100644 --- a/nex/friends-wiiu/update_comment.go +++ b/nex/friends-wiiu/update_comment.go @@ -8,12 +8,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func UpdateComment(err error, client *nex.Client, callID uint32, comment *friends_wiiu_types.Comment) uint32 { +func UpdateComment(err error, packet nex.PacketInterface, callID uint32, comment *friends_wiiu_types.Comment) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + changed, err := database_wiiu.UpdateUserComment(client.PID(), comment.Contents) if err != nil { globals.Logger.Critical(err.Error()) @@ -26,21 +28,23 @@ func UpdateComment(err error, client *nex.Client, callID uint32, comment *friend rmcResponseBody := rmcResponseStream.Bytes() - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodUpdateComment, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodUpdateComment + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/update_preference.go b/nex/friends-wiiu/update_preference.go index ff7fa57..52b4ab0 100644 --- a/nex/friends-wiiu/update_preference.go +++ b/nex/friends-wiiu/update_preference.go @@ -8,33 +8,37 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func UpdatePreference(err error, client *nex.Client, callID uint32, principalPreference *friends_wiiu_types.PrincipalPreference) uint32 { +func UpdatePreference(err error, packet nex.PacketInterface, callID uint32, principalPreference *friends_wiiu_types.PrincipalPreference) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + err = database_wiiu.UpdateUserPrincipalPreference(client.PID(), principalPreference) if err != nil { globals.Logger.Critical(err.Error()) return nex.Errors.FPD.Unknown } - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodUpdatePreference, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodUpdatePreference + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/friends-wiiu/update_presence.go b/nex/friends-wiiu/update_presence.go index a19fc55..5b6a746 100644 --- a/nex/friends-wiiu/update_presence.go +++ b/nex/friends-wiiu/update_presence.go @@ -9,12 +9,14 @@ import ( friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" ) -func UpdatePresence(err error, client *nex.Client, callID uint32, presence *friends_wiiu_types.NintendoPresenceV2) uint32 { +func UpdatePresence(err error, packet nex.PacketInterface, callID uint32, presence *friends_wiiu_types.NintendoPresenceV2) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.FPD.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + pid := client.PID() presence.Online = true // Force online status. I have no idea why this is always false @@ -35,21 +37,23 @@ func UpdatePresence(err error, client *nex.Client, callID uint32, presence *frie notifications_wiiu.SendPresenceUpdate(presence) - rmcResponse := nex.NewRMCResponse(friends_wiiu.ProtocolID, callID) - rmcResponse.SetSuccess(friends_wiiu.MethodUpdatePresence, nil) + rmcResponse := nex.NewRMCSuccess(nil) + rmcResponse.ProtocolID = friends_wiiu.ProtocolID + rmcResponse.MethodID = friends_wiiu.MethodUpdatePresence + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/register_common_authentication_server_protocols.go b/nex/register_common_authentication_server_protocols.go index de65361..aeb9b7d 100644 --- a/nex/register_common_authentication_server_protocols.go +++ b/nex/register_common_authentication_server_protocols.go @@ -28,5 +28,5 @@ func registerCommonAuthenticationServerProtocols() { ticketGrantingProtocol.SetBuildName(serverBuildString) ticketGrantingProtocol.EnableInsecureLogin() - globals.AuthenticationServer.SetPasswordFromPIDFunction(globals.PasswordFromPID) + globals.AuthenticationServer.PasswordFromPID = globals.PasswordFromPID } diff --git a/nex/secure-connection/register_ex.go b/nex/secure-connection/register_ex.go index 3f34eeb..2641df0 100644 --- a/nex/secure-connection/register_ex.go +++ b/nex/secure-connection/register_ex.go @@ -1,6 +1,7 @@ package nex_secure_connection import ( + "net" "time" database_3ds "github.com/PretendoNetwork/friends/database/3ds" @@ -11,18 +12,24 @@ import ( secure_connection "github.com/PretendoNetwork/nex-protocols-go/secure-connection" ) -func RegisterEx(err error, client *nex.Client, callID uint32, stationUrls []*nex.StationURL, loginData *nex.DataHolder) uint32 { +func RegisterEx(err error, packet nex.PacketInterface, callID uint32, stationUrls []*nex.StationURL, loginData *nex.DataHolder) uint32 { if err != nil { globals.Logger.Error(err.Error()) return nex.Errors.Core.InvalidArgument } + client := packet.Sender().(*nex.PRUDPClient) + retval := nex.NewResultSuccess(nex.Errors.Core.Unknown) rmcResponseStream := nex.NewStreamOut(globals.SecureServer) - // TODO: Validate loginData + // TODO - Validate loginData pid := client.PID() - user := globals.ConnectedUsers[pid] + + user := types.NewConnectedUser() + user.PID = pid + user.Client = client + lastOnline := nex.NewDateTime(0) lastOnline.FromTimestamp(time.Now()) @@ -50,17 +57,19 @@ func RegisterEx(err error, client *nex.Client, callID uint32, stationUrls []*nex } if retval.IsSuccess() { + globals.ConnectedUsers[pid] = user + localStation := stationUrls[0] - address := client.Address().IP.String() + address := client.Address().(*net.UDPAddr).IP.String() localStation.SetAddress(address) - localStation.SetPort(uint32(client.Address().Port)) + localStation.SetPort(uint32(client.Address().(*net.UDPAddr).Port)) localStationURL := localStation.EncodeToString() rmcResponseStream.WriteResult(retval) - rmcResponseStream.WriteUInt32LE(globals.SecureServer.ConnectionIDCounter().Increment()) + rmcResponseStream.WriteUInt32LE(globals.SecureServer.ConnectionIDCounter().Next()) rmcResponseStream.WriteString(localStationURL) } else { rmcResponseStream.WriteResult(retval) @@ -71,21 +80,23 @@ func RegisterEx(err error, client *nex.Client, callID uint32, stationUrls []*nex rmcResponseBody := rmcResponseStream.Bytes() // Build response packet - rmcResponse := nex.NewRMCResponse(secure_connection.ProtocolID, callID) - rmcResponse.SetSuccess(secure_connection.MethodRegisterEx, rmcResponseBody) + rmcResponse := nex.NewRMCSuccess(rmcResponseBody) + rmcResponse.ProtocolID = secure_connection.ProtocolID + rmcResponse.MethodID = secure_connection.MethodRegisterEx + rmcResponse.CallID = callID rmcResponseBytes := rmcResponse.Bytes() - responsePacket, _ := nex.NewPacketV0(client, nil) + responsePacket, _ := nex.NewPRUDPPacketV0(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) + responsePacket.SetSourceStreamType(packet.(nex.PRUDPPacketInterface).DestinationStreamType()) + responsePacket.SetSourcePort(packet.(nex.PRUDPPacketInterface).DestinationPort()) + responsePacket.SetDestinationStreamType(packet.(nex.PRUDPPacketInterface).SourceStreamType()) + responsePacket.SetDestinationPort(packet.(nex.PRUDPPacketInterface).SourcePort()) + responsePacket.SetPayload(rmcResponseBytes) globals.SecureServer.Send(responsePacket) diff --git a/nex/secure.go b/nex/secure.go index cc0cdb9..0019f80 100644 --- a/nex/secure.go +++ b/nex/secure.go @@ -3,6 +3,7 @@ package nex import ( "fmt" "os" + "strconv" "time" database_3ds "github.com/PretendoNetwork/friends/database/3ds" @@ -16,30 +17,25 @@ import ( ) func StartSecureServer() { - globals.SecureServer = nex.NewServer() - globals.SecureServer.SetFragmentSize(900) - globals.SecureServer.SetPRUDPVersion(0) + globals.SecureServer = nex.NewPRUDPServer() + globals.SecureServer.IsSecureServer = true + globals.SecureServer.SetFragmentSize(962) + globals.SecureServer.SetDefaultLibraryVersion(nex.NewLibraryVersion(1, 1, 0)) + globals.SecureServer.SetKerberosPassword([]byte("password")) globals.SecureServer.SetKerberosKeySize(16) - globals.SecureServer.SetKerberosPassword(globals.KerberosPassword) - globals.SecureServer.SetPingTimeout(20) // Maybe too long? globals.SecureServer.SetAccessKey("ridfebb9") - globals.SecureServer.SetDefaultNEXVersion(&nex.NEXVersion{ - Major: 1, - Minor: 1, - Patch: 0, - }) - globals.SecureServer.On("Data", func(packet *nex.PacketV0) { - request := packet.RMCRequest() + globals.SecureServer.OnData(func(packet nex.PacketInterface) { + request := packet.RMCMessage() fmt.Println("==Friends - Secure==") - fmt.Printf("Protocol ID: %#v\n", request.ProtocolID()) - fmt.Printf("Method ID: %#v\n", request.MethodID()) + fmt.Printf("Protocol ID: %#v\n", request.ProtocolID) + fmt.Printf("Method ID: %#v\n", request.MethodID) fmt.Println("====================") }) - globals.SecureServer.On("Kick", func(packet *nex.PacketV0) { - pid := packet.Sender().PID() + globals.SecureServer.OnClientRemoved(func(client *nex.PRUDPClient) { + pid := client.PID() if globals.ConnectedUsers[pid] == nil { return @@ -55,28 +51,23 @@ func StartSecureServer() { globals.Logger.Critical(err.Error()) } - notifications_wiiu.SendUserWentOfflineGlobally(packet.Sender()) + notifications_wiiu.SendUserWentOfflineGlobally(client) } else if platform == types.CTR { err := database_3ds.UpdateUserLastOnlineTime(pid, lastOnline) if err != nil { globals.Logger.Critical(err.Error()) } - notifications_3ds.SendUserWentOfflineGlobally(packet.Sender()) + notifications_3ds.SendUserWentOfflineGlobally(client) } delete(globals.ConnectedUsers, pid) fmt.Println("Leaving (Kick)") }) - globals.SecureServer.On("Disconnect", func(packet *nex.PacketV0) { - fmt.Println("Leaving (Disconnect)") - }) - - globals.SecureServer.On("Connect", connect) - registerCommonSecureServerProtocols() registerSecureServerProtocols() - globals.SecureServer.Listen(fmt.Sprintf(":%s", os.Getenv("PN_FRIENDS_SECURE_SERVER_PORT"))) + port, _ := strconv.Atoi(os.Getenv("PN_FRIENDS_SECURE_SERVER_PORT")) + globals.SecureServer.Listen(port) } diff --git a/notifications/3ds/send_comment_update.go b/notifications/3ds/send_comment_update.go index 834d4b4..b2e340b 100644 --- a/notifications/3ds/send_comment_update.go +++ b/notifications/3ds/send_comment_update.go @@ -10,7 +10,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendCommentUpdate(client *nex.Client, comment string) { +func SendCommentUpdate(client *nex.PRUDPClient, comment string) { notificationEvent := nintendo_notifications_types.NewNintendoNotificationEventGeneral() notificationEvent.StrParam = comment @@ -25,10 +25,10 @@ func SendCommentUpdate(client *nex.Client, comment string) { eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() @@ -42,16 +42,16 @@ func SendCommentUpdate(client *nex.Client, comment string) { connectedUser := globals.ConnectedUsers[friendsList[i].PID] if connectedUser != nil { - requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/3ds/send_favorite_update.go b/notifications/3ds/send_favorite_update.go index fd9eef0..39393db 100644 --- a/notifications/3ds/send_favorite_update.go +++ b/notifications/3ds/send_favorite_update.go @@ -11,7 +11,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendFavoriteUpdate(client *nex.Client, gameKey *friends_3ds_types.GameKey) { +func SendFavoriteUpdate(client *nex.PRUDPClient, gameKey *friends_3ds_types.GameKey) { eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() eventObject.Type = 2 eventObject.SenderPID = client.PID() @@ -23,10 +23,10 @@ func SendFavoriteUpdate(client *nex.Client, gameKey *friends_3ds_types.GameKey) eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() @@ -40,16 +40,16 @@ func SendFavoriteUpdate(client *nex.Client, gameKey *friends_3ds_types.GameKey) connectedUser := globals.ConnectedUsers[friendsList[i].PID] if connectedUser != nil { - requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/3ds/send_friendship_completed.go b/notifications/3ds/send_friendship_completed.go index a826986..988e20b 100644 --- a/notifications/3ds/send_friendship_completed.go +++ b/notifications/3ds/send_friendship_completed.go @@ -7,7 +7,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendFriendshipCompleted(client *nex.Client, friendPID uint32, senderPID uint32) { +func SendFriendshipCompleted(client *nex.PRUDPClient, friendPID uint32, senderPID uint32) { notificationEvent := nintendo_notifications_types.NewNintendoNotificationEventGeneral() notificationEvent.U32Param = 0 notificationEvent.U64Param1 = 0 @@ -24,23 +24,23 @@ func SendFriendshipCompleted(client *nex.Client, friendPID uint32, senderPID uin eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() - requestPacket, _ := nex.NewPacketV0(client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(client.DestinationStreamType) + requestPacket.SetSourcePort(client.DestinationPort) + requestPacket.SetDestinationStreamType(client.SourceStreamType) + requestPacket.SetDestinationPort(client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/3ds/send_mii_notification.go b/notifications/3ds/send_mii_notification.go index 9a30df0..75f3d2f 100644 --- a/notifications/3ds/send_mii_notification.go +++ b/notifications/3ds/send_mii_notification.go @@ -10,7 +10,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendMiiUpdateNotification(client *nex.Client) { +func SendMiiUpdateNotification(client *nex.PRUDPClient) { notificationEvent := nintendo_notifications_types.NewNintendoNotificationEventGeneral() eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() @@ -24,10 +24,10 @@ func SendMiiUpdateNotification(client *nex.Client) { eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() @@ -41,16 +41,16 @@ func SendMiiUpdateNotification(client *nex.Client) { connectedUser := globals.ConnectedUsers[friendsList[i].PID] if connectedUser != nil { - requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/3ds/send_presence_update.go b/notifications/3ds/send_presence_update.go index 2620606..22f03bc 100644 --- a/notifications/3ds/send_presence_update.go +++ b/notifications/3ds/send_presence_update.go @@ -11,7 +11,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendPresenceUpdate(client *nex.Client, presence *friends_3ds_types.NintendoPresence) { +func SendPresenceUpdate(client *nex.PRUDPClient, presence *friends_3ds_types.NintendoPresence) { eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() eventObject.Type = 1 eventObject.SenderPID = client.PID() @@ -23,10 +23,10 @@ func SendPresenceUpdate(client *nex.Client, presence *friends_3ds_types.Nintendo eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() @@ -40,17 +40,16 @@ func SendPresenceUpdate(client *nex.Client, presence *friends_3ds_types.Nintendo connectedUser := globals.ConnectedUsers[friendsList[i].PID] if connectedUser != nil { + requestPacket, _ := nex.NewPRUDPPacketV0(connectedUser.Client, 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) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/3ds/send_user_went_offline.go b/notifications/3ds/send_user_went_offline.go index 9e3982a..ad86539 100644 --- a/notifications/3ds/send_user_went_offline.go +++ b/notifications/3ds/send_user_went_offline.go @@ -10,7 +10,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendUserWentOfflineGlobally(client *nex.Client) { +func SendUserWentOfflineGlobally(client *nex.PRUDPClient) { friendsList, err := database_3ds.GetUserFriends(client.PID()) if err != nil && err != sql.ErrNoRows { globals.Logger.Critical(err.Error()) @@ -21,7 +21,7 @@ func SendUserWentOfflineGlobally(client *nex.Client) { } } -func SendUserWentOffline(client *nex.Client, pid uint32) { +func SendUserWentOffline(client *nex.PRUDPClient, pid uint32) { notificationEvent := nintendo_notifications_types.NewNintendoNotificationEventGeneral() eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() @@ -35,27 +35,27 @@ func SendUserWentOffline(client *nex.Client, pid uint32) { eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() connectedUser := globals.ConnectedUsers[pid] if connectedUser != nil { - requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(connectedUser.Client, nil) - requestPacket.SetVersion(0) - requestPacket.SetSource(0xA1) - requestPacket.SetDestination(0xAF) - requestPacket.SetType(nex.DataPacket) - requestPacket.SetPayload(rmcRequestBytes) + requestPacket.SetType(nex.DataPacket) + requestPacket.AddFlag(nex.FlagNeedsAck) + requestPacket.AddFlag(nex.FlagReliable) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) - requestPacket.AddFlag(nex.FlagNeedsAck) - requestPacket.AddFlag(nex.FlagReliable) - - globals.SecureServer.Send(requestPacket) + globals.SecureServer.Send(requestPacket) } } diff --git a/notifications/wiiu/send_friend_request.go b/notifications/wiiu/send_friend_request.go index 97264f8..a777db3 100644 --- a/notifications/wiiu/send_friend_request.go +++ b/notifications/wiiu/send_friend_request.go @@ -8,7 +8,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendFriendRequest(client *nex.Client, friendRequestNotificationData *friends_wiiu_types.FriendRequest) { +func SendFriendRequest(client *nex.PRUDPClient, friendRequestNotificationData *friends_wiiu_types.FriendRequest) { eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() eventObject.Type = 27 eventObject.SenderPID = friendRequestNotificationData.PrincipalInfo.PID @@ -20,23 +20,23 @@ func SendFriendRequest(client *nex.Client, friendRequestNotificationData *friend eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent2) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent2 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() - requestPacket, _ := nex.NewPacketV0(client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(client.DestinationStreamType) + requestPacket.SetSourcePort(client.DestinationPort) + requestPacket.SetDestinationStreamType(client.SourceStreamType) + requestPacket.SetDestinationPort(client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/wiiu/send_friend_request_accepted.go b/notifications/wiiu/send_friend_request_accepted.go index 9377e8b..3ff9653 100644 --- a/notifications/wiiu/send_friend_request_accepted.go +++ b/notifications/wiiu/send_friend_request_accepted.go @@ -8,7 +8,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendFriendRequestAccepted(client *nex.Client, friendInfo *friends_wiiu_types.FriendInfo) { +func SendFriendRequestAccepted(client *nex.PRUDPClient, friendInfo *friends_wiiu_types.FriendInfo) { eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() eventObject.Type = 30 eventObject.SenderPID = friendInfo.NNAInfo.PrincipalBasicInfo.PID @@ -20,23 +20,23 @@ func SendFriendRequestAccepted(client *nex.Client, friendInfo *friends_wiiu_type eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() - requestPacket, _ := nex.NewPacketV0(client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(client.DestinationStreamType) + requestPacket.SetSourcePort(client.DestinationPort) + requestPacket.SetDestinationStreamType(client.SourceStreamType) + requestPacket.SetDestinationPort(client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/wiiu/send_friendship_removed.go b/notifications/wiiu/send_friendship_removed.go index e9d82b2..da2513f 100644 --- a/notifications/wiiu/send_friendship_removed.go +++ b/notifications/wiiu/send_friendship_removed.go @@ -7,7 +7,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendFriendshipRemoved(client *nex.Client, senderPID uint32) { +func SendFriendshipRemoved(client *nex.PRUDPClient, senderPID uint32) { nintendoNotificationEventGeneral := nintendo_notifications_types.NewNintendoNotificationEventGeneral() eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() @@ -21,23 +21,23 @@ func SendFriendshipRemoved(client *nex.Client, senderPID uint32) { stream.WriteStructure(eventObject) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(stream.Bytes()) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = stream.Bytes() rmcRequestBytes := rmcRequest.Bytes() - requestPacket, _ := nex.NewPacketV0(client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(client.DestinationStreamType) + requestPacket.SetSourcePort(client.DestinationPort) + requestPacket.SetDestinationStreamType(client.SourceStreamType) + requestPacket.SetDestinationPort(client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/wiiu/send_presence_update.go b/notifications/wiiu/send_presence_update.go index 9eef5e2..6441813 100644 --- a/notifications/wiiu/send_presence_update.go +++ b/notifications/wiiu/send_presence_update.go @@ -24,10 +24,10 @@ func SendPresenceUpdate(presence *friends_wiiu_types.NintendoPresenceV2) { eventObjectBytes := eventObject.Bytes(stream) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent2) - rmcRequest.SetParameters(eventObjectBytes) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent2 + rmcRequest.Parameters = eventObjectBytes rmcRequestBytes := rmcRequest.Bytes() @@ -64,16 +64,16 @@ func SendPresenceUpdate(presence *friends_wiiu_types.NintendoPresenceV2) { connectedUser := globals.ConnectedUsers[friendPID] if connectedUser != nil { - requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/notifications/wiiu/send_user_went_offline.go b/notifications/wiiu/send_user_went_offline.go index d82c16d..1560348 100644 --- a/notifications/wiiu/send_user_went_offline.go +++ b/notifications/wiiu/send_user_went_offline.go @@ -11,7 +11,7 @@ import ( nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" ) -func SendUserWentOfflineGlobally(client *nex.Client) { +func SendUserWentOfflineGlobally(client *nex.PRUDPClient) { friendsList, err := database_wiiu.GetUserFriendList(client.PID()) if err != nil && err != database.ErrEmptyList { globals.Logger.Critical(err.Error()) @@ -22,7 +22,7 @@ func SendUserWentOfflineGlobally(client *nex.Client) { } } -func SendUserWentOffline(client *nex.Client, pid uint32) { +func SendUserWentOffline(client *nex.PRUDPClient, pid uint32) { lastOnline := nex.NewDateTime(0) lastOnline.FromTimestamp(time.Now()) @@ -44,26 +44,26 @@ func SendUserWentOffline(client *nex.Client, pid uint32) { stream.WriteStructure(eventObject) rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(nintendo_notifications.ProtocolID) - rmcRequest.SetCallID(3810693103) - rmcRequest.SetMethodID(nintendo_notifications.MethodProcessNintendoNotificationEvent1) - rmcRequest.SetParameters(stream.Bytes()) + rmcRequest.ProtocolID = nintendo_notifications.ProtocolID + rmcRequest.CallID = 3810693103 + rmcRequest.MethodID = nintendo_notifications.MethodProcessNintendoNotificationEvent1 + rmcRequest.Parameters = stream.Bytes() rmcRequestBytes := rmcRequest.Bytes() connectedUser := globals.ConnectedUsers[pid] if connectedUser != nil { - requestPacket, _ := nex.NewPacketV0(connectedUser.Client, nil) + requestPacket, _ := nex.NewPRUDPPacketV0(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) + requestPacket.SetSourceStreamType(connectedUser.Client.DestinationStreamType) + requestPacket.SetSourcePort(connectedUser.Client.DestinationPort) + requestPacket.SetDestinationStreamType(connectedUser.Client.SourceStreamType) + requestPacket.SetDestinationPort(connectedUser.Client.SourcePort) + requestPacket.SetPayload(rmcRequestBytes) globals.SecureServer.Send(requestPacket) } diff --git a/types/connected_user.go b/types/connected_user.go index a47b0d4..15d8ef4 100644 --- a/types/connected_user.go +++ b/types/connected_user.go @@ -9,7 +9,7 @@ import ( type ConnectedUser struct { PID uint32 Platform Platform - Client *nex.Client + Client *nex.PRUDPClient NNAInfo *friends_wiiu_types.NNAInfo Presence *friends_3ds_types.NintendoPresence PresenceV2 *friends_wiiu_types.NintendoPresenceV2