Commit | Line | Data |
---|---|---|
dd75774d | 1 | import { extractTime } from "@/utils/timeControl"; |
8ef2edfa | 2 | |
8ef2edfa BA |
3 | export function checkChallenge(c) |
4 | { | |
dac39588 BA |
5 | const vid = parseInt(c.vid); |
6 | if (isNaN(vid) || vid <= 0) | |
7 | return "Please select a variant"; | |
8ef2edfa | 8 | |
71468011 | 9 | const tc = extractTime(c.cadence); |
8ef2edfa BA |
10 | if (!tc) |
11 | return "Wrong time control"; | |
ab4f4bf2 | 12 | |
dac39588 BA |
13 | // Basic alphanumeric check for opponent name |
14 | if (!!c.to) | |
15 | { | |
4f298adb | 16 | // NOTE: slightly redundant (see data/userCheck.js) |
dac39588 BA |
17 | if (!c.to.match(/^[\w]+$/)) |
18 | return "Wrong characters in opponent name"; | |
19 | } | |
ab4f4bf2 | 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 | } |