X-Git-Url: https://git.auder.net/?p=vchess.git;a=blobdiff_plain;f=client%2Fsrc%2Fdata%2FchallengeCheck.js;h=db205ac7b8953cd31bd908d868f160175f39e17e;hp=e0aa978cda51ba36f589eb2d53da883fa2cb96b6;hb=4f298adbee00942323fc7ec517117552aeb5a08a;hpb=dd75774d31a140cabf80790bdade9a40048c38d5 diff --git a/client/src/data/challengeCheck.js b/client/src/data/challengeCheck.js index e0aa978c..db205ac7 100644 --- a/client/src/data/challengeCheck.js +++ b/client/src/data/challengeCheck.js @@ -2,34 +2,24 @@ import { extractTime } from "@/utils/timeControl"; export function checkChallenge(c) { - const vid = parseInt(c.vid); - if (isNaN(vid) || vid <= 0) - return "Please select a variant"; + const vid = parseInt(c.vid); + if (isNaN(vid) || vid <= 0) + return "Please select a variant"; const tc = extractTime(c.timeControl); if (!tc) return "Wrong time control"; - // Less than 3 days ==> live game (TODO: heuristic... 40 moves also) - c.liveGame = (tc.mainTime + 40 * tc.increment < 3*24*60*60); - // Basic alphanumeric check for players names - let playerCount = 0; - for (const pname of c.to) - { - if (pname.length > 0) - { - // TODO: slightly redundant (see data/userCheck.js) - if (!pname.match(/^[\w]+$/)) - return "Wrong characters in players names"; - playerCount++; - } - } - - if (playerCount > 0 && playerCount != c.nbPlayers-1) - return "None, or all of the opponent names must be filled" + // Basic alphanumeric check for opponent name + if (!!c.to) + { + // NOTE: slightly redundant (see data/userCheck.js) + if (!c.to.match(/^[\w]+$/)) + return "Wrong characters in opponent name"; + } // Allow custom FEN (and check it) only for individual challenges - if (c.fen.length > 0 && playerCount > 0) + if (c.fen.length > 0 && !!c.to) { if (!V.IsGoodFen(c.fen)) return "Bad FEN string";