From b76fd9a7bb4e78d60153dd52d25a870903e37b12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20=C3=98rstad?= Date: Mon, 20 Apr 2020 11:58:28 +0200 Subject: [PATCH] Made sure players can only join tournaments that have not gone past the starttime --- backend/api/tournament.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/backend/api/tournament.js b/backend/api/tournament.js index 38fada7..fdb706f 100644 --- a/backend/api/tournament.js +++ b/backend/api/tournament.js @@ -220,6 +220,8 @@ router.post("/join", (req, res) => { active: true, // the array of players cannot already contain the player players: { $nin: [playerId] }, + // we dont want tournaments that have gone past their starttime + startTime: { $gte: new Date() }, }, // Add the player to the array { @@ -500,6 +502,17 @@ function roundcheck(client, tournament) { //if there are less then two people left in the first round, or zero people left in the first round //the tournament ends } + if (rounds.length > 0) { + // If there is only one player in the tournaments first round and the starttime + // has expired, we end the tournament + if ( + left.length < 2 && + active == 1 && + new Date(start) < new Date() + ) { + end = true; + } + } functions .timeOut(client, tournament, timedOut, timedOutRounds) .then( -- GitLab