Skip to content

Commit

Permalink
Add implementations for notification data methods
Browse files Browse the repository at this point in the history
  • Loading branch information
shutterbug2000 committed Jul 3, 2024
1 parent e1957bb commit 236d8f1
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 0 deletions.
2 changes: 2 additions & 0 deletions globals/matchmaking_globals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
2 changes: 2 additions & 0 deletions match-making/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
55 changes: 55 additions & 0 deletions matchmake-extension/get_friend_notification_data.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 2 additions & 0 deletions matchmake-extension/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
40 changes: 40 additions & 0 deletions matchmake-extension/update_notification_data.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 236d8f1

Please sign in to comment.