- // Check all entries of gameInfo + cid:
- let error = GameModel.checkGameInfo(gameInfo);
- if (!error)
- {
- if (!cid.toString().match(/^[0-9]+$/))
- error = "Wrong challenge ID";
- }
- if (!!error)
- return res.json({errmsg:error});
- ChallengeModel.remove(cid);
- GameModel.create(
- gameInfo.vid, gameInfo.fen, gameInfo.cadence, gameInfo.players,
- (err,ret) => {
- access.checkRequest(res, err, ret, "Cannot create game", () => {
+ if (
+ Array.isArray(gameInfo.players) &&
+ gameInfo.players.some(p => p.id == req.userId) &&
+ cid.toString().match(/^[0-9]+$/) &&
+ GameModel.checkGameInfo(gameInfo)
+ ) {
+ ChallengeModel.remove(cid);
+ GameModel.create(
+ gameInfo.vid, gameInfo.fen, gameInfo.cadence, gameInfo.players,
+ (err,ret) => {