@@ -30,48 +30,67 @@ import { MatchEntity } from 'gameserver/model/match.entity';
30
30
import { MatchmakingMode } from 'gateway/shared-types/matchmaking-mode' ;
31
31
import { Dota_GameMode } from 'gateway/shared-types/dota-game-mode' ;
32
32
import { MatchmakingModeMappingEntity } from 'gameserver/model/matchmaking-mode-mapping.entity' ;
33
+ import { Dota_Map } from 'gateway/shared-types/dota-map' ;
33
34
34
35
@CommandHandler ( FindGameServerCommand )
35
36
export class FindGameServerHandler
36
- implements ICommandHandler < FindGameServerCommand > {
37
+ implements ICommandHandler < FindGameServerCommand >
38
+ {
37
39
private readonly logger = new Logger ( FindGameServerHandler . name ) ;
38
40
39
- private pendingGamesPool : Subject < FindGameServerCommand > = new Subject <
40
- FindGameServerCommand
41
- > ( ) ;
41
+ private pendingGamesPool : Subject < FindGameServerCommand > =
42
+ new Subject < FindGameServerCommand > ( ) ;
42
43
43
44
constructor (
44
45
private readonly gsSessionRepository : GameServerSessionRepository ,
45
46
@InjectRepository ( GameServerSessionEntity )
46
- private readonly gameServerSessionModelRepository : Repository <
47
- GameServerSessionEntity
48
- > ,
47
+ private readonly gameServerSessionModelRepository : Repository < GameServerSessionEntity > ,
49
48
private readonly ebus : EventBus ,
50
49
@InjectRepository ( MatchEntity )
51
50
private readonly matchEntityRepository : Repository < MatchEntity > ,
52
51
private readonly qbus : QueryBus ,
53
- @Inject ( ' QueryCore' ) private readonly redisEventQueue : ClientProxy ,
52
+ @Inject ( " QueryCore" ) private readonly redisEventQueue : ClientProxy ,
54
53
@InjectRepository ( MatchmakingModeMappingEntity )
55
54
private readonly matchmakingModeMappingEntityRepository : Repository < MatchmakingModeMappingEntity > ,
56
55
) {
57
56
this . pendingGamesPool
58
- . pipe ( asyncMap ( cmd => this . findServer ( cmd ) , 1 ) )
57
+ . pipe ( asyncMap ( ( cmd ) => this . findServer ( cmd ) , 1 ) )
59
58
. subscribe ( ) ;
60
59
}
61
60
62
61
async execute ( command : FindGameServerCommand ) {
63
62
this . pendingGamesPool . next ( command ) ;
64
63
}
65
64
66
- private async getGameModeForMatchMode ( mode : MatchmakingMode ) : Promise < Dota_GameMode > {
65
+ private async getMapForMatchMode ( mode : MatchmakingMode ) : Promise < Dota_Map > {
67
66
const mapping = await this . matchmakingModeMappingEntityRepository . findOne ( {
68
67
where : {
69
- lobbyType : mode
70
- }
68
+ lobbyType : mode ,
69
+ } ,
70
+ } ) ;
71
+
72
+ if ( ! mapping ) {
73
+ this . logger . error (
74
+ `No mapping found for lobby type ${ mode } ! Returning all pick` ,
75
+ ) ;
76
+ return Dota_Map . DOTA ;
77
+ }
78
+ return mapping . dotaMap ;
79
+ }
80
+
81
+ private async getGameModeForMatchMode (
82
+ mode : MatchmakingMode ,
83
+ ) : Promise < Dota_GameMode > {
84
+ const mapping = await this . matchmakingModeMappingEntityRepository . findOne ( {
85
+ where : {
86
+ lobbyType : mode ,
87
+ } ,
71
88
} ) ;
72
89
73
- if ( ! mapping ) {
74
- this . logger . error ( `No mapping found for lobby type ${ mode } ! Returning all pick` ) ;
90
+ if ( ! mapping ) {
91
+ this . logger . error (
92
+ `No mapping found for lobby type ${ mode } ! Returning all pick` ,
93
+ ) ;
75
94
return Dota_GameMode . ALLPICK ;
76
95
}
77
96
return mapping . dotaGameMode ;
@@ -81,7 +100,7 @@ export class FindGameServerHandler
81
100
const players : FullMatchPlayer [ ] = [ ] ;
82
101
83
102
// TODO: i dont like it and want to move username resolving into operator
84
- const resolves = matchInfo . players . map ( async t => {
103
+ const resolves = matchInfo . players . map ( async ( t ) => {
85
104
const res = await this . qbus . execute <
86
105
GetUserInfoQuery ,
87
106
GetUserInfoQueryResult
@@ -95,6 +114,7 @@ export class FindGameServerHandler
95
114
96
115
return new GSMatchInfo (
97
116
matchInfo . mode ,
117
+ await this . getMapForMatchMode ( matchInfo . mode ) ,
98
118
await this . getGameModeForMatchMode ( matchInfo . mode ) ,
99
119
matchInfo . roomId ,
100
120
players ,
@@ -110,7 +130,7 @@ export class FindGameServerHandler
110
130
111
131
const gsInfo = await this . extendMatchInfo ( command . matchInfo ) ;
112
132
113
- console . log ( ' FindServer called, pool' , freeServerPool ) ;
133
+ console . log ( " FindServer called, pool" , freeServerPool ) ;
114
134
115
135
const m = new MatchEntity ( ) ;
116
136
m . server = MatchEntity . NOT_DECIDED_SERVER ;
@@ -126,18 +146,18 @@ export class FindGameServerHandler
126
146
let i = 0 ;
127
147
let foundServer : GameServerEntity | undefined ;
128
148
129
- console . log ( ' Free pool:' , freeServerPool . length ) ;
149
+ console . log ( " Free pool:" , freeServerPool . length ) ;
130
150
while ( i < freeServerPool . length ) {
131
151
const candidate = freeServerPool [ i ] ;
132
152
const stackUrl = candidate . url ;
133
153
try {
134
154
const cmd = new LaunchGameServerCommand ( candidate . url , m . id , gsInfo ) ;
135
155
console . log ( JSON . stringify ( cmd , null , 2 ) ) ;
136
156
const req = await this . redisEventQueue
137
- . send < LaunchGameServerResponse , LaunchGameServerCommand > (
138
- LaunchGameServerCommand . name ,
139
- cmd ,
140
- )
157
+ . send <
158
+ LaunchGameServerResponse ,
159
+ LaunchGameServerCommand
160
+ > ( LaunchGameServerCommand . name , cmd )
141
161
. pipe ( timeout ( 15000 ) )
142
162
. toPromise ( ) ;
143
163
@@ -152,7 +172,7 @@ export class FindGameServerHandler
152
172
// i guess we skip? just try next server
153
173
}
154
174
} catch ( e ) {
155
- console . log ( ' Sadkek?' , e ) ;
175
+ console . log ( " Sadkek?" , e ) ;
156
176
console . error ( e . stack ) ;
157
177
// timeout means server is DEAD
158
178
this . ebus . publish ( new ServerNotRespondingEvent ( stackUrl ) ) ;
@@ -163,7 +183,7 @@ export class FindGameServerHandler
163
183
i ++ ;
164
184
}
165
185
166
- console . log ( ' So: ' , inspect ( foundServer ) ) ;
186
+ console . log ( " So: " , inspect ( foundServer ) ) ;
167
187
168
188
if ( foundServer ) {
169
189
m . server = foundServer . url ;
0 commit comments