-export function checkChallenge(c)
-{
- const vid = parseInt(c.vid);
- if (isNaN(vid) || vid <= 0)
- return "Please select a variant";
-
- const tcParts = c.timeControl.replace(/ /g,"").split('+');
- const mainTime = tcParts[0].match(/([0-9]+)([smhd])/);
- if (!mainTime)
- return "Wrong time control";
- const mainTimeValue = parseInt(mainTime[1]);
- const mainTimeUnit = mainTime[2];
- if (isNaN(mainTimeValue) || mainTimeValue <= 0)
- return "Main time should be strictly positive";
- c.mainTime = timeUnitToSeconds(mainTimeValue, mainTimeUnit);
- if (tcParts.length >= 2)
- {
- const increment = tcParts[1].match(/([0-9]+)([smhd])/);
- if (!increment)
- return "Wrong time control";
- const incrementValue = parseInt(increment[1]);
- const incrementUnit = increment[2];
- if (isLargerUnit(incrementUnit, mainTimeUnit))
- return "Increment unit cannot be larger than main unit";
- if (isNaN(incrementValue) || incrementValue < 0)
- return "Increment must be positive";
- c.increment = timeUnitToSeconds(incrementValue, incrementUnit);
+ // Basic alphanumeric check for opponent name
+ if (c.to) {
+ // NOTE: slightly redundant (see data/userCheck.js)
+ if (!c.to.match(/^[\w]+$/)) return "Name: alphanumerics and underscore";