diff options
| author | syuilo <Syuilotan@yahoo.co.jp> | 2024-01-24 16:37:06 +0900 |
|---|---|---|
| committer | syuilo <Syuilotan@yahoo.co.jp> | 2024-01-24 16:37:06 +0900 |
| commit | 5719a929ad5a048b59cf59b8683dcaaef01f2311 (patch) | |
| tree | 863fe9972e2ca7c63c06815c3f792acc755c14fc /packages/backend/src/core/ReversiService.ts | |
| parent | 2024.2.0-beta.6 (diff) | |
| download | sharkey-5719a929ad5a048b59cf59b8683dcaaef01f2311.tar.gz sharkey-5719a929ad5a048b59cf59b8683dcaaef01f2311.tar.bz2 sharkey-5719a929ad5a048b59cf59b8683dcaaef01f2311.zip | |
enhance(reversi): 変則なしマッチングを可能に
Diffstat (limited to 'packages/backend/src/core/ReversiService.ts')
| -rw-r--r-- | packages/backend/src/core/ReversiService.ts | 33 |
1 files changed, 24 insertions, 9 deletions
diff --git a/packages/backend/src/core/ReversiService.ts b/packages/backend/src/core/ReversiService.ts index f74416a58a..84721b2217 100644 --- a/packages/backend/src/core/ReversiService.ts +++ b/packages/backend/src/core/ReversiService.ts @@ -85,6 +85,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { map: game.map, bw: game.bw, crc32: game.crc32, + noIrregularRules: game.noIrregularRules, } satisfies Partial<MiReversiGame>; } @@ -138,7 +139,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { } @bindThis - public async matchAnyUser(me: MiUser, multiple = false): Promise<MiReversiGame | null> { + public async matchAnyUser(me: MiUser, options: { noIrregularRules: boolean }, multiple = false): Promise<MiReversiGame | null> { if (!multiple) { // 既にマッチしている対局が無いか探す(3分以内) const games = await this.reversiGamesRepository.find({ @@ -177,19 +178,29 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { 2, // 自分自身のIDが入っている場合もあるので2つ取得 'REV'); - const userIds = matchings.filter(id => id !== me.id); + const items = matchings.filter(id => !id.startsWith(me.id)); - if (userIds.length > 0) { - const matchedUserId = userIds[0]; + if (items.length > 0) { + const [matchedUserId, option] = items[0].split(':'); - await this.redisClient.zrem('reversi:matchAny', me.id, matchedUserId); + await this.redisClient.zrem('reversi:matchAny', + me.id, + matchedUserId, + me.id + ':noIrregularRules', + matchedUserId + ':noIrregularRules'); - const game = await this.matched(matchedUserId, me.id); + const game = await this.matched(matchedUserId, me.id, { + noIrregularRules: options.noIrregularRules || option === 'noIrregularRules', + }); return game; } else { const redisPipeline = this.redisClient.pipeline(); - redisPipeline.zadd('reversi:matchAny', Date.now(), me.id); + if (options.noIrregularRules) { + redisPipeline.zadd('reversi:matchAny', Date.now(), me.id + ':noIrregularRules'); + } else { + redisPipeline.zadd('reversi:matchAny', Date.now(), me.id); + } redisPipeline.expire('reversi:matchAny', 15, 'NX'); await redisPipeline.exec(); return null; @@ -203,7 +214,10 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { @bindThis public async matchAnyUserCancel(user: MiUser) { - await this.redisClient.zrem('reversi:matchAny', user.id); + const redisPipeline = this.redisClient.pipeline(); + redisPipeline.zrem('reversi:matchAny', user.id); + redisPipeline.zrem('reversi:matchAny', user.id + ':noIrregularRules'); + await redisPipeline.exec(); } @bindThis @@ -265,7 +279,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { } @bindThis - private async matched(parentId: MiUser['id'], childId: MiUser['id']): Promise<MiReversiGame> { + private async matched(parentId: MiUser['id'], childId: MiUser['id'], options: { noIrregularRules: boolean; }): Promise<MiReversiGame> { const game = await this.reversiGamesRepository.insert({ id: this.idService.gen(), user1Id: parentId, @@ -278,6 +292,7 @@ export class ReversiService implements OnApplicationShutdown, OnModuleInit { map: Reversi.maps.eighteight.data, bw: 'random', isLlotheo: false, + noIrregularRules: options.noIrregularRules, }).then(x => this.reversiGamesRepository.findOneOrFail({ where: { id: x.identifiers[0].id }, relations: ['user1', 'user2'], |