enhance(reversi): improve desync handling

This commit is contained in:
syuilo
2024-01-23 10:51:59 +09:00
parent f48f7149f8
commit e8ba0b3f54
17 changed files with 206 additions and 60 deletions

View File

@@ -4,7 +4,7 @@
*/
import { Inject, Injectable } from '@nestjs/common';
import type { MiReversiGame, ReversiGamesRepository } from '@/models/_.js';
import type { MiReversiGame } from '@/models/_.js';
import { DI } from '@/di-symbols.js';
import { bindThis } from '@/decorators.js';
import { ReversiService } from '@/core/ReversiService.js';
@@ -19,7 +19,6 @@ class ReversiGameChannel extends Channel {
constructor(
private reversiService: ReversiService,
private reversiGamesRepository: ReversiGamesRepository,
private reversiGameEntityService: ReversiGameEntityService,
id: string,
@@ -42,7 +41,6 @@ class ReversiGameChannel extends Channel {
case 'updateSettings': this.updateSettings(body.key, body.value); break;
case 'cancel': this.cancelGame(); break;
case 'putStone': this.putStone(body.pos, body.id); break;
case 'resync': this.resync(body.crc32); break;
case 'claimTimeIsUp': this.claimTimeIsUp(); break;
}
}
@@ -75,14 +73,6 @@ class ReversiGameChannel extends Channel {
this.reversiService.putStoneToGame(this.gameId!, this.user, pos, id);
}
@bindThis
private async resync(crc32: string | number) {
const game = await this.reversiService.checkCrc(this.gameId!, crc32);
if (game) {
this.send('resynced', game);
}
}
@bindThis
private async claimTimeIsUp() {
if (this.user == null) return;
@@ -104,9 +94,6 @@ export class ReversiGameChannelService implements MiChannelService<false> {
public readonly kind = ReversiGameChannel.kind;
constructor(
@Inject(DI.reversiGamesRepository)
private reversiGamesRepository: ReversiGamesRepository,
private reversiService: ReversiService,
private reversiGameEntityService: ReversiGameEntityService,
) {
@@ -116,7 +103,6 @@ export class ReversiGameChannelService implements MiChannelService<false> {
public create(id: string, connection: Channel['connection']): ReversiGameChannel {
return new ReversiGameChannel(
this.reversiService,
this.reversiGamesRepository,
this.reversiGameEntityService,
id,
connection,