| 1 | import { extractTime } from "@/utils/timeControl"; |
| 2 | |
| 3 | export function checkChallenge(c) { |
| 4 | const vid = parseInt(c.vid, 10); |
| 5 | if (isNaN(vid) || vid <= 0) return "Please select a variant"; |
| 6 | |
| 7 | const tc = extractTime(c.cadence); |
| 8 | if (!tc) return "Wrong time control"; |
| 9 | |
| 10 | // Basic alphanumeric check for opponent name |
| 11 | if (c.to) { |
| 12 | // NOTE: slightly redundant (see data/userCheck.js) |
| 13 | if (!c.to.match(/^[\w]+$/)) return "Name: alphanumerics and underscore"; |
| 14 | } |
| 15 | |
| 16 | // Allow custom FEN (and check it) only for individual challenges |
| 17 | if (c.fen.length > 0 && !!c.to) { |
| 18 | if (!V.IsGoodFen(c.fen)) return "Errors in FEN"; |
| 19 | } |
| 20 | else c.fen = ""; |
| 21 | |
| 22 | if (!V.IsValidOptions(c.options)) return "Invalid options"; |
| 23 | |
| 24 | return ""; |
| 25 | } |