From 91c2e53115fcc8dc3080e01498caae847d6db9e0 Mon Sep 17 00:00:00 2001 From: Jonathan Barrow Date: Wed, 29 Sep 2021 20:40:07 -0400 Subject: [PATCH] AddToBufferQueues death data --- add_to_buffer_queues.go | 43 ++++++++++++++++++++++++++ database.go | 10 ++++-- main.go | 1 + recommended_course_search_object.go | 48 +++++++++++++++++++++++++++-- suggested_course_search_object.go | 5 ++- 5 files changed, 101 insertions(+), 6 deletions(-) create mode 100644 add_to_buffer_queues.go diff --git a/add_to_buffer_queues.go b/add_to_buffer_queues.go new file mode 100644 index 0000000..966321f --- /dev/null +++ b/add_to_buffer_queues.go @@ -0,0 +1,43 @@ +package main + +import ( + nex "github.com/PretendoNetwork/nex-go" + nexproto "github.com/PretendoNetwork/nex-protocols-go" +) + +func addToBufferQueues(err error, client *nex.Client, callID uint32, params []*nexproto.BufferQueueParam, buffers [][]byte) { + pResults := make([]uint32, 0) + + for i := 0; i < len(params); i++ { + buffer := buffers[i] + param := params[i] + + insertBufferQueueData(param.DataID, param.Slot, buffer) + + pResults = append(pResults, 0x690001) + } + + rmcResponseStream := nex.NewStreamOut(nexServer) + + rmcResponseStream.WriteListUInt32LE(pResults) + + rmcResponseBody := rmcResponseStream.Bytes() + + rmcResponse := nex.NewRMCResponse(nexproto.DataStoreProtocolID, callID) + rmcResponse.SetSuccess(nexproto.DataStoreSMMMethodAddToBufferQueues, rmcResponseBody) + + rmcResponseBytes := rmcResponse.Bytes() + + responsePacket, _ := nex.NewPacketV1(client, nil) + + responsePacket.SetVersion(1) + responsePacket.SetSource(0xA1) + responsePacket.SetDestination(0xAF) + responsePacket.SetType(nex.DataPacket) + responsePacket.SetPayload(rmcResponseBytes) + + responsePacket.AddFlag(nex.FlagNeedsAck) + responsePacket.AddFlag(nex.FlagReliable) + + nexServer.Send(responsePacket) +} diff --git a/database.go b/database.go index d6531b8..2ad8bb9 100644 --- a/database.go +++ b/database.go @@ -75,8 +75,8 @@ func connectCassandra() { } if err := cassandraClusterSession.Query(`CREATE TABLE IF NOT EXISTS pretendo_smm.buffer_queues ( - id int PRIMARY KEY, - data_id int, + id uuid PRIMARY KEY, + data_id bigint, slot int, buffer blob )`).Exec(); err != nil { @@ -284,6 +284,12 @@ func getCourseMetadataByDataIDs(dataIDs []uint64) []*CourseMetadata { return courseMetadatas } +func insertBufferQueueData(dataID uint64, slot uint32, buffer []byte) { + if err := cassandraClusterSession.Query(`INSERT INTO pretendo_smm.buffer_queues( id, data_id, slot, buffer ) VALUES ( now(), ?, ?, ? ) IF NOT EXISTS`, dataID, slot, buffer).Exec(); err != nil { + log.Fatal(err) + } +} + ////////////////////////////// // // // MongoDB database methods // diff --git a/main.go b/main.go index 7ecd113..98274f0 100644 --- a/main.go +++ b/main.go @@ -69,6 +69,7 @@ func main() { dataStoreSmmServer.GetObjectInfos(getObjectInfos) dataStoreSmmServer.RateCustomRanking(rateCustomRanking) dataStoreSmmServer.GetCustomRankingByDataId(getCustomRankingByDataId) + dataStoreSmmServer.AddToBufferQueues(addToBufferQueues) dataStoreSmmServer.GetBufferQueue(getBufferQueue) dataStoreSmmServer.CompleteAttachFile(completeAttachFile) dataStoreSmmServer.PrepareAttachFile(prepareAttachFile) diff --git a/recommended_course_search_object.go b/recommended_course_search_object.go index e49f0d9..fd915fa 100644 --- a/recommended_course_search_object.go +++ b/recommended_course_search_object.go @@ -44,16 +44,58 @@ func recommendedCourseSearchObject(err error, client *nex.Client, callID uint32, rankingResult.MetaInfo.Flag = courseMetadata.Flag rankingResult.MetaInfo.ReferredTime = nex.NewDateTime(now) rankingResult.MetaInfo.ExpireTime = nex.NewDateTime(now) - rankingResult.MetaInfo.Tags = []string{""} // idk? + rankingResult.MetaInfo.Tags = []string{"AYMHAAADAAB2V0gFWV1WtQ"} // idk? rankingResult.MetaInfo.Ratings = []*nexproto.DataStoreRatingInfoWithSlot{ nexproto.NewDataStoreRatingInfoWithSlot(), + nexproto.NewDataStoreRatingInfoWithSlot(), + nexproto.NewDataStoreRatingInfoWithSlot(), + nexproto.NewDataStoreRatingInfoWithSlot(), + nexproto.NewDataStoreRatingInfoWithSlot(), + nexproto.NewDataStoreRatingInfoWithSlot(), + nexproto.NewDataStoreRatingInfoWithSlot(), } rankingResult.MetaInfo.Ratings[0].Slot = 0 rankingResult.MetaInfo.Ratings[0].Rating = nexproto.NewDataStoreRatingInfo() - rankingResult.MetaInfo.Ratings[0].Rating.TotalValue = 3 - rankingResult.MetaInfo.Ratings[0].Rating.Count = 3 + rankingResult.MetaInfo.Ratings[0].Rating.TotalValue = 0 + rankingResult.MetaInfo.Ratings[0].Rating.Count = 0 rankingResult.MetaInfo.Ratings[0].Rating.InitialValue = 0 + rankingResult.MetaInfo.Ratings[1].Slot = 1 + rankingResult.MetaInfo.Ratings[1].Rating = nexproto.NewDataStoreRatingInfo() + rankingResult.MetaInfo.Ratings[1].Rating.TotalValue = 0 + rankingResult.MetaInfo.Ratings[1].Rating.Count = 0 + rankingResult.MetaInfo.Ratings[1].Rating.InitialValue = 0 + + rankingResult.MetaInfo.Ratings[2].Slot = 2 + rankingResult.MetaInfo.Ratings[2].Rating = nexproto.NewDataStoreRatingInfo() + rankingResult.MetaInfo.Ratings[2].Rating.TotalValue = 0 + rankingResult.MetaInfo.Ratings[2].Rating.Count = 0 + rankingResult.MetaInfo.Ratings[2].Rating.InitialValue = 0 + + rankingResult.MetaInfo.Ratings[3].Slot = 3 + rankingResult.MetaInfo.Ratings[3].Rating = nexproto.NewDataStoreRatingInfo() + rankingResult.MetaInfo.Ratings[3].Rating.TotalValue = 0 + rankingResult.MetaInfo.Ratings[3].Rating.Count = 0 + rankingResult.MetaInfo.Ratings[3].Rating.InitialValue = 0 + + rankingResult.MetaInfo.Ratings[4].Slot = 4 + rankingResult.MetaInfo.Ratings[4].Rating = nexproto.NewDataStoreRatingInfo() + rankingResult.MetaInfo.Ratings[4].Rating.TotalValue = 0 + rankingResult.MetaInfo.Ratings[4].Rating.Count = 0 + rankingResult.MetaInfo.Ratings[4].Rating.InitialValue = 0 + + rankingResult.MetaInfo.Ratings[5].Slot = 5 + rankingResult.MetaInfo.Ratings[5].Rating = nexproto.NewDataStoreRatingInfo() + rankingResult.MetaInfo.Ratings[5].Rating.TotalValue = 0 + rankingResult.MetaInfo.Ratings[5].Rating.Count = 0 + rankingResult.MetaInfo.Ratings[5].Rating.InitialValue = 0 + + rankingResult.MetaInfo.Ratings[6].Slot = 6 + rankingResult.MetaInfo.Ratings[6].Rating = nexproto.NewDataStoreRatingInfo() + rankingResult.MetaInfo.Ratings[6].Rating.TotalValue = 0 + rankingResult.MetaInfo.Ratings[6].Rating.Count = 0 + rankingResult.MetaInfo.Ratings[6].Rating.InitialValue = 0 + pRankingResults = append(pRankingResults, rankingResult) } diff --git a/suggested_course_search_object.go b/suggested_course_search_object.go index e387d2e..cc5bb4e 100644 --- a/suggested_course_search_object.go +++ b/suggested_course_search_object.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "time" nex "github.com/PretendoNetwork/nex-go" @@ -12,7 +13,9 @@ func suggestedCourseSearchObject(err error, client *nex.Client, callID uint32, p pRankingResults := make([]*nexproto.DataStoreCustomRankingResult, 0) - courseMetadatas := getCourseMetadatasByLimit(100) // In PCAPs param.minimalRatingFrequency is 100 but is 0 here? + fmt.Println(param.MinimalRatingFrequency) + + courseMetadatas := getCourseMetadatasByLimit(4) // In PCAPs param.minimalRatingFrequency is 4 but is 0 here? for i := 0; i < len(courseMetadatas); i++ { now := uint64(time.Now().Unix())