From 569a56905cc62c39ca15cf0de9120aedc3d1921a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20L=C3=B3pez=20Guimaraes?= Date: Thu, 30 Jan 2025 16:36:08 +0000 Subject: [PATCH] fix(matchmake-extension): Fix incorrect SQL query for notifications Also improve and fix the NotificationData methods. --- matchmake-extension/database/get_notification_datas.go | 7 +++++++ .../database/inactivate_notification_datas.go | 1 + matchmake-extension/database/update_notification_data.go | 4 ++-- matchmake-extension/get_friend_notification_data.go | 3 ++- matchmake-extension/get_lst_friend_notification_data.go | 3 ++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/matchmake-extension/database/get_notification_datas.go b/matchmake-extension/database/get_notification_datas.go index 7dd79b6..b4b7c77 100644 --- a/matchmake-extension/database/get_notification_datas.go +++ b/matchmake-extension/database/get_notification_datas.go @@ -15,6 +15,13 @@ func GetNotificationDatas(manager *common_globals.MatchmakingManager, sourcePID var friendList []uint32 if manager.GetUserFriendPIDs != nil { friendList = manager.GetUserFriendPIDs(uint32(sourcePID)) + } else { + common_globals.Logger.Warning("GetNotificationDatas missing manager.GetUserFriendPIDs!") + } + + // * No friends to check + if len(friendList) == 0 { + return dataList, nil } rows, err := manager.Database.Query(`SELECT diff --git a/matchmake-extension/database/inactivate_notification_datas.go b/matchmake-extension/database/inactivate_notification_datas.go index 0556e71..21981ee 100644 --- a/matchmake-extension/database/inactivate_notification_datas.go +++ b/matchmake-extension/database/inactivate_notification_datas.go @@ -10,6 +10,7 @@ import ( func InactivateNotificationDatas(manager *common_globals.MatchmakingManager, sourcePID types.PID) *nex.Error { _, err := manager.Database.Exec(`UPDATE matchmaking.notifications SET active=false WHERE source_pid=$1`, sourcePID) if err != nil { + common_globals.Logger.Error(err.Error()) return nex.NewError(nex.ResultCodes.Core.Unknown, err.Error()) } diff --git a/matchmake-extension/database/update_notification_data.go b/matchmake-extension/database/update_notification_data.go index d5e5d86..df00d86 100644 --- a/matchmake-extension/database/update_notification_data.go +++ b/matchmake-extension/database/update_notification_data.go @@ -8,7 +8,7 @@ import ( // UpdateNotificationData updates the notification data of the specified user and type func UpdateNotificationData(manager *common_globals.MatchmakingManager, notificationData notifications_types.NotificationEvent) *nex.Error { - _, err := manager.Database.Exec(`INSERT INTO matchmaking.notifications ( + _, err := manager.Database.Exec(`INSERT INTO matchmaking.notifications AS n ( source_pid, type, param_1, @@ -21,7 +21,7 @@ func UpdateNotificationData(manager *common_globals.MatchmakingManager, notifica $4, $5 ) ON CONFLICT (source_pid, type) DO UPDATE SET - param_1=$3, param_2=$4, param_str=$5, active=true WHERE source_pid=$1 AND type=$2`, + param_1=$3, param_2=$4, param_str=$5, active=true WHERE n.source_pid=$1 AND n.type=$2`, notificationData.PIDSource, notificationData.Type, notificationData.Param1, diff --git a/matchmake-extension/get_friend_notification_data.go b/matchmake-extension/get_friend_notification_data.go index 9ae1879..75bef0b 100644 --- a/matchmake-extension/get_friend_notification_data.go +++ b/matchmake-extension/get_friend_notification_data.go @@ -6,6 +6,7 @@ import ( common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database" 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" ) @@ -25,7 +26,7 @@ func (commonProtocol *CommonProtocol) getFriendNotificationData(err error, packe commonProtocol.manager.Mutex.RLock() - notificationDatas, nexError := database.GetNotificationDatas(commonProtocol.manager, connection.PID(), []uint32{uint32(uiType)}) + notificationDatas, nexError := database.GetNotificationDatas(commonProtocol.manager, connection.PID(), []uint32{notifications.BuildNotificationType(uint32(uiType), 0)}) if nexError != nil { commonProtocol.manager.Mutex.RUnlock() return nil, nexError diff --git a/matchmake-extension/get_lst_friend_notification_data.go b/matchmake-extension/get_lst_friend_notification_data.go index 06a8852..7d9d7e1 100644 --- a/matchmake-extension/get_lst_friend_notification_data.go +++ b/matchmake-extension/get_lst_friend_notification_data.go @@ -4,6 +4,7 @@ import ( "github.com/PretendoNetwork/nex-go/v2" "github.com/PretendoNetwork/nex-go/v2/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" common_globals "github.com/PretendoNetwork/nex-protocols-common-go/v2/globals" "github.com/PretendoNetwork/nex-protocols-common-go/v2/matchmake-extension/database" @@ -25,7 +26,7 @@ func (commonProtocol *CommonProtocol) getlstFriendNotificationData(err error, pa return nil, nex.NewError(nex.ResultCodes.Core.InvalidArgument, "change_error") } - notificationTypes[i] = uint32(notificationType) + notificationTypes[i] = notifications.BuildNotificationType(uint32(notificationType), 0) } commonProtocol.manager.Mutex.RLock()