85d8571d1bee65d6e71b9df28c18d392405ad643
1 // 'vname' for 'variant name' is defined when run on client side
2 function checkChallenge(c
, vname
)
4 const vid
= parseInt(c
.vid
);
5 if (isNaN(vid
) || vid
<= 0)
6 return "Please select a variant";
8 const mainTime
= parseInt(c
.mainTime
);
9 const increment
= parseInt(c
.increment
);
10 if (isNaN(mainTime
) || mainTime
<= 0)
11 return "Main time should be strictly positive";
12 if (isNaN(increment
) || increment
< 0)
13 return "Increment must be positive";
15 // Basic alphanumeric check for players names
19 if (p
.name
.length
> 0)
21 if (!p
.name
.match(/^[\w]+$/))
22 return "Wrong characters in players names";
27 if (playerCount
> 0 && playerCount
!= c
.nbPlayers
-1)
28 return "None, or all of the opponent names must be filled"
30 if (typeof document
!== "undefined") //client side
32 const V
= eval(vname
+ "Rules");
33 // Allow custom FEN (and check it) only for individual challenges
34 if (c
.fen
.length
> 0 && playerCount
> 0)
36 if (!V
.IsGoodFen(c
.fen
))
37 return "Bad FEN string";
42 c
.fen
= V
.GenRandInitFen();
47 // Just characters check on server:
48 if (!c
.fen
.match(/^[a-zA-Z0-9, /-]*$/))
49 return "Bad FEN string";
53 try { module
.exports
= checkChallenge
; } catch(e
) { } //for server