From 155012846d8f142515390adb2754b45cdfbb74ef Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 8 Mar 2018 17:57:57 +0900 Subject: #1200 --- src/api/endpoints/othello/games.ts | 9 ++++++--- src/api/endpoints/othello/match.ts | 20 +++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) (limited to 'src/api/endpoints') diff --git a/src/api/endpoints/othello/games.ts b/src/api/endpoints/othello/games.ts index 39963fcd29..dd9fb5ef52 100644 --- a/src/api/endpoints/othello/games.ts +++ b/src/api/endpoints/othello/games.ts @@ -7,12 +7,15 @@ module.exports = (params, user) => new Promise(async (res, rej) => { if (myErr) return rej('invalid my param'); const q = my ? { + is_started: true, $or: [{ - black_user_id: user._id + user1_id: user._id }, { - white_user_id: user._id + user2_id: user._id }] - } : {}; + } : { + is_started: true + }; // Fetch games const games = await Game.find(q, { diff --git a/src/api/endpoints/othello/match.ts b/src/api/endpoints/othello/match.ts index cb094bbc65..05b87a541a 100644 --- a/src/api/endpoints/othello/match.ts +++ b/src/api/endpoints/othello/match.ts @@ -3,6 +3,7 @@ import Matching, { pack as packMatching } from '../../models/othello-matching'; import Game, { pack as packGame } from '../../models/othello-game'; import User from '../../models/user'; import { publishOthelloStream } from '../../event'; +import { eighteight } from '../../../common/othello/maps'; module.exports = (params, user) => new Promise(async (res, rej) => { // Get 'user_id' parameter @@ -26,16 +27,21 @@ module.exports = (params, user) => new Promise(async (res, rej) => { _id: exist._id }); - const parentIsBlack = Math.random() > 0.5; - - // Start game + // Create game const game = await Game.insert({ created_at: new Date(), - black_user_id: parentIsBlack ? exist.parent_id : user._id, - white_user_id: parentIsBlack ? user._id : exist.parent_id, - turn_user_id: parentIsBlack ? exist.parent_id : user._id, + user1_id: exist.parent_id, + user2_id: user._id, + user1_accepted: false, + user2_accepted: false, + is_started: false, is_ended: false, - logs: [] + logs: [], + settings: { + map: eighteight, + bw: 'random', + is_llotheo: false + } }); // Reponse -- cgit v1.2.3-freya