Skip to content

Commit 5079c0d

Browse files
committed
bug: fix issue with knife switching and doulbe eventing
1 parent 2370ebb commit 5079c0d

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/matches/events/KnifeSwitch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ export default class KnifeSwitch extends MatchEventProcessor<void> {
3535
},
3636
});
3737

38-
await this.matchAssistant.sendServerMatchId(this.matchId);
38+
await this.matchAssistant.knifeSwitch(this.matchId);
3939
}
4040
}

src/matches/match-assistant/match-assistant.service.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ export class MatchAssistantService {
6666
}
6767
}
6868

69+
public async knifeSwitch(matchId: string) {
70+
try {
71+
await this.command(matchId, `api_knife_switch`);
72+
} catch (error) {
73+
this.logger.warn(
74+
`[${matchId}] unable to send knife switch to the server`,
75+
error.message,
76+
);
77+
}
78+
}
79+
6980
public async uploadBackupRound(matchId: string, round: number) {
7081
try {
7182
await this.command(matchId, `upload_backup_round ${round}`);

src/matches/match-events.gateway.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { MatchEvents } from "./events";
1111
import MatchEventProcessor from "./events/abstracts/MatchEventProcessor";
1212
import { Logger } from "@nestjs/common";
1313
import { HasuraService } from "src/hasura/hasura.service";
14+
import { CacheService } from "src/cache/cache.service";
1415

1516
export type FiveStackGameServerWebSocketClient = WebSocket.WebSocket & {
1617
id: string;
@@ -25,6 +26,7 @@ export class MatchEventsGateway {
2526
private readonly logger: Logger,
2627
private readonly moduleRef: ModuleRef,
2728
private readonly hasura: HasuraService,
29+
private readonly cache: CacheService,
2830
) {}
2931

3032
async handleConnection(
@@ -78,6 +80,13 @@ export class MatchEventsGateway {
7880
@ConnectedSocket() client: WebSocket.WebSocket,
7981
) {
8082
const { matchId, messageId } = message;
83+
84+
if (await this.cache.has(`match-event-${matchId}-${messageId}`)) {
85+
return messageId;
86+
}
87+
88+
await this.cache.put(`${matchId}-${messageId}`, true, 10);
89+
8190
const { data, event } = message.data;
8291

8392
const Processor = MatchEvents[event as keyof typeof MatchEvents];

0 commit comments

Comments
 (0)