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

Add common Ranking protocol #19

Merged
merged 6 commits into from
Oct 11, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Code Review Changes
shutterbug2000 committed Oct 11, 2023
commit 470f32c0de0e91e9058a22f649ac4799a8a5aa64
5 changes: 3 additions & 2 deletions ranking/get_cached_top_x_ranking.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ func getCachedTopXRanking(err error, client *nex.Client, callID uint32, category
return nex.Errors.Core.NotImplemented
}

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
server := client.Server()

if err != nil {
@@ -41,7 +40,8 @@ func getCachedTopXRanking(err error, client *nex.Client, callID uint32, category
pResult := ranking_types.NewRankingCachedResult()
serverTime := nex.NewDateTime(0)
pResult.CreatedTime = nex.NewDateTime(serverTime.UTC())
pResult.ExpiredTime = nex.NewDateTime(serverTime.FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5)))) //The real server sends the "CreatedTime" + 5 minutes. It doesn't change, even on subsequent requests, until after the ExpiredTime has passed (seemingly what the "cached" means). Whether we need to replicate this idk, but in case, here's a note.
//The real server sends the "CreatedTime" + 5 minutes. It doesn't change, even on subsequent requests, until after the ExpiredTime has passed (seemingly what the "cached" means). Whether we need to replicate this idk, but in case, here's a note.
shutterbug2000 marked this conversation as resolved.
Show resolved Hide resolved
pResult.ExpiredTime = nex.NewDateTime(serverTime.FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5))))
pResult.MaxLength = 10 //This is the length Ultimate NES Remix uses. TODO: Does this matter? and are other games different?

rmcResponseStream := nex.NewStreamOut(server)
@@ -50,6 +50,7 @@ func getCachedTopXRanking(err error, client *nex.Client, callID uint32, category

rmcResponseBody := rmcResponseStream.Bytes()

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
rmcResponse.SetSuccess(ranking.MethodGetCachedTopXRanking, rmcResponseBody)

rmcResponseBytes := rmcResponse.Bytes()
16 changes: 9 additions & 7 deletions ranking/get_cached_top_x_rankings.go
Original file line number Diff line number Diff line change
@@ -14,7 +14,6 @@ func getCachedTopXRankings(err error, client *nex.Client, callID uint32, categor
return nex.Errors.Core.NotImplemented
}

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
server := client.Server()

if err != nil {
@@ -43,18 +42,21 @@ func getCachedTopXRankings(err error, client *nex.Client, callID uint32, categor
result := ranking_types.NewRankingCachedResult()
serverTime := nex.NewDateTime(0)
result.CreatedTime = nex.NewDateTime(serverTime.UTC())
result.ExpiredTime = nex.NewDateTime(serverTime.FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5)))) //The real server sends the "CreatedTime" + 5 minutes. It doesn't change, even on subsequent requests, until after the ExpiredTime has passed (seemingly what the "cached" means). Whether we need to replicate this idk, but in case, here's a note.
//The real server sends the "CreatedTime" + 5 minutes. It doesn't change, even on subsequent requests, until after the ExpiredTime has passed (seemingly what the "cached" means). Whether we need to replicate this idk, but in case, here's a note.
shutterbug2000 marked this conversation as resolved.
Show resolved Hide resolved
result.ExpiredTime = nex.NewDateTime(serverTime.FromTimestamp(time.Now().UTC().Add(time.Minute * time.Duration(5))))
result.MaxLength = 10 //This is the length Ultimate NES Remix uses. TODO: Does this matter? and are other games different?

result.SetParentType(rankingResult)
pResult = append(pResult, result)

rmcResponseStream := nex.NewStreamOut(server)
rmcResponseStream.WriteListStructure(pResult)
rmcResponseBody := rmcResponseStream.Bytes()
rmcResponse.SetSuccess(ranking.MethodGetCachedTopXRankings, rmcResponseBody)
}

rmcResponseStream := nex.NewStreamOut(server)
rmcResponseStream.WriteListStructure(pResult)
rmcResponseBody := rmcResponseStream.Bytes()

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
rmcResponse.SetSuccess(ranking.MethodGetCachedTopXRankings, rmcResponseBody)

rmcResponseBytes := rmcResponse.Bytes()

var responsePacket nex.PacketInterface
7 changes: 4 additions & 3 deletions ranking/get_common_data.go
Original file line number Diff line number Diff line change
@@ -11,23 +11,24 @@ func getCommonData(err error, client *nex.Client, callID uint32, uniqueID uint64
return nex.Errors.Core.NotImplemented
}

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
server := client.Server()

if err != nil {
logger.Error(err.Error())
return nex.Errors.Ranking.InvalidArgument
}

commonData, commonDataErr := commonRankingProtocol.getCommonDataHandler(uniqueID)
commonData, err := commonRankingProtocol.getCommonDataHandler(uniqueID)

if commonDataErr != nil {
if err != nil {
return nex.Errors.Ranking.NotFound
}

rmcResponseStream := nex.NewStreamOut(server)
rmcResponseStream.WriteBuffer(commonData)
rmcResponseBody := rmcResponseStream.Bytes()

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
rmcResponse.SetSuccess(ranking.MethodGetCommonData, rmcResponseBody)

rmcResponseBytes := rmcResponse.Bytes()
2 changes: 1 addition & 1 deletion ranking/get_ranking.go
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ func getRanking(err error, client *nex.Client, callID uint32, rankingMode uint8,
return nex.Errors.Core.NotImplemented
}

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
server := client.Server()

if err != nil {
@@ -42,6 +41,7 @@ func getRanking(err error, client *nex.Client, callID uint32, rankingMode uint8,

rmcResponseBody := rmcResponseStream.Bytes()

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
rmcResponse.SetSuccess(ranking.MethodGetRanking, rmcResponseBody)

rmcResponseBytes := rmcResponse.Bytes()
1 change: 0 additions & 1 deletion ranking/protocol.go
Original file line number Diff line number Diff line change
@@ -4,7 +4,6 @@ import (
"strings"

"github.com/PretendoNetwork/nex-go"
_ "github.com/PretendoNetwork/nex-protocols-go"
ranking "github.com/PretendoNetwork/nex-protocols-go/ranking"
ranking_mario_kart_8 "github.com/PretendoNetwork/nex-protocols-go/ranking/mario-kart-8"
ranking_types "github.com/PretendoNetwork/nex-protocols-go/ranking/types"
12 changes: 6 additions & 6 deletions ranking/upload_common_data.go
Original file line number Diff line number Diff line change
@@ -10,21 +10,21 @@ func uploadCommonData(err error, client *nex.Client, callID uint32, commonData [
logger.Warning("Ranking::UploadCommonData missing UploadCommonDataHandler!")
return nex.Errors.Core.NotImplemented
}

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)

server := client.Server()

if err != nil {
logger.Error(err.Error())
return nex.Errors.Ranking.InvalidArgument
}

insertErr := commonRankingProtocol.uploadCommonDataHandler(client.PID(), uniqueID, commonData)
if insertErr != nil {
logger.Critical(insertErr.Error())
err = commonRankingProtocol.uploadCommonDataHandler(client.PID(), uniqueID, commonData)
if err != nil {
logger.Critical(err.Error())
return nex.Errors.Ranking.Unknown
}


rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
rmcResponse.SetSuccess(ranking.MethodUploadCommonData, nil)

rmcResponseBytes := rmcResponse.Bytes()
12 changes: 6 additions & 6 deletions ranking/upload_score.go
Original file line number Diff line number Diff line change
@@ -11,21 +11,21 @@ func uploadScore(err error, client *nex.Client, callID uint32, scoreData *rankin
logger.Warning("Ranking::UploadScore missing InsertRankingByPIDAndRankingScoreDataHandler!")
return nex.Errors.Core.NotImplemented
}

rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)

server := client.Server()

if err != nil {
logger.Error(err.Error())
return nex.Errors.Ranking.InvalidArgument
}

insertErr := commonRankingProtocol.insertRankingByPIDAndRankingScoreDataHandler(client.PID(), scoreData, uniqueID)
if insertErr != nil {
logger.Critical(insertErr.Error())
err = commonRankingProtocol.insertRankingByPIDAndRankingScoreDataHandler(client.PID(), scoreData, uniqueID)
if err != nil {
logger.Critical(err.Error())
return nex.Errors.Ranking.Unknown
}


rmcResponse := nex.NewRMCResponse(ranking.ProtocolID, callID)
rmcResponse.SetSuccess(ranking.MethodUploadScore, nil)

rmcResponseBytes := rmcResponse.Bytes()