Ticket #3806: 3806_player_gamesetup_v1.5.patch

File 3806_player_gamesetup_v1.5.patch, 30.9 KB (added by Imarok, 8 years ago)

pass string as ref and reverted L74

  • binaries/data/mods/public/gui/aiconfig/aiconfig.js

     
    1616    let aiSelection = Engine.GetGUIObjectByName("aiSelection");
    1717    aiSelection.list = g_AIDescriptions.map(ai => ai.data.name);
    1818    aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id);
    19     aiSelection.hidden = !settings.isController;
     19    aiSelection.hidden = !settings.canBeChanged;
    2020
    2121    let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText");
    2222    aiSelectionText.caption = aiSelection.list[aiSelection.selected];
    23     aiSelectionText.hidden = settings.isController;
     23    aiSelectionText.hidden = settings.canBeChanged;
    2424
    2525    let aiDiff = Engine.GetGUIObjectByName("aiDifficulty");
    2626    aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title;
    2727    aiDiff.selected = settings.difficulty;
    28     aiDiff.hidden = !settings.isController;
     28    aiDiff.hidden = !settings.canBeChanged;
    2929
    3030    let aiDiffText = Engine.GetGUIObjectByName("aiDifficultyText");
    3131    aiDiffText.caption = aiDiff.list[aiDiff.selected];
    32     aiDiffText.hidden = settings.isController;
     32    aiDiffText.hidden = settings.canBeChanged;
    3333}
    3434
    3535function selectAI(idx)
  • binaries/data/mods/public/gui/common/settings.js

     
    3737        "MapTypes": loadMapTypes(),
    3838        "MapSizes": loadSettingValuesFile("map_sizes.json"),
    3939        "PlayerDefaults": loadPlayerDefaults(),
     40        "GuestSettings": loadSettingValuesFile("guest_settings.json"),
    4041        "PopulationCapacities": loadPopulationCapacities(),
    4142        "StartingResources": loadSettingValuesFile("starting_resources.json"),
    4243        "VictoryConditions": loadVictoryConditions()
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

     
    55const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly));
    66const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes);
    77const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes);
     8const g_GuestSettings = prepareForDropdown(g_Settings && g_Settings.GuestSettings);
    89const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities);
    910const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources);
    1011const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions);
     
    270271    initCivNameList();
    271272    initMapTypes();
    272273    initMapFilters();
     274    initDropdowns();
    273275
    274276    if (g_IsController)
    275277    {
     
    277279        g_GameAttributes.matchID = Engine.GetMatchID();
    278280        g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked;
    279281        g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined;
    280 
    281         initMapNameList();
    282         initNumberOfPlayers();
    283         initGameSpeed();
    284         initPopulationCaps();
    285         initStartingResources();
    286         initCeasefire();
    287         initWonderDurations();
    288         initVictoryConditions();
    289         initMapSizes();
    290         initRadioButtons();
    291282    }
    292283    else
    293284        hideControls();
     
    309300    }
    310301}
    311302
     303function initDropdowns()
     304{
     305    initMapNameList();
     306    initNumberOfPlayers();
     307    initGameSpeed();
     308    initGuestSettings();
     309    initPopulationCaps();
     310    initStartingResources();
     311    initCeasefire();
     312    initWonderDurations();
     313    initVictoryConditions();
     314    initMapSizes();
     315    initRadioButtons();
     316}
     317
    312318function initMapTypes()
    313319{
    314320    let mapTypes = Engine.GetGUIObjectByName("mapType");
     
    318324        if (this.selected != -1)
    319325            selectMapType(this.list_data[this.selected]);
    320326    };
    321     if (g_IsController)
    322         mapTypes.selected = g_MapTypes.Default;
     327    mapTypes.selected = g_MapTypes.Default;
    323328}
    324329
    325330function initMapFilters()
     
    331336        if (this.selected != -1)
    332337            selectMapFilter(this.list_data[this.selected]);
    333338    };
    334     if (g_IsController)
    335         mapFilters.selected = 0;
     339    mapFilters.selected = 0;
    336340    g_GameAttributes.mapFilter = "default";
    337341}
    338342
     
    349353        "optionPopulationCap",
    350354        "optionStartingResources",
    351355        "optionCeasefire",
     356        "optionGuestSettings",
    352357        "optionRevealMap",
    353358        "optionExploreMap",
    354359        "optionDisableTreasures",
     
    398403function initGameSpeed()
    399404{
    400405    let gameSpeed = Engine.GetGUIObjectByName("gameSpeed");
    401     gameSpeed.hidden = false;
    402     Engine.GetGUIObjectByName("gameSpeedText").hidden = true;
    403406    gameSpeed.list = g_GameSpeeds.Title;
    404407    gameSpeed.list_data = g_GameSpeeds.Speed;
    405408    gameSpeed.onSelectionChange = function() {
     
    453456    };
    454457}
    455458
     459function initGuestSettings()
     460{
     461    let guestSettings = Engine.GetGUIObjectByName("guestSettings");
     462    guestSettings.list = g_GuestSettings.Title;
     463    guestSettings.list_data = g_GuestSettings.Data;
     464    guestSettings.onSelectionChange = function() {
     465        if (this.selected != -1)
     466            g_GameAttributes.GuestSettings = g_GuestSettings.Data[this.selected];
     467
     468        updateGameAttributes();
     469    };
     470    if (guestSettings.selected == -1)
     471        guestSettings.selected = g_GuestSettings.Default;
     472}
     473
    456474function initVictoryConditions()
    457475{
    458476    let victoryConditions = Engine.GetGUIObjectByName("victoryCondition");
     
    533551function hideControls()
    534552{
    535553    for (let ctrl of ["mapType", "mapFilter", "mapSelection", "victoryCondition", "gameSpeed", "numPlayers"])
    536         hideControl(ctrl, ctrl + "Text");
     554        hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl));
    537555
    538     // TODO: Shouldn't players be able to choose their own assignment?
    539556    for (let i = 0; i < g_MaxPlayers; ++i)
    540557    {
    541558        Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = true;
     
    573590}
    574591
    575592/**
     593 * Returns if the player is allowed to change this setting
     594 */
     595function canPlayerChange(setting)
     596{
     597    if (g_GameAttributes.mapType == "scenario" &&
     598         ["victoryCondition", "wonderDuration", "populationCap",
     599         "startingResources", "ceasefire", "revealMap", "exploreMap",
     600         "disableTreasures", "lockTeams", "playerCiv", "playerTeam", "playerColor"].indexOf(setting) >= 0)
     601        return false;
     602
     603    if (g_GameAttributes.mapType != "random" && setting == "numPlayers")
     604        return false;
     605
     606    if (g_IsController)
     607        return true;
     608 
     609     if (setting == "guestSettings")
     610        return false;
     611
     612    if (g_GuestSettings.Data.indexOf(setting) == -1)
     613        return g_GameAttributes.GuestSettings == "all";
     614
     615    return g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) >= g_GuestSettings.Data.indexOf(setting);
     616}
     617
     618/**
    576619 * Hide and set some elements depending on whether we play single- or multiplayer.
    577620 */
    578621function initMultiplayerSettings()
     
    579622{
    580623    Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked;
    581624    Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked;
     625    Engine.GetGUIObjectByName("optionGuestSettings").hidden = !g_IsNetworked;
    582626    Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient();
    583627
    584628    Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame();
     
    695739}
    696740
    697741/**
    698  * Called whenever the host changed any setting.
     742 * Called whenever someone changed any setting.
    699743 * @param {Object} message
    700744 */
    701745function handleGamesetupMessage(message)
     
    10461090function selectNumPlayers(num)
    10471091{
    10481092    // Avoid recursion
    1049     if (g_IsInGuiUpdate || !g_IsController || g_GameAttributes.mapType != "random")
     1093    if (g_IsInGuiUpdate || !canPlayerChange("numPlayers") || g_GameAttributes.mapType != "random")
    10501094        return;
    10511095
    10521096    // Unassign players from nonexistent slots
     
    11101154function selectMapType(type)
    11111155{
    11121156    // Avoid recursion
    1113     if (g_IsInGuiUpdate || !g_IsController)
     1157    if (g_IsInGuiUpdate)
    11141158        return;
    11151159
    11161160    if (!g_MapPath[type])
     
    11401184function selectMapFilter(id)
    11411185{
    11421186    // Avoid recursion
    1143     if (g_IsInGuiUpdate || !g_IsController)
     1187    if (g_IsInGuiUpdate)
    11441188        return;
    11451189
    11461190    g_GameAttributes.mapFilter = id;
     
    11531197function selectMap(name)
    11541198{
    11551199    // Avoid recursion
    1156     if (g_IsInGuiUpdate || !g_IsController || !name)
     1200    if (g_IsInGuiUpdate || !name)
    11571201        return;
    11581202
    11591203    // Reset some map specific properties which are not necessarily redefined on each map
     
    12851329
    12861330    if (g_IsNetworked)
    12871331    {
    1288         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1332        Engine.NetworkChangeSettings(g_GameAttributes);
    12891333        Engine.StartNetworkGame();
    12901334    }
    12911335    else
     
    13241368    let mapFilterIdx = g_MapFilters.findIndex(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "default"));
    13251369    let mapTypeIdx = g_GameAttributes.mapType !== undefined ? g_MapTypes.Name.indexOf(g_GameAttributes.mapType) : g_MapTypes.Default;
    13261370    let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default;
     1371    let guestSettingsIdx = g_GameAttributes.GuestSettings !== undefined ? g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) : g_GuestSettings.Default;
    13271372
    13281373    // These dropdowns might set the default (as they ignore g_IsInGuiUpdate)
    13291374    let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default;
     
    13341379    let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
    13351380    let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers;
    13361381
    1337     if (g_IsController)
    1338     {
    1339         Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx;
    1340         Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx;
    1341         Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName);
    1342         Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx;
    1343         Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1;
    1344         Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
    1345         Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
    1346         Engine.GetGUIObjectByName("populationCap").selected = popIdx;
    1347         Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
    1348         Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
    1349         Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
    1350     }
    1351     else
    1352     {
    1353         Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx];
    1354         Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name;
    1355         Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName));
    1356         initMapNameList();
    1357     }
     1382    Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx;
     1383    Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx;
     1384    Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName);
     1385    Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx;
     1386    Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1;
     1387    Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
     1388    Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
     1389    Engine.GetGUIObjectByName("populationCap").selected = popIdx;
     1390    Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
     1391    Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
     1392    Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
     1393    Engine.GetGUIObjectByName("guestSettings").selected = guestSettingsIdx;
    13581394
     1395
     1396    initMapNameList();
     1397
    13591398    // Can be visible to both host and clients
    13601399    Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default");
    13611400    Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
    13621401    Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
    13631402    Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
     1403    Engine.GetGUIObjectByName("guestSettingsText").caption = g_GuestSettings.Title[guestSettingsIdx];
    13641404    Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
    13651405    Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
    13661406    Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
    13671407    Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx];
     1408    Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx];
     1409    Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name;
     1410    Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName));
    13681411
    13691412    setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled);
    13701413    setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures);
     
    13871430    Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom;
    13881431    Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController;
    13891432    Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController;
    1390     hideControl("numPlayers", "numPlayersText", isRandom && g_IsController);
    13911433
    1392     let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
    1393 
    13941434    for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap",
    13951435                      "startingResources", "ceasefire", "revealMap",
    1396                       "exploreMap", "disableTreasures", "lockTeams"])
    1397         hideControl(ctrl, ctrl + "Text", notScenario);
     1436                      "exploreMap", "disableTreasures", "lockTeams",
     1437                      "gameSpeed", "guestSettings", "enableCheats",
     1438                      "mapSelection", "numPlayers", "mapType", "mapFilter"])
     1439        hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl));
    13981440
     1441    let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
     1442
    13991443    setMapDescription();
    14001444
    14011445    for (let i = 0; i < g_MaxPlayers; ++i)
     
    14311475        pCiv.selected = civ ? pCiv.list_data.indexOf(civ) : 0;
    14321476        pTeam.selected = team !== undefined && team >= 0 ? team+1 : 0;
    14331477
    1434         hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", g_IsController);
    1435         hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", notScenario);
    1436         hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", notScenario);
     1478        hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", canPlayerChange("playerAssignment"));
     1479        hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", canPlayerChange("playerCiv"));
     1480        hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", canPlayerChange("playerTeam"));
    14371481
    14381482        // Allow host to chose player colors on non-scenario maps
    14391483        let pColorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]");
    14401484        let pColorPickerHeading = Engine.GetGUIObjectByName("playerColorHeading");
    1441         let canChangeColors = g_IsController && g_GameAttributes.mapType != "scenario";
    1442         pColorPicker.hidden = !canChangeColors;
    1443         pColorPickerHeading.hidden = !canChangeColors;
    1444         if (canChangeColors)
     1485        pColorPicker.hidden = !canPlayerChange("playerColor");
     1486        pColorPickerHeading.hidden = !canPlayerChange("playerColor");
     1487        if (canPlayerChange("playerColor"))
    14451488            pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color));
    14461489    }
    14471490
     
    15081551 */
    15091552function updateGameAttributes()
    15101553{
    1511     if (g_IsInGuiUpdate || !g_IsController)
     1554    if (g_IsInGuiUpdate)
    15121555        return;
    15131556
    15141557    if (g_IsNetworked)
    15151558    {
    1516         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1559        Engine.NetworkChangeSettings(g_GameAttributes);
    15171560        if (g_LoadingState >= 2)
    15181561            sendRegisterGameStanza();
    15191562    }
     
    15271570
    15281571    Engine.PushGuiPage("page_aiconfig.xml", {
    15291572        "callback": "AIConfigCallback",
    1530         "isController": g_IsController,
     1573        "canBeChanged": canPlayerChange("playerConfig"),
    15311574        "playerSlot": playerSlot,
    15321575        "id": g_GameAttributes.settings.PlayerData[playerSlot].AI,
    15331576        "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff
     
    15411584{
    15421585    g_LastViewedAIPlayer = -1;
    15431586
    1544     if (!ai.save || !g_IsController)
     1587    if (!ai.save)
    15451588        return;
    15461589
    15471590    g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id;
     
    15481591    g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty;
    15491592
    15501593    if (g_IsNetworked)
    1551         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1594        Engine.NetworkChangeSettings(g_GameAttributes);
    15521595    else
    15531596        updatePlayerList();
    15541597}
     
    16441687        {
    16451688            g_GameAttributes.settings.PlayerData[playerSlot].AI = "";
    16461689            if (g_IsNetworked)
    1647                 Engine.SetNetworkGameAttributes(g_GameAttributes);
     1690                Engine.NetworkChangeSettings(g_GameAttributes);
    16481691        }
    16491692
    16501693        let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]");
     
    16551698            assignBox.selected = selection;
    16561699        assignBoxText.caption = hostNameList[selection];
    16571700
    1658         if (g_IsController)
    1659             assignBox.onselectionchange = function() {
    1660                 if (g_IsInGuiUpdate)
    1661                     return;
     1701        assignBox.onSelectionChange = function() {
     1702            if (g_IsInGuiUpdate)
     1703                return;
    16621704
    1663                 let guid = hostGuidList[this.selected];
    1664                 if (!guid)
    1665                 {
    1666                     if (g_IsNetworked)
    1667                         // Unassign any host from this player slot
    1668                         Engine.AssignNetworkPlayer(playerID, "");
    1669                     // Remove AI from this player slot
    1670                     g_GameAttributes.settings.PlayerData[playerSlot].AI = "";
    1671                 }
    1672                 else if (guid.substr(0, 3) == "ai:")
    1673                 {
    1674                     if (g_IsNetworked)
    1675                         // Unassign any host from this player slot
    1676                         Engine.AssignNetworkPlayer(playerID, "");
    1677                     // Set the AI for this player slot
    1678                     g_GameAttributes.settings.PlayerData[playerSlot].AI = guid.substr(3);
    1679                 }
    1680                 else
    1681                     swapPlayers(guid, playerSlot);
     1705            let guid = hostGuidList[this.selected];
     1706            if (!guid)
     1707            {
     1708                if (g_IsNetworked)
     1709                    // Unassign any host from this player slot
     1710                    Engine.AssignNetworkPlayer(playerID, "");
     1711                // Remove AI from this player slot
     1712                g_GameAttributes.settings.PlayerData[playerSlot].AI = "";
     1713            }
     1714            else if (guid.substr(0, 3) == "ai:")
     1715            {
     1716                if (g_IsNetworked)
     1717                    // Unassign any host from this player slot
     1718                    Engine.AssignNetworkPlayer(playerID, "");
     1719                // Set the AI for this player slot
     1720                g_GameAttributes.settings.PlayerData[playerSlot].AI = guid.substr(3);
     1721            }
     1722            else
     1723                swapPlayers(guid, playerSlot);
    16821724
    1683                 if (g_IsNetworked)
    1684                     Engine.SetNetworkGameAttributes(g_GameAttributes);
    1685                 else
    1686                     updatePlayerList();
    1687                 updateReadyUI();
    1688             };
     1725            if (g_IsNetworked)
     1726                Engine.NetworkChangeSettings(g_GameAttributes);
     1727            else
     1728                updatePlayerList();
     1729            updateReadyUI();
     1730        };
    16891731    }
    16901732
    16911733    g_IsInGuiUpdate = false;
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    8080                            <object name="playerAssignment[n]" type="dropdown" style="ModernDropDown" size="22%+37 2 50%+35 30" tooltip_style="onscreenToolTip">
    8181                                <translatableAttribute id="tooltip">Select player.</translatableAttribute>
    8282                            </object>
    83                             <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+5 0 50%+35 30"/>
     83                            <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+33 0 50%+35 30"/>
    8484                            <object name="playerConfig[n]" type="button" style="StoneButton" size="50%+40 4 50%+64 28"
    8585                                tooltip_style="onscreenToolTip"
    8686                                font="sans-bold-stroke-12"
     
    336336                    </object>
    337337                </object>
    338338
     339                <object name="optionGuestSettings" size="14 188 94% 206">
     340                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     341                        <translatableAttribute id="caption">Guest Settings:</translatableAttribute>
     342                    </object>
     343                    <object name="guestSettingsText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     344                    <object name="guestSettings" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
     345                        <translatableAttribute id="tooltip">Set which settings can be changed by every player.</translatableAttribute>
     346                    </object>
     347                </object>
     348
    339349                <object name="optionRevealMap" size="14 218 94% 246">
    340350                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    341351                        <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute>
  • source/gui/scripting/ScriptFunctions.cpp

     
    332332        LOGERROR("Failed to save game");
    333333}
    334334
    335 void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
     335void NetworkChangeSettings(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
    336336{
    337     ENSURE(g_NetServer);
     337    ENSURE(g_NetClient);
    338338    //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere
    339339    // (with no obvious reason).
    340340    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
     
    341341    JSAutoRequest rq(cx);
    342342    JS::RootedValue attribs(cx, attribs1);
    343343
    344     g_NetServer->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));
     344    g_NetClient->SendChangeSettingsMessage(&attribs, *(pCxPrivate->pScriptInterface));
    345345}
    346346
    347347void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName)
     
    427427
    428428void AssignNetworkPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int playerID, const std::string& guid)
    429429{
    430     ENSURE(g_NetServer);
     430    ENSURE(g_NetClient);
    431431
    432     g_NetServer->AssignPlayer(playerID, guid);
     432    g_NetClient->SendAssignPlayerMessage(playerID, guid);
    433433}
    434434
    435435void SetNetworkPlayerStatus(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& guid, int ready)
     
    10481048    scriptInterface.RegisterFunction<std::string, &GetPlayerGUID>("GetPlayerGUID");
    10491049    scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer");
    10501050    scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient");
    1051     scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes");
     1051    scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSettings>("NetworkChangeSettings");
    10521052    scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer");
    10531053    scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus");
    10541054    scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady");
  • source/network/NetClient.cpp

     
    321321    SetCurrState(NCS_UNCONNECTED);
    322322}
    323323
     324void CNetClient::SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface)
     325{
     326    // Pass the attributes as JSON, since that's the easiest safe
     327    // cross-thread way of passing script data
     328    std::string attrsJSON = scriptInterface.StringifyJSON(attrs, false);
     329    CChangeSettingsMessage changeSetting;
     330    changeSetting.m_Settings = attrsJSON;
     331    SendMessage(&changeSetting);
     332}
     333
     334void CNetClient::SendAssignPlayerMessage(const int playerID, const std::string& guid)
     335{
     336    CAssignPlayerMessage assignPlayer;
     337    assignPlayer.m_PlayerID = playerID;
     338    assignPlayer.m_GUIDToAssign = guid;
     339    SendMessage(&assignPlayer);
     340}
     341
    324342void CNetClient::SendChatMessage(const std::wstring& text)
    325343{
    326344    CChatMessage chat;
  • source/network/NetClient.h

     
    187187     */
    188188    void LoadFinished();
    189189
     190    void SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
     191
     192    void SendAssignPlayerMessage(const int playerID, const std::string& guid);
     193
    190194    void SendChatMessage(const std::wstring& text);
    191195
    192196    void SendReadyMessage(const int status);
  • source/network/NetMessage.cpp

     
    199199        pNewMessage = new CSimulationMessage(scriptInterface);
    200200        break;
    201201
     202    case NMT_CHANGE_SETTINGS:
     203        pNewMessage = new CChangeSettingsMessage;
     204        break;
     205    case NMT_ASSIGN_PLAYER:
     206        pNewMessage = new CAssignPlayerMessage;
     207        break;
     208
    202209    default:
    203210        LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType());
    204211        break;
  • source/network/NetMessages.h

     
    2828
    2929#define PS_PROTOCOL_MAGIC               0x5073013f      // 'P', 's', 0x01, '?'
    3030#define PS_PROTOCOL_MAGIC_RESPONSE      0x50630121      // 'P', 'c', 0x01, '!'
    31 #define PS_PROTOCOL_VERSION             0x01010012      // Arbitrary protocol
     31#define PS_PROTOCOL_VERSION             0x01010013      // Arbitrary protocol
    3232#define PS_DEFAULT_PORT                 0x5073          // 'P', 's'
    3333
    3434// Defines the list of message types. The order of the list must not change.
     
    3737// positive values.
    3838enum NetMessageType
    3939{
    40     NMT_CONNECT_COMPLETE = -256,    // Connection is complete
     40    NMT_CONNECT_COMPLETE = -256,
    4141    NMT_CONNECTION_LOST,
    42     NMT_INVALID = 0,        // Invalid message
    43     NMT_SERVER_HANDSHAKE,   // Handshake stage
     42    NMT_INVALID = 0,
     43    NMT_SERVER_HANDSHAKE,
    4444    NMT_CLIENT_HANDSHAKE,
    4545    NMT_SERVER_HANDSHAKE_RESPONSE,
    46     NMT_AUTHENTICATE,       // Authentication stage
     46    NMT_AUTHENTICATE,
    4747    NMT_AUTHENTICATE_RESULT,
    48     NMT_CHAT,       // Common chat message
     48    NMT_CHAT,
    4949    NMT_READY,
    5050    NMT_GAME_SETUP,
    5151    NMT_PLAYER_ASSIGNMENT,
     
    6666    NMT_LOADED_GAME,
    6767    NMT_GAME_START,
    6868    NMT_END_COMMAND_BATCH,
    69     NMT_SYNC_CHECK, // OOS-detection hash checking
    70     NMT_SYNC_ERROR, // OOS-detection error
     69    NMT_SYNC_CHECK,
     70    NMT_SYNC_ERROR,
    7171    NMT_SIMULATION_COMMAND,
     72    NMT_CHANGE_SETTINGS,
     73    NMT_ASSIGN_PLAYER,
    7274    NMT_LAST                // Last message in the list
    7375};
    7476
     
    109111END_NMT_CLASS()
    110112
    111113START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
    112     NMT_FIELD(CStr8, m_GUID)
     114    NMT_FIELD(CStr, m_GUID)
    113115    NMT_FIELD(CStrW, m_Name)
    114116    NMT_FIELD(CStrW, m_Password)
    115117    NMT_FIELD_INT(m_IsLocalClient, u8, 1)
     
    122124END_NMT_CLASS()
    123125
    124126START_NMT_CLASS_(Chat, NMT_CHAT)
    125     NMT_FIELD(CStr8, m_GUID) // ignored when client->server, valid when server->client
     127    NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client
    126128    NMT_FIELD(CStrW, m_Message)
    127129END_NMT_CLASS()
    128130
    129131START_NMT_CLASS_(Ready, NMT_READY)
    130     NMT_FIELD(CStr8, m_GUID)
     132    NMT_FIELD(CStr, m_GUID)
    131133    NMT_FIELD_INT(m_Status, u8, 1)
    132134END_NMT_CLASS()
    133135
    134136START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
    135137    NMT_START_ARRAY(m_Hosts)
    136         NMT_FIELD(CStr8, m_GUID)
     138        NMT_FIELD(CStr, m_GUID)
    137139        NMT_FIELD(CStrW, m_Name)
    138140        NMT_FIELD_INT(m_PlayerID, i8, 1)
    139141        NMT_FIELD_INT(m_Status, u8, 1)
     
    151153
    152154START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA)
    153155    NMT_FIELD_INT(m_RequestID, u32, 4)
    154     NMT_FIELD(CStr8, m_Data)
     156    NMT_FIELD(CStr, m_Data)
    155157END_NMT_CLASS()
    156158
    157159START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK)
     
    163165END_NMT_CLASS()
    164166
    165167START_NMT_CLASS_(Rejoined, NMT_REJOINED)
    166     NMT_FIELD(CStr8, m_GUID)
     168    NMT_FIELD(CStr, m_GUID)
    167169END_NMT_CLASS()
    168170
    169171START_NMT_CLASS_(Kicked, NMT_KICKED)
     
    172174END_NMT_CLASS()
    173175
    174176START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT)
    175     NMT_FIELD(CStr8, m_GUID)
     177    NMT_FIELD(CStr, m_GUID)
    176178    NMT_FIELD_INT(m_LastReceivedTime, u32, 4)
    177179END_NMT_CLASS()
    178180
    179181START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE)
    180182    NMT_START_ARRAY(m_Clients)
    181         NMT_FIELD(CStr8, m_GUID)
     183        NMT_FIELD(CStr, m_GUID)
    182184        NMT_FIELD_INT(m_MeanRTT, u32, 4)
    183185    NMT_END_ARRAY()
    184186END_NMT_CLASS()
     
    208210    NMT_END_ARRAY()
    209211END_NMT_CLASS()
    210212
     213START_NMT_CLASS_(ChangeSettings, NMT_CHANGE_SETTINGS)
     214    NMT_FIELD(CStr, m_GUID)
     215    NMT_FIELD(CStr, m_Settings)
     216END_NMT_CLASS()
     217
     218START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER)
     219    NMT_FIELD_INT(m_PlayerID, i8, 1)
     220    NMT_FIELD(CStr, m_GUIDToAssign)
     221END_NMT_CLASS()
     222
    211223END_NMTS()
    212224
    213225#else
  • source/network/NetServer.cpp

     
    649649    session->AddTransition(NSS_PREGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
    650650    session->AddTransition(NSS_PREGAME, (uint)NMT_CHAT, NSS_PREGAME, (void*)&OnChat, context);
    651651    session->AddTransition(NSS_PREGAME, (uint)NMT_READY, NSS_PREGAME, (void*)&OnReady, context);
     652    session->AddTransition(NSS_PREGAME, (uint)NMT_CHANGE_SETTINGS, NSS_PREGAME, (void*)&OnChangeSettings, context);
     653    session->AddTransition(NSS_PREGAME, (uint)NMT_ASSIGN_PLAYER, NSS_PREGAME, (void*)&OnAssignPlayer, context);
    652654    session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context);
    653655
    654656    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
     
    11061108    return true;
    11071109}
    11081110
     1111bool CNetServerWorker::OnChangeSettings(void* context, CFsmEvent* event)
     1112{
     1113    ENSURE(event->GetType() == (uint)NMT_CHANGE_SETTINGS);
     1114    CNetServerSession* session = (CNetServerSession*)context;
     1115    CNetServerWorker& server = session->GetServer();
     1116
     1117    CChangeSettingsMessage* message = (CChangeSettingsMessage*)event->GetParamRef();
     1118    server.m_GameAttributesQueue.push_back(message->m_Settings);
     1119    return true;
     1120}
     1121
     1122bool CNetServerWorker::OnAssignPlayer(void* context, CFsmEvent* event)
     1123{
     1124    ENSURE(event->GetType() == (uint)NMT_ASSIGN_PLAYER);
     1125    CNetServerSession* session = (CNetServerSession*)context;
     1126    CNetServerWorker& server = session->GetServer();
     1127
     1128    CAssignPlayerMessage* message = (CAssignPlayerMessage*)event->GetParamRef();
     1129    server.m_AssignPlayerQueue.emplace_back(message->m_PlayerID, message->m_GUIDToAssign);
     1130    return true;
     1131}
     1132
    11091133bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
    11101134{
    11111135    ENSURE(event->GetType() == (uint)NMT_LOADED_GAME);
  • source/network/NetServer.h

     
    270270    static bool OnInGame(void* context, CFsmEvent* event);
    271271    static bool OnChat(void* context, CFsmEvent* event);
    272272    static bool OnReady(void* context, CFsmEvent* event);
     273    static bool OnChangeSettings(void* context, CFsmEvent* event);
     274    static bool OnAssignPlayer(void* context, CFsmEvent* event);
    273275    static bool OnLoadedGame(void* context, CFsmEvent* event);
    274276    static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event);
    275277    static bool OnRejoined(void* context, CFsmEvent* event);