diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2018-06-17 08:10:54 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2018-06-17 08:10:54 +0900 |
| commit | 1ef66c962a1cea81dee4f5db32cd011feac7de44 (patch) | |
| tree | 006945b7ae9d437cebb0fabc5eb5a849cff518c5 /src/server/api/endpoints/othello/match.ts | |
| parent | Add missing semicolon (diff) | |
| download | misskey-1ef66c962a1cea81dee4f5db32cd011feac7de44.tar.gz misskey-1ef66c962a1cea81dee4f5db32cd011feac7de44.tar.bz2 misskey-1ef66c962a1cea81dee4f5db32cd011feac7de44.zip | |
reversi :white_flower: :100:
Diffstat (limited to 'src/server/api/endpoints/othello/match.ts')
| -rw-r--r-- | src/server/api/endpoints/othello/match.ts | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/src/server/api/endpoints/othello/match.ts b/src/server/api/endpoints/othello/match.ts deleted file mode 100644 index e70e579755..0000000000 --- a/src/server/api/endpoints/othello/match.ts +++ /dev/null @@ -1,95 +0,0 @@ -import $ from 'cafy'; import ID from '../../../../cafy-id'; -import Matching, { pack as packMatching } from '../../../../models/othello-matching'; -import OthelloGame, { pack as packGame } from '../../../../models/othello-game'; -import User from '../../../../models/user'; -import publishUserStream, { publishOthelloStream } from '../../../../publishers/stream'; -import { eighteight } from '../../../../othello/maps'; - -module.exports = (params, user) => new Promise(async (res, rej) => { - // Get 'userId' parameter - const [childId, childIdErr] = $.type(ID).get(params.userId); - if (childIdErr) return rej('invalid userId param'); - - // Myself - if (childId.equals(user._id)) { - return rej('invalid userId param'); - } - - // Find session - const exist = await Matching.findOne({ - parentId: childId, - childId: user._id - }); - - if (exist) { - // Destroy session - Matching.remove({ - _id: exist._id - }); - - // Create game - const game = await OthelloGame.insert({ - createdAt: new Date(), - user1Id: exist.parentId, - user2Id: user._id, - user1Accepted: false, - user2Accepted: false, - isStarted: false, - isEnded: false, - logs: [], - settings: { - map: eighteight.data, - bw: 'random', - isLlotheo: false - } - }); - - // Reponse - res(await packGame(game, user)); - - publishOthelloStream(exist.parentId, 'matched', await packGame(game, exist.parentId)); - - const other = await Matching.count({ - childId: user._id - }); - - if (other == 0) { - publishUserStream(user._id, 'othello_no_invites'); - } - } else { - // Fetch child - const child = await User.findOne({ - _id: childId - }, { - fields: { - _id: true - } - }); - - if (child === null) { - return rej('user not found'); - } - - // 以前のセッションはすべて削除しておく - await Matching.remove({ - parentId: user._id - }); - - // セッションを作成 - const matching = await Matching.insert({ - createdAt: new Date(), - parentId: user._id, - childId: child._id - }); - - // Reponse - res(); - - const packed = await packMatching(matching, child); - - // 招待 - publishOthelloStream(child._id, 'invited', packed); - - publishUserStream(child._id, 'othello_invited', packed); - } -}); |