Merge remote-tracking branch 'misskey-dev/develop' into io

This commit is contained in:
まっちゃとーにゅ 2024-01-23 15:39:41 +09:00
commit 05b1b32f8e
No known key found for this signature in database
GPG key ID: 143DE582A97FE052
19 changed files with 269 additions and 53 deletions

View file

@ -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 type {
@ -254,7 +253,13 @@ export class ReversiService implements 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({
@ -275,12 +280,6 @@ export class ReversiService implements 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) {
@ -405,7 +404,7 @@ export class ReversiService implements OnModuleInit {
const serializeLogs = Reversi.Serializer.serializeLogs(logs);
const crc32 = CRC32.str(JSON.stringify(serializeLogs)).toString();
const crc32 = engine.calcCrc32().toString();
const updatedGame = {
...game,
@ -538,7 +537,7 @@ export class ReversiService implements OnModuleInit {
if (game == null) throw new Error('game not found');
if (crc32.toString() !== game.crc32) {
return await this.reversiGameEntityService.packDetail(game, null);
return game;
} else {
return null;
}