Experimental multi-tabs support (TODO: prevent multi-connect)
[vchess.git] / client / src / data / challengeCheck.js
1 import { extractTime } from "@/utils/timeControl";
2
3 export 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.cadence);
10 if (!tc)
11 return "Wrong time control";
12
13 // Basic alphanumeric check for opponent name
14 if (!!c.to)
15 {
16 // NOTE: slightly redundant (see data/userCheck.js)
17 if (!c.to.match(/^[\w]+$/))
18 return "Wrong characters in opponent name";
19 }
20
21 // Allow custom FEN (and check it) only for individual challenges
22 if (c.fen.length > 0 && !!c.to)
23 {
24 if (!V.IsGoodFen(c.fen))
25 return "Bad FEN string";
26 }
27 else
28 c.fen = "";
29 }