diff --git a/add_to_buffer_queues.go b/add_to_buffer_queues.go index 966321f..33ad55f 100644 --- a/add_to_buffer_queues.go +++ b/add_to_buffer_queues.go @@ -13,6 +13,7 @@ func addToBufferQueues(err error, client *nex.Client, callID uint32, params []*n param := params[i] insertBufferQueueData(param.DataID, param.Slot, buffer) + incrementCourseFailCount(param.DataID) pResults = append(pResults, 0x690001) } diff --git a/database.go b/database.go index 1603a8b..8a903de 100644 --- a/database.go +++ b/database.go @@ -311,6 +311,23 @@ func insertBufferQueueData(dataID uint64, slot uint32, buffer []byte) { } } +func getBufferQueueDeathData(dataID uint64) [][]byte { + pBufferQueue := make([][]byte, 0) + + var sliceMap []map[string]interface{} + var err error + + if sliceMap, err = cassandraClusterSession.Query(`SELECT buffer FROM pretendo_smm.buffer_queues WHERE data_id=? AND slot=3 ALLOW FILTERING`, dataID).Iter().SliceMap(); err != nil { + log.Fatal(err) + } + + for i := 0; i < len(sliceMap); i++ { + pBufferQueue = append(pBufferQueue, sliceMap[i]["buffer"].([]byte)) + } + + return pBufferQueue +} + func getCourseWorldRecord(dataID uint64) *CourseWorldRecord { var worldRecordFirstPID uint32 var worldRecordPID uint32 @@ -347,6 +364,30 @@ func updateCourseWorldRecord(courseID uint64, ownerPID uint32, score int32) { } } +func incrementCourseClearCount(courseID uint64) { + if err := cassandraClusterSession.Query(`UPDATE pretendo_smm.ratings SET completions=completions+1 WHERE data_id=?`, courseID).Exec(); err != nil { + log.Fatal(err) + } +} + +func incrementCourseStarCount(courseID uint64) { + if err := cassandraClusterSession.Query(`UPDATE pretendo_smm.ratings SET stars=stars+1 WHERE data_id=?`, courseID).Exec(); err != nil { + log.Fatal(err) + } +} + +func incrementCourseFailCount(courseID uint64) { + if err := cassandraClusterSession.Query(`UPDATE pretendo_smm.ratings SET failures=failures+1 WHERE data_id=?`, courseID).Exec(); err != nil { + log.Fatal(err) + } +} + +func incrementCourseAttemptCount(courseID uint64) { + if err := cassandraClusterSession.Query(`UPDATE pretendo_smm.ratings SET attempts=attempts+1 WHERE data_id=?`, courseID).Exec(); err != nil { + log.Fatal(err) + } +} + ////////////////////////////// // // // MongoDB database methods // diff --git a/get_buffer_queue.go b/get_buffer_queue.go index b8755fd..5433537 100644 --- a/get_buffer_queue.go +++ b/get_buffer_queue.go @@ -1,16 +1,32 @@ package main import ( + "fmt" + nex "github.com/PretendoNetwork/nex-go" nexproto "github.com/PretendoNetwork/nex-protocols-go" ) -func getBufferQueue(err error, client *nex.Client, callID uint32, bufferQueueParam *nexproto.BufferQueueParam) { +func getBufferQueue(err error, client *nex.Client, callID uint32, param *nexproto.BufferQueueParam) { rmcResponseStream := nex.NewStreamOut(nexServer) + fmt.Printf("%+v\n", param) + // TODO complete this - rmcResponseStream.WriteUInt32LE(0x00000000) // pBufferQueue List length 0 + pBufferQueue := make([][]byte, 0) + + switch param.Slot { + case 0: // unknown + pBufferQueue = make([][]byte, 0) + case 3: // death data + pBufferQueue = getBufferQueueDeathData(param.DataID) + incrementCourseAttemptCount(param.DataID) // We also know this is when a user attempts a course + default: + fmt.Printf("[Warning] DataStoreSMMProtocol::GetBufferQueue Unsupported slot: %v\n", param.Slot) + } + + rmcResponseStream.WriteListQBuffer(pBufferQueue) rmcResponseBody := rmcResponseStream.Bytes() diff --git a/rate_custom_ranking.go b/rate_custom_ranking.go index 0521341..c581aac 100644 --- a/rate_custom_ranking.go +++ b/rate_custom_ranking.go @@ -5,9 +5,90 @@ import ( nexproto "github.com/PretendoNetwork/nex-protocols-go" ) -func rateCustomRanking(err error, client *nex.Client, callID uint32, dataStoreRateCustomRankingParams []*nexproto.DataStoreRateCustomRankingParam) { - // STUBBED - // TODO: DO SOMETHING WITH THE DATA +func rateCustomRanking(err error, client *nex.Client, callID uint32, params []*nexproto.DataStoreRateCustomRankingParam) { + + /* + This has to change. We need to figure out what DataStoreRateCustomRankingParam.applicationId means. + This method sends a set number of DataStoreRateCustomRankingParam's in the params list depending + on what action the user does. + + - Course upload: 4 params + - DataStoreRateCustomRankingParam.dataId is always the course ID + - DataStoreRateCustomRankingParam.score is always 0 + - DataStoreRateCustomRankingParam.period is always 36500 + - DataStoreRateCustomRankingParam.applicationId is: + - 0 (seen in other requests relating to Mii data?) + - 2400 + - 200000000 + - 200002400 + + - Course clear: 2 params + - DataStoreRateCustomRankingParam.dataId is always the course ID + - DataStoreRateCustomRankingParam.score is always 1 + - DataStoreRateCustomRankingParam.period is always 36500 + - DataStoreRateCustomRankingParam.applicationId is: + - 200000000 + - 200002400 + + - Course star: 12 params + - DataStoreRateCustomRankingParam.dataId is: + - course ID + - course ID + - course ID + - course ID + - course ID + - course ID + - uploader PID + - uploader PID + - uploader PID + - uploader PID + - uploader PID + - uploader PID + - DataStoreRateCustomRankingParam.score is always 1 + - DataStoreRateCustomRankingParam.period is: + - 36500 + - 36500 + - 1 + - 1 + - 1 + - 1 + - 36500 + - 36500 + - 1 + - 1 + - 1 + - 1 + - DataStoreRateCustomRankingParam.applicationId is: + - 0 (seen in other requests relating to Mii data?) + - 2400 + - 119700101 + - 119702501 + - 1497730516 + - 1497732916 + - 300000000 (seen in other requests relating to Mii data?) + - 300002400 + - 419700101 + - 419702501 + - 1797730516 + - 1797732916 + + It seems like many applicationId's are actually a different ID with 2400 added to it? + + Since it always sends a set number of params per action, a quick and dirty way to tell them apart is + to check the param list length. However this should NOT be relied on forever and we NEED to learn more + about applicationId, as it IS used in many other requests + */ + + if len(params) == 2 { + // assume "course clear" action + incrementCourseClearCount(params[0].DataID) + } + + if len(params) == 12 { + // assume "star course" action + incrementCourseStarCount(params[0].DataID) + } + rmcResponse := nex.NewRMCResponse(nexproto.DataStoreSMMProtocolID, callID) rmcResponse.SetSuccess(nexproto.DataStoreSMMMethodRateCustomRanking, nil)