msgid "Caution, this feature is experimental; any feedback will be appreciated"
msgstr "Attention, cette fonctionnalité est expérimentale ; tout commentaire sera grandement apprécié"
+msgid "Sorry, this server doesn't support player renaming."
+msgstr "Désolé, ce serveur ne prend pas en charge le changement de nom."
+
+msgid "Could not change your name. Please check that it's not already used by someone else!"
+msgstr "Impossible de changer votre nom. Veuillez vérifier que personne n’utilise déjà ce nom !"
+
msgid "joker"
msgstr "joker"
msgid "Caution, this feature is experimental; any feedback will be appreciated"
msgstr ""
+msgid "Sorry, this server doesn't support player renaming."
+msgstr ""
+
+msgid "Could not change your name. Please check that it's not already used by someone else!"
+msgstr ""
+
msgid "joker"
msgstr ""
(function () {
"use strict";
- const VERSION = 202005070130;
+ const VERSION = 202508050000;
const Conf = window.TrivabbleConf || {};
let currentMessageId = 1;
const waitingMsgs = [];
+ const msgCmdById = {};
let lastPlayer = null;
blink(countCell);
nbTilesInRacks += player.rackCount;
}
+
+ if (Object.prototype.hasOwnProperty.call(player, "newName")) {
+ const newName = player.newName;
+ tablePlayers[newName] = tablePlayers[playerName];
+ delete tablePlayers[playerName];
+ playerNameCell = tablePlayers[playerName].querySelector("td");
+ playerNameCell.textContent = newName;
+ if (playerName == getSetting("PlayerName")) {
+ setSetting("PlayerName", newName);
+ name.textContent = newName;
+ } else {
+ blink(playerNameCell);
+ }
+ }
}
refreshCurrentPlayer();
return;
}
+ let cmdName = null;
+
if (data.id) {
const pos = waitingMsgs.indexOf(data.id);
if (pos !== -1) {
waitingMsgs.splice(pos, 1);
+ cmdName = msgCmdById[data.id];
+ delete msgCmdById[data.id];
}
}
}
if (data.error) {
- fatalError(new Error("Error from the server: " + data.error + " - " + data.reason));
+ if (cmdName === "changePlayerName") {
+ alert(_("Could not change your name. Please check that it's not already used by someone else!");
+ } else {
+ fatalError(new Error("Error from the server: " + data.error + " - " + data.reason));
+ }
}
if (data.stopping) {
for (const cmd of cmds) {
waitingMsgs.push(currentMessageId);
cmd.id = currentMessageId++;
+ msgCmdById[cmd.id] = cmd.cmd;
}
}
}
function changeName() {
+ if (serverVersion < 202508050000) {
+ alert(_("Sorry, this server doesn't support player renaming."));
+ return;
+ }
+
myPrompt(
_("To change your name, enter a new one. You can keep using your current name by cancelling. Please note that if you change your name and you have games in progress, you will not be able to keep playing them anymore unless you get back to your current name."),
function (newName) {
- if (newName && newName.trim()) {
- setSetting("PlayerName", newName.trim());
- name.textContent = getSetting("PlayerName");
+ const n = newName && newName.trim();
+ if (n) {
+ sendCmds([{cmd: "changePlayerName", playerName: n}]);
}
},
- getSetting("PlayerNamer")
+ getSetting("PlayerName")
);
}
const CHECK_FIRST_WORD = 1; // 1: check, 0: not set, -1: no check
const FREEZE_PLAYED_TILES = -1; // 1: freeze, 0: not set, -1: no freeze
-const VERSION = 202005070100;
+const VERSION = 202508050000;
function envTrue(name) {
return (process.env[name] || "").toLowerCase() === "true";
return res;
}
+// if you add something there that stores the player name, please make sure to
+// update changePlayerName
// eslint-disable-next-line max-params
Game.prototype.init = function (lang, label, factor, checkFirstWord, freezePlayedTiles) {
this.label = label || DEFAULT_BOARD_LABEL;
this.playerJoined();
};
+Game.prototype.changePlayerName = function (playerName, newName) {
+ if (!newName || !newName.trim()) {
+ return "";
+ }
+
+ const n = newName.trim();
+ if (n === playerName) {
+ return "";
+ }
+
+ const currentPlayerID = "#" + playerName;
+ const newPlayerID = "#" + n;
+ if (
+ !Object.prototype.hasOwnProperty.call(this.racks, currentPlayerID) ||
+ Object.prototype.hasOwnProperty.call(this.racks, newPlayerID)
+ ) {
+ return "";
+ }
+
+ if (this.currentPlayer === playerName) {
+ this.currentPlayer = n;
+ }
+
+ this.racks[newPlayerID] = this.racks[currentPlayerID];
+ delete this.racks[currentPlayerID];
+
+ this.scores[newPlayerID] = this.scores[currentPlayerID];
+ delete this.scores[currentPlayerID];
+
+ for (const [key, player] of Object.entries(this.tileOwner)) {
+ if (player === playerName) {
+ this.tileOwner[key] = n;
+ }
+ }
+
+ this.pendingEvents.push({
+ players: [{
+ player: playerName,
+ newName: n
+ }]
+ });
+ this.commit();
+ return n;
+};
+
function newGameId() {
let number;
function joinGame(gameNumber, message) {
if (!gameNumber) {
- gameNumber = ((message) && (parseInt(message.gameNumber) > 0)) ? message.gameNumber : newGameId();
+ gameNumber = (message && (parseInt(message.gameNumber) > 0))
+ ? message.gameNumber
+ : newGameId();
}
- message.gameNumber = gameNumber;
-
let game;
if (games[gameNumber]) {
break;
}
+ case "changePlayerName": {
+ const newName = game.changePlayerName(playerName, cmd.playerName);
+ if (newName) {
+ message.playerName = newName;
+ }
+ reply(message, response, cmdNumber, {error: newName ? 0 : 1});
+ break;
+ }
+
case "hello": {
game.playerJoined(playerName);
reply(message, response, cmdNumber, {error: 0, boardLang: game.lang, boardLabel: game.label, bagFactor: game.factor, version: VERSION});