-
Notifications
You must be signed in to change notification settings - Fork 12
/
protocol.go
367 lines (311 loc) · 19.1 KB
/
protocol.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
// Package protocol implements the DataStoreSuperMarioMaker protocol
package protocol
import (
"fmt"
nex "github.com/PretendoNetwork/nex-go"
datastore "github.com/PretendoNetwork/nex-protocols-go/datastore"
datastore_super_mario_maker_types "github.com/PretendoNetwork/nex-protocols-go/datastore/super-mario-maker/types"
datastore_types "github.com/PretendoNetwork/nex-protocols-go/datastore/types"
"github.com/PretendoNetwork/nex-protocols-go/globals"
"golang.org/x/exp/slices"
)
const (
// ProtocolID is the Protocol ID for the DataStore (Super Mario Maker) protocol
ProtocolID = 0x73
// MethodGetObjectInfos is the method ID for the GetObjectInfos method
MethodGetObjectInfos = 0x2D
// MethodGetMetaByOwnerID is the method ID for the GetMetaByOwnerID method
MethodGetMetaByOwnerID = 0x2E
// MethodCustomSearchObject is the method ID for the CustomSearchObject method
MethodCustomSearchObject = 0x2F
// MethodRateCustomRanking is the method ID for the RateCustomRanking method
MethodRateCustomRanking = 0x30
// MethodGetCustomRanking is the method ID for the GetCustomRanking method
MethodGetCustomRanking = 0x31
// MethodGetCustomRankingByDataID is the method ID for the GetCustomRankingByDataID method
MethodGetCustomRankingByDataID = 0x32
// MethodDeleteCustomRanking is the method ID for the DeleteCustomRanking method
MethodDeleteCustomRanking = 0x33
// MethodAddToBufferQueue is the method ID for the AddToBufferQueue method
MethodAddToBufferQueue = 0x34
// MethodAddToBufferQueues is the method ID for the AddToBufferQueues method
MethodAddToBufferQueues = 0x35
// MethodGetBufferQueue is the method ID for the GetBufferQueue method
MethodGetBufferQueue = 0x36
// MethodGetBufferQueues is the method ID for the GetBufferQueues method
MethodGetBufferQueues = 0x37
// MethodClearBufferQueues is the method ID for the ClearBufferQueues method
MethodClearBufferQueues = 0x38
// MethodCompleteAttachFile is the method ID for the CompleteAttachFile method
MethodCompleteAttachFile = 0x39
// MethodCompleteAttachFileV1 is the method ID for the CompleteAttachFileV1 method
MethodCompleteAttachFileV1 = 0x3A
// MethodPrepareAttachFile is the method ID for the PrepareAttachFile method
MethodPrepareAttachFile = 0x3B
// MethodConditionalSearchObject is the method ID for the ConditionalSearchObject method
MethodConditionalSearchObject = 0x3C
// MethodGetApplicationConfig is the method ID for the GetApplicationConfig method
MethodGetApplicationConfig = 0x3D
// MethodSetApplicationConfig is the method ID for the SetApplicationConfig method
MethodSetApplicationConfig = 0x3E
// MethodDeleteApplicationConfig is the method ID for the DeleteApplicationConfig method
MethodDeleteApplicationConfig = 0x3F
// MethodLatestCourseSearchObject is the method ID for the LatestCourseSearchObject method
MethodLatestCourseSearchObject = 0x40
// MethodFollowingsLatestCourseSearchObject is the method ID for the FollowingsLatestCourseSearchObject method
MethodFollowingsLatestCourseSearchObject = 0x41
// MethodRecommendedCourseSearchObject is the method ID for the RecommendedCourseSearchObject method
MethodRecommendedCourseSearchObject = 0x42
// MethodScoreRangeCascadedSearchObject is the method ID for the ScoreRangeCascadedSearchObject method
MethodScoreRangeCascadedSearchObject = 0x43
// MethodSuggestedCourseSearchObject is the method ID for the SuggestedCourseSearchObject method
MethodSuggestedCourseSearchObject = 0x44
// MethodPreparePostObjectWithOwnerIDAndDataID is the method ID for the PreparePostObjectWithOwnerIDAndDataID method
MethodPreparePostObjectWithOwnerIDAndDataID = 0x45
// MethodCompletePostObjectWithOwnerID is the method ID for the CompletePostObjectWithOwnerID method
MethodCompletePostObjectWithOwnerID = 0x46
// MethodUploadCourseRecord is the method ID for the UploadCourseRecord method
MethodUploadCourseRecord = 0x47
// MethodGetCourseRecord is the method ID for the GetCourseRecord method
MethodGetCourseRecord = 0x48
// MethodDeleteCourseRecord is the method ID for the DeleteCourseRecord method
MethodDeleteCourseRecord = 0x49
// MethodGetApplicationConfigString is the method ID for the GetApplicationConfigString method
MethodGetApplicationConfigString = 0x4A
// MethodSetApplicationConfigString is the method ID for the SetApplicationConfigString method
MethodSetApplicationConfigString = 0x4B
// MethodGetDeletionReason is the method ID for the GetDeletionReason method
MethodGetDeletionReason = 0x4C
// MethodSetDeletionReason is the method ID for the SetDeletionReason method
MethodSetDeletionReason = 0x4D
// MethodGetMetasWithCourseRecord is the method ID for the GetMetasWithCourseRecord method
MethodGetMetasWithCourseRecord = 0x4E
// MethodCheckRateCustomRankingCounter is the method ID for the CheckRateCustomRankingCounter method
MethodCheckRateCustomRankingCounter = 0x4F
// MethodResetRateCustomRankingCounter is the method ID for the ResetRateCustomRankingCounter method
MethodResetRateCustomRankingCounter = 0x50
// MethodBestScoreRateCourseSearchObject is the method ID for the BestScoreRateCourseSearchObject method
MethodBestScoreRateCourseSearchObject = 0x51
// MethodCTRPickUpCourseSearchObject is the method ID for the CTRPickUpCourseSearchObject method
MethodCTRPickUpCourseSearchObject = 0x52
// MethodSetCachedRanking is the method ID for the SetCachedRanking method
MethodSetCachedRanking = 0x53
// MethodDeleteCachedRanking is the method ID for the DeleteCachedRanking method
MethodDeleteCachedRanking = 0x54
// MethodChangePlayablePlatform is the method ID for the ChangePlayablePlatform method
MethodChangePlayablePlatform = 0x55
// MethodSearchUnknownPlatformObjects is the method ID for the SearchUnknownPlatformObjects method
MethodSearchUnknownPlatformObjects = 0x56
// MethodReportCourse is the method ID for the ReportCourse method
MethodReportCourse = 0x57
)
var patchedMethods = []uint32{
MethodGetObjectInfos,
MethodGetMetaByOwnerID,
MethodCustomSearchObject,
MethodRateCustomRanking,
MethodGetCustomRanking,
MethodGetCustomRankingByDataID,
MethodDeleteCustomRanking,
MethodAddToBufferQueue,
MethodAddToBufferQueues,
MethodGetBufferQueue,
MethodGetBufferQueues,
MethodClearBufferQueues,
MethodCompleteAttachFile,
MethodCompleteAttachFileV1,
MethodPrepareAttachFile,
MethodConditionalSearchObject,
MethodGetApplicationConfig,
MethodSetApplicationConfig,
MethodDeleteApplicationConfig,
MethodLatestCourseSearchObject,
MethodFollowingsLatestCourseSearchObject,
MethodRecommendedCourseSearchObject,
MethodScoreRangeCascadedSearchObject,
MethodSuggestedCourseSearchObject,
MethodPreparePostObjectWithOwnerIDAndDataID,
MethodCompletePostObjectWithOwnerID,
MethodUploadCourseRecord,
MethodGetCourseRecord,
MethodDeleteCourseRecord,
MethodGetApplicationConfigString,
MethodSetApplicationConfigString,
MethodGetDeletionReason,
MethodSetDeletionReason,
MethodGetMetasWithCourseRecord,
MethodCheckRateCustomRankingCounter,
MethodResetRateCustomRankingCounter,
MethodBestScoreRateCourseSearchObject,
MethodCTRPickUpCourseSearchObject,
MethodSetCachedRanking,
MethodDeleteCachedRanking,
MethodChangePlayablePlatform,
MethodSearchUnknownPlatformObjects,
MethodReportCourse,
}
type dataStoreProtocol = datastore.Protocol
// Protocol stores all the RMC method handlers for the DataStore (Super Mario Maker) protocol and listens for requests
// Embeds the DataStore protocol
type Protocol struct {
Server *nex.Server
dataStoreProtocol
getObjectInfosHandler func(err error, packet nex.PacketInterface, callID uint32, dataIDs []uint64) uint32
getMetaByOwnerIDHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetMetaByOwnerIDParam) uint32
customSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, condition uint32, param *datastore_types.DataStoreSearchParam) uint32
rateCustomRankingHandler func(err error, packet nex.PacketInterface, callID uint32, params []*datastore_super_mario_maker_types.DataStoreRateCustomRankingParam) uint32
getCustomRankingHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCustomRankingParam) uint32
getCustomRankingByDataIDHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCustomRankingByDataIDParam) uint32
deleteCustomRankingHandler func(err error, packet nex.PacketInterface, callID uint32, dataIDList []uint64) uint32
addToBufferQueueHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.BufferQueueParam, buffer []byte) uint32
addToBufferQueuesHandler func(err error, packet nex.PacketInterface, callID uint32, params []*datastore_super_mario_maker_types.BufferQueueParam, buffers [][]byte) uint32
getBufferQueueHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.BufferQueueParam) uint32
getBufferQueuesHandler func(err error, packet nex.PacketInterface, callID uint32, params []*datastore_super_mario_maker_types.BufferQueueParam) uint32
clearBufferQueuesHandler func(err error, packet nex.PacketInterface, callID uint32, params []*datastore_super_mario_maker_types.BufferQueueParam) uint32
completeAttachFileHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParam) uint32
completeAttachFileV1Handler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreCompletePostParamV1) uint32
prepareAttachFileHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreAttachFileParam) uint32
conditionalSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, condition uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
getApplicationConfigHandler func(err error, packet nex.PacketInterface, callID uint32, applicationID uint32) uint32
setApplicationConfigHandler func(err error, packet nex.PacketInterface, callID uint32, applicationID uint32, key uint32, value int32) uint32
deleteApplicationConfigHandler func(err error, packet nex.PacketInterface, callID uint32, applicationID uint32, key uint32) uint32
latestCourseSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
followingsLatestCourseSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
recommendedCourseSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
scoreRangeCascadedSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
suggestedCourseSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
preparePostObjectWithOwnerIDAndDataIDHandler func(err error, packet nex.PacketInterface, callID uint32, ownerID uint32, dataID uint64, param *datastore_types.DataStorePreparePostParam) uint32
completePostObjectWithOwnerIDHandler func(err error, packet nex.PacketInterface, callID uint32, ownerID uint32, param *datastore_types.DataStoreCompletePostParam) uint32
uploadCourseRecordHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreUploadCourseRecordParam) uint32
getCourseRecordHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCourseRecordParam) uint32
deleteCourseRecordHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreGetCourseRecordParam) uint32
getApplicationConfigStringHandler func(err error, packet nex.PacketInterface, callID uint32, applicationID uint32) uint32
setApplicationConfigStringHandler func(err error, packet nex.PacketInterface, callID uint32, applicationID uint32, key uint32, value string) uint32
getDeletionReasonHandler func(err error, packet nex.PacketInterface, callID uint32, dataIDLst []uint64) uint32
setDeletionReasonHandler func(err error, packet nex.PacketInterface, callID uint32, dataIDLst []uint64, deletionReason uint32) uint32
getMetasWithCourseRecordHandler func(err error, packet nex.PacketInterface, callID uint32, params []*datastore_super_mario_maker_types.DataStoreGetCourseRecordParam, metaParam *datastore_types.DataStoreGetMetaParam) uint32
checkRateCustomRankingCounterHandler func(err error, packet nex.PacketInterface, callID uint32, applicationID uint32) uint32
resetRateCustomRankingCounterHandler func(err error, packet nex.PacketInterface, callID uint32, applicationID uint32) uint32
bestScoreRateCourseSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
cTRPickUpCourseSearchObjectHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_types.DataStoreSearchParam, extraData []string) uint32
setCachedRankingHandler func(err error, packet nex.PacketInterface, callID uint32, rankingType string, rankingArgs []string, dataIDLst []uint64) uint32
deleteCachedRankingHandler func(err error, packet nex.PacketInterface, callID uint32, rankingType string, rankingArgs []string) uint32
changePlayablePlatformHandler func(err error, packet nex.PacketInterface, callID uint32, params []*datastore_super_mario_maker_types.DataStoreChangePlayablePlatformParam) uint32
searchUnknownPlatformObjectsHandler func(err error, packet nex.PacketInterface, callID uint32, packetPayload []byte) uint32
reportCourseHandler func(err error, packet nex.PacketInterface, callID uint32, param *datastore_super_mario_maker_types.DataStoreReportCourseParam) uint32
}
// Setup initializes the protocol
func (protocol *Protocol) Setup() {
protocol.Server.On("Data", func(packet nex.PacketInterface) {
request := packet.RMCRequest()
if request.ProtocolID() == ProtocolID {
if slices.Contains(patchedMethods, request.MethodID()) {
protocol.HandlePacket(packet)
} else {
protocol.dataStoreProtocol.HandlePacket(packet)
}
}
})
}
// HandlePacket sends the packet to the correct RMC method handler
func (protocol *Protocol) HandlePacket(packet nex.PacketInterface) {
request := packet.RMCRequest()
switch request.MethodID() {
case MethodGetObjectInfos:
go protocol.handleGetObjectInfos(packet)
case MethodGetMetaByOwnerID:
go protocol.handleGetMetaByOwnerID(packet)
case MethodCustomSearchObject:
go protocol.handleCustomSearchObject(packet)
case MethodRateCustomRanking:
go protocol.handleRateCustomRanking(packet)
case MethodGetCustomRanking:
go protocol.handleGetCustomRanking(packet)
case MethodGetCustomRankingByDataID:
go protocol.handleGetCustomRankingByDataID(packet)
case MethodDeleteCustomRanking:
go protocol.handleDeleteCustomRanking(packet)
case MethodAddToBufferQueue:
go protocol.handleAddToBufferQueue(packet)
case MethodAddToBufferQueues:
go protocol.handleAddToBufferQueues(packet)
case MethodGetBufferQueue:
go protocol.handleGetBufferQueue(packet)
case MethodGetBufferQueues:
go protocol.handleGetBufferQueues(packet)
case MethodClearBufferQueues:
go protocol.handleClearBufferQueues(packet)
case MethodCompleteAttachFile:
go protocol.handleCompleteAttachFile(packet)
case MethodCompleteAttachFileV1:
go protocol.handleCompleteAttachFileV1(packet)
case MethodPrepareAttachFile:
go protocol.handlePrepareAttachFile(packet)
case MethodConditionalSearchObject:
go protocol.handleConditionalSearchObject(packet)
case MethodGetApplicationConfig:
go protocol.handleGetApplicationConfig(packet)
case MethodSetApplicationConfig:
go protocol.handleSetApplicationConfig(packet)
case MethodDeleteApplicationConfig:
go protocol.handleDeleteApplicationConfig(packet)
case MethodLatestCourseSearchObject:
go protocol.handleLatestCourseSearchObject(packet)
case MethodFollowingsLatestCourseSearchObject:
go protocol.handleFollowingsLatestCourseSearchObject(packet)
case MethodRecommendedCourseSearchObject:
go protocol.handleRecommendedCourseSearchObject(packet)
case MethodScoreRangeCascadedSearchObject:
go protocol.handleScoreRangeCascadedSearchObject(packet)
case MethodSuggestedCourseSearchObject:
go protocol.handleSuggestedCourseSearchObject(packet)
case MethodPreparePostObjectWithOwnerIDAndDataID:
go protocol.handlePreparePostObjectWithOwnerIDAndDataID(packet)
case MethodCompletePostObjectWithOwnerID:
go protocol.handleCompletePostObjectWithOwnerID(packet)
case MethodUploadCourseRecord:
go protocol.handleUploadCourseRecord(packet)
case MethodGetCourseRecord:
go protocol.handleGetCourseRecord(packet)
case MethodDeleteCourseRecord:
go protocol.handleDeleteCourseRecord(packet)
case MethodGetApplicationConfigString:
go protocol.handleGetApplicationConfigString(packet)
case MethodSetApplicationConfigString:
go protocol.handleSetApplicationConfigString(packet)
case MethodGetDeletionReason:
go protocol.handleGetDeletionReason(packet)
case MethodSetDeletionReason:
go protocol.handleSetDeletionReason(packet)
case MethodGetMetasWithCourseRecord:
go protocol.handleGetMetasWithCourseRecord(packet)
case MethodCheckRateCustomRankingCounter:
go protocol.handleCheckRateCustomRankingCounter(packet)
case MethodResetRateCustomRankingCounter:
go protocol.handleResetRateCustomRankingCounter(packet)
case MethodBestScoreRateCourseSearchObject:
go protocol.handleBestScoreRateCourseSearchObject(packet)
case MethodCTRPickUpCourseSearchObject:
go protocol.handleCTRPickUpCourseSearchObject(packet)
case MethodSetCachedRanking:
go protocol.handleSetCachedRanking(packet)
case MethodDeleteCachedRanking:
go protocol.handleDeleteCachedRanking(packet)
case MethodChangePlayablePlatform:
go protocol.handleChangePlayablePlatform(packet)
case MethodSearchUnknownPlatformObjects:
go protocol.handleSearchUnknownPlatformObjects(packet)
case MethodReportCourse:
go protocol.handleReportCourse(packet)
default:
go globals.RespondError(packet, ProtocolID, nex.Errors.Core.NotImplemented)
fmt.Printf("Unsupported DataStore (Super Mario Maker) method ID: %#v\n", request.MethodID())
}
}
// NewProtocol returns a new DataStoreSuperMarioMaker protocol
func NewProtocol(server *nex.Server) *Protocol {
protocol := &Protocol{Server: server}
protocol.dataStoreProtocol.Server = server
protocol.Setup()
return protocol
}