- // fen cannot be undefined; TODO: generate fen on server instead
- create: function(c, cb)
- {
- db.serialize(function() {
- let query =
- "INSERT INTO Challenges " +
- "(added, uid, vid, nbPlayers, fen, mainTime, addTime) VALUES " +
- "(" + Date.now() + "," + c.uid + "," + c.vid + "," + c.nbPlayers +
- ",'" + c.fen + "'," + c.mainTime + "," + c.increment + ")";
- db.run(query, err => {
- if (!!err)
- return cb(err);
- db.get("SELECT last_insert_rowid() AS rowid", (err2,lastId) => {
- query =
- "INSERT INTO WillPlay VALUES " +
- "(" + lastId["rowid"] + "," + c.uid + ")";
- db.run(query, (err,ret) => {
- cb(err, lastId); //all we need is the challenge ID
- });
- });
- });
- });
- },
+ checkChallenge: function(c)
+ {
+ if (!c.vid.toString().match(/^[0-9]+$/))
+ return "Wrong variant ID";
+ if (!c.timeControl.match(/^[0-9dhms +]+$/))
+ return "Wrong characters in time control";
+ if (!c.fen.match(/^[a-zA-Z0-9, /-]*$/))
+ return "Bad FEN string";
+ return "";
+ },