// Automatic challenge sending, for tournaments
this.loadNewchallVariant(
() => {
- this.newchallenge = {
- fen: "",
- vid:
- this.st.variants
- .find(v => v.name == this.$route.query["variant"])
- .id,
- to: this.$route.query["challenge"],
- color: this.$route.query["color"] || '',
- cadence: this.$route.query["cadence"],
- // Tournament: no randomness (TODO: for now at least)
- randomness: 0,
- memorize: false
- };
- this.issueNewChallenge();
+ this.newchallenge = Object.assign(
+ this.newchallenge,
+ {
+ fen: "",
+ vid:
+ this.st.variants
+ .find(v => v.name == this.$route.query["variant"])
+ .id,
+ to: this.$route.query["challenge"],
+ color: this.$route.query["color"] || '',
+ cadence: this.$route.query["cadence"],
+ // Tournament: no randomness (TODO: for now at least)
+ randomness: 0,
+ memorize: false
+ }
+ );
+ window.doClick("modalNewgame");
+ //this.issueNewChallenge(); //NOTE: doesn't work yet.
},
this.$route.query["variant"]
);
}
}
);
- } else addChallenges();
+ }
+ else addChallenges();
}
}
);
// o: challenge or game
classifyObject: function(o) {
// No imported games here
- return (
- o.cadence.indexOf("d") >= 0
- ? "corr"
- : (o.cadence.indexOf("/") >= 0 ? "simul" : "live")
- );
+ return (o.cadence.indexOf("d") >= 0 ? "corr" : "live");
},
setDisplay: function(letter, type, e) {
this[letter + "display"] = type;
// For self multi-connects tests:
this.newConnect[data.from[0]] = true;
this.send("askidentity", { target: data.from[0], page: page });
- } else {
+ }
+ else {
this.people[data.from[0]].tmpIds[data.from[1]] =
{ page: page, focus: true };
this.$forceUpdate(); //TODO: shouldn't be required
"all"
);
}
- } else {
+ }
+ else {
// Remove the matching live game if now unreachable
const gid = data.page.match(/[a-zA-Z0-9]+$/)[0];
// Corr games are always reachable:
}
break;
}
- case "entersimul":
- // TODO: confirm box accept/refuse.
- // If accept, update seat (array in this case)
- break;
case "game": // Individual request
case "newgame": {
const game = data.data;
);
});
this.games = this.games.concat(moreGames);
- } else this.hasMore = false;
+ }
+ else this.hasMore = false;
}
}
);
.getElementById("btnC" + newChall.type)
.classList.add("somethingnew");
}
- if (!!chall.to) {
+ if (!!chall.to && chall.to == this.st.user.name) {
notify(
"New challenge",
// fromValues.name should exist since the player is online, but
// let's consider there is some chance that the challenge arrives
// right after we connected and before receiving the poll result:
- { body: "from " + (fromValues.name || "unknown yet...") }
+ { body: "from " + (fromValues.name || "@nonymous") }
);
}
}
position: parsedFen.position
//,orientation: parsedFen.turn
});
- } else this.newchallenge.diag = "";
+ }
+ else this.newchallenge.diag = "";
},
newChallFromPreset(pchall) {
this.partialResetNewchallenge();
if (ctype == "live") {
// Live challenges have a random ID
finishAddChallenge(null);
- } else {
+ }
+ else {
// Correspondence game: send challenge to server
ajax(
"/challenges",
else
// Corr challenge: just remove the challenge
this.send("deletechallenge_s", { data: { cid: c.id } });
- } else {
+ }
+ else {
const oppsid = this.getOppsid(c);
if (!!oppsid)
this.send("refusechallenge", { data: c.id, target: oppsid });
alert(this.st.tr["Please log in to accept corr challenges"]);
return;
}
- if (c.type == "simul") {
- // Just notify that I wanna enter the simultaneous game(s)
- // TODO: dans défi, indiquer si positions aleatoires, si tjours blancs ou noirs
- // --> /w30 ou b1h ou juste 30 (random, sans préfixe).
- // => message "entersimul" to c.from
- return;
- }
else {
c.accepted = true;
await import("@/variants/" + c.vname + ".js")
{ data: { id: c.id } }
);
}
- else if (c.type == "simul" && !!c.seat && Array.isArray(c.seat))
- // TODO: if some players entered, start game
- this.launchSimultaneous(c);
this.send("deletechallenge_s", { data: { cid: c.id } });
}
// In all cases, the challenge is consumed:
ArrayFun.remove(this.challenges, ch => ch.id == c.id);
},
// NOTE: when launching game, the challenge is already being deleted
- // TODO: adapt for simultaneous games, or just write a new function (better)
- launchSimultaneous: function(c) {
- // TODO
- },
launchGame: function(c) {
// White player index 0, black player index 1:
let players =
// on game just after, the main Hall will be notified.
};
if (c.type == "live") {
+ // TODO: ask my IP + opp IP, to add to game infos? (potential bans)
notifyNewgame();
this.startNewGame(gameInfo);
- } else {
+ // Increment game stats counter in DB
+ ajax(
+ "/gamestat",
+ "POST",
+ { data: { vid: gameInfo.vid } }
+ );
+ }
+ else {
// corr: game only on server
ajax(
"/games",
new Audio("/sounds/newgame.flac").play().catch(() => {});
notify(
"New live game",
- { body: "vs " + game.players[1-myIdx].name || "@nonymous" }
+ { body: "vs " + (game.players[1-myIdx].name || "@nonymous") }
);
}
this.$router.push("/game/" + gameInfo.id);