Skip to content

Commit d02ed85

Browse files
committed
Fix empty achievements for newbies
1 parent 36c4f8c commit d02ed85

File tree

2 files changed

+64
-41
lines changed

2 files changed

+64
-41
lines changed

src/gameserver/event-handler/server-status.handler.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ServerStatusEvent } from 'gateway/events/gs/server-status.event';
33
import { GameServerSessionEntity } from 'gameserver/model/game-server-session.entity';
44
import { InjectRepository } from '@nestjs/typeorm';
55
import { Repository } from 'typeorm';
6+
import { GameServerStoppedEvent } from 'gateway/events/game-server-stopped.event';
67
import { Logger } from '@nestjs/common';
78
import FinishedMatchEntity from 'gameserver/model/finished-match.entity';
89

@@ -48,12 +49,12 @@ export class ServerStatusHandler implements IEventHandler<ServerStatusEvent> {
4849
await this.gameServerSessionModelRepository.save(existingSession);
4950
} else if (!event.running && existingSession) {
5051
// remove session if it exists
51-
// this.ebus.publish(
52-
// new GameServerStoppedEvent(
53-
// event.url,
54-
// existingSession.matchInfoJson.version,
55-
// ),
56-
// );
52+
this.ebus.publish(
53+
new GameServerStoppedEvent(
54+
event.url,
55+
existingSession.matchInfoJson.version,
56+
),
57+
);
5758
}
5859
}
5960
}

src/rest/player.controller.ts

+57-35
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ import PlayerInMatchEntity from 'gameserver/model/player-in-match.entity';
3434
import FinishedMatchEntity from 'gameserver/model/finished-match.entity';
3535
import { makePage } from 'gateway/util/make-page';
3636
import { ProcessRankedMatchHandler } from 'gameserver/command/ProcessRankedMatch/process-ranked-match.handler';
37+
import { AchievementKey } from 'gateway/shared-types/achievemen-key';
3738

38-
@Controller('player')
39-
@ApiTags('player')
39+
@Controller("player")
40+
@ApiTags("player")
4041
export class PlayerController {
4142
private static leaderboardLimit = 1000;
4243

@@ -60,30 +61,45 @@ export class PlayerController {
6061
private readonly achievementEntityRepository: Repository<AchievementEntity>,
6162
) {}
6263

63-
@Get('/:id/achievements')
64+
@Get("/:id/achievements")
6465
public async playerAchievements(
65-
@Param('id') steamId: string,
66+
@Param("id") steamId: string,
6667
): Promise<AchievementDto[]> {
6768
const ach = Array.from(this.achievements.achievementMap.values());
6869

6970
const achievementsQ = this.achievementEntityRepository
70-
.createQueryBuilder('a')
71+
.createQueryBuilder("a")
7172
.leftJoinAndMapOne(
72-
'a.match',
73+
"a.match",
7374
FinishedMatchEntity,
74-
'fm',
75+
"fm",
7576
'fm.id = a."matchId"',
7677
)
7778
.leftJoinAndMapOne(
78-
'a.pim',
79+
"a.pim",
7980
PlayerInMatchEntity,
80-
'pim',
81+
"pim",
8182
`pim."playerId" = a.steam_id and pim."matchId" = a."matchId"`,
8283
)
8384
.where({ steam_id: steamId });
8485

8586
const achievements = await achievementsQ.getMany();
86-
return achievements.map(t => {
87+
88+
const paddedAchievements = Object.keys(AchievementKey)
89+
.filter(
90+
(key) =>
91+
isNaN(Number(key)) &&
92+
achievements.findIndex(
93+
(ach) => ach.achievement_key === Number(key),
94+
) === -1,
95+
)
96+
.map((key) => ({
97+
steam_id: steamId,
98+
progress: 0,
99+
achievement_key: AchievementKey[key],
100+
} as AchievementEntity));
101+
102+
return achievements.concat(paddedAchievements).map((t) => {
87103
if (t.match) {
88104
t.match.players = [];
89105
}
@@ -92,18 +108,18 @@ export class PlayerController {
92108
}
93109

94110
@ApiQuery({
95-
name: 'page',
111+
name: "page",
96112
required: true,
97113
})
98114
@ApiQuery({
99-
name: 'per_page',
115+
name: "per_page",
100116
required: false,
101117
})
102118
@Get(`/:id/teammates`)
103119
async playerTeammates(
104-
@Param('id') steamId: string,
105-
@Query('page', NullableIntPipe) page: number,
106-
@Query('per_page', NullableIntPipe) perPage: number = 25,
120+
@Param("id") steamId: string,
121+
@Query("page", NullableIntPipe) page: number,
122+
@Query("per_page", NullableIntPipe) perPage: number = 25,
107123
): Promise<PlayerTeammatePage> {
108124
const totalEntries = await this.connection.query<{ count: number }[]>(
109125
`select count(distinct pim."playerId")::int
@@ -154,10 +170,10 @@ offset $2 limit $3`,
154170
}
155171

156172
@CacheTTL(120)
157-
@Get('/summary/:version/:id')
173+
@Get("/summary/:version/:id")
158174
async playerSummary(
159-
@Param('version') version: Dota2Version,
160-
@Param('id') steam_id: string,
175+
@Param("version") version: Dota2Version,
176+
@Param("id") steam_id: string,
161177
): Promise<PlayerSummaryDto> {
162178
await this.cbus.execute(new MakeSureExistsCommand(new PlayerId(steam_id)));
163179

@@ -187,13 +203,15 @@ offset $2 limit $3`,
187203
? 0
188204
: Math.max(0, UNRANKED_GAMES_REQUIRED_FOR_RANKED - lb.games),
189205

190-
calibrationGamesLeft: Math.max(ProcessRankedMatchHandler.TOTAL_CALIBRATION_GAMES - lb.ranked_games, 0)
206+
calibrationGamesLeft: Math.max(
207+
ProcessRankedMatchHandler.TOTAL_CALIBRATION_GAMES - lb.ranked_games,
208+
0,
209+
),
191210
};
192211
}
193212

194-
const summary: Summary | undefined = await this.playerService.fullSummary(
195-
steam_id,
196-
);
213+
const summary: Summary | undefined =
214+
await this.playerService.fullSummary(steam_id);
197215

198216
const rank = await this.playerService.getRank(version, steam_id);
199217

@@ -221,27 +239,31 @@ offset $2 limit $3`,
221239
(summary?.unranked_games || 0),
222240
),
223241

224-
calibrationGamesLeft: Math.max(ProcessRankedMatchHandler.TOTAL_CALIBRATION_GAMES - (summary?.ranked_games || 0), 0)
242+
calibrationGamesLeft: Math.max(
243+
ProcessRankedMatchHandler.TOTAL_CALIBRATION_GAMES -
244+
(summary?.ranked_games || 0),
245+
0,
246+
),
225247
};
226248
}
227249

228-
@Get('/leaderboard')
250+
@Get("/leaderboard")
229251
@CacheTTL(60 * 30)
230252
@ApiQuery({
231-
name: 'page',
253+
name: "page",
232254
required: true,
233255
})
234256
@ApiQuery({
235-
name: 'per_page',
257+
name: "per_page",
236258
required: false,
237259
})
238260
async leaderboard(
239-
@Query('page', NullableIntPipe) page: number,
240-
@Query('per_page', NullableIntPipe) perPage: number = 100,
261+
@Query("page", NullableIntPipe) page: number,
262+
@Query("per_page", NullableIntPipe) perPage: number = 100,
241263
): Promise<LeaderboardEntryPageDto> {
242264
const [data, total] = await this.leaderboardViewRepository.findAndCount({
243265
order: {
244-
mmr: 'DESC',
266+
mmr: "DESC",
245267
},
246268
take: perPage,
247269
skip: perPage * page,
@@ -253,21 +275,21 @@ offset $2 limit $3`,
253275
@CacheTTL(120)
254276
@Get(`/summary/heroes/:version/:id`)
255277
async playerHeroSummary(
256-
@Param('version') version: Dota2Version,
257-
@Param('id') steam_id: string,
278+
@Param("version") version: Dota2Version,
279+
@Param("id") steam_id: string,
258280
): Promise<HeroStatsDto[]> {
259281
await this.cbus.execute(new MakeSureExistsCommand(new PlayerId(steam_id)));
260282

261283
return await this.playerService.heroStats(version, steam_id);
262284
}
263285

264-
@Get('/hero/:hero/players')
265-
async getHeroPlayers(@Param('hero') hero: string) {
286+
@Get("/hero/:hero/players")
287+
async getHeroPlayers(@Param("hero") hero: string) {
266288
return this.playerService.getHeroPlayers(hero);
267289
}
268290

269291
@Get(`/ban_info/:id`)
270-
async banInfo(@Param('id') steam_id: string): Promise<BanStatusDto> {
292+
async banInfo(@Param("id") steam_id: string): Promise<BanStatusDto> {
271293
const ban = await this.playerBanRepository.findOne({
272294
where: { steam_id: steam_id },
273295
});
@@ -280,7 +302,7 @@ offset $2 limit $3`,
280302
};
281303
}
282304

283-
@Post('/report')
305+
@Post("/report")
284306
async reportPlayer(@Body() dto: ReportPlayerDto) {
285307
this.ebus.publish(
286308
new PlayerReportEvent(dto.matchId, dto.reporter, dto.reported, dto.text),

0 commit comments

Comments
 (0)