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