@xmobitea/gn-server 2.6.6 → 2.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/LICENSE +198 -5
  2. package/dist/GN-app-api/handler/controller/handler/characterPlayer/model/GroupMemberParam.d.ts +0 -1
  3. package/dist/GN-app-api/handler/controller/handler/cloudScript/ExecuteFunctionRequestHandler.d.ts +1 -1
  4. package/dist/GN-app-api/handler/controller/handler/group/model/GroupMemberParam.d.ts +0 -1
  5. package/dist/GN-app-api/handler/controller/handler/masterPlayer/SetPlayerBanRequestHandler.d.ts +2 -0
  6. package/dist/GN-app-api/service/CloudScriptEventService.d.ts +144 -0
  7. package/dist/GN-app-api/service/CloudScriptService.d.ts +1 -1
  8. package/dist/GN-app-api/service/EventCallbackService.d.ts +9 -17
  9. package/dist/GN-app-api/service/ICloudScriptService.d.ts +2 -2
  10. package/dist/GN-app-api/service/IEventCallbackService.d.ts +0 -14
  11. package/dist/GN-app-api/{handler/controller/handler/multiplayer/MatchmakingHandler.d.ts → service/IMatchmakingService.d.ts} +2 -19
  12. package/dist/GN-app-api/service/MatchmakingService.d.ts +21 -0
  13. package/dist/GN-startup/cloudScript/CloudScriptAdmin.ts +74 -0
  14. package/dist/GN-startup/cloudScript/CloudScriptDatabase.ts +93 -0
  15. package/dist/GN-startup/cloudScript/CloudScriptEvent.ts +158 -0
  16. package/dist/GN-startup/cloudScript/CloudScriptHttp.ts +31 -0
  17. package/dist/GN-startup/cloudScript/CloudScriptMail.ts +26 -0
  18. package/dist/GN-startup/cloudScript/CloudScriptMatchmaking.ts +14 -0
  19. package/dist/GN-startup/cloudScript/CloudScriptPushNotification.ts +65 -0
  20. package/dist/GN-startup/cloudScript/CloudScriptSocket.ts +64 -0
  21. package/dist/GN-startup/cloudScript/eventCallbackCloudScriptData.json +59 -17
  22. package/dist/GN-startup/cloudScript/templateCloudScript.ts +26 -385
  23. package/dist/GN-startup/cloudScript/templateEventCallback.ts +301 -509
  24. package/dist/GN-startup/middleware/ApiMiddleware.d.ts +1 -0
  25. package/dist/GN-startup/routes/SocketAppHandler.d.ts +7 -0
  26. package/dist/GNServer.d.ts +5 -1
  27. package/dist/RequestControllerUtils.d.ts +4 -0
  28. package/dist/index.d.ts +1 -1
  29. package/dist/index.js +2487 -2413
  30. package/package.json +3 -3
  31. package/apiReferences/Authenticate.json +0 -1
  32. package/apiReferences/CharacterPlayer.json +0 -1
  33. package/apiReferences/CloudScript.json +0 -1
  34. package/apiReferences/Content.json +0 -1
  35. package/apiReferences/GamePlayer.json +0 -1
  36. package/apiReferences/Group.json +0 -1
  37. package/apiReferences/Inventory.json +0 -1
  38. package/apiReferences/MasterAdmin.json +0 -1
  39. package/apiReferences/MasterPlayer.json +0 -1
  40. package/apiReferences/Multiplayer.json +0 -1
  41. package/apiReferences/StoreInventory.json +0 -1
@@ -69,382 +69,25 @@ import {
69
69
  GNUtils,
70
70
  } from "@xmobitea/gn-typescript-client";
71
71
 
72
+ // dont remove this import
73
+
72
74
  import * as mongodb from "mongodb";
73
75
  import * as axios from "axios";
74
76
 
75
- enum CloudScriptEventType {
76
- SendToUser = 0,
77
- SendToMore = 1,
78
- SendToAll = 2,
79
- }
80
-
81
- interface CloudScriptEvent {
82
- eventType: CloudScriptEventType;
83
- operationEvent: {
84
- eventCode: string;
85
- parameters: {} | null;
86
- };
87
- receiver: string[] | string | null;
88
- }
89
-
90
- class CloudScriptAdmin {
91
- public readonly characterPlayer = GNNetwork.characterPlayer.admin;
92
- public readonly content = GNNetwork.content.admin;
93
- public readonly gamePlayer = GNNetwork.gamePlayer.admin;
94
- public readonly group = GNNetwork.group.admin;
95
- public readonly inventory = GNNetwork.inventory.admin;
96
- public readonly masterPlayer = GNNetwork.masterPlayer.admin;
97
- public readonly storeInventory = GNNetwork.storeInventory.admin;
98
- public readonly multiplayer = GNNetwork.multiplayer.admin;
99
- public readonly cloudScript = GNNetwork.cloudScript.admin;
100
- public readonly dashboard = {
101
- getAdminAccountList: GNNetwork.dashboard.getAdminAccountList,
102
- getAdminAccountListAsync: GNNetwork.dashboard.getAdminAccountListAsync,
103
- getGameInformation: GNNetwork.dashboard.getGameInformation,
104
- getGameInformationAsync: GNNetwork.dashboard.getGameInformationAsync,
105
- getGameList: GNNetwork.dashboard.getGameList,
106
- getGameListAsync: GNNetwork.dashboard.getGameListAsync,
107
- getMasterGameSettings: GNNetwork.dashboard.getMasterGameSettings,
108
- getMasterGameSettingsAsync: GNNetwork.dashboard.getMasterGameSettingsAsync,
109
- getSecretInfoInformation: GNNetwork.dashboard.getSecretInfoInformation,
110
- getSecretInfoInformationAsync: GNNetwork.dashboard.getSecretInfoInformationAsync,
111
- getSecretInfoList: GNNetwork.dashboard.getSecretInfoList,
112
- getSecretInfoListAsync: GNNetwork.dashboard.getSecretInfoListAsync,
113
- getServerLog: GNNetwork.dashboard.getServerLog,
114
- getServerLogAsync: GNNetwork.dashboard.getServerLogAsync,
115
- setGameInformation: GNNetwork.dashboard.setGameInformation,
116
- setGameInformationAsync: GNNetwork.dashboard.setGameInformationAsync,
117
- getUsernameAdminAccount: GNNetwork.dashboard.getUsernameAdminAccount,
118
- getUsernameAdminAccountAsync: GNNetwork.dashboard.getUsernameAdminAccountAsync,
119
- getAnalytics: GNNetwork.dashboard.getAnalytics,
120
- getAnalyticsAsync: GNNetwork.dashboard.getAnalyticsAsync,
121
- resetStatisticsLeaderboard: GNNetwork.dashboard.resetStatisticsLeaderboard,
122
- resetStatisticsLeaderboardAsync: GNNetwork.dashboard.resetStatisticsLeaderboardAsync,
123
- getBackupStatisticsLeaderboardVersion: GNNetwork.dashboard.getBackupStatisticsLeaderboardVersion,
124
- getBackupStatisticsLeaderboardVersionAsync: GNNetwork.dashboard.getBackupStatisticsLeaderboardVersionAsync,
125
- getServerGameData: GNNetwork.dashboard.getServerGameData,
126
- getServerGameDataAsync: GNNetwork.dashboard.getServerGameDataAsync,
127
- deleteInDatabase: GNNetwork.dashboard.deleteInDatabase,
128
- deleteInDatabaseAsync: GNNetwork.dashboard.deleteInDatabaseAsync,
129
- };
130
- public send(
131
- requestType: RequestType,
132
- role: RequestRole,
133
- request: OperationRequest,
134
- onResponse: Action1<OperationResponse>,
135
- overrideAuthToken: string,
136
- overrideSecretKey: string,
137
- customTags: GNHashtable
138
- ): void {
139
- GNNetwork.sendViaHttp(requestType, role, request, onResponse, overrideAuthToken, overrideSecretKey, customTags);
140
- }
141
-
142
- public sendAsync(
143
- requestType: RequestType,
144
- role: RequestRole,
145
- request: OperationRequest,
146
- overrideAuthToken: string,
147
- overrideSecretKey: string,
148
- customTags: GNHashtable
149
- ): Promise<OperationResponse> {
150
- return GNNetwork.sendViaHttpAsync(requestType, role, request, overrideAuthToken, overrideSecretKey, customTags);
151
- }
152
- }
153
-
154
- class CloudScriptDatabase {
155
- private static readonly DOT: string = ".";
156
- private static readonly RUNTIME: string = "Runtime" + CloudScriptDatabase.DOT;
157
- private static readonly META: string = "Meta" + CloudScriptDatabase.DOT;
158
- private static readonly SYSTEM: string = "System" + CloudScriptDatabase.DOT;
159
-
160
- private client: mongodb.MongoClient;
161
- private db: mongodb.Db;
162
-
163
- private logClient: mongodb.MongoClient;
164
- private logDb: mongodb.Db;
165
-
166
- init(url: string, dbName: string, logUrl: string, logDbName: string, options?: mongodb.MongoClientOptions): void {
167
- this.client = new mongodb.MongoClient(url, options);
168
-
169
- this.db = this.client.db(dbName);
170
-
171
- if (!logUrl || logUrl == "" || logUrl == url) {
172
- this.logClient = this.client;
173
- this.logDb = this.db;
174
- }
175
- else {
176
- this.logClient = new mongodb.MongoClient(logUrl, options);
177
- this.logDb = this.logClient.db(logDbName);
178
- }
179
- }
180
-
181
- public runtimeCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string): mongodb.Collection<TSchema> {
182
- return this.collection<TSchema>(CloudScriptDatabase.RUNTIME + collectionName);
183
- }
184
-
185
- public metaCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string): mongodb.Collection<TSchema> {
186
- return this.collection<TSchema>(CloudScriptDatabase.META + collectionName);
187
- }
188
-
189
- public systemCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string): mongodb.Collection<TSchema> {
190
- return this.collection<TSchema>(CloudScriptDatabase.SYSTEM + collectionName);
191
- }
192
-
193
- public runtimeGameCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string, gameId: string): mongodb.Collection<TSchema> {
194
- return this.collection<TSchema>(CloudScriptDatabase.RUNTIME + gameId + CloudScriptDatabase.DOT + collectionName);
195
- }
196
-
197
- public metaGameCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string, gameId: string): mongodb.Collection<TSchema> {
198
- return this.collection<TSchema>(CloudScriptDatabase.META + gameId + CloudScriptDatabase.DOT + collectionName);
199
- }
200
-
201
- public systemGameCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string, gameId: string): mongodb.Collection<TSchema> {
202
- return this.collection<TSchema>(CloudScriptDatabase.SYSTEM + gameId + CloudScriptDatabase.DOT + collectionName);
203
- }
204
-
205
- public collection<TSchema extends mongodb.Document = mongodb.Document>(fullCollectionName: string): mongodb.Collection<TSchema> {
206
- return this.db.collection<TSchema>(fullCollectionName);
207
- }
208
-
209
- public createCollection(name: string, options?: mongodb.CreateCollectionOptions): Promise<mongodb.Collection<mongodb.BSON.Document>> {
210
- return this.db.createCollection(name, options);
211
- }
212
-
213
- public logRuntimeCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string): mongodb.Collection<TSchema> {
214
- return this.logCollection<TSchema>(CloudScriptDatabase.RUNTIME + collectionName);
215
- }
216
-
217
- public logMetaCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string): mongodb.Collection<TSchema> {
218
- return this.logCollection<TSchema>(CloudScriptDatabase.META + collectionName);
219
- }
220
-
221
- public logSystemCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string): mongodb.Collection<TSchema> {
222
- return this.logCollection<TSchema>(CloudScriptDatabase.SYSTEM + collectionName);
223
- }
224
-
225
- public logRuntimeGameCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string, gameId: string): mongodb.Collection<TSchema> {
226
- return this.logCollection<TSchema>(CloudScriptDatabase.RUNTIME + gameId + CloudScriptDatabase.DOT + collectionName);
227
- }
228
-
229
- public logMetaGameCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string, gameId: string): mongodb.Collection<TSchema> {
230
- return this.logCollection<TSchema>(CloudScriptDatabase.META + gameId + CloudScriptDatabase.DOT + collectionName);
231
- }
232
-
233
- public logSystemGameCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string, gameId: string): mongodb.Collection<TSchema> {
234
- return this.logCollection<TSchema>(CloudScriptDatabase.SYSTEM + gameId + CloudScriptDatabase.DOT + collectionName);
235
- }
236
-
237
- public logCollection<TSchema extends mongodb.Document = mongodb.Document>(fullCollectionName: string): mongodb.Collection<TSchema> {
238
- return this.logDb.collection<TSchema>(fullCollectionName);
239
- }
240
-
241
- public logCreateCollection<TSchema extends mongodb.Document = mongodb.Document>(collectionName: string, options?: mongodb.CreateCollectionOptions) {
242
- return this.logDb.createCollection<TSchema>(collectionName, options)
243
- }
244
- }
245
-
246
- class CloudScriptHttp {
247
- public async get<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R> {
248
- return await axios.default.get<T, R, D>(url, config);
249
- }
250
-
251
- public async delete<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R> {
252
- return await axios.default.delete<T, R, D>(url, config);
253
- }
254
-
255
- public async head<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R> {
256
- return await axios.default.head<T, R, D>(url, config);
257
- }
258
-
259
- public async options<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, config?: axios.AxiosRequestConfig<D>): Promise<R> {
260
- return await axios.default.options<T, R, D>(url, config);
261
- }
262
-
263
- public async post<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: any, config?: axios.AxiosRequestConfig<D>): Promise<R> {
264
- return await axios.default.post<T, R, D>(url, data, config);
265
- }
266
-
267
- public async put<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: any, config?: axios.AxiosRequestConfig<D>): Promise<R> {
268
- return await axios.default.put<T, R, D>(url, data, config);
269
- }
270
-
271
- public async patch<T = any, R = axios.AxiosResponse<T>, D = any>(url: string, data?: any, config?: axios.AxiosRequestConfig<D>): Promise<R> {
272
- return await axios.default.patch<T, R, D>(url, data, config);
273
- }
274
- }
275
-
276
- class CloudScriptSocket {
277
- public async sendEventTo(userId: string, operationEvent: OperationEvent): Promise<void> {
278
- return await this.sendEvent({
279
- eventType: CloudScriptEventType.SendToUser,
280
- receiver: userId,
281
- operationEvent: {
282
- eventCode: operationEvent.getEventCode(),
283
- parameters: operationEvent.getParameters()?.toData() ?? null,
284
- }
285
- });
286
- }
287
-
288
- public async sendEventToMoreUser(userIds: string[], operationEvent: OperationEvent): Promise<void> {
289
- return await this.sendEvent({
290
- eventType: CloudScriptEventType.SendToMore,
291
- receiver: userIds,
292
- operationEvent: {
293
- eventCode: operationEvent.getEventCode(),
294
- parameters: operationEvent.getParameters()?.toData() ?? null,
295
- }
296
- });
297
- }
298
-
299
- public async sendEventToAllPlayer(operationEvent: OperationEvent): Promise<void> {
300
- return await this.sendEvent({
301
- eventType: CloudScriptEventType.SendToAll,
302
- receiver: null,
303
- operationEvent: {
304
- eventCode: operationEvent.getEventCode(),
305
- parameters: operationEvent.getParameters()?.toData() ?? null,
306
- }
307
- });
308
- }
309
-
310
- private async sendEvent(event: CloudScriptEvent) {
311
- if (process?.send)
312
- process.send(event);
313
- }
314
- }
315
-
316
- class CloudScriptMail {
317
- public async send(email: string, subject: string, contentHtml: string) {
318
- if (process?.send)
319
- process.send({
320
- eventType: 20,
321
- receiver: null,
322
- operationEvent: {
323
- eventCode: 0,
324
- parameters: {
325
- email: email,
326
- subject: subject,
327
- contentHtml: contentHtml,
328
- },
329
- },
330
- });
331
- }
332
-
333
- public async sendToMore(emails: string[], subject: string, contentHtml: string) {
334
- if (process?.send)
335
- process.send({
336
- eventType: 21,
337
- receiver: null,
338
- operationEvent: {
339
- eventCode: 0,
340
- parameters: {
341
- emails: emails,
342
- subject: subject,
343
- contentHtml: contentHtml,
344
- },
345
- },
346
- });
347
- }
348
- }
349
-
350
- class CloudScriptPushNotification {
351
- public async send(token: string, title: string, body: string, badge?: number, sound?: string, icon?: string, data?: { [k: string]: any }) {
352
- if (process?.send)
353
- process.send({
354
- eventType: 30,
355
- receiver: null,
356
- operationEvent: {
357
- eventCode: 0,
358
- parameters: {
359
- token: token,
360
- title: title,
361
- body: body,
362
- badge: badge,
363
- sound: sound,
364
- icon: icon,
365
- data: data,
366
- },
367
- },
368
- });
369
- }
370
-
371
- public async sendToMore(tokens: string[], title: string, body: string, badge?: number, sound?: string, icon?: string, data?: { [k: string]: any }) {
372
- if (process?.send)
373
- process.send({
374
- eventType: 31,
375
- receiver: null,
376
- operationEvent: {
377
- eventCode: 0,
378
- parameters: {
379
- tokens: tokens,
380
- title: title,
381
- body: body,
382
- badge: badge,
383
- sound: sound,
384
- icon: icon,
385
- data: data,
386
- },
387
- },
388
- });
389
- }
390
-
391
- public async sendToTopic(topic: string, title: string, body: string, badge?: number, sound?: string, icon?: string, data?: { [k: string]: any }) {
392
- if (process?.send)
393
- process.send({
394
- eventType: 32,
395
- receiver: null,
396
- operationEvent: {
397
- eventCode: 0,
398
- parameters: {
399
- topic: topic,
400
- title: title,
401
- body: body,
402
- badge: badge,
403
- sound: sound,
404
- icon: icon,
405
- data: data,
406
- },
407
- },
408
- });
409
- }
410
-
411
- public async subscribeToTopic(tokens: string[], topic: string) {
412
- if (process?.send)
413
- process.send({
414
- eventType: 33,
415
- receiver: null,
416
- operationEvent: {
417
- eventCode: 0,
418
- parameters: {
419
- tokens: tokens,
420
- topic: topic,
421
- },
422
- },
423
- });
424
- }
425
-
426
- public async unsubscribeFromTopic(tokens: string[], topic: string) {
427
- if (process?.send)
428
- process.send({
429
- eventType: 34,
430
- receiver: null,
431
- operationEvent: {
432
- eventCode: 0,
433
- parameters: {
434
- tokens: tokens,
435
- topic: topic,
436
- },
437
- },
438
- });
439
- }
440
- }
77
+ import { CloudScriptAdmin } from "./CloudScriptAdmin";
78
+ import { CloudScriptDatabase } from "./CloudScriptDatabase";
79
+ import { CloudScriptHttp } from "./CloudScriptHttp";
80
+ import { CloudScriptSocket } from "./CloudScriptSocket";
81
+ import { CloudScriptMail } from "./CloudScriptMail";
82
+ import { CloudScriptPushNotification } from "./CloudScriptPushNotification";
441
83
 
442
84
  interface CloudScriptRequest {
443
85
  requestId: string;
444
86
  userId: string;
445
87
  name: string;
446
- parameters: object;
88
+ parameters: any;
447
89
  customTags: { [k: string]: any };
90
+ context: { [k: string]: any };
448
91
  }
449
92
 
450
93
  interface CloudScriptResponse {
@@ -452,17 +95,17 @@ interface CloudScriptResponse {
452
95
  memoryUsedInBytes: number;
453
96
  executeTimeInMs: number;
454
97
  };
455
- response: FunctionResponse;
456
98
  responseId: string;
99
+ response: FunctionResponse;
457
100
  logs: string[];
458
101
  }
459
102
 
460
103
  interface FunctionRequest {
461
- userId: string;
462
- name: string;
463
- parameters: any;
464
- customTags: { [k: string]: any };
465
- context: {};
104
+ args: any,
105
+ context: {
106
+ userId: string,
107
+ customTags: { [k: string]: any };
108
+ },
466
109
  log: (log: any) => void;
467
110
  }
468
111
 
@@ -475,7 +118,7 @@ enum ExecuteResponseStatus {
475
118
  interface FunctionResponse {
476
119
  status: ExecuteResponseStatus;
477
120
  result: any;
478
- errorMessage: any;
121
+ errorMessage: string;
479
122
  }
480
123
 
481
124
  const ConvertObject = (result: any) => {
@@ -536,17 +179,14 @@ process?.on("message", async (request: CloudScriptRequest) => {
536
179
 
537
180
  let logs: string[] = [];
538
181
  let functionRequest: FunctionRequest = {
539
- userId: request.userId,
540
- name: request.name,
541
- parameters: request.parameters,
542
- context: {},
543
- customTags: request.customTags,
182
+ args: request.parameters,
183
+ context: { ...request.context, userId: request.userId, customTags: request.customTags },
544
184
  log(log: any) {
545
185
  logs.push(JSON.stringify(log));
546
186
  },
547
187
  };
548
188
 
549
- let handleResponse = await ___handleFunction(functionRequest);
189
+ let handleResponse = await ___handleCloudScriptFunction(request.name, functionRequest);
550
190
 
551
191
  if (handleResponse.result) {
552
192
  if (handleResponse.result instanceof GNHashtable) {
@@ -609,25 +249,25 @@ process?.on("message", async (request: CloudScriptRequest) => {
609
249
  process.send(response);
610
250
  });
611
251
 
612
- async function ___handleFunction(request: FunctionRequest): Promise<FunctionResponse> {
613
- let handler = handlers[request.name];
252
+ async function ___handleCloudScriptFunction(name: string, request: FunctionRequest): Promise<FunctionResponse> {
253
+ let handler = handlers[name];
614
254
 
615
255
  if (handler == null) {
616
256
  return {
617
257
  status: ExecuteResponseStatus.FunctionNameNotFound,
618
258
  result: null,
619
- errorMessage: null,
259
+ errorMessage: null as any,
620
260
  };
621
261
  }
622
262
 
623
263
  let answer: FunctionResponse = {
624
264
  status: ExecuteResponseStatus.Ok,
625
- errorMessage: null,
265
+ errorMessage: null as any,
626
266
  result: null,
627
267
  };
628
268
 
629
269
  try {
630
- answer.result = await handler(request.parameters, { userId: request.userId, customTags: request.customTags }, request.log);
270
+ answer.result = await handler(request.args, request.context, request.log);
631
271
  } catch (err: any) {
632
272
  answer.status = ExecuteResponseStatus.Exception;
633
273
  answer.errorMessage = err.message;
@@ -660,6 +300,7 @@ const pushNotification = new CloudScriptPushNotification();
660
300
  database.init(dbConnection.url, dbConnection.dbName, dbConnection.logUrl, dbConnection.logDbName, dbConnection.options);
661
301
  }
662
302
 
303
+ // release for the security
663
304
  process.env.dbConnection = "";
664
305
  process.env.gnServerSettingsOptions = "";
665
306