From 144927bd13368eb67b78482a5394a45487a3d1f1 Mon Sep 17 00:00:00 2001 From: SuperMarioDaBom Date: Fri, 21 Feb 2025 09:56:13 -0800 Subject: [PATCH] Update to latest library versions --- go.mod | 10 +-- go.sum | 8 +++ grpc/send_friends_notification.go | 36 +++++----- nex/match-making-ext/end_participation.go | 38 ++++------- nex/match-making/find_by_single_id.go | 55 ++++++++------- nex/match-making/get_session_urls.go | 44 ++++-------- nex/match-making/unregister_gathering.go | 35 +++++----- .../create_matchmake_session.go | 44 +++++------- .../get_friend_notification_data.go | 54 ++++++--------- .../join_matchmake_session_ex.go | 38 +++++------ nex/matchmake-extension/open_participation.go | 31 +++------ .../update_notification_data.go | 67 ++++++++----------- .../process_notification_event.go | 64 ++++++++++-------- 13 files changed, 228 insertions(+), 296 deletions(-) diff --git a/go.mod b/go.mod index c4d2788..2dd4e82 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/PretendoNetwork/wiiu-chat -go 1.22.1 +go 1.23.0 toolchain go1.23.4 @@ -8,8 +8,8 @@ require ( github.com/PretendoNetwork/grpc-go v1.0.2 github.com/PretendoNetwork/nex-go/v2 v2.1.2 github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.2.2 - github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.0 - github.com/PretendoNetwork/plogger-go v1.0.4 + github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.1 + github.com/PretendoNetwork/plogger-go v1.1.0 github.com/joho/godotenv v1.5.1 github.com/lib/pq v1.10.9 google.golang.org/grpc v1.58.3 @@ -21,13 +21,13 @@ require ( github.com/fatih/color v1.18.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/jwalton/go-supportscolor v1.2.0 // indirect - github.com/klauspost/compress v1.17.11 // indirect + github.com/klauspost/compress v1.18.0 // indirect github.com/lxzan/gws v1.8.8 // indirect github.com/mattn/go-colorable v0.1.14 // indirect github.com/mattn/go-isatty v0.0.20 // indirect github.com/rasky/go-lzo v0.0.0-20200203143853-96a758eda86e // indirect github.com/superwhiskers/crunch/v3 v3.5.7 // indirect - golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac // indirect + golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa // indirect golang.org/x/mod v0.23.0 // indirect golang.org/x/net v0.33.0 // indirect golang.org/x/sys v0.30.0 // indirect diff --git a/go.sum b/go.sum index 7251336..628039f 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,12 @@ github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.2.2 h1:rBJNZDJ92pa9fU3O github.com/PretendoNetwork/nex-protocols-common-go/v2 v2.2.2/go.mod h1:iuNMuBK/zww+44d6ajfLsOusXx/6Llj3zSkmhJwMuuM= github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.0 h1:abbCXgYN9icR9hmGV9GkuiOvg92+WBeVTnvtiAU06QU= github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.0/go.mod h1:+soBHmwX6ixGxj6cphLuCvfJqxcZPuowc/5e7Qi9Bz0= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.1 h1:/dsuP0W7bZNvrXoXH0ZRdxpxonfbWmmson51WCQdpEQ= +github.com/PretendoNetwork/nex-protocols-go/v2 v2.2.1/go.mod h1:+soBHmwX6ixGxj6cphLuCvfJqxcZPuowc/5e7Qi9Bz0= github.com/PretendoNetwork/plogger-go v1.0.4 h1:PF7xHw9eDRHH+RsAP9tmAE7fG0N0p6H4iPwHKnsoXwc= github.com/PretendoNetwork/plogger-go v1.0.4/go.mod h1:7kD6M4vPq1JL4LTuPg6kuB1OvUBOwQOtAvTaUwMbwvU= +github.com/PretendoNetwork/plogger-go v1.1.0 h1:x2XgyeeM8zDFGy+NcIZd3SYC2fNrVWpBBbkqTejOfiM= +github.com/PretendoNetwork/plogger-go v1.1.0/go.mod h1:wpltahp91IXr9nOvWgwep8zGtUKDeCVwm+/Wa484lQ4= github.com/PretendoNetwork/pq-extended v1.0.0 h1:GHZ0hLvCvmYKQPTV9I9XtTx8J1iB5Z9CEnfW2tUpsYg= github.com/PretendoNetwork/pq-extended v1.0.0/go.mod h1:bq6Ai+3lG4/M0iamUBt2Uzi5vL/nYy1a1Ar2ow9NDF0= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= @@ -30,6 +34,8 @@ github.com/jwalton/go-supportscolor v1.2.0 h1:g6Ha4u7Vm3LIsQ5wmeBpS4gazu0UP1DRDE github.com/jwalton/go-supportscolor v1.2.0/go.mod h1:hFVUAZV2cWg+WFFC4v8pT2X/S2qUUBYMioBD9AINXGs= github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= +github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= +github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o= github.com/lxzan/gws v1.8.8 h1:st193ZG8qN8sSw8/g/UituFhs7etmKzS7jUqhijg5wM= @@ -48,6 +54,8 @@ github.com/superwhiskers/crunch/v3 v3.5.7 h1:N9RLxaR65C36i26BUIpzPXGy2f6pQ7wisu2 github.com/superwhiskers/crunch/v3 v3.5.7/go.mod h1:4ub2EKgF1MAhTjoOCTU4b9uLMsAweHEa89aRrfAypXA= golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac h1:l5+whBCLH3iH2ZNHYLbAe58bo7yrN4mVcnkHDYz5vvs= golang.org/x/exp v0.0.0-20250210185358-939b2ce775ac/go.mod h1:hH+7mtFmImwwcMvScyxUhjuVHR3HGaDPMn9rMSUUbxo= +golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa h1:t2QcU6V556bFjYgu4L6C+6VrCPyJZ+eyRsABUPs1mz4= +golang.org/x/exp v0.0.0-20250218142911-aa4b98e5adaa/go.mod h1:BHOTPb3L19zxehTsLoJXVaTktb06DFgmdW6Wb9s8jqk= golang.org/x/mod v0.23.0 h1:Zb7khfcRGKk+kqfxFaP5tZqCnDZMjC5VtUBs87Hr6QM= golang.org/x/mod v0.23.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I= diff --git a/grpc/send_friends_notification.go b/grpc/send_friends_notification.go index 58c6834..79381f7 100644 --- a/grpc/send_friends_notification.go +++ b/grpc/send_friends_notification.go @@ -2,18 +2,17 @@ package grpc import ( "context" - "encoding/binary" pb "github.com/PretendoNetwork/grpc-go/friends" - nex "github.com/PretendoNetwork/nex-go" - friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/friends-wiiu/types" - nintendo_notifications "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications" - nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/nintendo-notifications/types" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + friends_wiiu_types "github.com/PretendoNetwork/nex-protocols-go/v2/friends-wiiu/types" + nintendo_notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/nintendo-notifications/types" + "github.com/PretendoNetwork/wiiu-chat/globals" "google.golang.org/grpc/metadata" ) -func SendFriendsNotification(caller uint32, target uint32, ringing bool) { +func SendFriendsNotification(caller types.PID, target types.PID, ringing types.Bool) { ctx := metadata.NewOutgoingContext(context.Background(), globals.GRPCFriendsCommonMetadata) presence := friends_wiiu_types.NewNintendoPresenceV2() @@ -22,31 +21,30 @@ func SendFriendsNotification(caller uint32, target uint32, ringing bool) { presence.GameKey = friends_wiiu_types.NewGameKey() presence.GameServerID = 0x1005A000 presence.PID = 1 // This is not a PID, but the amount of times the PID is repeated in bytes in the application data. - presence.GatheringID = caller + presence.GatheringID = types.NewUInt32(uint32(caller)) if ringing { - presence.Unknown2 = 0x65 + presence.Unknown2 = types.NewUInt32(0x65) } - targetBytes := make([]byte, 4) - binary.BigEndian.PutUint32(targetBytes, target) + targetBytes := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + target.WriteTo(targetBytes) - presence.ApplicationData = targetBytes + presence.ApplicationData = targetBytes.Bytes() presence.GameKey.TitleID = 0x000500101005A100 presence.GameKey.TitleVersion = 55 eventObject := nintendo_notifications_types.NewNintendoNotificationEvent() - eventObject.Type = nintendo_notifications.NotificationTypes.FriendStartedTitle eventObject.SenderPID = caller - eventObject.DataHolder = nex.NewDataHolder() - eventObject.DataHolder.SetTypeName("NintendoPresenceV2") - eventObject.DataHolder.SetObjectData(presence) + eventObject.DataHolder = types.NewDataHolder() + eventObject.DataHolder.Object = presence - stream := nex.NewStreamOut(globals.NEXServer) - eventObjectBytes := eventObject.Bytes(stream) + stream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + eventObject.WriteTo(stream) + eventObjectBytes := stream.Bytes() - _, err := globals.GRPCFriendsClient.SendUserNotificationWiiU(ctx, &pb.SendUserNotificationWiiURequest{Pid: target, NotificationData: eventObjectBytes}) + _, err := globals.GRPCFriendsClient.SendUserNotificationWiiU(ctx, &pb.SendUserNotificationWiiURequest{Pid: uint32(target), NotificationData: eventObjectBytes}) if err != nil { globals.Logger.Criticalf("Greeting Friends gRPC failed! : %v", err) } diff --git a/nex/match-making-ext/end_participation.go b/nex/match-making-ext/end_participation.go index a0ff998..408d57b 100644 --- a/nex/match-making-ext/end_participation.go +++ b/nex/match-making-ext/end_participation.go @@ -1,38 +1,26 @@ package nex_match_making_ext import ( - "strconv" + "fmt" - "github.com/PretendoNetwork/nex-go" - match_making_ext "github.com/PretendoNetwork/nex-protocols-go/match-making-ext" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + match_making_ext "github.com/PretendoNetwork/nex-protocols-go/v2/match-making-ext" + "github.com/PretendoNetwork/wiiu-chat/globals" ) -func EndParticipation(err error, client *nex.Client, callID uint32, idGathering uint32, strMessage string) { - globals.Logger.Info("ENDING PARTICIPATION: GID: " + strconv.FormatUint(uint64(idGathering), 10) + ", MESSAGE: " + strMessage) +func EndParticipation(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32, strMessage types.String) (*nex.RMCMessage, *nex.Error) { + globals.Logger.Info(fmt.Sprintf("ENDING PARTICIPATION: GID: %d, MESSAGE: %s", idGathering, strMessage)) - rmcResponseStream := nex.NewStreamOut(globals.NEXServer) + rmcResponseStream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) // TODO - Check if this is always true or not, and if not when to set to false rmcResponseStream.WriteBool(true) - rmcResponseBody := rmcResponseStream.Bytes() + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseStream.Bytes()) + rmcResponse.ProtocolID = match_making_ext.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = match_making_ext.MethodEndParticipation - rmcResponse := nex.NewRMCResponse(match_making_ext.ProtocolID, callID) - rmcResponse.SetSuccess(match_making_ext.MethodEndParticipation, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/match-making/find_by_single_id.go b/nex/match-making/find_by_single_id.go index 2a4ec3d..88dfe07 100644 --- a/nex/match-making/find_by_single_id.go +++ b/nex/match-making/find_by_single_id.go @@ -1,16 +1,18 @@ package nex_match_making import ( - nex "github.com/PretendoNetwork/nex-go" - match_making "github.com/PretendoNetwork/nex-protocols-go/match-making" - match_making_types "github.com/PretendoNetwork/nex-protocols-go/match-making/types" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + "github.com/PretendoNetwork/nex-go/v2/types" + + nex "github.com/PretendoNetwork/nex-go/v2" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + "github.com/PretendoNetwork/wiiu-chat/globals" ) -func FindBySingleID(err error, client *nex.Client, callID uint32, id uint32) { - caller := id // Gathering ID and caller are the same here +func FindBySingleID(err error, packet nex.PacketInterface, callID uint32, id types.UInt32) (*nex.RMCMessage, *nex.Error) { + caller := types.NewPID(uint64(id)) // Gathering ID and caller are the same here - result := true + result := types.NewBool(true) gathering := match_making_types.NewGathering() gathering.ID = id @@ -20,29 +22,26 @@ func FindBySingleID(err error, client *nex.Client, callID uint32, id uint32) { gathering.MaximumParticipants = 2 gathering.Description = "Doors Invite Request" - dataHolder := nex.NewDataHolder() - dataHolder.SetTypeName("Gathering") - dataHolder.SetObjectData(gathering) + // Gathering does not support being within an AnyDataHolder for some reason, + // so we have to create the AnyDataHolder info manually + dataHolder := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + gathering.WriteTo(dataHolder) + dataHolderBytes := dataHolder.Bytes() - rmcResponseStream := nex.NewStreamOut(globals.NEXServer) - rmcResponseStream.WriteBool(result) - rmcResponseStream.WriteDataHolder(dataHolder) + name := types.NewString("Gathering") + holderLen := types.NewUInt32(uint32(len(dataHolderBytes)) + 4) + holderBuf := types.NewBuffer(dataHolderBytes) - rmcResponse := nex.NewRMCResponse(match_making.ProtocolID, callID) - rmcResponse.SetSuccess(match_making.MethodFindBySingleID, rmcResponseStream.Bytes()) + rmcResponseStream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + result.WriteTo(rmcResponseStream) + name.WriteTo(rmcResponseStream) + holderLen.WriteTo(rmcResponseStream) + holderBuf.WriteTo(rmcResponseStream) - rmcResponseBytes := rmcResponse.Bytes() + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseStream.Bytes()) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = match_making.MethodFindBySingleID - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/match-making/get_session_urls.go b/nex/match-making/get_session_urls.go index 81ffd8a..a40b351 100644 --- a/nex/match-making/get_session_urls.go +++ b/nex/match-making/get_session_urls.go @@ -1,40 +1,24 @@ package nex_match_making import ( - nex "github.com/PretendoNetwork/nex-go" - match_making "github.com/PretendoNetwork/nex-protocols-go/match-making" - "github.com/PretendoNetwork/wiiu-chat-secure/database" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + "github.com/PretendoNetwork/wiiu-chat/globals" ) -func GetSessionUrls(err error, client *nex.Client, callID uint32, gid uint32) { - var stationUrlStrings []string +func GetSessionUrls(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) { + caller := types.NewPID(uint64(gid)) // Gathering ID and caller are the same here - hostpid, _, _ := database.GetCallInfoByCaller(gid) + stationUrlStrings := globals.SecureEndpoint.FindConnectionByPID(uint64(caller)).StationURLs - stationUrlStrings = globals.NEXServer.FindClientFromPID(hostpid).StationURLs() + rmcResponseStream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + stationUrlStrings.WriteTo(rmcResponseStream) - rmcResponseStream := nex.NewStreamOut(globals.NEXServer) - rmcResponseStream.WriteListString(stationUrlStrings) + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseStream.Bytes()) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = match_making.MethodGetSessionURLs - rmcResponseBody := rmcResponseStream.Bytes() - - // Build response packet - rmcResponse := nex.NewRMCResponse(match_making.ProtocolID, callID) - rmcResponse.SetSuccess(match_making.MethodGetSessionURLs, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/match-making/unregister_gathering.go b/nex/match-making/unregister_gathering.go index 3ea4ee3..39c9453 100644 --- a/nex/match-making/unregister_gathering.go +++ b/nex/match-making/unregister_gathering.go @@ -1,30 +1,27 @@ package nex_match_making import ( - nex "github.com/PretendoNetwork/nex-go" - match_making "github.com/PretendoNetwork/nex-protocols-go/match-making" - "github.com/PretendoNetwork/wiiu-chat-secure/database" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + "github.com/PretendoNetwork/wiiu-chat/database" + "github.com/PretendoNetwork/wiiu-chat/globals" ) -func UnregisterGathering(err error, client *nex.Client, callID uint32, idGathering uint32) { - database.EndCall(idGathering) +func UnregisterGathering(err error, packet nex.PacketInterface, callID uint32, idGathering types.UInt32) (*nex.RMCMessage, *nex.Error) { + caller := types.NewPID(uint64(idGathering)) // Gathering ID and caller are the same here - rmcResponse := nex.NewRMCResponse(match_making.MethodUnregisterGathering, callID) - rmcResponse.SetSuccess(match_making.ProtocolID, []byte{0x01}) + database.EndCall(caller) - rmcResponseBytes := rmcResponse.Bytes() + success := types.NewBool(true) - responsePacket, _ := nex.NewPacketV1(client, nil) + rmcResponseStream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + success.WriteTo(rmcResponseStream) - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseStream.Bytes()) + rmcResponse.ProtocolID = match_making.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = match_making.MethodUnregisterGathering - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/matchmake-extension/create_matchmake_session.go b/nex/matchmake-extension/create_matchmake_session.go index a5bb08a..f35489a 100644 --- a/nex/matchmake-extension/create_matchmake_session.go +++ b/nex/matchmake-extension/create_matchmake_session.go @@ -3,39 +3,27 @@ package nex_matchmake_extension import ( //"math/rand" - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/wiiu-chat/globals" - matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" + match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func CreateMatchmakeSession(err error, client *nex.Client, callID uint32, anyGathering *nex.DataHolder, message string, participationCount uint16) { - var gid uint32 = client.PID() // TODO: Random this +func CreateMatchmakeSession(err error, packet nex.PacketInterface, callID uint32, anyGathering match_making_types.GatheringHolder, message types.String, participationCount types.UInt16) (*nex.RMCMessage, *nex.Error) { + var gid types.UInt32 = types.NewUInt32(uint32(packet.Sender().PID())) // TODO: Randomize this sessionKey := make([]byte, 32) - //rand.Read(sessionKey) + sessionKeyBuffer := types.NewBuffer(sessionKey) - rmcResponseStream := nex.NewStreamOut(globals.NEXServer) + rmcResponseStream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + gid.WriteTo(rmcResponseStream) + sessionKeyBuffer.WriteTo(rmcResponseStream) - rmcResponseStream.WriteUInt32LE(gid) - rmcResponseStream.WriteBuffer(sessionKey) + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseStream.Bytes()) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = matchmake_extension.MethodCreateMatchmakeSession - rmcResponseBody := rmcResponseStream.Bytes() - - rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) - rmcResponse.SetSuccess(matchmake_extension.MethodCreateMatchmakeSession, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/matchmake-extension/get_friend_notification_data.go b/nex/matchmake-extension/get_friend_notification_data.go index 6f850b5..66c6a1e 100644 --- a/nex/matchmake-extension/get_friend_notification_data.go +++ b/nex/matchmake-extension/get_friend_notification_data.go @@ -1,56 +1,44 @@ package nex_matchmake_extension import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/wiiu-chat-secure/database" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/wiiu-chat/database" + "github.com/PretendoNetwork/wiiu-chat/globals" - matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - "github.com/PretendoNetwork/nex-protocols-go/notifications" - notifications_types "github.com/PretendoNetwork/nex-protocols-go/notifications/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" ) -func GetFriendNotificationData(err error, client *nex.Client, callID uint32, uiType int32) { - dataList := make([]*notifications_types.NotificationEvent, 0) +func GetFriendNotificationData(err error, packet nex.PacketInterface, callID uint32, uiType types.Int32) (*nex.RMCMessage, *nex.Error) { + dataList := types.NewList[notifications_types.NotificationEvent]() - caller, target, ringing := database.GetCallInfoByTarget(client.PID()) + caller, target, ringing := database.GetCallInfoByTarget(packet.Sender().PID()) // TODO: Multiple calls. Wii U Chat can handle it, but we don't support it yet - if caller != 0 && target == client.PID() && ringing { + if caller != 0 && target == packet.Sender().PID() && ringing { // Being called notificationType := notifications.BuildNotificationType(notifications.NotificationCategories.RequestJoinGathering, notifications.NotificationSubTypes.RequestJoinGathering.None) notification := notifications_types.NewNotificationEvent() notification.PIDSource = caller - notification.Type = notificationType - notification.Param1 = caller - notification.Param2 = target + notification.Type = types.NewUInt32(notificationType) + notification.Param1 = types.NewUInt32(uint32(caller)) + notification.Param2 = types.NewUInt32(uint32(target)) notification.StrParam = "Invite Request" dataList = append(dataList, notification) } - rmcResponseStream := nex.NewStreamOut(globals.NEXServer) - rmcResponseStream.WriteListStructure(dataList) + rmcResponseStream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + dataList.WriteTo(rmcResponseStream) - rmcResponseBody := rmcResponseStream.Bytes() + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseStream.Bytes()) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = matchmake_extension.MethodGetFriendNotificationData - rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) - rmcResponse.SetSuccess(matchmake_extension.MethodGetFriendNotificationData, rmcResponseBody) - - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/matchmake-extension/join_matchmake_session_ex.go b/nex/matchmake-extension/join_matchmake_session_ex.go index ae0c7a2..862e414 100644 --- a/nex/matchmake-extension/join_matchmake_session_ex.go +++ b/nex/matchmake-extension/join_matchmake_session_ex.go @@ -1,35 +1,29 @@ package nex_matchmake_extension import ( - nex "github.com/PretendoNetwork/nex-go" - matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - "github.com/PretendoNetwork/wiiu-chat-secure/database" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + "github.com/PretendoNetwork/wiiu-chat/database" + "github.com/PretendoNetwork/wiiu-chat/globals" ) -func JoinMatchmakeSessionEx(err error, client *nex.Client, callID uint32, gid uint32, strMessage string, dontCareMyBlockList bool, participationCount uint16) { +func JoinMatchmakeSessionEx(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32, strMessage types.String, dontCareMyBlockList types.Bool, participationCount types.UInt16) (*nex.RMCMessage, *nex.Error) { globals.Logger.Infof("gid: %d, strMessage: %s, dontCareMyBlockList: %t, participationCount: %d\r\n", gid, strMessage, dontCareMyBlockList, participationCount) - database.EndCallRinging(gid) + caller := types.NewPID(uint64(gid)) // Gathering ID and caller are the same here - output := nex.NewStreamOut(globals.NEXServer) - output.WriteBuffer(make([]byte, 32)) + database.EndCallRinging(caller) - rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) - rmcResponse.SetSuccess(matchmake_extension.MethodJoinMatchmakeSessionEx, output.Bytes()) + sessionKey := types.NewBuffer(make([]byte, 32)) - rmcResponseBytes := rmcResponse.Bytes() + rmcResponseStream := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + sessionKey.WriteTo(rmcResponseStream) - responsePacket, _ := nex.NewPacketV1(client, nil) + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, rmcResponseStream.Bytes()) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = matchmake_extension.MethodJoinMatchmakeSessionEx - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/matchmake-extension/open_participation.go b/nex/matchmake-extension/open_participation.go index fbcef25..04f77e2 100644 --- a/nex/matchmake-extension/open_participation.go +++ b/nex/matchmake-extension/open_participation.go @@ -1,31 +1,20 @@ package nex_matchmake_extension import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/wiiu-chat/globals" - matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" ) -func OpenParticipation(err error, client *nex.Client, callID uint32, gid uint32) { +func OpenParticipation(err error, packet nex.PacketInterface, callID uint32, gid types.UInt32) (*nex.RMCMessage, *nex.Error) { // TODO: Implement this - // Build response packet - rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) - rmcResponse.SetSuccess(matchmake_extension.MethodOpenParticipation, nil) + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = matchmake_extension.MethodOpenParticipation - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/matchmake-extension/update_notification_data.go b/nex/matchmake-extension/update_notification_data.go index 5f0a91c..b1f420d 100644 --- a/nex/matchmake-extension/update_notification_data.go +++ b/nex/matchmake-extension/update_notification_data.go @@ -1,64 +1,53 @@ package nex_matchmake_extension import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/wiiu-chat-secure/database" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" - "github.com/PretendoNetwork/wiiu-chat-secure/grpc" - nex_notifications "github.com/PretendoNetwork/wiiu-chat-secure/nex/notifications" + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + "github.com/PretendoNetwork/wiiu-chat/database" + "github.com/PretendoNetwork/wiiu-chat/globals" + "github.com/PretendoNetwork/wiiu-chat/grpc" + nex_notifications "github.com/PretendoNetwork/wiiu-chat/nex/notifications" - matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/matchmake-extension" - "github.com/PretendoNetwork/nex-protocols-go/notifications" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" ) -func UpdateNotificationData(err error, client *nex.Client, callID uint32, uiType uint32, uiParam1 uint32, uiParam2 uint32, strParam string) { +func UpdateNotificationData(err error, packet nex.PacketInterface, callID uint32, uiType types.UInt32, uiParam1 types.UInt32, uiParam2 types.UInt32, strParam types.String) (*nex.RMCMessage, *nex.Error) { globals.Logger.Infof("uiType: %d, uiParam1: %d, uiParam2: %d, strParam: %s\r\n", uiType, uiParam1, uiParam2, strParam) - recipientClient := globals.NEXServer.FindClientFromPID(uiParam2) + recipientClient := globals.SecureEndpoint.FindConnectionByPID(uint64(uiParam2)) - if uiType == notifications.NotificationCategories.RequestJoinGathering { + if uiType.Equals(types.NewUInt32(notifications.NotificationCategories.RequestJoinGathering)) { notificationType := notifications.BuildNotificationType(notifications.NotificationCategories.RequestJoinGathering, notifications.NotificationSubTypes.RequestJoinGathering.None) - database.NewCall(client.PID(), uiParam2) + target := types.NewPID(uint64(uiParam2)) + database.NewCall(packet.Sender().PID(), target) // If they don't have a session with the app, tell Friends to alert them on the HOME menu. - if recipientClient != nil && recipientClient.StationURLs() != nil { - nex_notifications.ProcessNotificationEvent(callID, client.PID(), notificationType, uiParam1, uiParam2, strParam) + if recipientClient != nil && recipientClient.StationURLs != nil { + nex_notifications.ProcessNotificationEvent(callID, packet, types.NewUInt32(notificationType), uiParam1, uiParam2, strParam) } else { - grpc.SendFriendsNotification(client.PID(), uiParam2, true) + grpc.SendFriendsNotification(packet.Sender().PID(), types.NewPID(uint64(uiParam2)), true) } } - if uiType == notifications.NotificationCategories.EndGathering { + if uiType.Equals(types.NewUInt32(notifications.NotificationCategories.EndGathering)) { notificationType := notifications.BuildNotificationType(notifications.NotificationCategories.EndGathering, notifications.NotificationSubTypes.EndGathering.None) - database.EndCall(uiParam1) + caller := types.NewPID(uint64(uiParam1)) + + database.EndCall(caller) // Alert the other side we aren't calling anymore. - if recipientClient != nil && recipientClient.StationURLs() != nil { - nex_notifications.ProcessNotificationEvent(callID, client.PID(), notificationType, uiParam1, uiParam2, strParam) + if recipientClient != nil && recipientClient.StationURLs != nil { + nex_notifications.ProcessNotificationEvent(callID, packet, types.NewUInt32(notificationType), uiParam1, uiParam2, strParam) } else { - grpc.SendFriendsNotification(client.PID(), uiParam2, false) + grpc.SendFriendsNotification(packet.Sender().PID(), types.NewPID(uint64(uiParam2)), false) } - - // The user must be kicked, otherwise the app hangs forever. - globals.NEXServer.TimeoutKick(client) } - // Build response packet - rmcResponse := nex.NewRMCResponse(matchmake_extension.ProtocolID, callID) - rmcResponse.SetSuccess(matchmake_extension.MethodUpdateNotificationData, nil) + rmcResponse := nex.NewRMCSuccess(globals.SecureEndpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.CallID = callID + rmcResponse.MethodID = matchmake_extension.MethodUpdateNotificationData - rmcResponseBytes := rmcResponse.Bytes() - - responsePacket, _ := nex.NewPacketV1(client, nil) - - responsePacket.SetVersion(1) - responsePacket.SetSource(0xA1) - responsePacket.SetDestination(0xAF) - responsePacket.SetType(nex.DataPacket) - responsePacket.SetPayload(rmcResponseBytes) - - responsePacket.AddFlag(nex.FlagNeedsAck) - responsePacket.AddFlag(nex.FlagReliable) - - globals.NEXServer.Send(responsePacket) + return rmcResponse, nil } diff --git a/nex/notifications/process_notification_event.go b/nex/notifications/process_notification_event.go index 40ff94a..2f976cd 100644 --- a/nex/notifications/process_notification_event.go +++ b/nex/notifications/process_notification_event.go @@ -1,44 +1,54 @@ package nex_notifications import ( - nex "github.com/PretendoNetwork/nex-go" - "github.com/PretendoNetwork/nex-protocols-go/notifications" - notifications_types "github.com/PretendoNetwork/nex-protocols-go/notifications/types" - "github.com/PretendoNetwork/wiiu-chat-secure/globals" + nex "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/constants" + "github.com/PretendoNetwork/nex-go/v2/types" + notifications "github.com/PretendoNetwork/nex-protocols-go/v2/notifications" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" + "github.com/PretendoNetwork/wiiu-chat/globals" ) -func ProcessNotificationEvent(callID uint32, pidSource uint32, uiType uint32, uiParam1 uint32, uiParam2 uint32, strParam string) { +func ProcessNotificationEvent(callID uint32, packet nex.PacketInterface, uiType types.UInt32, uiParam1 types.UInt32, uiParam2 types.UInt32, strParam types.String) { event := notifications_types.NewNotificationEvent() - event.PIDSource = pidSource // Sender PID - event.Type = uiType // Notification type - event.Param1 = uiParam1 // Gathering ID - event.Param2 = uiParam2 // Recipient PID - event.StrParam = strParam // Unknown + event.PIDSource = packet.Sender().PID() // Sender PID + event.Type = uiType // Notification type + event.Param1 = uiParam1 // Gathering ID + event.Param2 = uiParam2 // Recipient PID + event.StrParam = strParam // Unknown - eventObject := nex.NewStreamOut(globals.NEXServer) - eventObject.WriteStructure(event) + eventObject := nex.NewByteStreamOut(globals.SecureServer.LibraryVersions, globals.SecureServer.ByteStreamSettings) + event.WriteTo(eventObject) - rmcRequest := nex.NewRMCRequest() - rmcRequest.SetProtocolID(notifications.ProtocolID) - rmcRequest.SetCallID(0xFFFF + callID) - rmcRequest.SetMethodID(notifications.MethodProcessNotificationEvent) - rmcRequest.SetParameters(eventObject.Bytes()) + rmcRequest := nex.NewRMCRequest(globals.SecureEndpoint) + rmcRequest.ProtocolID = notifications.ProtocolID + rmcRequest.CallID = 0xFFFF + callID + rmcRequest.MethodID = notifications.MethodProcessNotificationEvent + rmcRequest.Parameters = eventObject.Bytes() rmcRequestBytes := rmcRequest.Bytes() - targetClient := globals.NEXServer.FindClientFromPID(uiParam2) + targetClient := globals.SecureEndpoint.FindConnectionByPID(uint64(uiParam2)) - requestPacket, _ := nex.NewPacketV1(targetClient, nil) + var responsePacket nex.PacketInterface + var prudpPacket nex.PRUDPPacketInterface - requestPacket.SetVersion(1) - requestPacket.SetSource(0xA1) - requestPacket.SetDestination(0xAF) - requestPacket.SetType(nex.DataPacket) - requestPacket.SetPayload(rmcRequestBytes) + endpoint := globals.SecureEndpoint + server := endpoint.Server + prudpPacket, _ = nex.NewPRUDPPacketV1(server, targetClient, nil) - requestPacket.AddFlag(nex.FlagNeedsAck) - requestPacket.AddFlag(nex.FlagReliable) + prudpPacket.SetType(constants.DataPacket) + prudpPacket.AddFlag(constants.PacketFlagReliable) + prudpPacket.AddFlag(constants.PacketFlagNeedsAck) + prudpPacket.SetSourceVirtualPortStreamType(packet.(*nex.PRUDPPacketV1).DestinationVirtualPortStreamType()) + prudpPacket.SetSourceVirtualPortStreamID(packet.(*nex.PRUDPPacketV1).DestinationVirtualPortStreamID()) + prudpPacket.SetDestinationVirtualPortStreamType(packet.(*nex.PRUDPPacketV1).SourceVirtualPortStreamType()) + prudpPacket.SetDestinationVirtualPortStreamID(packet.(*nex.PRUDPPacketV1).SourceVirtualPortStreamID()) + prudpPacket.SetSubstreamID(packet.(*nex.PRUDPPacketV1).SubstreamID()) - globals.NEXServer.Send(requestPacket) + responsePacket = prudpPacket + responsePacket.SetPayload(rmcRequestBytes) + + packet.Sender().Endpoint().Send(responsePacket) }