X-Git-Url: https://git.auder.net/?a=blobdiff_plain;f=client%2Fsrc%2Fdata%2FchallengeCheck.js;h=554dfdffe2879798802595be04d856fc6ec12fa2;hb=4313762da3237b04f204e121a20cab3ba7bb5dd2;hp=db205ac7b8953cd31bd908d868f160175f39e17e;hpb=4f298adbee00942323fc7ec517117552aeb5a08a;p=vchess.git diff --git a/client/src/data/challengeCheck.js b/client/src/data/challengeCheck.js index db205ac7..554dfdff 100644 --- a/client/src/data/challengeCheck.js +++ b/client/src/data/challengeCheck.js @@ -1,29 +1,25 @@ import { extractTime } from "@/utils/timeControl"; -export function checkChallenge(c) -{ - const vid = parseInt(c.vid); - if (isNaN(vid) || vid <= 0) - return "Please select a variant"; +export function checkChallenge(c) { + const vid = parseInt(c.vid, 10); + if (isNaN(vid) || vid <= 0) return "Please select a variant"; - const tc = extractTime(c.timeControl); - if (!tc) - return "Wrong time control"; + const tc = extractTime(c.cadence); + if (!tc) return "Wrong time control"; // 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"; + if (c.to) { + // NOTE: slightly redundant (see data/userCheck.js) + if (!c.to.match(/^[\w]+$/)) return "Name: alphanumerics and underscore"; } // Allow custom FEN (and check it) only for individual challenges - if (c.fen.length > 0 && !!c.to) - { - if (!V.IsGoodFen(c.fen)) - return "Bad FEN string"; + if (c.fen.length > 0 && !!c.to) { + if (!V.IsGoodFen(c.fen)) return "Errors in FEN"; } - else - c.fen = ""; + else c.fen = ""; + + if (!V.IsValidOptions(c.options)) return "Invalid options"; + + return ""; }