From 236d8f159b73e23b93101e6abbb7e34999a58c3c Mon Sep 17 00:00:00 2001 From: shutterbug2000 Date: Tue, 2 Jul 2024 22:13:45 -0500 Subject: [PATCH] Add implementations for notification data methods --- globals/matchmaking_globals.go | 2 + match-making/protocol.go | 2 + .../get_friend_notification_data.go | 55 +++++++++++++++++++ matchmake-extension/protocol.go | 2 + .../update_notification_data.go | 40 ++++++++++++++ 5 files changed, 101 insertions(+) create mode 100644 matchmake-extension/get_friend_notification_data.go create mode 100644 matchmake-extension/update_notification_data.go diff --git a/globals/matchmaking_globals.go b/globals/matchmaking_globals.go index 135f91f..7b10878 100644 --- a/globals/matchmaking_globals.go +++ b/globals/matchmaking_globals.go @@ -3,6 +3,7 @@ package common_globals import ( "github.com/PretendoNetwork/nex-go/v2" match_making_types "github.com/PretendoNetwork/nex-protocols-go/v2/match-making/types" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" ) type CommonMatchmakeSession struct { @@ -12,6 +13,7 @@ type CommonMatchmakeSession struct { } var Sessions map[uint32]*CommonMatchmakeSession +var NotificationDatas map[uint64]*notifications_types.NotificationEvent var GetUserFriendPIDsHandler func(pid uint32) []uint32 var CurrentGatheringID = nex.NewCounter[uint32](0) var CurrentMatchmakingCallID = nex.NewCounter[uint32](0) diff --git a/match-making/protocol.go b/match-making/protocol.go index 96d7271..d7011e9 100644 --- a/match-making/protocol.go +++ b/match-making/protocol.go @@ -6,6 +6,7 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" _ "github.com/PretendoNetwork/nex-protocols-go/v2" match_making "github.com/PretendoNetwork/nex-protocols-go/v2/match-making" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" ) type CommonProtocol struct { @@ -29,6 +30,7 @@ func NewCommonProtocol(protocol match_making.Interface) *CommonProtocol { } common_globals.Sessions = make(map[uint32]*common_globals.CommonMatchmakeSession) + common_globals.NotificationDatas = make(map[uint64]*notifications_types.NotificationEvent) protocol.SetHandlerUnregisterGathering(commonProtocol.unregisterGathering) protocol.SetHandlerFindBySingleID(commonProtocol.findBySingleID) diff --git a/matchmake-extension/get_friend_notification_data.go b/matchmake-extension/get_friend_notification_data.go new file mode 100644 index 0000000..cab94a2 --- /dev/null +++ b/matchmake-extension/get_friend_notification_data.go @@ -0,0 +1,55 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) getFriendNotificationData(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveS32) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + if common_globals.GetUserFriendPIDsHandler == nil { + common_globals.Logger.Error("Missing GetUserFriendPIDsHandler!") + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + var friendList []uint32 + if len(friendList) == 0 { + friendList = common_globals.GetUserFriendPIDsHandler(uint32(connection.PID().Value())) // TODO - This grpc method needs to support the Switch + } + + dataList := types.NewList[*notifications_types.NotificationEvent]() + for _, pid := range friendList { + if notificationEvent, ok := common_globals.NotificationDatas[uint64(pid)]; ok { + if (notificationEvent.Type.Value / 1000) == uint32(uiType.Value){ + dataList.Append(notificationEvent) + } + } + } + + rmcResponseStream := nex.NewByteStreamOut(endpoint.LibraryVersions(), endpoint.ByteStreamSettings()) + + dataList.WriteTo(rmcResponseStream) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCSuccess(endpoint, rmcResponseBody) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodGetFriendNotificationData + rmcResponse.CallID = callID + + /*if commonProtocol.OnAfterJoinMatchmakeSession != nil { + go commonProtocol.OnAfterJoinMatchmakeSession(packet, gid, strMessage) + }*/ + + return rmcResponse, nil +} diff --git a/matchmake-extension/protocol.go b/matchmake-extension/protocol.go index 34fb51d..d93d14a 100644 --- a/matchmake-extension/protocol.go +++ b/matchmake-extension/protocol.go @@ -58,6 +58,8 @@ func NewCommonProtocol(protocol matchmake_extension.Interface) *CommonProtocol { protocol.SetHandlerModifyCurrentGameAttribute(commonProtocol.modifyCurrentGameAttribute) protocol.SetHandlerBrowseMatchmakeSession(commonProtocol.browseMatchmakeSession) protocol.SetHandlerJoinMatchmakeSessionEx(commonProtocol.joinMatchmakeSessionEx) + protocol.SetHandlerUpdateNotificationData(commonProtocol.updateNotificationData) + protocol.SetHandlerGetFriendNotificationData(commonProtocol.getFriendNotificationData) return commonProtocol } diff --git a/matchmake-extension/update_notification_data.go b/matchmake-extension/update_notification_data.go new file mode 100644 index 0000000..f49b3c2 --- /dev/null +++ b/matchmake-extension/update_notification_data.go @@ -0,0 +1,40 @@ +package matchmake_extension + +import ( + "github.com/PretendoNetwork/nex-go/v2" + "github.com/PretendoNetwork/nex-go/v2/types" + notifications_types "github.com/PretendoNetwork/nex-protocols-go/v2/notifications/types" + common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" + matchmake_extension "github.com/PretendoNetwork/nex-protocols-go/v2/matchmake-extension" +) + +func (commonProtocol *CommonProtocol) updateNotificationData(err error, packet nex.PacketInterface, callID uint32, uiType *types.PrimitiveU32, uiParam1 *types.PrimitiveU32, uiParam2 *types.PrimitiveU32, strParam *types.String) (*nex.RMCMessage, *nex.Error) { + if err != nil { + common_globals.Logger.Error(err.Error()) + return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") + } + + connection := packet.Sender().(*nex.PRUDPConnection) + endpoint := connection.Endpoint().(*nex.PRUDPEndPoint) + + event := notifications_types.NewNotificationEvent() + event.PIDSource = connection.PID() + event.Type = types.NewPrimitiveU32(uiType.Value * 1000) + event.Param1 = uiParam1 + event.Param2 = uiParam2 + event.StrParam = strParam + event.Param3 = types.NewPrimitiveU32(0xffffffff) + + common_globals.NotificationDatas[connection.PID().Value()] = event + + rmcResponse := nex.NewRMCSuccess(endpoint, nil) + rmcResponse.ProtocolID = matchmake_extension.ProtocolID + rmcResponse.MethodID = matchmake_extension.MethodUpdateNotificationData + rmcResponse.CallID = callID + + /*if commonProtocol.OnAfterJoinMatchmakeSession != nil { + go commonProtocol.OnAfterJoinMatchmakeSession(packet, gid, strMessage) + }*/ + + return rmcResponse, nil +}