diff options
| author | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-29 01:20:40 +0900 |
|---|---|---|
| committer | Akihiko Odaki <nekomanma@pixiv.co.jp> | 2018-03-29 01:54:41 +0900 |
| commit | 90f8fe7e538bb7e52d2558152a0390e693f39b11 (patch) | |
| tree | 0f830887053c8f352b1cd0c13ca715fd14c1f030 /src/server/api/endpoints/othello/games | |
| parent | Implement remote account resolution (diff) | |
| download | misskey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.gz misskey-90f8fe7e538bb7e52d2558152a0390e693f39b11.tar.bz2 misskey-90f8fe7e538bb7e52d2558152a0390e693f39b11.zip | |
Introduce processor
Diffstat (limited to 'src/server/api/endpoints/othello/games')
| -rw-r--r-- | src/server/api/endpoints/othello/games/show.ts | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/server/api/endpoints/othello/games/show.ts b/src/server/api/endpoints/othello/games/show.ts new file mode 100644 index 0000000000..2b0db4dd00 --- /dev/null +++ b/src/server/api/endpoints/othello/games/show.ts @@ -0,0 +1,32 @@ +import $ from 'cafy'; +import Game, { pack } from '../../../models/othello-game'; +import Othello from '../../../../common/othello/core'; + +module.exports = (params, user) => new Promise(async (res, rej) => { + // Get 'game_id' parameter + const [gameId, gameIdErr] = $(params.game_id).id().$; + if (gameIdErr) return rej('invalid game_id param'); + + const game = await Game.findOne({ _id: gameId }); + + if (game == null) { + return rej('game not found'); + } + + const o = new Othello(game.settings.map, { + isLlotheo: game.settings.is_llotheo, + canPutEverywhere: game.settings.can_put_everywhere, + loopedBoard: game.settings.looped_board + }); + + game.logs.forEach(log => { + o.put(log.color, log.pos); + }); + + const packed = await pack(game, user); + + res(Object.assign({ + board: o.board, + turn: o.turn + }, packed)); +}); |