Ticket #3143: 3143_lobby_data_v2.6.3.patch

File 3143_lobby_data_v2.6.3.patch, 16.2 KB (added by Imarok, 8 years ago)

only remove the lengt limitation of escapeText for some parts

  • binaries/data/mods/public/gui/common/functions_utility.js

     
    5959 * Escape tag start and escape characters, so users cannot use special formatting.
    6060 * Also limit string length to 256 characters (not counting escape characters).
    6161 */
    62 function escapeText(text)
     62function escapeText(text, limitLength = true)
    6363{
    6464    if (!text)
    6565        return text;
    6666
    67     return text.substr(0, 255).replace(/\\/g, "\\\\").replace(/\[/g, "\\[");
     67    return limitLength ? text.substr(0, 255).replace(/\\/g, "\\\\").replace(/\[/g, "\\["); :
     68        text.replace(/\\/g, "\\\\").replace(/\[/g, "\\[");
    6869}
    6970
     71function unescapeText(text)
     72{
     73    if (!text)
     74        return text;
     75    return text.replace(/\\\\/g, "\\").replace(/\\\[/g, "\[");
     76}
     77
    7078function translateMapTitle(mapTitle)
    7179{
    7280    return mapTitle == "random" ? translateWithContext("map selection", "Random") : translate(mapTitle);
     
    226234
    227235    for (let playerData of playerDataArray)
    228236    {
    229         if (playerData == null || playerData.Civ == "gaia")
     237        if (playerData == null || playerData.Civ && playerData.Civ == "gaia")
    230238            continue;
    231239
    232240        ++playerIdx;
    233241        let teamIdx = playerData.Team;
    234242        let isAI = playerData.AI && playerData.AI != "";
    235         let playerState = playerStates && playerStates[playerIdx];
     243        let playerState = playerStates && playerStates[playerIdx] || playerData.State;
    236244        let isActive = !playerState || playerState == "active";
     245        let isOffline = playerData.Offline;
    237246
    238247        let playerDescription;
    239248        if (isAI)
    240249        {
    241             if (isActive)
    242                 // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
    243                 playerDescription = translate("%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s)");
     250            if (playerData.Civ)
     251            {
     252                if (isActive)
     253                    // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     254                    playerDescription = translate("%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s)");
     255                else
     256                    // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     257                    playerDescription = translate("%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s, %(state)s)");
     258            }
    244259            else
    245                 // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
    246                 playerDescription = translate("%(playerName)s (%(civ)s, %(AIdifficulty)s %(AIname)s, %(state)s)");
     260            {
     261                if (isActive)
     262                    // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     263                    playerDescription = translate("%(playerName)s (%(AIdifficulty)s %(AIname)s)");
     264                else
     265                    // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     266                    playerDescription = translate("%(playerName)s (%(AIdifficulty)s %(AIname)s, %(state)s)");
     267            }
    247268        }
    248269        else
    249270        {
    250             if (isActive)
    251                 // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
    252                 playerDescription = translate("%(playerName)s (%(civ)s)");
     271            if (isOffline)
     272            {
     273                if (playerData.Civ)
     274                    if (isActive)
     275                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     276                        playerDescription = translate("%(playerName)s (OFFLINE, %(civ)s)");
     277                    else
     278                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     279                        playerDescription = translate("%(playerName)s (OFFLINE, %(civ)s, %(state)s)");
     280                else
     281                    if (isActive)
     282                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     283                        playerDescription = translate("%(playerName)s (OFFLINE)");
     284                    else
     285                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     286                        playerDescription = translate("%(playerName)s (OFFLINE, %(state)s)");
     287            }
    253288            else
    254                 // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
    255                 playerDescription = translate("%(playerName)s (%(civ)s, %(state)s)");
     289            {
     290                if (playerData.Civ)
     291                    if (isActive)
     292                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     293                        playerDescription = translate("%(playerName)s (%(civ)s)");
     294                    else
     295                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     296                        playerDescription = translate("%(playerName)s (%(civ)s, %(state)s)");
     297                else
     298                    if (isActive)
     299                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     300                        playerDescription = translate("%(playerName)s");
     301                    else
     302                        // Translation: Describe a player in a selected game, f.e. in the replay- or savegame menu
     303                        playerDescription = translate("%(playerName)s (%(state)s)");
     304            }
    256305        }
    257306
    258307        // Sort player descriptions by team
     
    262311        playerDescriptions[teamIdx].push(sprintf(playerDescription, {
    263312            "playerName":
    264313                '[color="' +
    265                 rgbToGuiColor(playerData.Color || g_Settings.PlayerDefaults[playerIdx].Color) +
     314                ((typeof getPlayerColor == 'function' && (isAI && ("255 255 255") || getPlayerColor(playerData.Name))) ||
     315                    rgbToGuiColor(playerData.Color || g_Settings.PlayerDefaults[playerIdx].Color)) +
    266316                '"]' + escapeText(playerData.Name) + "[/color]",
    267317
    268318            "civ":
     
    283333    }
    284334
    285335    let teams = Object.keys(playerDescriptions);
     336    if (teams.indexOf("observer") > -1)
     337        teams.splice(teams.indexOf("observer"), 1);
    286338
     339    let teamDescription = [];
     340
    287341    // If there are no teams, merge all playersDescriptions
    288342    if (teams.length == 1)
    289         return playerDescriptions[teams[0]].join("\n") + "\n";
     343        teamDescription.push(playerDescriptions[teams[0]].join("\n"));
    290344
    291345    // If there are teams, merge "Team N:" + playerDescriptions
    292     return teams.map(team => {
     346    else
     347        teamDescription = teamDescription.concat(teams.map(team => {
    293348
    294         let teamCaption = team == -1 ?
    295             translate("No Team") :
    296             sprintf(translate("Team %(team)s"), { "team": +team + 1 });
     349            let teamCaption = team == -1 ?
     350                translate("No Team") :
     351                sprintf(translate("Team %(team)s"), { "team": +team + 1 });
    297352
    298         // Translation: Describe players of one team in a selected game, f.e. in the replay- or savegame menu or lobby
    299         return sprintf(translate("%(team)s:\n%(playerDescriptions)s"), {
    300             "team": '[font="sans-bold-14"]' + teamCaption + "[/font]",
    301             "playerDescriptions": playerDescriptions[team].join("\n")
    302         });
    303     }).join("\n\n");
     353            // Translation: Describe players of one team in a selected game, f.e. in the replay- or savegame menu or lobby
     354            return sprintf(translate("%(team)s:\n%(playerDescriptions)s"), {
     355                "team": '[font="sans-bold-14"]' + teamCaption + "[/font]",
     356                "playerDescriptions": playerDescriptions[team].join("\n")
     357            });
     358        }));
     359
     360    if (playerDescriptions.observer)
     361        teamDescription.push(sprintf(translatePlural(
     362            '[font="sans-bold-14"]Observer:[/font]\n%(observerDescription)s',
     363            '[font="sans-bold-14"]Observers:[/font]\n%(observerDescription)s',
     364            playerDescriptions.observer.length),
     365            {"observerDescription": playerDescriptions.observer.join("\n")}
     366        ));
     367
     368    return teamDescription.join("\n\n");
    304369}
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    676676{
    677677    if (g_IsController && Engine.HasXmppClient())
    678678    {
    679         let playerNames = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name);
    680         Engine.SendChangeStateGame(playerNames.length, playerNames.join(", "));
     679        let clients = formatClients();
     680        Engine.SendChangeStateGame(clients.nbp, clients.list);
    681681    }
    682682
    683683    Engine.SwitchGuiPage("page_loading.xml", {
     
    19361936        setReady(false, false);
    19371937}
    19381938
     1939function formatClients()
     1940{
     1941    let numberOfPlayers = 0;
     1942    let list = [];
     1943    for (let guid in g_PlayerAssignments)
     1944    {
     1945        if (g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1])
     1946        {
     1947            ++numberOfPlayers;
     1948            list.push({
     1949                "Name": g_PlayerAssignments[guid].name
     1950            });
     1951        }
     1952        else
     1953            list.push({
     1954                "Name": g_PlayerAssignments[guid].name,
     1955                "Team": "observer"
     1956            });
     1957    }
     1958    return {
     1959        "list": escapeText(JSON.stringify(list), false),
     1960        "nbp": numberOfPlayers
     1961    };
     1962}
     1963
    19391964/**
    19401965 * Send the relevant gamesettings to the lobbybot.
    19411966 */
     
    19491974
    19501975    let mapSize = g_GameAttributes.mapType == "random" ? Engine.GetGUIObjectByName("mapSize").list_data[selectedMapSize] : "Default";
    19511976    let victoryCondition = Engine.GetGUIObjectByName("victoryCondition").list[selectedVictoryCondition];
    1952     let playerNames = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name).sort();
     1977    let clients = formatClients();
    19531978
    19541979    let stanza = {
    19551980        "name": g_ServerName,
     
    19591984        "mapSize": mapSize,
    19601985        "mapType": g_GameAttributes.mapType,
    19611986        "victoryCondition": victoryCondition,
    1962         "nbp": Object.keys(g_PlayerAssignments).length || 1,
    1963         "tnbp": g_GameAttributes.settings.PlayerData.length,
    1964         "players": playerNames.join(", ")
     1987        "nbp": clients.nbp,
     1988        "maxnbp": g_GameAttributes.settings.PlayerData.length,
     1989        "players": clients.list,
    19651990    };
    19661991
    19671992    // Only send the stanza if the relevant settings actually changed
  • binaries/data/mods/public/gui/lobby/lobby.js

     
    285285        return true;
    286286
    287287    if (playersNumberFilter.selected != 0 &&
    288         game.tnbp != playersNumberFilter.list_data[playersNumberFilter.selected])
     288        game.maxnbp != playersNumberFilter.list_data[playersNumberFilter.selected])
    289289        return true;
    290290
    291291    if (mapTypeFilter.selected != 0 &&
     
    292292        game.mapType != mapTypeFilter.list_data[mapTypeFilter.selected])
    293293        return true;
    294294
    295     if (!showFullFilter.checked && game.tnbp <= game.nbp)
     295    if (!showFullFilter.checked && game.maxnbp <= game.nbp)
    296296        return true;
    297297
    298298    return false;
     
    546546            break;
    547547        case 'nPlayers':
    548548            // Compare playercount ratio
    549             sortA = a.nbp * b.tnbp;
    550             sortB = b.nbp * a.tnbp;
     549            sortA = a.nbp * b.maxnbp;
     550            sortB = b.nbp * a.maxnbp;
    551551            break;
    552552        case 'status':
    553553        default:
     
    582582        list_mapName.push(translateMapTitle(game.niceMapName));
    583583        list_mapSize.push(translateMapSize(game.mapSize));
    584584        list_mapType.push(g_MapTypes.Title[mapTypeIdx] || "");
    585         list_nPlayers.push(game.nbp + "/" + game.tnbp);
     585        list_nPlayers.push(game.nbp + "/" + game.maxnbp);
    586586        list.push(gameName);
    587587        list_data.push(i);
    588588    }
     
    616616
    617617    Engine.GetGUIObjectByName("sgMapName").caption = translateMapTitle(game.niceMapName);
    618618    Engine.GetGUIObjectByName("sgNbPlayers").caption = sprintf(
    619         translate("Players: %(current)s/%(total)s"), {
     619        translate("Players: %(current)s/%(max)s"), {
    620620            "current": game.nbp,
    621             "total": game.tnbp
     621            "max": game.maxnbp
    622622        });
    623623
    624     Engine.GetGUIObjectByName("sgPlayersNames").caption = game.players;
     624    Engine.GetGUIObjectByName("sgPlayersNames").caption = formatPlayerInfo(JSON.parse(unescapeText(game.players)));
    625625    Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(game.mapSize);
    626626
    627627    let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType);
     
    653653
    654654    let username = g_UserRating ? g_Username + " (" + g_UserRating + ")" : g_Username;
    655655
    656     if (game.state == "init" || game.players.split(", ").indexOf(username) > -1)
     656    if (game.state == "init" || JSON.parse(unescapeText(game.players)).some(player => player.Name == username))
    657657        joinSelectedGame();
    658658    else
    659659        messageBox(
  • binaries/data/mods/public/gui/session/messages.js

     
    544544
    545545    // Update lobby gamestatus
    546546    if (g_IsController && Engine.HasXmppClient())
    547     {
    548         let players = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name);
    549         Engine.SendChangeStateGame(Object.keys(g_PlayerAssignments).length, players.join(", "));
    550     }
     547        sendLobbyReportUpdate();
    551548}
    552549
    553550function onClientJoin(guid)
     
    746743
    747744function formatDefeatMessage(msg)
    748745{
     746    if (g_IsController && Engine.HasXmppClient())
     747        sendLobbyReportUpdate();
     748
    749749    return sprintf(
    750750        msg.resign ?
    751751            translate("%(player)s has resigned.") :
  • binaries/data/mods/public/gui/session/session.js

     
    288288    if (hotloadData)
    289289        g_Selection.selected = hotloadData.selection;
    290290
     291    if (g_IsController && Engine.HasXmppClient())
     292        sendLobbyReportUpdate();
     293
    291294    onSimulationUpdate();
    292295
    293296    setTimeout(displayGamestateNotifications, 1000);
  • binaries/data/mods/public/gui/session/utility_functions.js

     
    131131    alpha = alpha > 125 ? 125 : alpha;
    132132    return "color:255 0 0 " + alpha;
    133133}
     134 
     135function sendLobbyReportUpdate()
     136{
     137    let playerDataArray = JSON.parse(JSON.stringify(g_GameAttributes.settings.PlayerData));
     138    let numberOfPlayers = 0;
     139    let playerStates = {};
     140
     141    for (let player of g_Players)
     142    {
     143        playerStates[player.name] = {};
     144        playerStates[player.name].State = player.state;
     145        playerStates[player.name].Offline = player.offline;
     146    }
     147
     148    for (let guid in g_PlayerAssignments)
     149    {
     150        let pData = g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1];
     151
     152        //if client is no observer
     153        if (pData)
     154            ++numberOfPlayers;
     155        else
     156            playerDataArray.push({
     157                "Name": g_PlayerAssignments[guid].name,
     158                "Team": "observer"
     159            });
     160    }
     161
     162    for (let playerData of playerDataArray)
     163    {
     164        delete playerData.Civ;
     165        delete playerData.Color;
     166
     167        if (!g_GameAttributes.settings.LockTeams && playerData.Team != "observer")
     168            delete playerData.Team;
     169
     170        let pState = playerStates[playerData.Name];
     171        if (pState)
     172        {
     173            playerData.State = pState.State;
     174            playerData.Offline = pState.Offline;
     175        }
     176    }
     177    Engine.SendChangeStateGame(numberOfPlayers, escapeText(JSON.stringify(playerDataArray), false));
     178}
  • source/lobby/XmppClient.cpp

     
    502502    JSAutoRequest rq(cx);
    503503
    504504    scriptInterface.Eval("([])", ret);
    505     const char* stats[] = { "name", "ip", "port", "state", "nbp", "tnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" };
     505    const char* stats[] = { "name", "ip", "port", "state", "nbp", "maxnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" };
    506506    for(const glooxwrapper::Tag* const& t : m_GameList)
    507507    {
    508508        JS::RootedValue game(cx);
  • source/tools/XpartaMuPP/XpartaMuPP.py

     
    301301    if JID in self.gameList:
    302302      if self.gameList[JID]['nbp-init'] > data['nbp']:
    303303        logging.debug("change game (%s) state from %s to %s", JID, self.gameList[JID]['state'], 'waiting')
    304         self.gameList[JID]['nbp'] = data['nbp']
    305304        self.gameList[JID]['state'] = 'waiting'
    306305      else:
    307306        logging.debug("change game (%s) state from %s to %s", JID, self.gameList[JID]['state'], 'running')
    308         self.gameList[JID]['nbp'] = data['nbp']
    309307        self.gameList[JID]['state'] = 'running'
     308      self.gameList[JID]['nbp'] = data['nbp']
     309      self.gameList[JID]['players'] = data['players']
    310310
    311311## Class which manages different game reports from clients ##
    312312##   and calls leaderboard functions as appropriate.       ##