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.
- package/dist/dto/app-table/card.dto.d.ts +1 -0
- package/dist/dto/app-table/card.dto.js +11 -0
- package/dist/dto/app-table/card.dto.js.map +1 -1
- package/dist/dto/app-table/player.dto.d.ts +1 -0
- package/dist/dto/app-table/player.dto.js +11 -0
- package/dist/dto/app-table/player.dto.js.map +1 -1
- package/dist/dto/games/fool/fool-table.dto.d.ts +1 -0
- package/dist/dto/games/fool/fool-table.dto.js +10 -0
- package/dist/dto/games/fool/fool-table.dto.js.map +1 -1
- package/dist/modules/anti-freeze-system/anti-freeze-system.module.d.ts +3 -1
- package/dist/modules/anti-freeze-system/anti-freeze-system.module.js +8 -4
- package/dist/modules/anti-freeze-system/anti-freeze-system.module.js.map +1 -1
- package/dist/modules/anti-freeze-system/anti-freeze-system.service.d.ts +6 -2
- package/dist/modules/anti-freeze-system/anti-freeze-system.service.js +37 -10
- package/dist/modules/anti-freeze-system/anti-freeze-system.service.js.map +1 -1
- package/dist/modules/base-achievements/base-achievements.module.js +2 -2
- package/dist/modules/base-achievements/base-achievements.module.js.map +1 -1
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.d.ts +1 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.js +5 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.constants.js.map +1 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.d.ts +13 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.js +3 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.interfaces.js.map +1 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.d.ts +15 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.js +77 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.module.js.map +1 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.d.ts +19 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.js +83 -0
- package/dist/modules/confirmation-message-manager/confirmation-message-manager.service.js.map +1 -0
- package/dist/modules/event-bus/events-bus.module.js +3 -0
- package/dist/modules/event-bus/events-bus.module.js.map +1 -1
- package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.d.ts +10 -0
- package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.js +26 -0
- package/dist/modules/event-bus/events-bus.player-ws-message.subscribe.service.js.map +1 -0
- package/dist/modules/event-bus/index.d.ts +1 -0
- package/dist/modules/event-bus/index.js +3 -1
- package/dist/modules/event-bus/index.js.map +1 -1
- package/dist/modules/events/events.gateway.d.ts +6 -1
- package/dist/modules/events/events.gateway.js +19 -5
- package/dist/modules/events/events.gateway.js.map +1 -1
- package/dist/modules/index.d.ts +1 -0
- package/dist/modules/index.js +3 -1
- package/dist/modules/index.js.map +1 -1
- package/dist/modules/main/main.controller.d.ts +0 -1
- package/dist/modules/main/main.controller.js +0 -12
- package/dist/modules/main/main.controller.js.map +1 -1
- package/dist/modules/main/main.module.js +1 -1
- package/dist/modules/main/main.module.js.map +1 -1
- package/dist/modules/main/main.service.d.ts +0 -1
- package/dist/modules/main/main.service.js +0 -13
- package/dist/modules/main/main.service.js.map +1 -1
- package/dist/modules/many-tables-tournament/many-tables-tournament.controller.d.ts +1 -0
- package/dist/modules/many-tables-tournament/many-tables-tournament.controller.js +12 -0
- package/dist/modules/many-tables-tournament/many-tables-tournament.controller.js.map +1 -1
- package/dist/modules/many-tables-tournament/many-tables-tournament.module.js +7 -2
- package/dist/modules/many-tables-tournament/many-tables-tournament.module.js.map +1 -1
- package/dist/modules/many-tables-tournament/many-tables-tournament.service.d.ts +4 -1
- package/dist/modules/many-tables-tournament/many-tables-tournament.service.js +18 -2
- package/dist/modules/many-tables-tournament/many-tables-tournament.service.js.map +1 -1
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.module.js +2 -0
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.module.js.map +1 -1
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.d.ts +3 -2
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.js +9 -6
- package/dist/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.js.map +1 -1
- package/dist/modules/menu/menu-screen.view.d.ts +2 -1
- package/dist/modules/menu/menu-screen.view.js +9 -3
- package/dist/modules/menu/menu-screen.view.js.map +1 -1
- package/dist/modules/menu/menu.interfaces.d.ts +1 -0
- package/dist/modules/menu/menu.service.js +1 -1
- package/dist/modules/menu/menu.service.js.map +1 -1
- package/dist/modules/one-table-tournament/one-table-tournament.module.js +1 -1
- package/dist/modules/one-table-tournament/one-table-tournament.module.js.map +1 -1
- package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.module.js +2 -0
- package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.module.js.map +1 -1
- package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.d.ts +3 -2
- package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.js +9 -6
- package/dist/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.js.map +1 -1
- package/dist/modules/simple-rooms-manager/simple-rooms-manager.module.js +2 -0
- package/dist/modules/simple-rooms-manager/simple-rooms-manager.module.js.map +1 -1
- package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.d.ts +3 -2
- package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.js +8 -5
- package/dist/modules/simple-rooms-manager/simple-rooms-manager.service.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/game-table-result.d.ts +4 -3
- package/dist/utils/game-table-result.js +54 -4
- package/dist/utils/game-table-result.js.map +1 -1
- package/package.json +57 -57
- package/src/dto/app-screen/app-screen-app-bar.dto.ts +36 -36
- package/src/dto/app-screen/app-screen-dialog.dto.ts +64 -64
- package/src/dto/app-screen/app-screen-field-list-item.dto.ts +42 -42
- package/src/dto/app-screen/app-screen-field.dto.ts +59 -59
- package/src/dto/app-screen/app-screen-section-button.dto.ts +60 -60
- package/src/dto/app-screen/app-screen-section-buttons.dto.ts +14 -14
- package/src/dto/app-screen/app-screen-section-image.dto.ts +33 -33
- package/src/dto/app-screen/app-screen-section-list-item.dto.ts +105 -105
- package/src/dto/app-screen/app-screen-section-req.dto.ts +33 -33
- package/src/dto/app-screen/app-screen-section.dto.ts +76 -76
- package/src/dto/app-screen/app-screen.dto.ts +50 -50
- package/src/dto/app-screen/base-app-screen.dto.ts +16 -16
- package/src/dto/app-screen/index.ts +10 -10
- package/src/dto/app-table/bids-panel-item.dto.ts +33 -33
- package/src/dto/app-table/bids-panel.dto.ts +32 -32
- package/src/dto/app-table/card.dto.ts +63 -54
- package/src/dto/app-table/cards-deck.dto.ts +22 -22
- package/src/dto/app-table/cards-pair-slots-item.dto.ts +45 -45
- package/src/dto/app-table/cards-pair-slots.dto.ts +13 -13
- package/src/dto/app-table/cards-panel.dto.ts +48 -48
- package/src/dto/app-table/cards-player.dto.ts +14 -14
- package/src/dto/app-table/cards-slots-item.dto.ts +40 -40
- package/src/dto/app-table/cards-slots.dto.ts +13 -13
- package/src/dto/app-table/index.ts +15 -15
- package/src/dto/app-table/moves-panel-button.dto.ts +24 -24
- package/src/dto/app-table/moves-panel.dto.ts +23 -23
- package/src/dto/app-table/player.dto.ts +78 -69
- package/src/dto/app-table/summary-item.dto.ts +51 -51
- package/src/dto/app-table/summary.dto.ts +13 -13
- package/src/dto/common/find-free-table.dto.ts +3 -3
- package/src/dto/common/index.ts +2 -2
- package/src/dto/common/join-tournament.dto.ts +33 -33
- package/src/dto/common/log.dto.ts +9 -9
- package/src/dto/common/many-tables-tournament-create.dto.ts +125 -125
- package/src/dto/common/many-tables-tournament-update.dto.ts +3 -3
- package/src/dto/common/player-check-state.dto.ts +33 -33
- package/src/dto/common/player-connected.dto.ts +58 -58
- package/src/dto/games/fool/fool-player.dto.ts +3 -3
- package/src/dto/games/fool/fool-table.dto.ts +89 -81
- package/src/dto/games/index.ts +2 -2
- package/src/dto/games/poker/poker-player.dto.ts +3 -3
- package/src/dto/games/poker/poker-table.dto.ts +81 -81
- package/src/dto/index.ts +4 -4
- package/src/exception/error-code.enum.ts +4 -4
- package/src/exception/global-exception-filter.ts +53 -53
- package/src/exception/http-exception-wth-snackbar.ts +27 -27
- package/src/exception/index.ts +4 -4
- package/src/exception/not-enough-money-for-purchase.exception.ts +14 -14
- package/src/exception/not-found-free-room-for-fast-game.exception.ts +14 -14
- package/src/index.ts +4 -4
- package/src/modules/anti-freeze-system/anti-freeze-system.constants.ts +1 -1
- package/src/modules/anti-freeze-system/anti-freeze-system.interfaces.ts +20 -20
- package/src/modules/anti-freeze-system/anti-freeze-system.module.ts +59 -55
- package/src/modules/anti-freeze-system/anti-freeze-system.service.ts +136 -105
- package/src/modules/anti-freeze-system/index.ts +1 -1
- package/src/modules/base-achievements/base-achievements.module.ts +324 -322
- package/src/modules/base-achievements/index.ts +1 -1
- package/src/modules/confirmation-message-manager/confirmation-message-manager.constants.ts +3 -0
- package/src/modules/confirmation-message-manager/confirmation-message-manager.interfaces.ts +20 -0
- package/src/modules/confirmation-message-manager/confirmation-message-manager.module.ts +77 -0
- package/src/modules/confirmation-message-manager/confirmation-message-manager.service.ts +91 -0
- package/src/modules/event-bus/events-bus.app.subscribe.service.ts +20 -20
- package/src/modules/event-bus/events-bus.main-tables.subscribe.service.ts +34 -34
- package/src/modules/event-bus/events-bus.many-tables-tournament.subscribe.service.ts +6 -6
- package/src/modules/event-bus/events-bus.module.ts +26 -23
- package/src/modules/event-bus/events-bus.one-table-tournament.subscribe.service.ts +6 -6
- package/src/modules/event-bus/events-bus.player-ws-message.subscribe.service.ts +30 -0
- package/src/modules/event-bus/events-bus.tournament.subscribe.service.ts +18 -18
- package/src/modules/event-bus/index.ts +6 -5
- package/src/modules/events/events.constants.ts +1 -1
- package/src/modules/events/events.gateway.ts +84 -70
- package/src/modules/events/events.interfaces.ts +17 -17
- package/src/modules/events/events.module.ts +32 -32
- package/src/modules/events/index.ts +1 -1
- package/src/modules/index.ts +28 -27
- package/src/modules/logger/index.ts +2 -2
- package/src/modules/logger/jp-logger.module.ts +10 -10
- package/src/modules/logger/jp-logger.service.ts +38 -38
- package/src/modules/main/index.ts +1 -1
- package/src/modules/main/main-tables-list-screen.view.ts +275 -275
- package/src/modules/main/main.constants.ts +1 -1
- package/src/modules/main/main.controller.ts +51 -72
- package/src/modules/main/main.interfaces.ts +17 -17
- package/src/modules/main/main.module.ts +73 -73
- package/src/modules/main/main.service.ts +154 -183
- package/src/modules/many-tables-tournament/index.ts +1 -1
- package/src/modules/many-tables-tournament/many-tables-tournament-status-screen.view.ts +143 -143
- package/src/modules/many-tables-tournament/many-tables-tournament-tables-list-screen.view.ts +63 -63
- package/src/modules/many-tables-tournament/many-tables-tournament.constants.ts +3 -3
- package/src/modules/many-tables-tournament/many-tables-tournament.controller.ts +164 -151
- package/src/modules/many-tables-tournament/many-tables-tournament.interfaces.ts +20 -20
- package/src/modules/many-tables-tournament/many-tables-tournament.module.ts +89 -80
- package/src/modules/many-tables-tournament/many-tables-tournament.service.ts +241 -208
- package/src/modules/many-tables-tournament-rooms-manager/index.ts +2 -2
- package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.constants.ts +3 -3
- package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.interfaces.ts +37 -37
- package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.module.ts +89 -84
- package/src/modules/many-tables-tournament-rooms-manager/many-tables-tournament-rooms-manager.service.ts +333 -331
- package/src/modules/menu/index.ts +1 -1
- package/src/modules/menu/menu-screen.view.ts +78 -71
- package/src/modules/menu/menu.constants.ts +1 -1
- package/src/modules/menu/menu.controller.ts +16 -16
- package/src/modules/menu/menu.interfaces.ts +18 -17
- package/src/modules/menu/menu.module.ts +39 -39
- package/src/modules/menu/menu.service.ts +40 -39
- package/src/modules/one-table-tournament/index.ts +1 -1
- package/src/modules/one-table-tournament/one-table-tournament-status-screen.view.ts +166 -166
- package/src/modules/one-table-tournament/one-table-tournament.constants.ts +3 -3
- package/src/modules/one-table-tournament/one-table-tournament.controller.ts +104 -104
- package/src/modules/one-table-tournament/one-table-tournament.interfaces.ts +20 -20
- package/src/modules/one-table-tournament/one-table-tournament.module.ts +80 -76
- package/src/modules/one-table-tournament/one-table-tournament.service.ts +146 -146
- package/src/modules/one-table-tournament-rooms-manager/index.ts +2 -2
- package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.constants.ts +3 -3
- package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.interfaces.ts +31 -31
- package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.module.ts +71 -66
- package/src/modules/one-table-tournament-rooms-manager/one-table-tournament-rooms-manager.service.ts +222 -220
- package/src/modules/players-manager/index.ts +2 -2
- package/src/modules/players-manager/players-manager.module.ts +9 -9
- package/src/modules/players-manager/players-manager.service.ts +27 -27
- package/src/modules/simple-rooms/index.ts +1 -1
- package/src/modules/simple-rooms/simple-rooms.constants.ts +1 -1
- package/src/modules/simple-rooms/simple-rooms.controller.ts +63 -63
- package/src/modules/simple-rooms/simple-rooms.interfaces.ts +20 -20
- package/src/modules/simple-rooms/simple-rooms.module.ts +39 -39
- package/src/modules/simple-rooms/simple-rooms.service.ts +95 -95
- package/src/modules/simple-rooms-manager/index.ts +2 -2
- package/src/modules/simple-rooms-manager/simple-rooms-manager.constants.ts +3 -3
- package/src/modules/simple-rooms-manager/simple-rooms-manager.interfaces.ts +26 -26
- package/src/modules/simple-rooms-manager/simple-rooms-manager.module.ts +65 -60
- package/src/modules/simple-rooms-manager/simple-rooms-manager.service.ts +192 -190
- package/src/modules/support/dump.service.ts +11 -11
- package/src/modules/support/index.ts +1 -1
- package/src/modules/support/metric.service.ts +41 -41
- package/src/modules/support/support.constants.ts +1 -1
- package/src/modules/support/support.controller.ts +79 -79
- package/src/modules/support/support.interfaces.ts +16 -16
- package/src/modules/support/support.module.ts +35 -35
- package/src/modules/support/support.service.ts +27 -27
- package/src/utils/date.ts +7 -7
- package/src/utils/game-table-result.ts +190 -129
- package/src/views/index.ts +5 -5
- package/src/views/many-tables-tournament-conifrm-exit-dialog.view.ts +37 -37
- package/src/views/one-table-tournament-conifrm-exit-dialog.view.ts +37 -37
- package/src/views/simple-room-conifrm-exit-dialog.view.ts +37 -37
- package/src/views/table-summary.view.ts +104 -104
- package/src/views/tournament-buy-ticket-dialog.view.ts +34 -34
|
@@ -1,331 +1,333 @@
|
|
|
1
|
-
import { InjectConnection } from '@nestjs/mongoose';
|
|
2
|
-
import { Connection } from 'mongoose';
|
|
3
|
-
import dayjs from 'dayjs';
|
|
4
|
-
import schedule, { Job } from 'node-schedule';
|
|
5
|
-
import {
|
|
6
|
-
Inject,
|
|
7
|
-
Injectable,
|
|
8
|
-
InternalServerErrorException,
|
|
9
|
-
} from '@nestjs/common';
|
|
10
|
-
import {
|
|
11
|
-
BaseGameEvent,
|
|
12
|
-
GameMaster,
|
|
13
|
-
GamePlayer,
|
|
14
|
-
GameTableFinishedEvent,
|
|
15
|
-
GameTournamentCancelledEvent,
|
|
16
|
-
GameTournamentFinishedEvent,
|
|
17
|
-
GameTournamentPlayerJoinedTheTournamentEvent,
|
|
18
|
-
GameTournamentPlayerLeavedTheTournamentEvent,
|
|
19
|
-
GameTournamentStartedEvent,
|
|
20
|
-
GameTournamentWaitedEvent,
|
|
21
|
-
LocalService,
|
|
22
|
-
ManyTablesTournamentRoom,
|
|
23
|
-
ManyTablesTournamentRoomConfig,
|
|
24
|
-
NoStartStrategy,
|
|
25
|
-
RoomUpdateStateEvent,
|
|
26
|
-
TournamentMaster,
|
|
27
|
-
} from 'jp.ms.common.engine';
|
|
28
|
-
import {
|
|
29
|
-
GameResultRepository,
|
|
30
|
-
PurchaseRepository,
|
|
31
|
-
ManyTablesTournamentRoomDocument,
|
|
32
|
-
ManyTablesTournamentRoomsRepository,
|
|
33
|
-
UsersRepository,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
import {
|
|
42
|
-
import {
|
|
43
|
-
import {
|
|
44
|
-
import {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
import {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
private
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
private readonly
|
|
60
|
-
private readonly
|
|
61
|
-
private readonly
|
|
62
|
-
private readonly
|
|
63
|
-
private readonly
|
|
64
|
-
|
|
65
|
-
private readonly
|
|
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
|
-
this.
|
|
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
|
-
await session.
|
|
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
|
-
void this.
|
|
243
|
-
} else if (event instanceof
|
|
244
|
-
void this.
|
|
245
|
-
} else if (event instanceof
|
|
246
|
-
void this.
|
|
247
|
-
} else if (
|
|
248
|
-
event
|
|
249
|
-
|
|
250
|
-
event instanceof
|
|
251
|
-
event instanceof
|
|
252
|
-
event instanceof
|
|
253
|
-
event instanceof
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
this.
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
this.
|
|
284
|
-
this.
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
.set('
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
const
|
|
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
|
-
}
|
|
1
|
+
import { InjectConnection } from '@nestjs/mongoose';
|
|
2
|
+
import { Connection } from 'mongoose';
|
|
3
|
+
import dayjs from 'dayjs';
|
|
4
|
+
import schedule, { Job } from 'node-schedule';
|
|
5
|
+
import {
|
|
6
|
+
Inject,
|
|
7
|
+
Injectable,
|
|
8
|
+
InternalServerErrorException,
|
|
9
|
+
} from '@nestjs/common';
|
|
10
|
+
import {
|
|
11
|
+
BaseGameEvent,
|
|
12
|
+
GameMaster,
|
|
13
|
+
GamePlayer,
|
|
14
|
+
GameTableFinishedEvent,
|
|
15
|
+
GameTournamentCancelledEvent,
|
|
16
|
+
GameTournamentFinishedEvent,
|
|
17
|
+
GameTournamentPlayerJoinedTheTournamentEvent,
|
|
18
|
+
GameTournamentPlayerLeavedTheTournamentEvent,
|
|
19
|
+
GameTournamentStartedEvent,
|
|
20
|
+
GameTournamentWaitedEvent,
|
|
21
|
+
LocalService,
|
|
22
|
+
ManyTablesTournamentRoom,
|
|
23
|
+
ManyTablesTournamentRoomConfig,
|
|
24
|
+
NoStartStrategy,
|
|
25
|
+
RoomUpdateStateEvent,
|
|
26
|
+
TournamentMaster,
|
|
27
|
+
} from 'jp.ms.common.engine';
|
|
28
|
+
import {
|
|
29
|
+
GameResultRepository,
|
|
30
|
+
PurchaseRepository,
|
|
31
|
+
ManyTablesTournamentRoomDocument,
|
|
32
|
+
ManyTablesTournamentRoomsRepository,
|
|
33
|
+
UsersRepository,
|
|
34
|
+
RatingRepository,
|
|
35
|
+
} from 'jp.db.schemas';
|
|
36
|
+
|
|
37
|
+
import {
|
|
38
|
+
saveGameTablesResultForTournamentRoom,
|
|
39
|
+
saveTournamentResult,
|
|
40
|
+
} from '../../utils/game-table-result';
|
|
41
|
+
import { JpLoggerService } from '../logger';
|
|
42
|
+
import { getHours, getMinutes } from '../../utils/date';
|
|
43
|
+
import { ManyTablesTournamentCreateDto } from '../../dto/common/many-tables-tournament-create.dto';
|
|
44
|
+
import { ManyTablesTournamentUpdateDto } from '../../dto/common/many-tables-tournament-update.dto';
|
|
45
|
+
import {
|
|
46
|
+
EventsBusMainTablesSubscribeService,
|
|
47
|
+
EventsBusManyTablesTournamentSubscribeService,
|
|
48
|
+
} from '../event-bus';
|
|
49
|
+
|
|
50
|
+
import { MANY_TABLES_TOURNAMENT_ROOMS_MANAGER_OPTIONS } from './many-tables-tournament-rooms-manager.constants';
|
|
51
|
+
import { ManyTablesTournamentRoomsFactoryOptions } from './many-tables-tournament-rooms-manager.interfaces';
|
|
52
|
+
|
|
53
|
+
@Injectable()
|
|
54
|
+
export class ManyTablesTournamentRoomsManagerService {
|
|
55
|
+
private readonly rooms: Map<string, ManyTablesTournamentRoom>;
|
|
56
|
+
private createDailyTournamentJob: Job | null;
|
|
57
|
+
|
|
58
|
+
constructor(
|
|
59
|
+
private readonly tournamentRepository: ManyTablesTournamentRoomsRepository,
|
|
60
|
+
private readonly usersRepository: UsersRepository,
|
|
61
|
+
private readonly gameResultRepository: GameResultRepository,
|
|
62
|
+
private readonly purchaseRepository: PurchaseRepository,
|
|
63
|
+
private readonly ratingRepository: RatingRepository,
|
|
64
|
+
private readonly eventsBusMainTablesSubscribeService: EventsBusMainTablesSubscribeService,
|
|
65
|
+
private readonly eventsBusManyTablesTournamentSubscribeService: EventsBusManyTablesTournamentSubscribeService,
|
|
66
|
+
@Inject(MANY_TABLES_TOURNAMENT_ROOMS_MANAGER_OPTIONS)
|
|
67
|
+
private readonly options: ManyTablesTournamentRoomsFactoryOptions,
|
|
68
|
+
@InjectConnection() private readonly connection: Connection,
|
|
69
|
+
@Inject() private readonly logger: JpLoggerService,
|
|
70
|
+
) {
|
|
71
|
+
this.rooms = new Map<string, ManyTablesTournamentRoom>();
|
|
72
|
+
this.createDailyTournamentJob = null;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get gameType() {
|
|
76
|
+
return this.options.gameType;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
getRoomById(roomId: string): ManyTablesTournamentRoom | undefined {
|
|
80
|
+
return this.rooms.get(roomId);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
getRoomByTableId(tableId: string): ManyTablesTournamentRoom | undefined {
|
|
84
|
+
const { roomId } = GameMaster.parseTableId(tableId);
|
|
85
|
+
|
|
86
|
+
return this.getRoomById(roomId);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getRooms(): Array<ManyTablesTournamentRoom> {
|
|
90
|
+
return Array.from(this.rooms.values());
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
getTables(): Array<GameMaster> {
|
|
94
|
+
return this.getRooms().reduce((result, currentValue) => {
|
|
95
|
+
return [...result, ...currentValue.getMasters()];
|
|
96
|
+
}, [] as Array<GameMaster>);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
addRoom(room: ManyTablesTournamentRoom) {
|
|
100
|
+
this.rooms.set(room.getId(), room);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
async hydrateTournamentsFromDB() {
|
|
104
|
+
const templates = await this.tournamentRepository.findActualTournaments(
|
|
105
|
+
this.gameType,
|
|
106
|
+
);
|
|
107
|
+
templates.forEach((item) => {
|
|
108
|
+
this.addRoom(
|
|
109
|
+
this.options.createTournamentRoom(
|
|
110
|
+
this.manyTablesTournamentDocumentToTournamentRoom(item),
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
async runDailyTournamentJob() {
|
|
117
|
+
if (
|
|
118
|
+
this.options.dailyTournamentScheduleTaskTime &&
|
|
119
|
+
this.options.dailyTournamentTime
|
|
120
|
+
) {
|
|
121
|
+
await this.createDailyTournament(this.options.dailyTournamentTime);
|
|
122
|
+
|
|
123
|
+
this.createDailyTournamentJob = schedule.scheduleJob(
|
|
124
|
+
this.options.dailyTournamentScheduleTaskTime,
|
|
125
|
+
() => this.createDailyTournament(this.options.dailyTournamentTime),
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
async createTournament(createTournamentDto: ManyTablesTournamentCreateDto) {
|
|
131
|
+
const newTournament =
|
|
132
|
+
await this.tournamentRepository.createTournament(createTournamentDto);
|
|
133
|
+
|
|
134
|
+
this.addRoom(
|
|
135
|
+
this.options.createTournamentRoom(
|
|
136
|
+
this.manyTablesTournamentDocumentToTournamentRoom(newTournament),
|
|
137
|
+
),
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async updateTournament(
|
|
142
|
+
tournamentId: string,
|
|
143
|
+
updateTournamentDto: ManyTablesTournamentUpdateDto,
|
|
144
|
+
) {
|
|
145
|
+
const updatedTournament = await this.tournamentRepository.updateTournament(
|
|
146
|
+
tournamentId,
|
|
147
|
+
updateTournamentDto,
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
this.getRoomById(tournamentId)
|
|
151
|
+
?.getRoomMaster<TournamentMaster>()
|
|
152
|
+
.cancelTournament();
|
|
153
|
+
|
|
154
|
+
this.addRoom(
|
|
155
|
+
this.options.createTournamentRoom(
|
|
156
|
+
this.manyTablesTournamentDocumentToTournamentRoom(updatedTournament),
|
|
157
|
+
),
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
async removeTournament(tournamentId: string) {
|
|
162
|
+
await this.tournamentRepository.removeTournament(tournamentId);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async buyTicket(tournamentId: string, player: GamePlayer) {
|
|
166
|
+
const tournament = this.getRoomById(tournamentId);
|
|
167
|
+
const user = await this.usersRepository.findById(player.id);
|
|
168
|
+
|
|
169
|
+
if (!tournament || !user) {
|
|
170
|
+
throw new InternalServerErrorException();
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
const session = await this.connection.startSession();
|
|
174
|
+
session.startTransaction();
|
|
175
|
+
|
|
176
|
+
try {
|
|
177
|
+
player.decreaseBalance(tournament.getTicketPrice());
|
|
178
|
+
tournament.addParticipant(player);
|
|
179
|
+
void this.purchaseRepository.addManyTablesTournamentTicketPurchase(
|
|
180
|
+
player.id,
|
|
181
|
+
player.fullName,
|
|
182
|
+
tournamentId,
|
|
183
|
+
tournament.getTicketPrice(),
|
|
184
|
+
tournament.getGameType(),
|
|
185
|
+
);
|
|
186
|
+
void this.usersRepository.subtractFromBalance(
|
|
187
|
+
player.id,
|
|
188
|
+
tournament.getTicketPrice(),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
await this.tournamentRepository.addPlayerToParticipants(tournamentId, {
|
|
192
|
+
playerId: player.id,
|
|
193
|
+
playerAvatarUrl: player.avatarUrl,
|
|
194
|
+
playerName: player.fullName,
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
await session.commitTransaction();
|
|
198
|
+
} catch (error) {
|
|
199
|
+
await session.abortTransaction();
|
|
200
|
+
throw error;
|
|
201
|
+
} finally {
|
|
202
|
+
await session.endSession();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
private manyTablesTournamentDocumentToTournamentRoom(
|
|
207
|
+
tournamentDocument: ManyTablesTournamentRoomDocument,
|
|
208
|
+
): ManyTablesTournamentRoomConfig {
|
|
209
|
+
return {
|
|
210
|
+
id: tournamentDocument.tournamentId,
|
|
211
|
+
gameType: tournamentDocument.gameType,
|
|
212
|
+
roomType: tournamentDocument.roomType,
|
|
213
|
+
rulesType: tournamentDocument.rulesType,
|
|
214
|
+
deckType: tournamentDocument.deckType,
|
|
215
|
+
tableSize: tournamentDocument.tableSize,
|
|
216
|
+
bet: tournamentDocument.bet,
|
|
217
|
+
ticketPrice: tournamentDocument.ticketPrice,
|
|
218
|
+
title: tournamentDocument.title,
|
|
219
|
+
subtitle: tournamentDocument.subtitle,
|
|
220
|
+
description: tournamentDocument.description,
|
|
221
|
+
enableForFastGame: false,
|
|
222
|
+
scheduleDate: tournamentDocument.scheduleDate,
|
|
223
|
+
turnTimeout: this.options.playersTurnTimeout,
|
|
224
|
+
restartTimeout: this.options.restartGameTimeout,
|
|
225
|
+
instantFinishMode: this.options.instantFinishMode,
|
|
226
|
+
minPlayersForMergeTables: this.options.minPlayersForMergeTables,
|
|
227
|
+
localeService: this.options.i18n as LocalService,
|
|
228
|
+
startStrategy: new NoStartStrategy(),
|
|
229
|
+
onRoomEvent: this.handleRoomEvent,
|
|
230
|
+
tournamentPrizeTable: this.options.tournamentPrizeTable,
|
|
231
|
+
tournamentInitialStatus: tournamentDocument.status,
|
|
232
|
+
tournamentWinners: tournamentDocument.winners,
|
|
233
|
+
maxParticipants: tournamentDocument.maxParticipants,
|
|
234
|
+
participants: tournamentDocument.participants,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private handleRoomEvent = (event: BaseGameEvent) => {
|
|
239
|
+
this.logger.log(event.toLog());
|
|
240
|
+
|
|
241
|
+
if (event instanceof GameTableFinishedEvent) {
|
|
242
|
+
void this.handleRoomTableGameFinished(event.master);
|
|
243
|
+
} else if (event instanceof GameTournamentStartedEvent) {
|
|
244
|
+
void this.handleTournamentRoomStarted(event.room.getRoomMaster());
|
|
245
|
+
} else if (event instanceof GameTournamentCancelledEvent) {
|
|
246
|
+
void this.handleTournamentRoomCancelled(event.room.getRoomMaster());
|
|
247
|
+
} else if (event instanceof GameTournamentFinishedEvent) {
|
|
248
|
+
void this.handleTournamentRoomFinished(event.room.getRoomMaster());
|
|
249
|
+
} else if (
|
|
250
|
+
event instanceof GameTournamentPlayerJoinedTheTournamentEvent ||
|
|
251
|
+
event instanceof GameTournamentPlayerLeavedTheTournamentEvent ||
|
|
252
|
+
event instanceof GameTournamentCancelledEvent ||
|
|
253
|
+
event instanceof GameTournamentWaitedEvent ||
|
|
254
|
+
event instanceof GameTournamentStartedEvent ||
|
|
255
|
+
event instanceof GameTournamentFinishedEvent
|
|
256
|
+
) {
|
|
257
|
+
void this.handleRoomStatusUpdated(
|
|
258
|
+
new RoomUpdateStateEvent(event.gameType, event.roomId),
|
|
259
|
+
);
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
private handleRoomTableGameFinished = async (master: GameMaster) => {
|
|
264
|
+
await saveGameTablesResultForTournamentRoom(
|
|
265
|
+
master,
|
|
266
|
+
this.connection,
|
|
267
|
+
this.gameResultRepository,
|
|
268
|
+
this.usersRepository,
|
|
269
|
+
);
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
private handleTournamentRoomStarted = async (master: TournamentMaster) => {
|
|
273
|
+
await this.tournamentRepository.startTournament(master.getTournamentId());
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
private handleTournamentRoomCancelled = async (master: TournamentMaster) => {
|
|
277
|
+
await this.tournamentRepository.cancelTournament(master.getTournamentId());
|
|
278
|
+
};
|
|
279
|
+
|
|
280
|
+
private handleTournamentRoomFinished = async (master: TournamentMaster) => {
|
|
281
|
+
await saveTournamentResult(
|
|
282
|
+
master,
|
|
283
|
+
this.connection,
|
|
284
|
+
this.tournamentRepository,
|
|
285
|
+
this.usersRepository,
|
|
286
|
+
this.ratingRepository,
|
|
287
|
+
);
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
private handleRoomStatusUpdated = (event: RoomUpdateStateEvent) => {
|
|
291
|
+
this.eventsBusMainTablesSubscribeService.pushNewRoomState(event);
|
|
292
|
+
this.eventsBusManyTablesTournamentSubscribeService.pushNewRoomState(event);
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
private createDailyTournament = async (dailyTournamentTime: string) => {
|
|
296
|
+
const hour = getHours(dailyTournamentTime);
|
|
297
|
+
const minutes = getMinutes(dailyTournamentTime);
|
|
298
|
+
const jobEveningDate = dayjs()
|
|
299
|
+
.set('hour', hour)
|
|
300
|
+
.set('minute', minutes)
|
|
301
|
+
.set('second', 0);
|
|
302
|
+
const addingDay = dayjs().isBefore(jobEveningDate) ? 0 : 1;
|
|
303
|
+
|
|
304
|
+
const startDate = dayjs().add(addingDay, 'day').startOf('day');
|
|
305
|
+
const endDate = dayjs().add(addingDay, 'day').endOf('day');
|
|
306
|
+
|
|
307
|
+
const tournamentDate = dayjs()
|
|
308
|
+
.add(addingDay, 'day')
|
|
309
|
+
.set('hour', hour)
|
|
310
|
+
.set('minute', minutes);
|
|
311
|
+
|
|
312
|
+
const waitedTournament =
|
|
313
|
+
await this.tournamentRepository.findWaitingTournamentByDate(
|
|
314
|
+
this.gameType,
|
|
315
|
+
startDate.toDate(),
|
|
316
|
+
endDate.toDate(),
|
|
317
|
+
);
|
|
318
|
+
|
|
319
|
+
if (!waitedTournament) {
|
|
320
|
+
const newTournament =
|
|
321
|
+
await this.tournamentRepository.scheduleTournamentFromMasterTemplate(
|
|
322
|
+
this.gameType,
|
|
323
|
+
tournamentDate.toDate(),
|
|
324
|
+
);
|
|
325
|
+
|
|
326
|
+
this.addRoom(
|
|
327
|
+
this.options.createTournamentRoom(
|
|
328
|
+
this.manyTablesTournamentDocumentToTournamentRoom(newTournament),
|
|
329
|
+
),
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
}
|