diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2024-01-23 10:51:59 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2024-01-23 10:51:59 +0900 |
| commit | e8ba0b3f54c2f25566f467d27c45c66139cbf102 (patch) | |
| tree | c45b699d83806eb2086efef6c0efa482f76c4212 /packages/backend/src/core/ReversiService.ts | |
| parent | :art: (diff) | |
| download | sharkey-e8ba0b3f54c2f25566f467d27c45c66139cbf102.tar.gz sharkey-e8ba0b3f54c2f25566f467d27c45c66139cbf102.tar.bz2 sharkey-e8ba0b3f54c2f25566f467d27c45c66139cbf102.zip | |
enhance(reversi): improve desync handling
Diffstat (limited to 'packages/backend/src/core/ReversiService.ts')
| -rw-r--r-- | packages/backend/src/core/ReversiService.ts | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/packages/backend/src/core/ReversiService.ts b/packages/backend/src/core/ReversiService.ts index 0d5f989c11..66296f1ed4 100644 --- a/packages/backend/src/core/ReversiService.ts +++ b/packages/backend/src/core/ReversiService.ts @@ -5,7 +5,6 @@ import { Inject, Injectable } from '@nestjs/common'; import * as Redis from 'ioredis'; -import CRC32 from 'crc-32'; import { ModuleRef } from '@nestjs/core'; import * as Reversi from 'misskey-reversi'; import { IsNull } from 'typeorm'; @@ -255,7 +254,13 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { bw = parseInt(game.bw, 10); } - const crc32 = CRC32.str(JSON.stringify(game.logs)).toString(); + const engine = new Reversi.Game(game.map, { + isLlotheo: game.isLlotheo, + canPutEverywhere: game.canPutEverywhere, + loopedBoard: game.loopedBoard, + }); + + const crc32 = engine.calcCrc32().toString(); const updatedGame = await this.reversiGamesRepository.createQueryBuilder().update() .set({ @@ -276,12 +281,6 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { this.cacheGame(updatedGame); //#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理 - const engine = new Reversi.Game(updatedGame.map, { - isLlotheo: updatedGame.isLlotheo, - canPutEverywhere: updatedGame.canPutEverywhere, - loopedBoard: updatedGame.loopedBoard, - }); - if (engine.isEnded) { let winnerId; if (engine.winner === true) { @@ -406,7 +405,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { const serializeLogs = Reversi.Serializer.serializeLogs(logs); - const crc32 = CRC32.str(JSON.stringify(serializeLogs)).toString(); + const crc32 = engine.calcCrc32().toString(); const updatedGame = { ...game, @@ -536,7 +535,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { if (game == null) throw new Error('game not found'); if (crc32.toString() !== game.crc32) { - return await this.reversiGameEntityService.packDetail(game); + return game; } else { return null; } |