Started code review + some fixes (unfinished)
[vchess.git] / client / src / data / challengeCheck.js
CommitLineData
dd75774d 1import { extractTime } from "@/utils/timeControl";
8ef2edfa 2
6808d7a1 3export function checkChallenge(c) {
dac39588 4 const vid = parseInt(c.vid);
6808d7a1 5 if (isNaN(vid) || vid <= 0) return "Please select a variant";
8ef2edfa 6
71468011 7 const tc = extractTime(c.cadence);
6808d7a1 8 if (!tc) return "Wrong time control";
ab4f4bf2 9
dac39588 10 // Basic alphanumeric check for opponent name
6808d7a1
BA
11 if (c.to) {
12 // NOTE: slightly redundant (see data/userCheck.js)
13 if (!c.to.match(/^[\w]+$/)) return "Wrong characters in opponent name";
dac39588 14 }
ab4f4bf2 15
9d58ef95 16 // Allow custom FEN (and check it) only for individual challenges
6808d7a1
BA
17 if (c.fen.length > 0 && !!c.to) {
18 if (!V.IsGoodFen(c.fen)) return "Bad FEN string";
19 } else c.fen = "";
20
21 return "";
ab4f4bf2 22}