Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!(ranking): Add new methods for the different ranking modes on GetRanking #34

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion ranking/get_ranking.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,54 @@ func (commonProtocol *CommonProtocol) getRanking(err error, packet nex.PacketInt
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
}

if commonProtocol.GetNearbyRankingsAndCountByCategoryAndRankingOrderParam == nil {
common_globals.Logger.Warning("Ranking::GetRanking missing GetNearbyRankingsAndCountByCategoryAndRankingOrderParam!")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
}

if commonProtocol.GetFriendsRankingsAndCountByCategoryAndRankingOrderParam == nil {
common_globals.Logger.Warning("Ranking::GetRanking missing GetFriendsRankingsAndCountByCategoryAndRankingOrderParam!")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
}

if commonProtocol.GetNearbyFriendsRankingsAndCountByCategoryAndRankingOrderParam == nil {
common_globals.Logger.Warning("Ranking::GetRanking missing GetNearbyFriendsRankingsAndCountByCategoryAndRankingOrderParam!")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
}

if commonProtocol.GetOwnRankingByCategoryAndRankingOrderParam == nil {
common_globals.Logger.Warning("Ranking::GetRanking missing GetOwnRankingByCategoryAndRankingOrderParam!")
return nil, nex.NewError(nex.ResultCodes.Core.NotImplemented, "change_error")
}

if err != nil {
common_globals.Logger.Error(err.Error())
return nil, nex.NewError(nex.ResultCodes.Ranking.InvalidArgument, "change_error")
}

connection := packet.Sender()
endpoint := connection.Endpoint()
callerPid := principalID
// * PUYOPUYOTETRIS seems to do this sometimes
if callerPid.Value() == 0 {
callerPid = connection.PID()
}

var rankDataList *types.List[*ranking_types.RankingRankData]
var totalCount uint32

if rankingMode.Value == 0 {
Copy link

@ItzSwirlz ItzSwirlz Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if rankingMode.Value == 0 {
switch rankingMode.Value {
case 0:
rankDataList, totalCount, err = commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam(category, orderParam)
case 1:
rankDataList, totalCount, err = commonProtocol.GetNearbyRankingsAndCountByCategoryAndRankingOrderParam(callerPid, category, orderParam)
case 2:
rankDataList, totalCount, err = commonProtocol.GetFriendsRankingsAndCountByCategoryAndRankingOrderParam(callerPid, category, orderParam)
case 3:
rankDataList, totalCount, err = commonProtocol.GetNearbyFriendsRankingsAndCountByCategoryAndRankingOrderParam(callerPid, category, orderParam)
default: // rankingMode.Value == 4
rankDataList, totalCount, err = commonProtocol.GetOwnRankingByCategoryAndRankingOrderParam(callerPid, category, orderParam)
}

man I still cant figure out suggestions with GitHub for multiple lines

rankDataList, totalCount, err = commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam(category, orderParam)
} else if rankingMode.Value == 1 {
rankDataList, totalCount, err = commonProtocol.GetNearbyRankingsAndCountByCategoryAndRankingOrderParam(callerPid, category, orderParam)
} else if rankingMode.Value == 2 {
rankDataList, totalCount, err = commonProtocol.GetFriendsRankingsAndCountByCategoryAndRankingOrderParam(callerPid, category, orderParam)
} else if rankingMode.Value == 3 {
rankDataList, totalCount, err = commonProtocol.GetNearbyFriendsRankingsAndCountByCategoryAndRankingOrderParam(callerPid, category, orderParam)
} else { // rankingMode.Value == 4
rankDataList, totalCount, err = commonProtocol.GetOwnRankingByCategoryAndRankingOrderParam(callerPid, category, orderParam)
}

rankDataList, totalCount, err := commonProtocol.GetRankingsAndCountByCategoryAndRankingOrderParam(category, orderParam)
if err != nil {
common_globals.Logger.Critical(err.Error())
return nil, nex.NewError(nex.ResultCodes.Ranking.Unknown, "change_error")
Expand Down
28 changes: 16 additions & 12 deletions ranking/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,22 @@ import (
)

type CommonProtocol struct {
endpoint nex.EndpointInterface
protocol ranking.Interface
GetCommonData func(uniqueID *types.PrimitiveU64) (*types.Buffer, error)
UploadCommonData func(pid *types.PID, uniqueID *types.PrimitiveU64, commonData *types.Buffer) error
InsertRankingByPIDAndRankingScoreData func(pid *types.PID, rankingScoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) error
GetRankingsAndCountByCategoryAndRankingOrderParam func(category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error)
OnAfterGetCachedTopXRanking func(packet nex.PacketInterface, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam)
OnAfterGetCachedTopXRankings func(packet nex.PacketInterface, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam])
OnAfterGetCommonData func(packet nex.PacketInterface, uniqueID *types.PrimitiveU64)
OnAfterGetRanking func(packet nex.PacketInterface, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID)
OnAfterUploadCommonData func(packet nex.PacketInterface, commonData *types.Buffer, uniqueID *types.PrimitiveU64)
OnAfterUploadScore func(packet nex.PacketInterface, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64)
endpoint nex.EndpointInterface
protocol ranking.Interface
GetCommonData func(uniqueID *types.PrimitiveU64) (*types.Buffer, error)
UploadCommonData func(pid *types.PID, uniqueID *types.PrimitiveU64, commonData *types.Buffer) error
InsertRankingByPIDAndRankingScoreData func(pid *types.PID, rankingScoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64) error
GetRankingsAndCountByCategoryAndRankingOrderParam func(category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error)
GetNearbyRankingsAndCountByCategoryAndRankingOrderParam func(pid *types.PID, category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error)
GetFriendsRankingsAndCountByCategoryAndRankingOrderParam func(pid *types.PID, category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error)
GetNearbyFriendsRankingsAndCountByCategoryAndRankingOrderParam func(pid *types.PID, category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error)
GetOwnRankingByCategoryAndRankingOrderParam func(pid *types.PID, category *types.PrimitiveU32, rankingOrderParam *ranking_types.RankingOrderParam) (*types.List[*ranking_types.RankingRankData], uint32, error)
OnAfterGetCachedTopXRanking func(packet nex.PacketInterface, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam)
OnAfterGetCachedTopXRankings func(packet nex.PacketInterface, categories *types.List[*types.PrimitiveU32], orderParams *types.List[*ranking_types.RankingOrderParam])
OnAfterGetCommonData func(packet nex.PacketInterface, uniqueID *types.PrimitiveU64)
OnAfterGetRanking func(packet nex.PacketInterface, rankingMode *types.PrimitiveU8, category *types.PrimitiveU32, orderParam *ranking_types.RankingOrderParam, uniqueID *types.PrimitiveU64, principalID *types.PID)
OnAfterUploadCommonData func(packet nex.PacketInterface, commonData *types.Buffer, uniqueID *types.PrimitiveU64)
OnAfterUploadScore func(packet nex.PacketInterface, scoreData *ranking_types.RankingScoreData, uniqueID *types.PrimitiveU64)
}

// NewCommonProtocol returns a new CommonProtocol
Expand Down