Ticket #3143: 3143_lobby_data.patch

File 3143_lobby_data.patch, 12.0 KB (added by Imarok, 8 years ago)

Show only full games as full. Display the connected players arranged according their team in the lobby window. Display observers in the lobby window. refs #3476

  • 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 playersAndObservers = formatPlayersAndObservers();
     680        Engine.SendChangeStateGame(playersAndObservers.players.length, playersAndObservers.players, playersAndObservers.observers);
    681681    }
    682682
    683683    Engine.SwitchGuiPage("page_loading.xml", {
     
    19221922        setReady(false, false);
    19231923}
    19241924
     1925function formatPlayersAndObservers()
     1926{
     1927    let observerNames = [];
     1928    let playerNames = [];
     1929    for (let guid in g_PlayerAssignments)
     1930    {
     1931        if (g_PlayerAssignments[guid].player == -1)
     1932            observerNames.push(g_PlayerAssignments[guid].name);
     1933        else
     1934            playerNames.push(g_PlayerAssignments[guid].name + ", " + (g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1].Team + 1));
     1935    }
     1936    return {"players": playerNames, "observers": observerNames.sort()};
     1937}
     1938
    19251939/**
    19261940 * Send the relevant gamesettings to the lobbybot.
    19271941 */
     
    19351949
    19361950    let mapSize = g_GameAttributes.mapType == "random" ? Engine.GetGUIObjectByName("mapSize").list_data[selectedMapSize] : "Default";
    19371951    let victoryCondition = Engine.GetGUIObjectByName("victoryCondition").list[selectedVictoryCondition];
    1938     let playerNames = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name).sort();
     1952    let playersAndObservers = formatPlayersAndObservers();
    19391953
    19401954    let stanza = {
    19411955        "name": g_ServerName,
     
    19451959        "mapSize": mapSize,
    19461960        "mapType": g_GameAttributes.mapType,
    19471961        "victoryCondition": victoryCondition,
    1948         "nbp": Object.keys(g_PlayerAssignments).length || 1,
    1949         "tnbp": g_GameAttributes.settings.PlayerData.length,
    1950         "players": playerNames.join(", ")
     1962        "nbp": playersAndObservers.players.length,
     1963        "maxnbp": g_GameAttributes.settings.PlayerData.length,
     1964        "players": playersAndObservers.players.join(", "),
     1965        "observers": playersAndObservers.observers.join(", ")
    19511966    };
    19521967
    19531968    // 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;
     
    555555            break;
    556556        case 'nPlayers':
    557557            // Compare playercount ratio
    558             sortA = a.nbp * b.tnbp;
    559             sortB = b.nbp * a.tnbp;
     558            sortA = a.nbp * b.maxnbp;
     559            sortB = b.nbp * a.maxnbp;
    560560            break;
    561561        case 'status':
    562562        default:
     
    591591        list_mapName.push(translate(game.niceMapName));
    592592        list_mapSize.push(translateMapSize(game.mapSize));
    593593        list_mapType.push(g_MapTypes.Title[mapTypeIdx] || "");
    594         list_nPlayers.push(game.nbp + "/" + game.tnbp);
     594        list_nPlayers.push(game.nbp + "/" + game.maxnbp);
    595595        list.push(gameName);
    596596        list_data.push(i);
    597597    }
     
    625625
    626626    Engine.GetGUIObjectByName("sgMapName").caption = translate(game.niceMapName);
    627627    Engine.GetGUIObjectByName("sgNbPlayers").caption = sprintf(
    628         translate("Players: %(current)s/%(total)s"), {
     628        translate("Players: %(current)s/%(max)s"), {
    629629            "current": game.nbp,
    630             "total": game.tnbp
     630            "max": game.maxnbp
    631631        });
    632632
    633     Engine.GetGUIObjectByName("sgPlayersNames").caption = game.players;
     633    let players = game.players.split(", ");
     634    let teams = [];
     635    for (let i = 0; i < players.length; i += 2)
     636    {
     637        let teamIndex = players[i + 1];
     638        if (!teams[teamIndex])
     639            teams[teamIndex] = [];
     640        teams[teamIndex].push(players[i]);
     641    }
     642
     643    let playersCaption = "";
     644    for (let team in teams)
     645    {
     646        teams[team].sort();
     647        playersCaption = playersCaption.concat(
     648            (team == 0? translate("No Team"): translate("Team") + " " + team)
     649            + ": " + teams[team].join(", ") + "\n"
     650        );
     651    }
     652    if (game.observers)
     653        playersCaption = playersCaption.concat(translate("Observers") + ": " + game.observers);
     654
     655    Engine.GetGUIObjectByName("sgPlayersNames").caption = playersCaption;
    634656    Engine.GetGUIObjectByName("sgMapSize").caption = translateMapSize(game.mapSize);
    635657
    636658    let mapTypeIdx = g_MapTypes.Name.indexOf(game.mapType);
     
    662684
    663685    let username = g_UserRating ? g_Username + " (" + g_UserRating + ")" : g_Username;
    664686
    665     if (game.state == "init" || game.players.split(", ").indexOf(username) > -1)
     687    if (game.state == "init" || game.players.str.split(/,\s[0-9],\s/).indexOf(username) > -1)
    666688        joinSelectedGame();
    667689    else
    668690        messageBox(
  • binaries/data/mods/public/gui/session/messages.js

     
    482482    // Update lobby gamestatus
    483483    if (g_IsController && Engine.HasXmppClient())
    484484    {
    485         let players = Object.keys(g_PlayerAssignments).map(guid => g_PlayerAssignments[guid].name);
    486         Engine.SendChangeStateGame(Object.keys(g_PlayerAssignments).length, players.join(", "));
     485        let observerNames = [];
     486        let playerNames = [];
     487        let playerData = getPlayerData();
     488        for (let guid in g_PlayerAssignments)
     489        {
     490            if (g_PlayerAssignments[guid].player == -1)
     491                observerNames.push(g_PlayerAssignments[guid].name);
     492            else
     493                playerNames.push(g_PlayerAssignments[guid].name + ", " + (playerData[g_PlayerAssignments[guid].player].team + 1));
     494        }
     495        observerNames = observerNames.sort();
     496        Engine.SendChangeStateGame(playerNames.length, playerNames.join(", "), observerNames.join(", "));
    487497    }
    488498}
    489499
  • source/lobby/IXmppClient.h

     
    3838    virtual void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data) = 0;
    3939    virtual void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data) = 0;
    4040    virtual void SendIqUnregisterGame() = 0;
    41     virtual void SendIqChangeStateGame(const std::string& nbp, const std::string& players) = 0;
     41    virtual void SendIqChangeStateGame(const std::string& nbp, const std::string& players, const std::string& observers) = 0;
    4242    virtual void SetNick(const std::string& nick) = 0;
    4343    virtual void GetNick(std::string& nick) = 0;
    4444    virtual void kick(const std::string& nick, const std::string& reason) = 0;
  • source/lobby/scripting/JSInterface_Lobby.cpp

     
    4545    scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendRegisterGame>("SendRegisterGame");
    4646    scriptInterface.RegisterFunction<void, JS::HandleValue, &JSI_Lobby::SendGameReport>("SendGameReport");
    4747    scriptInterface.RegisterFunction<void, &JSI_Lobby::SendUnregisterGame>("SendUnregisterGame");
    48     scriptInterface.RegisterFunction<void, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame");
     48    scriptInterface.RegisterFunction<void, std::wstring, std::wstring, std::wstring, &JSI_Lobby::SendChangeStateGame>("SendChangeStateGame");
    4949    scriptInterface.RegisterFunction<JS::Value, &JSI_Lobby::GetPlayerList>("GetPlayerList");
    5050    scriptInterface.RegisterFunction<void, &JSI_Lobby::LobbyClearPresenceUpdates>("LobbyClearPresenceUpdates");
    5151    scriptInterface.RegisterFunction<int, &JSI_Lobby::LobbyGetMucMessageCount>("LobbyGetMucMessageCount");
     
    170170    g_XmppClient->SendIqUnregisterGame();
    171171}
    172172
    173 void JSI_Lobby::SendChangeStateGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nbp, const std::wstring& players)
     173void JSI_Lobby::SendChangeStateGame(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::wstring& nbp, const std::wstring& players, const std::wstring& observers)
    174174{
    175175    if (!g_XmppClient)
    176176        return;
    177     g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players));
     177    g_XmppClient->SendIqChangeStateGame(utf8_from_wstring(nbp), utf8_from_wstring(players), utf8_from_wstring(observers));
    178178}
    179179
    180180JS::Value JSI_Lobby::GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate)
  • source/lobby/scripting/JSInterface_Lobby.h

     
    4343    void SendGameReport(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data);
    4444    void SendRegisterGame(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue data);
    4545    void SendUnregisterGame(ScriptInterface::CxPrivate* pCxPrivate);
    46     void SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nbp, const std::wstring& players);
     46    void SendChangeStateGame(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& nbp, const std::wstring& players, const std::wstring& observers);
    4747    JS::Value GetPlayerList(ScriptInterface::CxPrivate* pCxPrivate);
    4848    void LobbyClearPresenceUpdates(ScriptInterface::CxPrivate* pCxPrivate);
    4949    int LobbyGetMucMessageCount(ScriptInterface::CxPrivate* pCxPrivate);
  • source/lobby/XmppClient.cpp

     
    408408 * decides which - but we need to update the current players that are
    409409 * in-game so the server can make the calculation.
    410410 */
    411 void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players)
     411void XmppClient::SendIqChangeStateGame(const std::string& nbp, const std::string& players, const std::string& observers)
    412412{
    413413    glooxwrapper::JID xpartamuppJid(m_xpartamuppId);
    414414
     
    418418    glooxwrapper::Tag* game = glooxwrapper::Tag::allocate("game");
    419419    game->addAttribute("nbp", nbp);
    420420    game->addAttribute("players", players);
     421    game->addAttribute("observers", observers);
    421422    g->m_GameList.emplace_back(game);
    422423
    423424    glooxwrapper::IQ iq(gloox::IQ::Set, xpartamuppJid);
     
    502503    JSAutoRequest rq(cx);
    503504
    504505    scriptInterface.Eval("([])", ret);
    505     const char* stats[] = { "name", "ip", "port", "state", "nbp", "tnbp", "players", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" };
     506    const char* stats[] = { "name", "ip", "port", "state", "nbp", "maxnbp", "players", "observers", "mapName", "niceMapName", "mapSize", "mapType", "victoryCondition" };
    506507    for(const glooxwrapper::Tag* const& t : m_GameList)
    507508    {
    508509        JS::RootedValue game(cx);
  • source/lobby/XmppClient.h

     
    6868    void SendIqGameReport(ScriptInterface& scriptInterface, JS::HandleValue data);
    6969    void SendIqRegisterGame(ScriptInterface& scriptInterface, JS::HandleValue data);
    7070    void SendIqUnregisterGame();
    71     void SendIqChangeStateGame(const std::string& nbp, const std::string& players);
     71    void SendIqChangeStateGame(const std::string& nbp, const std::string& players, const std::string& observers);
    7272    void SetNick(const std::string& nick);
    7373    void GetNick(std::string& nick);
    7474    void kick(const std::string& nick, const std::string& reason);