diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2024-01-21 10:07:43 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2024-01-21 10:07:43 +0900 |
| commit | a17251d913c822e3113b47ed8135eecb3f06c445 (patch) | |
| tree | c90dadc24b723acaa4eba9c0a1f66bc5551c5e4f /packages/backend/src/server | |
| parent | enhance(frontend): ノート作成画面の添付メニューから直接フ... (diff) | |
| download | sharkey-a17251d913c822e3113b47ed8135eecb3f06c445.tar.gz sharkey-a17251d913c822e3113b47ed8135eecb3f06c445.tar.bz2 sharkey-a17251d913c822e3113b47ed8135eecb3f06c445.zip | |
enhance(reversi): tweak reversi
Diffstat (limited to 'packages/backend/src/server')
| -rw-r--r-- | packages/backend/src/server/api/endpoints/reversi/surrender.ts | 2 | ||||
| -rw-r--r-- | packages/backend/src/server/api/stream/channels/reversi-game.ts | 49 |
2 files changed, 17 insertions, 34 deletions
diff --git a/packages/backend/src/server/api/endpoints/reversi/surrender.ts b/packages/backend/src/server/api/endpoints/reversi/surrender.ts index c47d36be33..c809142e07 100644 --- a/packages/backend/src/server/api/endpoints/reversi/surrender.ts +++ b/packages/backend/src/server/api/endpoints/reversi/surrender.ts @@ -62,7 +62,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint- throw new ApiError(meta.errors.accessDenied); } - await this.reversiService.surrender(game, me); + await this.reversiService.surrender(game.id, me); }); } } diff --git a/packages/backend/src/server/api/stream/channels/reversi-game.ts b/packages/backend/src/server/api/stream/channels/reversi-game.ts index c5d05e5cfb..77eaa6d1d3 100644 --- a/packages/backend/src/server/api/stream/channels/reversi-game.ts +++ b/packages/backend/src/server/api/stream/channels/reversi-game.ts @@ -32,11 +32,6 @@ class ReversiGameChannel extends Channel { public async init(params: any) { this.gameId = params.gameId as string; - const game = await this.reversiGamesRepository.findOneBy({ - id: this.gameId, - }); - if (game == null) return; - this.subscriber.on(`reversiGameStream:${this.gameId}`, this.send); } @@ -46,7 +41,8 @@ class ReversiGameChannel extends Channel { case 'ready': this.ready(body); break; case 'updateSettings': this.updateSettings(body.key, body.value); break; case 'putStone': this.putStone(body.pos, body.id); break; - case 'heatbeat': this.heatbeat(body.crc32); break; + case 'checkState': this.checkState(body.crc32); break; + case 'claimTimeIsUp': this.claimTimeIsUp(); break; } } @@ -54,51 +50,38 @@ class ReversiGameChannel extends Channel { private async updateSettings(key: string, value: any) { if (this.user == null) return; - // TODO: キャッシュしたい - const game = await this.reversiGamesRepository.findOneBy({ id: this.gameId! }); - if (game == null) throw new Error('game not found'); - - this.reversiService.updateSettings(game, this.user, key, value); + this.reversiService.updateSettings(this.gameId!, this.user, key, value); } @bindThis private async ready(ready: boolean) { if (this.user == null) return; - const game = await this.reversiGamesRepository.findOneBy({ id: this.gameId! }); - if (game == null) throw new Error('game not found'); - - this.reversiService.gameReady(game, this.user, ready); + this.reversiService.gameReady(this.gameId!, this.user, ready); } @bindThis private async putStone(pos: number, id: string) { if (this.user == null) return; - // TODO: キャッシュしたい - const game = await this.reversiGamesRepository.findOneBy({ id: this.gameId! }); - if (game == null) throw new Error('game not found'); - - this.reversiService.putStoneToGame(game, this.user, pos, id); + this.reversiService.putStoneToGame(this.gameId!, this.user, pos, id); } @bindThis - private async heatbeat(crc32?: string | number | null) { - // TODO: キャッシュしたい - const game = await this.reversiGamesRepository.findOneBy({ id: this.gameId! }); - if (game == null) throw new Error('game not found'); - - if (!game.isStarted) return; + private async checkState(crc32: string | number) { + if (crc32 != null) return; - if (crc32 != null) { - if (crc32.toString() !== game.crc32) { - this.send('rescue', await this.reversiGameEntityService.packDetail(game, this.user)); - } + const game = await this.reversiService.checkCrc(this.gameId!, crc32); + if (game) { + this.send('rescue', game); } + } - if (this.user && (game.user1Id === this.user.id || game.user2Id === this.user.id)) { - this.reversiService.heatbeat(game, this.user); - } + @bindThis + private async claimTimeIsUp() { + if (this.user == null) return; + + this.reversiService.checkTimeout(this.gameId!); } @bindThis |