Skip to content

Commit f33725e

Browse files
committed
Fixes
1 parent c2a63b0 commit f33725e

9 files changed

+78
-11
lines changed

src/app.module.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import { outerQuery } from 'gateway/util/outerQuery';
2020
import { QueryCache } from 'rcache';
2121
import { CacheModule } from '@nestjs/cache-manager';
2222
import { MatchService } from 'rest/match/match.service';
23-
import { CrimeController } from 'rest/crime.controller';
2423
import { MatchMapper } from 'rest/match/match.mapper';
2524
import { MatchController } from 'rest/match/match.controller';
2625
import { MetaMapper } from 'rest/meta/meta.mapper';
2726
import { InfoMapper } from 'rest/info/info.mapper';
2827
import { InfoService } from 'rest/info/info.service';
28+
import { CrimeController } from 'rest/crime/crime.controller';
2929

3030

3131
export function qCache<T, B>() {

src/gameserver/event-handler/crime-log-created.handler.ts

+25-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,21 @@ export const getBasePunishment = (crime: BanReason) => {
2626
}
2727
};
2828

29+
export const getPunishmentCumulativeInterval = (crime: BanReason): string => {
30+
switch (crime) {
31+
case BanReason.INFINITE_BAN:
32+
return "1y";
33+
case BanReason.GAME_DECLINE:
34+
return "4h";
35+
case BanReason.LOAD_FAILURE:
36+
return "24h";
37+
case BanReason.ABANDON:
38+
return "7d";
39+
default:
40+
return "1m";
41+
}
42+
};
43+
2944
export const countCrimes = (crimes: PlayerCrimeLogEntity[]) => {
3045
const grouped: Map<BanReason, number> = new Map();
3146
for (let crime of crimes) {
@@ -71,12 +86,13 @@ export class CrimeLogCreatedHandler
7186
return;
7287
}
7388

74-
// TODO: make this SQL based with interval
89+
const cumInterval = getPunishmentCumulativeInterval(thisCrime.crime);
90+
7591
const frequentCrimesCount = await this.playerCrimeLogEntityRepository
7692
.createQueryBuilder("pc")
7793
.select()
7894
.where("pc.steam_id = :sid", { sid: thisCrime.steam_id })
79-
.andWhere("pc.created_at >= now() - '24h'::interval") // interval here
95+
.andWhere(`pc.created_at >= now() - ${cumInterval}::interval`) // interval here
8096
.getMany();
8197

8298
// total crimes done within 24 hours
@@ -86,7 +102,13 @@ export class CrimeLogCreatedHandler
86102
const basePunishment = getBasePunishment(thisCrime.crime);
87103
let punishmentDuration = basePunishment * totalPunishmentCount;
88104

89-
console.log(countedCrimes, totalPunishmentCount, basePunishment, punishmentDuration, thisCrime)
105+
console.log(
106+
countedCrimes,
107+
totalPunishmentCount,
108+
basePunishment,
109+
punishmentDuration,
110+
thisCrime,
111+
);
90112

91113
this.logger.log(
92114
`Punishment: ${punishmentDuration / 1000 / 60} minutes for ${

src/gameserver/model/leaderboard.view.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Index, ViewColumn, ViewEntity } from 'typeorm';
33
@ViewEntity({
44
expression: `with cte as (select plr."playerId" as steam_id,
55
count(*)::int as any_games,
6+
sum((m.winner = plr.team)::int)::int as bot_wins,
67
sum((m.matchmaking_mode in (0, 1))::int)::int as games,
78
sum((m.winner = plr.team and m.matchmaking_mode in (0, 1))::int)::int as wins,
89
sum((m.matchmaking_mode = 0 and m.timestamp > now() - '14 days'::interval)::int) as recent_ranked_games,
@@ -15,6 +16,7 @@ select p.steam_id,
1516
p.wins,
1617
p.games,
1718
p.any_games,
19+
p.bot_wins,
1820
p.mmr as mmr,
1921
avg(pim.kills)::float as kills,
2022
avg(pim.deaths)::float as deaths,
@@ -25,7 +27,7 @@ select p.steam_id,
2527
from cte p
2628
inner join player_in_match pim on pim."playerId" = p.steam_id
2729
inner join finished_match m on pim."matchId" = m.id
28-
group by p.steam_id, p.recent_ranked_games, p.mmr, p.games, p.wins, p.any_games
30+
group by p.steam_id, p.recent_ranked_games, p.mmr, p.games, p.wins, p.any_games, p.bot_wins
2931
order by rank, games desc`,
3032
materialized: true,
3133
})
@@ -44,6 +46,9 @@ export class LeaderboardView {
4446
@ViewColumn()
4547
any_games: number;
4648

49+
@ViewColumn()
50+
bot_wins: number;
51+
4752
@Index()
4853
@ViewColumn()
4954
games: number;
File renamed without changes.

src/rest/crime/crime.service.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Injectable } from '@nestjs/common';
2+
import { InjectRepository } from '@nestjs/typeorm';
3+
import { PlayerCrimeLogEntity } from 'gameserver/model/player-crime-log.entity';
4+
import { Repository } from 'typeorm';
5+
6+
@Injectable()
7+
export class CrimeService {
8+
constructor(
9+
@InjectRepository(PlayerCrimeLogEntity)
10+
private readonly playerCrimeLogEntityRepository: Repository<PlayerCrimeLogEntity>,
11+
) {
12+
}
13+
14+
15+
16+
public async getCrimePage(page: number, perPage: number, ){
17+
18+
}
19+
}

src/rest/dto/crime.dto.ts

+7
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ export class CrimeLogPageDto extends Page<CrimeLogDto> {
2525
perPage: number;
2626
page: number;
2727
}
28+
29+
30+
31+
export class PageRequest<T = string | number> {
32+
cursor?: T;
33+
perPage: number;
34+
}

src/rest/dto/player.dto.ts

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ export class PlayerSummaryDto extends LeaderboardEntryDto {
3030
newbieUnrankedGamesLeft: number;
3131
playedAnyGame: boolean;
3232
calibrationGamesLeft: number;
33+
34+
35+
hasUnrankedAccess: boolean;
3336
}
3437

3538
export class BanStatusDto {

src/rest/player.controller.ts

+13-5
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,14 @@ export class PlayerController {
9393
(ach) => ach.achievement_key === AchievementKey[key],
9494
) === -1,
9595
)
96-
.map((key) => ({
97-
steam_id: steamId,
98-
progress: 0,
99-
achievement_key: AchievementKey[key],
100-
} as AchievementEntity));
96+
.map(
97+
(key) =>
98+
({
99+
steam_id: steamId,
100+
progress: 0,
101+
achievement_key: AchievementKey[key],
102+
}) as AchievementEntity,
103+
);
101104

102105
return achievements.concat(paddedAchievements).map((t) => {
103106
if (t.match) {
@@ -198,6 +201,9 @@ offset $2 limit $3`,
198201

199202
play_time: lb.play_time,
200203
playedAnyGame: lb.any_games > 0,
204+
205+
hasUnrankedAccess: lb.bot_wins > 0,
206+
201207
newbieUnrankedGamesLeft:
202208
lb.ranked_games > 0
203209
? 0
@@ -230,6 +236,8 @@ offset $2 limit $3`,
230236

231237
playedAnyGame: summary && summary.any_games > 0,
232238

239+
hasUnrankedAccess: (summary?.bot_wins || 0) > 0,
240+
233241
newbieUnrankedGamesLeft:
234242
(summary?.ranked_games || 0) > 0
235243
? 0

src/rest/service/player.service.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type Summary =
1616
ranked_games: number;
1717
unranked_games: number;
1818
any_games: number;
19+
bot_wins: number;
1920
});
2021

2122
// TODO: we probably need to orm this shit up
@@ -160,6 +161,7 @@ order by score desc`;
160161
const some = await this.playerInMatchRepository.query(
161162
`with cte as (select plr."playerId" as steam_id,
162163
count(*)::int as any_games,
164+
sum((m.winner = plr.team )::int)::int as bot_wins,
163165
sum((m.matchmaking_mode in (0, 1))::int)::int as games,
164166
sum((m.winner = plr.team and m.matchmaking_mode in (0, 1))::int)::int as wins,
165167
sum((m.matchmaking_mode = 0 and m.timestamp > now() - '14 days'::interval)::int) as recent_ranked_games,
@@ -173,6 +175,7 @@ select p.steam_id,
173175
p.wins,
174176
p.games,
175177
p.any_games,
178+
p.bot_wins,
176179
p.mmr as mmr,
177180
avg(pim.kills)::float as kills,
178181
avg(pim.deaths)::float as deaths,
@@ -183,7 +186,7 @@ select p.steam_id,
183186
from cte p
184187
inner join player_in_match pim on pim."playerId" = p.steam_id
185188
inner join finished_match m on pim."matchId" = m.id
186-
group by p.steam_id, p.recent_ranked_games, p.mmr, p.games, p.wins, p.any_games`,
189+
group by p.steam_id, p.recent_ranked_games, p.mmr, p.games, p.wins, p.any_games, p.bot_wins`,
187190
[steam_id, MatchmakingMode.RANKED, MatchmakingMode.UNRANKED],
188191
);
189192

0 commit comments

Comments
 (0)