jp.ms.common.modules 1.0.41 → 1.0.43

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 (234) hide show
  1. package/dist/dto/app-table/card.dto.d.ts +1 -0
  2. package/dist/dto/app-table/card.dto.js +11 -0
  3. package/dist/dto/app-table/card.dto.js.map +1 -1
  4. package/dist/dto/app-table/player.dto.d.ts +1 -0
  5. package/dist/dto/app-table/player.dto.js +11 -0
  6. package/dist/dto/app-table/player.dto.js.map +1 -1
  7. package/dist/dto/games/fool/fool-table.dto.d.ts +1 -0
  8. package/dist/dto/games/fool/fool-table.dto.js +10 -0
  9. package/dist/dto/games/fool/fool-table.dto.js.map +1 -1
  10. package/dist/modules/anti-freeze-system/anti-freeze-system.module.d.ts +3 -1
  11. package/dist/modules/anti-freeze-system/anti-freeze-system.module.js +8 -4
  12. package/dist/modules/anti-freeze-system/anti-freeze-system.module.js.map +1 -1
  13. package/dist/modules/anti-freeze-system/anti-freeze-system.service.d.ts +6 -2
  14. package/dist/modules/anti-freeze-system/anti-freeze-system.service.js +37 -10
  15. package/dist/modules/anti-freeze-system/anti-freeze-system.service.js.map +1 -1
  16. package/dist/modules/base-achievements/base-achievements.module.js +2 -2
  17. package/dist/modules/base-achievements/base-achievements.module.js.map +1 -1
  18. package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.d.ts +1 -0
  19. package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.js +5 -0
  20. package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.js.map +1 -0
  21. package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.d.ts +13 -0
  22. package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.js +3 -0
  23. package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.js.map +1 -0
  24. package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.d.ts +15 -0
  25. package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.js +77 -0
  26. package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.js.map +1 -0
  27. package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.d.ts +19 -0
  28. package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.js +83 -0
  29. package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.js.map +1 -0
  30. package/dist/modules/event-bus/events-bus.module.js +3 -0
  31. package/dist/modules/event-bus/events-bus.module.js.map +1 -1
  32. package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.d.ts +10 -0
  33. package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.js +26 -0
  34. package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.js.map +1 -0
  35. package/dist/modules/event-bus/index.d.ts +1 -0
  36. package/dist/modules/event-bus/index.js +3 -1
  37. package/dist/modules/event-bus/index.js.map +1 -1
  38. package/dist/modules/events/events.gateway.d.ts +6 -1
  39. package/dist/modules/events/events.gateway.js +19 -5
  40. package/dist/modules/events/events.gateway.js.map +1 -1
  41. package/dist/modules/index.d.ts +1 -0
  42. package/dist/modules/index.js +3 -1
  43. package/dist/modules/index.js.map +1 -1
  44. package/dist/modules/main/main.controller.d.ts +0 -1
  45. package/dist/modules/main/main.controller.js +0 -12
  46. package/dist/modules/main/main.controller.js.map +1 -1
  47. package/dist/modules/main/main.module.js +1 -1
  48. package/dist/modules/main/main.module.js.map +1 -1
  49. package/dist/modules/main/main.service.d.ts +0 -1
  50. package/dist/modules/main/main.service.js +0 -13
  51. package/dist/modules/main/main.service.js.map +1 -1
  52. package/dist/modules/many-tables-tournament/many-tables-tournament.controller.d.ts +1 -0
  53. package/dist/modules/many-tables-tournament/many-tables-tournament.controller.js +12 -0
  54. package/dist/modules/many-tables-tournament/many-tables-tournament.controller.js.map +1 -1
  55. package/dist/modules/many-tables-tournament/many-tables-tournament.module.js +7 -2
  56. package/dist/modules/many-tables-tournament/many-tables-tournament.module.js.map +1 -1
  57. package/dist/modules/many-tables-tournament/many-tables-tournament.service.d.ts +4 -1
  58. package/dist/modules/many-tables-tournament/many-tables-tournament.service.js +18 -2
  59. package/dist/modules/many-tables-tournament/many-tables-tournament.service.js.map +1 -1
  60. package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.module.js +2 -0
  61. package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.module.js.map +1 -1
  62. package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.d.ts +3 -2
  63. package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.js +9 -6
  64. package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.js.map +1 -1
  65. package/dist/modules/menu/menu-screen.view.d.ts +2 -1
  66. package/dist/modules/menu/menu-screen.view.js +9 -3
  67. package/dist/modules/menu/menu-screen.view.js.map +1 -1
  68. package/dist/modules/menu/menu.interfaces.d.ts +1 -0
  69. package/dist/modules/menu/menu.service.js +1 -1
  70. package/dist/modules/menu/menu.service.js.map +1 -1
  71. package/dist/modules/one-table-tournament/one-table-tournament.module.js +1 -1
  72. package/dist/modules/one-table-tournament/one-table-tournament.module.js.map +1 -1
  73. package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.module.js +2 -0
  74. package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.module.js.map +1 -1
  75. package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.d.ts +3 -2
  76. package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.js +9 -6
  77. package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.js.map +1 -1
  78. package/dist/modules/simple-rooms-manager/simple-rooms-manager.module.js +2 -0
  79. package/dist/modules/simple-rooms-manager/simple-rooms-manager.module.js.map +1 -1
  80. package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.d.ts +3 -2
  81. package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.js +8 -5
  82. package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.js.map +1 -1
  83. package/dist/tsconfig.tsbuildinfo +1 -1
  84. package/dist/utils/game-table-result.d.ts +4 -3
  85. package/dist/utils/game-table-result.js +54 -4
  86. package/dist/utils/game-table-result.js.map +1 -1
  87. package/package.json +57 -57
  88. package/src/dto/app-screen/app-screen-app-bar.dto.ts +36 -36
  89. package/src/dto/app-screen/app-screen-dialog.dto.ts +64 -64
  90. package/src/dto/app-screen/app-screen-field-list-item.dto.ts +42 -42
  91. package/src/dto/app-screen/app-screen-field.dto.ts +59 -59
  92. package/src/dto/app-screen/app-screen-section-button.dto.ts +60 -60
  93. package/src/dto/app-screen/app-screen-section-buttons.dto.ts +14 -14
  94. package/src/dto/app-screen/app-screen-section-image.dto.ts +33 -33
  95. package/src/dto/app-screen/app-screen-section-list-item.dto.ts +105 -105
  96. package/src/dto/app-screen/app-screen-section-req.dto.ts +33 -33
  97. package/src/dto/app-screen/app-screen-section.dto.ts +76 -76
  98. package/src/dto/app-screen/app-screen.dto.ts +50 -50
  99. package/src/dto/app-screen/base-app-screen.dto.ts +16 -16
  100. package/src/dto/app-screen/index.ts +10 -10
  101. package/src/dto/app-table/bids-panel-item.dto.ts +33 -33
  102. package/src/dto/app-table/bids-panel.dto.ts +32 -32
  103. package/src/dto/app-table/card.dto.ts +63 -54
  104. package/src/dto/app-table/cards-deck.dto.ts +22 -22
  105. package/src/dto/app-table/cards-pair-slots-item.dto.ts +45 -45
  106. package/src/dto/app-table/cards-pair-slots.dto.ts +13 -13
  107. package/src/dto/app-table/cards-panel.dto.ts +48 -48
  108. package/src/dto/app-table/cards-player.dto.ts +14 -14
  109. package/src/dto/app-table/cards-slots-item.dto.ts +40 -40
  110. package/src/dto/app-table/cards-slots.dto.ts +13 -13
  111. package/src/dto/app-table/index.ts +15 -15
  112. package/src/dto/app-table/moves-panel-button.dto.ts +24 -24
  113. package/src/dto/app-table/moves-panel.dto.ts +23 -23
  114. package/src/dto/app-table/player.dto.ts +78 -69
  115. package/src/dto/app-table/summary-item.dto.ts +51 -51
  116. package/src/dto/app-table/summary.dto.ts +13 -13
  117. package/src/dto/common/find-free-table.dto.ts +3 -3
  118. package/src/dto/common/index.ts +2 -2
  119. package/src/dto/common/join-tournament.dto.ts +33 -33
  120. package/src/dto/common/log.dto.ts +9 -9
  121. package/src/dto/common/many-tables-tournament-create.dto.ts +125 -125
  122. package/src/dto/common/many-tables-tournament-update.dto.ts +3 -3
  123. package/src/dto/common/player-check-state.dto.ts +33 -33
  124. package/src/dto/common/player-connected.dto.ts +58 -58
  125. package/src/dto/games/fool/fool-player.dto.ts +3 -3
  126. package/src/dto/games/fool/fool-table.dto.ts +89 -81
  127. package/src/dto/games/index.ts +2 -2
  128. package/src/dto/games/poker/poker-player.dto.ts +3 -3
  129. package/src/dto/games/poker/poker-table.dto.ts +81 -81
  130. package/src/dto/index.ts +4 -4
  131. package/src/exception/error-code.enum.ts +4 -4
  132. package/src/exception/global-exception-filter.ts +53 -53
  133. package/src/exception/http-exception-wth-snackbar.ts +27 -27
  134. package/src/exception/index.ts +4 -4
  135. package/src/exception/not-enough-money-for-purchase.exception.ts +14 -14
  136. package/src/exception/not-found-free-room-for-fast-game.exception.ts +14 -14
  137. package/src/index.ts +4 -4
  138. package/src/modules/anti-freeze-system/anti-freeze-system.constants.ts +1 -1
  139. package/src/modules/anti-freeze-system/anti-freeze-system.interfaces.ts +20 -20
  140. package/src/modules/anti-freeze-system/anti-freeze-system.module.ts +59 -55
  141. package/src/modules/anti-freeze-system/anti-freeze-system.service.ts +136 -105
  142. package/src/modules/anti-freeze-system/index.ts +1 -1
  143. package/src/modules/base-achievements/base-achievements.module.ts +324 -322
  144. package/src/modules/base-achievements/index.ts +1 -1
  145. package/src/modules/confirmation-message-manager/confirmation-message-manager.constants.ts +3 -0
  146. package/src/modules/confirmation-message-manager/confirmation-message-manager.interfaces.ts +20 -0
  147. package/src/modules/confirmation-message-manager/confirmation-message-manager.module.ts +77 -0
  148. package/src/modules/confirmation-message-manager/confirmation-message-manager.service.ts +91 -0
  149. package/src/modules/event-bus/events-bus.app.subscribe.service.ts +20 -20
  150. package/src/modules/event-bus/events-bus.main-tables.subscribe.service.ts +34 -34
  151. package/src/modules/event-bus/events-bus.many-tables-tournament.subscribe.service.ts +6 -6
  152. package/src/modules/event-bus/events-bus.module.ts +26 -23
  153. package/src/modules/event-bus/events-bus.one-table-tournament.subscribe.service.ts +6 -6
  154. package/src/modules/event-bus/events-bus.player-ws-message.subscribe.service.ts +30 -0
  155. package/src/modules/event-bus/events-bus.tournament.subscribe.service.ts +18 -18
  156. package/src/modules/event-bus/index.ts +6 -5
  157. package/src/modules/events/events.constants.ts +1 -1
  158. package/src/modules/events/events.gateway.ts +84 -70
  159. package/src/modules/events/events.interfaces.ts +17 -17
  160. package/src/modules/events/events.module.ts +32 -32
  161. package/src/modules/events/index.ts +1 -1
  162. package/src/modules/index.ts +28 -27
  163. package/src/modules/logger/index.ts +2 -2
  164. package/src/modules/logger/jp-logger.module.ts +10 -10
  165. package/src/modules/logger/jp-logger.service.ts +38 -38
  166. package/src/modules/main/index.ts +1 -1
  167. package/src/modules/main/main-tables-list-screen.view.ts +275 -275
  168. package/src/modules/main/main.constants.ts +1 -1
  169. package/src/modules/main/main.controller.ts +51 -72
  170. package/src/modules/main/main.interfaces.ts +17 -17
  171. package/src/modules/main/main.module.ts +73 -73
  172. package/src/modules/main/main.service.ts +154 -183
  173. package/src/modules/many-tables-tournament/index.ts +1 -1
  174. package/src/modules/many-tables-tournament/many-tables-tournament-status-screen.view.ts +143 -143
  175. package/src/modules/many-tables-tournament/many-tables-tournament-tables-list-screen.view.ts +63 -63
  176. package/src/modules/many-tables-tournament/many-tables-tournament.constants.ts +3 -3
  177. package/src/modules/many-tables-tournament/many-tables-tournament.controller.ts +164 -151
  178. package/src/modules/many-tables-tournament/many-tables-tournament.interfaces.ts +20 -20
  179. package/src/modules/many-tables-tournament/many-tables-tournament.module.ts +89 -80
  180. package/src/modules/many-tables-tournament/many-tables-tournament.service.ts +241 -208
  181. package/src/modules/many-tables-tournament-rooms-manager/index.ts +2 -2
  182. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.constants.ts +3 -3
  183. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.interfaces.ts +37 -37
  184. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.module.ts +89 -84
  185. package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.ts +333 -331
  186. package/src/modules/menu/index.ts +1 -1
  187. package/src/modules/menu/menu-screen.view.ts +78 -71
  188. package/src/modules/menu/menu.constants.ts +1 -1
  189. package/src/modules/menu/menu.controller.ts +16 -16
  190. package/src/modules/menu/menu.interfaces.ts +18 -17
  191. package/src/modules/menu/menu.module.ts +39 -39
  192. package/src/modules/menu/menu.service.ts +40 -39
  193. package/src/modules/one-table-tournament/index.ts +1 -1
  194. package/src/modules/one-table-tournament/one-table-tournament-status-screen.view.ts +166 -166
  195. package/src/modules/one-table-tournament/one-table-tournament.constants.ts +3 -3
  196. package/src/modules/one-table-tournament/one-table-tournament.controller.ts +104 -104
  197. package/src/modules/one-table-tournament/one-table-tournament.interfaces.ts +20 -20
  198. package/src/modules/one-table-tournament/one-table-tournament.module.ts +80 -76
  199. package/src/modules/one-table-tournament/one-table-tournament.service.ts +146 -146
  200. package/src/modules/one-table-tournament-rooms-manager/index.ts +2 -2
  201. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.constants.ts +3 -3
  202. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.interfaces.ts +31 -31
  203. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.module.ts +71 -66
  204. package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.ts +222 -220
  205. package/src/modules/players-manager/index.ts +2 -2
  206. package/src/modules/players-manager/players-manager.module.ts +9 -9
  207. package/src/modules/players-manager/players-manager.service.ts +27 -27
  208. package/src/modules/simple-rooms/index.ts +1 -1
  209. package/src/modules/simple-rooms/simple-rooms.constants.ts +1 -1
  210. package/src/modules/simple-rooms/simple-rooms.controller.ts +63 -63
  211. package/src/modules/simple-rooms/simple-rooms.interfaces.ts +20 -20
  212. package/src/modules/simple-rooms/simple-rooms.module.ts +39 -39
  213. package/src/modules/simple-rooms/simple-rooms.service.ts +95 -95
  214. package/src/modules/simple-rooms-manager/index.ts +2 -2
  215. package/src/modules/simple-rooms-manager/simple-rooms-manager.constants.ts +3 -3
  216. package/src/modules/simple-rooms-manager/simple-rooms-manager.interfaces.ts +26 -26
  217. package/src/modules/simple-rooms-manager/simple-rooms-manager.module.ts +65 -60
  218. package/src/modules/simple-rooms-manager/simple-rooms-manager.service.ts +192 -190
  219. package/src/modules/support/dump.service.ts +11 -11
  220. package/src/modules/support/index.ts +1 -1
  221. package/src/modules/support/metric.service.ts +41 -41
  222. package/src/modules/support/support.constants.ts +1 -1
  223. package/src/modules/support/support.controller.ts +79 -79
  224. package/src/modules/support/support.interfaces.ts +16 -16
  225. package/src/modules/support/support.module.ts +35 -35
  226. package/src/modules/support/support.service.ts +27 -27
  227. package/src/utils/date.ts +7 -7
  228. package/src/utils/game-table-result.ts +190 -129
  229. package/src/views/index.ts +5 -5
  230. package/src/views/many-tables-tournament-conifrm-exit-dialog.view.ts +37 -37
  231. package/src/views/one-table-tournament-conifrm-exit-dialog.view.ts +37 -37
  232. package/src/views/simple-room-conifrm-exit-dialog.view.ts +37 -37
  233. package/src/views/table-summary.view.ts +104 -104
  234. package/src/views/tournament-buy-ticket-dialog.view.ts +34 -34
@@ -0,0 +1,20 @@
1
+ import { ModuleMetadata } from '@nestjs/common';
2
+ import { Type } from '@nestjs/common/interfaces/type.interface';
3
+ import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
4
+ import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
5
+
6
+ export interface ConfirmationMessageManagerOptions extends Pick<
7
+ ModuleMetadata,
8
+ 'imports'
9
+ > {
10
+ imports?: Array<
11
+ Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
12
+ >;
13
+ inject?: any[];
14
+ useFactory?: (...args: any[]) => ConfirmationMessageManagerFactoryOptions;
15
+ }
16
+
17
+ export interface ConfirmationMessageManagerFactoryOptions {
18
+ confirmationMessageManagerTime: string;
19
+ confirmationMessageManagerAttemptCount: number;
20
+ }
@@ -0,0 +1,77 @@
1
+ import {
2
+ DynamicModule,
3
+ Global,
4
+ Inject,
5
+ Module,
6
+ Provider,
7
+ } from '@nestjs/common';
8
+ import schedule, { Job } from 'node-schedule';
9
+ import { BaseWsEvent } from 'jp.ms.common.engine';
10
+
11
+ import { JpLoggerService } from '../logger';
12
+ import { EventsBusPlayerWsMessageSubscribeService } from '../event-bus';
13
+
14
+ import { ConfirmationMessageManagerService } from './confirmation-message-manager.service';
15
+ import {
16
+ ConfirmationMessageManagerFactoryOptions,
17
+ ConfirmationMessageManagerOptions,
18
+ } from './confirmation-message-manager.interfaces';
19
+ import { CONFIRMATION_MESSAGE_MANAGER_OPTIONS } from './confirmation-message-manager.constants';
20
+
21
+ @Global()
22
+ @Module({
23
+ providers: [ConfirmationMessageManagerService],
24
+ exports: [ConfirmationMessageManagerService],
25
+ })
26
+ export class ConfirmationMessageManagerModule {
27
+ private confirmationMessageManagerJob: Job;
28
+
29
+ constructor(
30
+ private readonly confirmationMessageManagerService: ConfirmationMessageManagerService,
31
+ private readonly eventsBusPlayerWsMessageSubscribeService: EventsBusPlayerWsMessageSubscribeService,
32
+ @Inject(CONFIRMATION_MESSAGE_MANAGER_OPTIONS)
33
+ private readonly options: ConfirmationMessageManagerFactoryOptions,
34
+ @Inject() private readonly logger: JpLoggerService,
35
+ ) {}
36
+
37
+ static forRootAsync(
38
+ options: ConfirmationMessageManagerOptions,
39
+ ): DynamicModule {
40
+ return {
41
+ module: ConfirmationMessageManagerModule,
42
+ imports: options.imports ?? [],
43
+ providers: [
44
+ {
45
+ provide: CONFIRMATION_MESSAGE_MANAGER_OPTIONS,
46
+ useFactory: options.useFactory,
47
+ inject: options.inject || [],
48
+ } as Provider,
49
+ ],
50
+ };
51
+ }
52
+
53
+ onModuleInit() {
54
+ this.eventsBusPlayerWsMessageSubscribeService.subscribeOnSendMessage(
55
+ (wsEvent: BaseWsEvent) => {
56
+ this.confirmationMessageManagerService.addToQueue(wsEvent);
57
+ },
58
+ );
59
+
60
+ this.eventsBusPlayerWsMessageSubscribeService.subscribeOnGotMessageFromClient(
61
+ (wsEvent: BaseWsEvent) => {
62
+ this.confirmationMessageManagerService.removeFromQueue(wsEvent.key);
63
+ },
64
+ );
65
+
66
+ const confirmationMessageManagerTime =
67
+ this.options.confirmationMessageManagerTime;
68
+
69
+ if (confirmationMessageManagerTime) {
70
+ this.logger.log(`${ConfirmationMessageManagerModule.name}: scheduleJob`);
71
+ this.confirmationMessageManagerJob = schedule.scheduleJob(
72
+ confirmationMessageManagerTime,
73
+ () => this.confirmationMessageManagerService.process(),
74
+ );
75
+ }
76
+ }
77
+ }
@@ -0,0 +1,91 @@
1
+ import { Inject, Injectable } from '@nestjs/common';
2
+ import { BaseWsEvent } from 'jp.ms.common.engine';
3
+
4
+ import { PlayersManagerService } from '../players-manager';
5
+ import { JpLoggerService } from '../logger';
6
+
7
+ import { CONFIRMATION_MESSAGE_MANAGER_OPTIONS } from './confirmation-message-manager.constants';
8
+ import { ConfirmationMessageManagerFactoryOptions } from './confirmation-message-manager.interfaces';
9
+
10
+ interface IGameMessageConfirmationManagerMessage {
11
+ event: BaseWsEvent;
12
+ repeatCount: number;
13
+ }
14
+
15
+ @Injectable()
16
+ export class ConfirmationMessageManagerService {
17
+ private queue: Map<string, IGameMessageConfirmationManagerMessage>;
18
+ private jobId: NodeJS.Timeout | null = null;
19
+
20
+ constructor(
21
+ private readonly playersManagerService: PlayersManagerService,
22
+ @Inject(CONFIRMATION_MESSAGE_MANAGER_OPTIONS)
23
+ private readonly options: ConfirmationMessageManagerFactoryOptions,
24
+ @Inject() private readonly logger: JpLoggerService,
25
+ ) {
26
+ this.queue = new Map<string, IGameMessageConfirmationManagerMessage>();
27
+ }
28
+
29
+ getByKey(key: string) {
30
+ this.queue.get(key);
31
+ }
32
+
33
+ addToQueue(message: BaseWsEvent): void {
34
+ this.logger.log(
35
+ `${ConfirmationMessageManagerService.name}: add to queue ws message key: ${message.key}, type: ${message.type}`,
36
+ );
37
+
38
+ const foundMessage = this.queue.get(message.key);
39
+
40
+ if (foundMessage) {
41
+ foundMessage.repeatCount += 1;
42
+ } else {
43
+ this.queue.set(message.key, {
44
+ event: message,
45
+ repeatCount: 0,
46
+ });
47
+ }
48
+ }
49
+
50
+ removeFromQueue(key: string): void {
51
+ this.logger.log(
52
+ `${ConfirmationMessageManagerService.name}: remove from queue ws message key: ${key}`,
53
+ );
54
+
55
+ this.queue.delete(key);
56
+ }
57
+
58
+ process() {
59
+ this.clearQueue();
60
+ this.repeatSendingMessages();
61
+ }
62
+
63
+ private isExpired(message: IGameMessageConfirmationManagerMessage): boolean {
64
+ return (
65
+ message.repeatCount >= this.options.confirmationMessageManagerAttemptCount
66
+ );
67
+ }
68
+
69
+ private clearQueue(): void {
70
+ for (const [key, message] of this.queue) {
71
+ if (this.isExpired(message)) {
72
+ this.logger.log(
73
+ `${ConfirmationMessageManagerService.name}: clear expired ws message key: ${message.event.key}, type: ${message.event.type}`,
74
+ );
75
+ this.queue.delete(key);
76
+ }
77
+ }
78
+ }
79
+
80
+ private repeatSendingMessages(): void {
81
+ for (const [, message] of this.queue) {
82
+ const foundPlayer = this.playersManagerService.getPlayerById(
83
+ message.event.playerId,
84
+ );
85
+ this.logger.log(
86
+ `${ConfirmationMessageManagerService.name}: repeat ws message key: ${message.event.key}, type: ${message.event.type}, repeatCount: ${message.repeatCount}`,
87
+ );
88
+ foundPlayer?.sendMessage(message.event);
89
+ }
90
+ }
91
+ }
@@ -1,20 +1,20 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { BaseAppEvent } from 'jp.ms.common.engine';
3
- import { Subject } from 'rxjs';
4
-
5
- @Injectable()
6
- export class EventsBusAppSubscribeService {
7
- private readonly appEventSubject: Subject<BaseAppEvent>;
8
-
9
- constructor() {
10
- this.appEventSubject = new Subject<BaseAppEvent>();
11
- }
12
-
13
- pushNewEvent(event: BaseAppEvent) {
14
- this.appEventSubject.next(event);
15
- }
16
-
17
- subscribe(onHandleAppEvent: (event: BaseAppEvent) => void) {
18
- this.appEventSubject.subscribe(onHandleAppEvent);
19
- }
20
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { BaseAppEvent } from 'jp.ms.common.engine';
3
+ import { Subject } from 'rxjs';
4
+
5
+ @Injectable()
6
+ export class EventsBusAppSubscribeService {
7
+ private readonly appEventSubject: Subject<BaseAppEvent>;
8
+
9
+ constructor() {
10
+ this.appEventSubject = new Subject<BaseAppEvent>();
11
+ }
12
+
13
+ pushNewEvent(event: BaseAppEvent) {
14
+ this.appEventSubject.next(event);
15
+ }
16
+
17
+ subscribe(onHandleAppEvent: (event: BaseAppEvent) => void) {
18
+ this.appEventSubject.subscribe(onHandleAppEvent);
19
+ }
20
+ }
@@ -1,34 +1,34 @@
1
- import { Injectable } from '@nestjs/common';
2
- import { GamePlayer, RoomUpdateStateEvent } from 'jp.ms.common.engine';
3
- import { Subject } from 'rxjs';
4
-
5
- @Injectable()
6
- export class EventsBusMainTablesSubscribeService {
7
- private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
8
- private readonly tablesSubscribers: Map<string, GamePlayer>;
9
-
10
- constructor() {
11
- this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
12
- this.tablesSubscribers = new Map();
13
- }
14
-
15
- getTablesSubscribers() {
16
- return Array.from(this.tablesSubscribers.values());
17
- }
18
-
19
- addTablesSubscriber(player: GamePlayer) {
20
- this.tablesSubscribers.set(player.id, player);
21
- }
22
-
23
- removeTablesSubbcriber(player: GamePlayer) {
24
- this.tablesSubscribers.delete(player.id);
25
- }
26
-
27
- pushNewRoomState(event: RoomUpdateStateEvent) {
28
- this.roomStatesSubject.next(event);
29
- }
30
-
31
- subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
32
- this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
33
- }
34
- }
1
+ import { Injectable } from '@nestjs/common';
2
+ import { GamePlayer, RoomUpdateStateEvent } from 'jp.ms.common.engine';
3
+ import { Subject } from 'rxjs';
4
+
5
+ @Injectable()
6
+ export class EventsBusMainTablesSubscribeService {
7
+ private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
8
+ private readonly tablesSubscribers: Map<string, GamePlayer>;
9
+
10
+ constructor() {
11
+ this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
12
+ this.tablesSubscribers = new Map();
13
+ }
14
+
15
+ getTablesSubscribers() {
16
+ return Array.from(this.tablesSubscribers.values());
17
+ }
18
+
19
+ addTablesSubscriber(player: GamePlayer) {
20
+ this.tablesSubscribers.set(player.id, player);
21
+ }
22
+
23
+ removeTablesSubbcriber(player: GamePlayer) {
24
+ this.tablesSubscribers.delete(player.id);
25
+ }
26
+
27
+ pushNewRoomState(event: RoomUpdateStateEvent) {
28
+ this.roomStatesSubject.next(event);
29
+ }
30
+
31
+ subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
32
+ this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
33
+ }
34
+ }
@@ -1,6 +1,6 @@
1
- import { Injectable } from '@nestjs/common';
2
-
3
- import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
-
5
- @Injectable()
6
- export class EventsBusManyTablesTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
+
5
+ @Injectable()
6
+ export class EventsBusManyTablesTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
@@ -1,23 +1,26 @@
1
- import { Global, Module } from '@nestjs/common';
2
-
3
- import { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
4
- import { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
5
- import { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
6
- import { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
7
-
8
- @Global()
9
- @Module({
10
- providers: [
11
- EventsBusMainTablesSubscribeService,
12
- EventsBusOneTableTournamentSubscribeService,
13
- EventsBusManyTablesTournamentSubscribeService,
14
- EventsBusAppSubscribeService,
15
- ],
16
- exports: [
17
- EventsBusMainTablesSubscribeService,
18
- EventsBusOneTableTournamentSubscribeService,
19
- EventsBusManyTablesTournamentSubscribeService,
20
- EventsBusAppSubscribeService,
21
- ],
22
- })
23
- export class EventsBusModule {}
1
+ import { Global, Module } from '@nestjs/common';
2
+
3
+ import { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
4
+ import { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
5
+ import { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
6
+ import { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
7
+ import { EventsBusPlayerWsMessageSubscribeService } from './events-bus.player-ws-message.subscribe.service';
8
+
9
+ @Global()
10
+ @Module({
11
+ providers: [
12
+ EventsBusMainTablesSubscribeService,
13
+ EventsBusOneTableTournamentSubscribeService,
14
+ EventsBusManyTablesTournamentSubscribeService,
15
+ EventsBusAppSubscribeService,
16
+ EventsBusPlayerWsMessageSubscribeService,
17
+ ],
18
+ exports: [
19
+ EventsBusMainTablesSubscribeService,
20
+ EventsBusOneTableTournamentSubscribeService,
21
+ EventsBusManyTablesTournamentSubscribeService,
22
+ EventsBusAppSubscribeService,
23
+ EventsBusPlayerWsMessageSubscribeService,
24
+ ],
25
+ })
26
+ export class EventsBusModule {}
@@ -1,6 +1,6 @@
1
- import { Injectable } from '@nestjs/common';
2
-
3
- import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
-
5
- @Injectable()
6
- export class EventsBusOneTableTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
1
+ import { Injectable } from '@nestjs/common';
2
+
3
+ import { EventsBusTournamentSubscribeService } from './events-bus.tournament.subscribe.service';
4
+
5
+ @Injectable()
6
+ export class EventsBusOneTableTournamentSubscribeService extends EventsBusTournamentSubscribeService {}
@@ -0,0 +1,30 @@
1
+ import { BaseWsEvent } from 'jp.ms.common.engine';
2
+ import { Subject } from 'rxjs';
3
+
4
+ export class EventsBusPlayerWsMessageSubscribeService {
5
+ private readonly subjectSendMessage: Subject<BaseWsEvent>;
6
+ private readonly subjectGotMessage: Subject<BaseWsEvent>;
7
+
8
+ constructor() {
9
+ this.subjectSendMessage = new Subject<BaseWsEvent>();
10
+ this.subjectGotMessage = new Subject<BaseWsEvent>();
11
+ }
12
+
13
+ pushSendMessage(event: BaseWsEvent) {
14
+ this.subjectSendMessage.next(event);
15
+ }
16
+
17
+ pushGotMessage(event: BaseWsEvent) {
18
+ this.subjectGotMessage.next(event);
19
+ }
20
+
21
+ subscribeOnSendMessage(onHandleWsEvent: (event: BaseWsEvent) => void) {
22
+ this.subjectSendMessage.subscribe(onHandleWsEvent);
23
+ }
24
+
25
+ subscribeOnGotMessageFromClient(
26
+ onHandleWsEvent: (event: BaseWsEvent) => void,
27
+ ) {
28
+ this.subjectGotMessage.subscribe(onHandleWsEvent);
29
+ }
30
+ }
@@ -1,18 +1,18 @@
1
- import { RoomUpdateStateEvent } from 'jp.ms.common.engine';
2
- import { Subject } from 'rxjs';
3
-
4
- export abstract class EventsBusTournamentSubscribeService {
5
- private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
6
-
7
- constructor() {
8
- this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
9
- }
10
-
11
- pushNewRoomState(event: RoomUpdateStateEvent) {
12
- this.roomStatesSubject.next(event);
13
- }
14
-
15
- subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
16
- this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
17
- }
18
- }
1
+ import { RoomUpdateStateEvent } from 'jp.ms.common.engine';
2
+ import { Subject } from 'rxjs';
3
+
4
+ export abstract class EventsBusTournamentSubscribeService {
5
+ private readonly roomStatesSubject: Subject<RoomUpdateStateEvent>;
6
+
7
+ constructor() {
8
+ this.roomStatesSubject = new Subject<RoomUpdateStateEvent>();
9
+ }
10
+
11
+ pushNewRoomState(event: RoomUpdateStateEvent) {
12
+ this.roomStatesSubject.next(event);
13
+ }
14
+
15
+ subscribe(onHandleStatusRoomChange: (event: RoomUpdateStateEvent) => void) {
16
+ this.roomStatesSubject.subscribe(onHandleStatusRoomChange);
17
+ }
18
+ }
@@ -1,5 +1,6 @@
1
- export { EventsBusModule } from './events-bus.module';
2
- export { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
3
- export { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
4
- export { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
5
- export { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
1
+ export { EventsBusModule } from './events-bus.module';
2
+ export { EventsBusMainTablesSubscribeService } from './events-bus.main-tables.subscribe.service';
3
+ export { EventsBusOneTableTournamentSubscribeService } from './events-bus.one-table-tournament.subscribe.service';
4
+ export { EventsBusManyTablesTournamentSubscribeService } from './events-bus.many-tables-tournament.subscribe.service';
5
+ export { EventsBusAppSubscribeService } from './events-bus.app.subscribe.service';
6
+ export { EventsBusPlayerWsMessageSubscribeService } from './events-bus.player-ws-message.subscribe.service';
@@ -1 +1 @@
1
- export const EVENTS_OPTIONS = Symbol('EVENTS_OPTIONS');
1
+ export const EVENTS_OPTIONS = Symbol('EVENTS_OPTIONS');
@@ -1,70 +1,84 @@
1
- import {
2
- WebSocketServer,
3
- OnGatewayConnection,
4
- OnGatewayDisconnect,
5
- WebSocketGateway,
6
- } from '@nestjs/websockets';
7
- import { Server, Socket } from 'socket.io';
8
- import { UsersRepository } from 'jp.db.schemas';
9
- import { Inject } from '@nestjs/common';
10
-
11
- import { PlayersManagerService } from '../players-manager/players-manager.service';
12
-
13
- import { EVENTS_OPTIONS } from './events.constants';
14
- import { EventsFactoryOptions } from './events.interfaces';
15
-
16
- @WebSocketGateway({ cors: { origin: '*' } })
17
- export class EventsGateway
18
- implements OnGatewayConnection<Socket>, OnGatewayDisconnect<Socket>
19
- {
20
- @WebSocketServer()
21
- server: Server;
22
-
23
- constructor(
24
- private readonly playersManager: PlayersManagerService,
25
- private readonly usersRepository: UsersRepository,
26
- @Inject(EVENTS_OPTIONS) private readonly options: EventsFactoryOptions,
27
- ) {}
28
-
29
- async handleConnection(client: Socket) {
30
- const playerId = client.handshake.auth.token as string | undefined;
31
-
32
- const player = this.playersManager.getPlayerById(playerId ?? '');
33
- if (player) {
34
- player.connections.addConnection(client);
35
- } else {
36
- const user = await this.usersRepository.findById(playerId ?? '');
37
- if (user) {
38
- const player = this.options.createPlayer({
39
- id: user.userId,
40
- fullName: user.fullName,
41
- avatarUrl: user.avatarUrl,
42
- balance: user.balance,
43
- experience: user.experience,
44
- level: user.level,
45
- language: user.normalizedLang,
46
- });
47
- this.playersManager.addPlayer(player);
48
- player.connections.addConnection(client);
49
- }
50
- }
51
- }
52
-
53
- handleDisconnect(client: Socket): void {
54
- const playerId = client.handshake.auth.token as string | undefined;
55
- const connectedPlayer = this.playersManager.getPlayerById(playerId ?? '');
56
-
57
- if (connectedPlayer) {
58
- connectedPlayer.disconnect();
59
-
60
- if (
61
- !connectedPlayer.isPlayer() &&
62
- !connectedPlayer.isTableQueuer() &&
63
- !connectedPlayer.isRoomQueuer() &&
64
- !connectedPlayer.hasOpenConnection()
65
- ) {
66
- this.playersManager.removePlayer(playerId ?? '');
67
- }
68
- }
69
- }
70
- }
1
+ import {
2
+ WebSocketServer,
3
+ OnGatewayConnection,
4
+ OnGatewayDisconnect,
5
+ WebSocketGateway,
6
+ } from '@nestjs/websockets';
7
+ import { Server, Socket } from 'socket.io';
8
+ import { UsersRepository } from 'jp.db.schemas';
9
+ import { Inject } from '@nestjs/common';
10
+ import { BaseWsEvent } from 'jp.ms.common.engine';
11
+
12
+ import { PlayersManagerService } from '../players-manager/players-manager.service';
13
+ import { EventsBusPlayerWsMessageSubscribeService } from '../event-bus';
14
+
15
+ import { EVENTS_OPTIONS } from './events.constants';
16
+ import { EventsFactoryOptions } from './events.interfaces';
17
+
18
+ @WebSocketGateway({ cors: { origin: '*' } })
19
+ export class EventsGateway
20
+ implements OnGatewayConnection<Socket>, OnGatewayDisconnect<Socket>
21
+ {
22
+ @WebSocketServer()
23
+ server: Server;
24
+
25
+ constructor(
26
+ private readonly playersManager: PlayersManagerService,
27
+ private readonly usersRepository: UsersRepository,
28
+ private readonly eventsBusPlayerWsMessageSubscribeService: EventsBusPlayerWsMessageSubscribeService,
29
+ @Inject(EVENTS_OPTIONS) private readonly options: EventsFactoryOptions,
30
+ ) {}
31
+
32
+ async handleConnection(client: Socket) {
33
+ const playerId = client.handshake.auth.token as string | undefined;
34
+
35
+ const player = this.playersManager.getPlayerById(playerId ?? '');
36
+ if (player) {
37
+ player.connections.addConnection(client);
38
+ } else {
39
+ const user = await this.usersRepository.findById(playerId ?? '');
40
+ if (user) {
41
+ const player = this.options.createPlayer({
42
+ id: user.userId,
43
+ fullName: user.publicFullName,
44
+ avatarUrl: user.publicAvatarUrl,
45
+ avatarFrame: user.avatarFrame,
46
+ balance: user.balance,
47
+ experience: user.experience,
48
+ level: user.level,
49
+ language: user.normalizedLang,
50
+ cardsSkin: user.cardSkin,
51
+ onSendWsMessage: this.handleSendWsMessage,
52
+ onGotWsMessageClientResponse: this.handleGotWsMessageClientResponse,
53
+ });
54
+ this.playersManager.addPlayer(player);
55
+ player.connections.addConnection(client);
56
+ }
57
+ }
58
+ }
59
+
60
+ handleDisconnect(client: Socket): void {
61
+ const playerId = client.handshake.auth.token as string | undefined;
62
+ const connectedPlayer = this.playersManager.getPlayerById(playerId ?? '');
63
+
64
+ if (connectedPlayer) {
65
+ connectedPlayer.disconnect();
66
+ if (
67
+ !connectedPlayer.isPlayer() &&
68
+ !connectedPlayer.isTableQueuer() &&
69
+ !connectedPlayer.isRoomQueuer() &&
70
+ !connectedPlayer.hasOpenConnection()
71
+ ) {
72
+ this.playersManager.removePlayer(playerId ?? '');
73
+ }
74
+ }
75
+ }
76
+
77
+ handleSendWsMessage = (wsEvent: BaseWsEvent) => {
78
+ this.eventsBusPlayerWsMessageSubscribeService.pushSendMessage(wsEvent);
79
+ };
80
+
81
+ handleGotWsMessageClientResponse = (wsEvent: BaseWsEvent) => {
82
+ this.eventsBusPlayerWsMessageSubscribeService.pushGotMessage(wsEvent);
83
+ };
84
+ }
@@ -1,17 +1,17 @@
1
- import { GamePlayer, IGamePlayerConfig } from 'jp.ms.common.engine';
2
- import { ModuleMetadata } from '@nestjs/common';
3
- import { Type } from '@nestjs/common/interfaces/type.interface';
4
- import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
5
- import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
6
-
7
- export interface EventsModuleOptions extends Pick<ModuleMetadata, 'imports'> {
8
- imports?: Array<
9
- Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
10
- >;
11
- inject?: any[];
12
- useFactory?: (...args: any[]) => Promise<any> | any;
13
- }
14
-
15
- export interface EventsFactoryOptions {
16
- createPlayer: (config: IGamePlayerConfig) => GamePlayer;
17
- }
1
+ import { GamePlayer, IGamePlayerConfig } from 'jp.ms.common.engine';
2
+ import { ModuleMetadata } from '@nestjs/common';
3
+ import { Type } from '@nestjs/common/interfaces/type.interface';
4
+ import { DynamicModule } from '@nestjs/common/interfaces/modules/dynamic-module.interface';
5
+ import { ForwardReference } from '@nestjs/common/interfaces/modules/forward-reference.interface';
6
+
7
+ export interface EventsModuleOptions extends Pick<ModuleMetadata, 'imports'> {
8
+ imports?: Array<
9
+ Type<any> | DynamicModule | Promise<DynamicModule> | ForwardReference
10
+ >;
11
+ inject?: any[];
12
+ useFactory?: (...args: any[]) => Promise<any> | any;
13
+ }
14
+
15
+ export interface EventsFactoryOptions {
16
+ createPlayer: (config: IGamePlayerConfig) => GamePlayer;
17
+ }