summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/api')
-rw-r--r--src/api/stream/othello-game.ts30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/api/stream/othello-game.ts b/src/api/stream/othello-game.ts
index 5c826e5b41..9ca4864a54 100644
--- a/src/api/stream/othello-game.ts
+++ b/src/api/stream/othello-game.ts
@@ -113,6 +113,36 @@ export default function(request: websocket.request, connection: websocket.connec
}
});
+ //#region 盤面に最初から石がないなどして始まった瞬間に勝敗が決定する場合があるのでその処理
+ const o = new Othello(freshGame.settings.map, {
+ isLlotheo: freshGame.settings.is_llotheo
+ });
+
+ if (o.isEnded) {
+ let winner;
+ if (o.winner == 'black') {
+ winner = freshGame.black == 1 ? freshGame.user1_id : freshGame.user2_id;
+ } else if (o.winner == 'white') {
+ winner = freshGame.black == 1 ? freshGame.user2_id : freshGame.user1_id;
+ } else {
+ winner = null;
+ }
+
+ await Game.update({
+ _id: gameId
+ }, {
+ $set: {
+ is_ended: true,
+ winner_id: winner
+ }
+ });
+
+ publishOthelloGameStream(gameId, 'ended', {
+ winner_id: winner
+ });
+ }
+ //#endregion
+
publishOthelloGameStream(gameId, 'started', await pack(gameId));
}, 3000);
}