Several small improvements + integrate options + first working draft of Cwda
[vchess.git] / client / src / data / challengeCheck.js
index 789952f..554dfdf 100644 (file)
@@ -1,7 +1,7 @@
 import { extractTime } from "@/utils/timeControl";
 
 export function checkChallenge(c) {
-  const vid = parseInt(c.vid);
+  const vid = parseInt(c.vid, 10);
   if (isNaN(vid) || vid <= 0) return "Please select a variant";
 
   const tc = extractTime(c.cadence);
@@ -10,13 +10,16 @@ export function checkChallenge(c) {
   // Basic alphanumeric check for opponent name
   if (c.to) {
     // NOTE: slightly redundant (see data/userCheck.js)
-    if (!c.to.match(/^[\w]+$/)) return "Wrong characters in opponent name";
+    if (!c.to.match(/^[\w]+$/)) return "Name: alphanumerics and underscore";
   }
 
   // Allow custom FEN (and check it) only for individual challenges
   if (c.fen.length > 0 && !!c.to) {
-    if (!V.IsGoodFen(c.fen)) return "Bad FEN string";
-  } else c.fen = "";
+    if (!V.IsGoodFen(c.fen)) return "Errors in FEN";
+  }
+  else c.fen = "";
+
+  if (!V.IsValidOptions(c.options)) return "Invalid options";
 
   return "";
 }