Commit | Line | Data |
---|---|---|
dd75774d | 1 | import { extractTime } from "@/utils/timeControl"; |
8ef2edfa | 2 | |
6808d7a1 | 3 | export function checkChallenge(c) { |
e50a8025 | 4 | const vid = parseInt(c.vid, 10); |
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) | |
866842c3 | 13 | if (!c.to.match(/^[\w]+$/)) return "Name: alphanumerics and underscore"; |
dac39588 | 14 | } |
ab4f4bf2 | 15 | |
9d58ef95 | 16 | // Allow custom FEN (and check it) only for individual challenges |
6808d7a1 | 17 | if (c.fen.length > 0 && !!c.to) { |
866842c3 | 18 | if (!V.IsGoodFen(c.fen)) return "Errors in FEN"; |
0705a80c BA |
19 | } |
20 | else c.fen = ""; | |
6808d7a1 | 21 | |
4313762d BA |
22 | if (!V.IsValidOptions(c.options)) return "Invalid options"; |
23 | ||
6808d7a1 | 24 | return ""; |
ab4f4bf2 | 25 | } |