Adjustments
[vchess.git] / client / src / data / challengeCheck.js
CommitLineData
dd75774d 1import { extractTime } from "@/utils/timeControl";
8ef2edfa 2
6808d7a1 3export 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
BA
21
22 return "";
ab4f4bf2 23}