Ticket #3806: 3806_player_gamesetup_v0.8.patch

File 3806_player_gamesetup_v0.8.patch, 25.9 KB (added by Imarok, 8 years ago)

wip patch

  • 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); //["None", "Color", "Civilization","Team", "All"];
    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);
     
    141142 */
    142143const g_RandomCiv = '[color="' + g_ColorRandom + '"]' + translateWithContext("civilization", "Random") + '[/color]';
    143144
    144 // Is this is a networked game, or offline
     145// Is this a networked game, or offline
    145146var g_IsNetworked;
    146147
    147148// Is this user in control of game settings (i.e. is a network server, or offline player)
     
    248249        g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked;
    249250        g_GameAttributes.settings.RatingEnabled = Engine.IsRankedGame() || undefined;
    250251
    251         initMapNameList();
    252         initNumberOfPlayers();
    253         initGameSpeed();
    254         initPopulationCaps();
    255         initStartingResources();
    256         initCeasefire();
    257         initWonderDurations();
    258         initVictoryConditions();
    259         initMapSizes();
    260         initRadioButtons();
     252        initDropdowns();
    261253    }
    262     else
    263         hideControls();
    264254
    265255    initMultiplayerSettings();
    266256    initPlayerAssignments();
     
    279269    }
    280270}
    281271
     272function initDropdowns()
     273{
     274    initMapNameList();
     275    initNumberOfPlayers();
     276    initGameSpeed();
     277    initGuestSettings();
     278    initPopulationCaps();
     279    initStartingResources();
     280    initCeasefire();
     281    initWonderDurations();
     282    initVictoryConditions();
     283    initMapSizes();
     284    initRadioButtons();
     285}
     286
    282287function initMapTypes()
    283288{
    284289    let mapTypes = Engine.GetGUIObjectByName("mapTypeSelection");
     
    319324        "optionPopulationCap",
    320325        "optionStartingResources",
    321326        "optionCeasefire",
     327        "optionGuestSettings",
    322328        "optionRevealMap",
    323329        "optionExploreMap",
    324330        "optionDisableTreasures",
     
    368374function initGameSpeed()
    369375{
    370376    let gameSpeed = Engine.GetGUIObjectByName("gameSpeed");
    371     gameSpeed.hidden = false;
    372     Engine.GetGUIObjectByName("gameSpeedText").hidden = true;
     377    gameSpeed.hidden = !canPlayerChange("gameSpeed");
     378    Engine.GetGUIObjectByName("gameSpeedText").hidden = canPlayerChange("gameSpeed");
    373379    gameSpeed.list = g_GameSpeeds.Title;
    374380    gameSpeed.list_data = g_GameSpeeds.Speed;
    375381    gameSpeed.onSelectionChange = function() {
     
    423429    };
    424430}
    425431
     432function initGuestSettings()
     433{
     434    let guestSettings = Engine.GetGUIObjectByName("guestSettings");
     435    guestSettings.list = g_GuestSettings.Title;
     436    guestSettings.list_data = g_GuestSettings.Data;
     437    guestSettings.selected = g_GuestSettings.Default;
     438    guestSettings.onSelectionChange = function() {
     439        if (this.selected != -1)
     440            g_GameAttributes.settings.GuestSettings = g_GuestSettings.Data[this.selected];
     441
     442        updateGameAttributes();
     443    };
     444}
     445
    426446function initVictoryConditions()
    427447{
    428448    let victoryConditions = Engine.GetGUIObjectByName("victoryCondition");
     
    502522 */
    503523function hideControls()
    504524{
    505     hideControl("mapTypeSelection", "mapTypeText");
    506     hideControl("mapFilterSelection", "mapFilterText");
    507     hideControl("mapSelection", "mapSelectionText");
    508     hideControl("victoryCondition", "victoryConditionText");
    509     hideControl("gameSpeed", "gameSpeedText");
    510     hideControl("numPlayersSelection", "numPlayersText");
     525    hideControl("mapTypeSelection", "mapTypeText", canPlayerChange("mapType"));
     526    hideControl("mapFilterSelection", "mapFilterText", canPlayerChange("mapFilter"));
     527    hideControl("mapSelection", "mapSelectionText", canPlayerChange("mapSelection"));
     528    hideControl("victoryCondition", "victoryConditionText", canPlayerChange("victoryCondition"));
     529    hideControl("gameSpeed", "gameSpeedText", canPlayerChange("gameSpeed"));
     530    hideControl("numPlayersSelection", "numPlayersText", canPlayerChange("numPlayers"));
    511531
    512532    // TODO: Shouldn't players be able to choose their own assignment?
    513533    for (let i = 0; i < g_MaxPlayers; ++i)
     
    547567}
    548568
    549569/**
     570 * Returns if the player is allowed to change this setting
     571 */
     572function canPlayerChange(setting) // TODO
     573{
     574    if (g_GameAttributes.mapType == "scenario" && ["victoryCondition", "wonderDuration", "populationCap", "startingResources", "ceasefire",
     575                                                  "revealMap", "exploreMap", "disableTreasures", "lockTeams"].indexOf(setting) >= 0)
     576        return false;
     577    if (g_GameAttributes.mapType != "random" && setting == "numPlayers")
     578        return false;
     579    //TODO scenario etc.?
     580    if (g_IsController)
     581        return true;
     582
     583    switch (setting)
     584    {
     585        case "guestSettings": return false;
     586        case "color": return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("color");
     587        case "playerCiv": return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("civ");
     588        case "playerTeam": return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("team");
     589        default: return g_GuestSettings.Data.indexOf(g_GameAttributes.settings.GuestSettings) >= g_GuestSettings.Data.indexOf("all");
     590    }
     591}
     592
     593/**
    550594 * Hide and set some elements depending on whether we play single- or multiplayer.
    551595 */
    552596function initMultiplayerSettings()
     
    553597{
    554598    Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked;
    555599    Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked;
     600    Engine.GetGUIObjectByName("optionGuestSettings").hidden = !g_IsNetworked;
    556601    Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient();
    557602
    558603    Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame();
     
    863908/**
    864909 * Sets the gameattributes the way they were the last time the user left the gamesetup.
    865910 */
    866 function loadPersistMatchSettings()
     911function loadPersistMatchSettings() //TODO is the guestSettings setting getting restored?
    867912{
    868913    if (Engine.ConfigDB_GetValue("user", "persistmatchsettings") != "true")
    869914        return;
     
    9871032        initGUIObjects();
    9881033        ++g_LoadingState;
    9891034    }
    990     else if (g_LoadingState == 2)
     1035    else if (g_LoadingState == 2 || g_LoadingState == 3)
    9911036    {
    9921037        while (true)
    9931038        {
     
    9981043            log("Net message: " + uneval(message));
    9991044
    10001045            if (g_NetMessageTypes[message.type])
     1046            {
    10011047                g_NetMessageTypes[message.type](message);
     1048                if (g_LoadingState == 2 && message.type == "gamesetup")
     1049                {
     1050                    ++g_LoadingState;
     1051                    initDropdowns();
     1052                    hideControls();
     1053                }
     1054            }
    10021055            else
    10031056                error("Unrecognised net message type " + message.type);
    10041057        }
     
    10141067function selectNumPlayers(num)
    10151068{
    10161069    // Avoid recursion
    1017     if (g_IsInGuiUpdate || !g_IsController || g_GameAttributes.mapType != "random")
     1070    if (g_IsInGuiUpdate || !canPlayerChange("numPlayers") || g_GameAttributes.mapType != "random")
    10181071        return;
    1019 
    10201072    // Unassign players from nonexistent slots
    10211073    if (g_IsNetworked)
    10221074    {
    10231075        for (let i = g_MaxPlayers; i > num; --i)
    1024             Engine.AssignNetworkPlayer(i, "");
     1076            Engine.AssignNetworkPlayer(i, ""); //TODO: AssignNetworkPlayer only works for host
    10251077    }
    10261078    else if (g_PlayerAssignments.local.player > num)
    10271079        g_PlayerAssignments.local.player = 1;
     
    13011353    let startingResIdx = mapSettings.StartingResources !== undefined ? g_StartingResources.Resources.indexOf(mapSettings.StartingResources) : g_StartingResources.Default;
    13021354    let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default;
    13031355    let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers;
     1356    let guestSettingsIdx = mapSettings.GuestSettings !== undefined ? g_GuestSettings.Data.indexOf(mapSettings.GuestSettings) : g_GuestSettings.Default;
    13041357
     1358    Engine.GetGUIObjectByName("mapTypeSelection").selected = mapTypeIdx;
     1359    Engine.GetGUIObjectByName("mapFilterSelection").selected = mapFilterIdx;
     1360    Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName);
     1361    Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx;
     1362    Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1;
     1363    Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
     1364    Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
     1365    Engine.GetGUIObjectByName("guestSettings").selected = guestSettingsIdx;
     1366    Engine.GetGUIObjectByName("populationCap").selected = popIdx;
     1367    Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
     1368    Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
     1369    Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
     1370
    13051371    if (g_IsController)
    1306     {
    1307         Engine.GetGUIObjectByName("mapTypeSelection").selected = mapTypeIdx;
    1308         Engine.GetGUIObjectByName("mapFilterSelection").selected = mapFilterIdx;
    1309         Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName);
    1310         Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx;
    1311         Engine.GetGUIObjectByName("numPlayersSelection").selected = numPlayers - 1;
    1312         Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx;
    1313         Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx;
    1314         Engine.GetGUIObjectByName("populationCap").selected = popIdx;
    1315         Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx;
    1316         Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx;
    1317         Engine.GetGUIObjectByName("startingResources").selected = startingResIdx;
    1318     }
    1319     else
    1320     {
    1321         Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx];
    1322         Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name;
    1323         Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName));
    13241372        initMapNameList();
    1325     }
    13261373
    13271374    // Can be visible to both host and clients
    13281375    Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default");
     
    13291376    Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers;
    13301377    Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx];
    13311378    Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx];
     1379    Engine.GetGUIObjectByName("guestSettingsText").caption = g_GuestSettings.Title[guestSettingsIdx];
    13321380    Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx];
    13331381    Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx];
    13341382    Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx];
    13351383    Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx];
     1384    Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx];
     1385    Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name;
     1386    Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName));
    13361387
    13371388    setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled);
    13381389    setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures);
     
    13551406    Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom;
    13561407    Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController;
    13571408    Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController;
    1358     hideControl("numPlayersSelection", "numPlayersText", isRandom && g_IsController);
     1409    hideControl("numPlayersSelection", "numPlayersText", canPlayerChange("numPlayers"));
    13591410
    1360     let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;
    1361     hideControl("victoryCondition", "victoryConditionText", notScenario);
     1411    let controlsToHide = ["victoryCondition", "wonderDuration", "populationCap",
     1412                          "startingResources", "ceasefire", "revealMap",
     1413                          "exploreMap", "disableTreasures", "lockTeams",
     1414                          "gameSpeed", "guestSettings", "enableCheats",
     1415                          "mapSelection"];
     1416    for (let ctrl of controlsToHide)
     1417        hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl));
     1418
     1419
     1420    let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController;
     1421    /*hideControl("victoryCondition", "victoryConditionText", notScenario);
    13621422    hideControl("wonderDuration", "wonderDurationText", notScenario);
    13631423    hideControl("populationCap", "populationCapText", notScenario);
    13641424    hideControl("startingResources", "startingResourcesText", notScenario);
     
    13681428    hideControl("disableTreasures", "disableTreasuresText", notScenario);
    13691429    hideControl("lockTeams", "lockTeamsText", notScenario);
    13701430
     1431    hideControl("gameSpeed", "gameSpeedText", canPlayerChange("gameSpeedText"));
     1432
     1433    hideControl("guestSettings", "guestSettingsText", canPlayerChange("guestSettingsText"));*/
     1434
    13711435    setMapDescription();
    13721436
    13731437    for (let i = 0; i < g_MaxPlayers; ++i)
     
    14801544 */
    14811545function updateGameAttributes()
    14821546{
    1483     if (g_IsInGuiUpdate || !g_IsController)
     1547    if (g_IsInGuiUpdate )//|| !g_IsController)TODO
    14841548        return;
    14851549
    14861550    if (g_IsNetworked)
    14871551    {
    1488         Engine.SetNetworkGameAttributes(g_GameAttributes);
     1552        Engine.NetworkChangeSettings(g_GameAttributes);
    14891553        if (g_LoadingState >= 2)
    14901554            sendRegisterGameStanza();
    14911555    }
  • binaries/data/mods/public/gui/gamesetup/gamesetup.xml

     
    251251                <action on="Press">cancelSetup();</action>
    252252            </object>
    253253
     254            <object
     255                name="testButton"
     256                type="button"
     257                style="StoneButton"
     258                size="100%-500 100%-52 100%-400 100%-24"
     259                tooltip_style="onscreenToolTip"
     260            >
     261                <translatableAttribute id="caption">Test</translatableAttribute>
     262                <action on="Press">warn("test: " + g_GameAttributes.settings.RevealMap);
     263                g_GameAttributes.settings.RevealMap = false;
     264                updateGameAttributes();
     265                warn("after: " + g_GameAttributes.settings.RevealMap)
     266                </action>
     267            </object>
     268 
    254269            <!-- Options -->
    255270            <object name="gameOptionsBox" size="100%-425 529 100%-25 525">
    256271                <!-- More Options Button -->
     
    336351                    </object>
    337352                </object>
    338353
     354                <object name="optionGuestSettings" size="14 188 94% 206">
     355                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
     356                        <translatableAttribute id="caption">Guest Settings:</translatableAttribute>
     357                    </object>
     358                    <object name="guestSettingsText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/>
     359                    <object name="guestSettings" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip">
     360                        <translatableAttribute id="tooltip">Set which settings can be changed by every player.</translatableAttribute>
     361                    </object>
     362                </object>
     363
    339364                <object name="optionRevealMap" size="14 218 94% 246">
    340365                    <object size="0 0 40% 28" type="text" style="ModernRightLabelText">
    341366                        <translatableAttribute id="caption" comment="Make sure to differentiate between the revealed map and explored map options!">Revealed Map:</translatableAttribute>
  • binaries/data/mods/public/simulation/data/settings/guest_settings.json

     
     1{
     2    "TranslatedKeys": ["Title"],
     3    "TranslationContext": "players can change",
     4    "Data":
     5    [
     6        {
     7            "Title": "None",
     8            "Data": "none"
     9        },
     10        {
     11            "Title": "Color",
     12            "Data": "color",
     13            "Default": true
     14        },
     15        {
     16            "Title": "Color & Civilization",
     17            "Data": "civ"
     18        },
     19        {
     20            "Title": "Color, Civilization & Team",
     21            "Data": "team"
     22        },
     23        {
     24            "Title": "All",
     25            "Data": "all"
     26        }
     27    ]
     28}
  • source/gui/scripting/ScriptFunctions.cpp

     
    344344    g_NetServer->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));
    345345}
    346346
     347void NetworkChangeSettings(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)
     348{
     349    ENSURE(g_NetClient);
     350    //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere
     351    // (with no obvious reason).
     352    JSContext* cx = pCxPrivate->pScriptInterface->GetContext();
     353    JSAutoRequest rq(cx);
     354    JS::RootedValue attribs(cx, attribs1);
     355
     356    g_NetClient->SendChangeSettingsMessage(&attribs, *(pCxPrivate->pScriptInterface));
     357}
     358
    347359void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName)
    348360{
    349361    ENSURE(!g_NetClient);
     
    10431055    scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer");
    10441056    scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient");
    10451057    scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes");
     1058    scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSettings>("NetworkChangeSettings");
    10461059    scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer");
    10471060    scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus");
    10481061    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    /*const CStr& setting, const CStr& value)
     334{
     335    CChangeSettingsMessage changeSetting;
     336    changeSetting.m_Setting = setting;
     337    changeSetting.m_Value = value;
     338    SendMessage(&changeSetting);*/
     339}
     340
    324341void CNetClient::SendChatMessage(const std::wstring& text)
    325342{
    326343    CChatMessage chat;
  • source/network/NetClient.h

     
    187187     */
    188188    void LoadFinished();
    189189
     190    void SendChangeSettingsMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface);
     191
    190192    void SendChatMessage(const std::wstring& text);
    191193
    192194    void SendReadyMessage(const int status);
  • source/network/NetMessage.cpp

     
    198198    case NMT_SIMULATION_COMMAND:
    199199        pNewMessage = new CSimulationMessage(scriptInterface);
    200200        break;
     201    case NMT_CHANGE_SETTINGS:
     202        pNewMessage = new CChangeSettingsMessage;
     203        break;
    201204
    202205    default:
    203206        LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType());
  • source/network/NetMessages.h

     
    4545    NMT_SERVER_HANDSHAKE_RESPONSE,
    4646    NMT_AUTHENTICATE,       // Authentication stage
    4747    NMT_AUTHENTICATE_RESULT,
    48     NMT_CHAT,       // Common chat message
     48    NMT_CHAT,               // Common chat message
    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,         // OOS-detection hash checking
     70    NMT_SYNC_ERROR,         // OOS-detection error
    7171    NMT_SIMULATION_COMMAND,
     72    NMT_CHANGE_SETTINGS,        // User changes a setting in gamesetup
    7273    NMT_LAST                // Last message in the list
    7374};
    7475
     
    109110END_NMT_CLASS()
    110111
    111112START_NMT_CLASS_(Authenticate, NMT_AUTHENTICATE)
    112     NMT_FIELD(CStr8, m_GUID)
     113    NMT_FIELD(CStr, m_GUID)
    113114    NMT_FIELD(CStrW, m_Name)
    114115    NMT_FIELD(CStrW, m_Password)
    115116    NMT_FIELD_INT(m_IsLocalClient, u8, 1)
     
    122123END_NMT_CLASS()
    123124
    124125START_NMT_CLASS_(Chat, NMT_CHAT)
    125     NMT_FIELD(CStr8, m_GUID) // ignored when client->server, valid when server->client
     126    NMT_FIELD(CStr, m_GUID) // ignored when client->server, valid when server->client
    126127    NMT_FIELD(CStrW, m_Message)
    127128END_NMT_CLASS()
    128129
    129130START_NMT_CLASS_(Ready, NMT_READY)
    130     NMT_FIELD(CStr8, m_GUID)
     131    NMT_FIELD(CStr, m_GUID)
    131132    NMT_FIELD_INT(m_Status, u8, 1)
    132133END_NMT_CLASS()
    133134
    134135START_NMT_CLASS_(PlayerAssignment, NMT_PLAYER_ASSIGNMENT)
    135136    NMT_START_ARRAY(m_Hosts)
    136         NMT_FIELD(CStr8, m_GUID)
     137        NMT_FIELD(CStr, m_GUID)
    137138        NMT_FIELD(CStrW, m_Name)
    138139        NMT_FIELD_INT(m_PlayerID, i8, 1)
    139140        NMT_FIELD_INT(m_Status, u8, 1)
     
    151152
    152153START_NMT_CLASS_(FileTransferData, NMT_FILE_TRANSFER_DATA)
    153154    NMT_FIELD_INT(m_RequestID, u32, 4)
    154     NMT_FIELD(CStr8, m_Data)
     155    NMT_FIELD(CStr, m_Data)
    155156END_NMT_CLASS()
    156157
    157158START_NMT_CLASS_(FileTransferAck, NMT_FILE_TRANSFER_ACK)
     
    163164END_NMT_CLASS()
    164165
    165166START_NMT_CLASS_(Rejoined, NMT_REJOINED)
    166     NMT_FIELD(CStr8, m_GUID)
     167    NMT_FIELD(CStr, m_GUID)
    167168END_NMT_CLASS()
    168169
    169170START_NMT_CLASS_(Kicked, NMT_KICKED)
     
    172173END_NMT_CLASS()
    173174
    174175START_NMT_CLASS_(ClientTimeout, NMT_CLIENT_TIMEOUT)
    175     NMT_FIELD(CStr8, m_GUID)
     176    NMT_FIELD(CStr, m_GUID)
    176177    NMT_FIELD_INT(m_LastReceivedTime, u32, 4)
    177178END_NMT_CLASS()
    178179
    179180START_NMT_CLASS_(ClientPerformance, NMT_CLIENT_PERFORMANCE)
    180181    NMT_START_ARRAY(m_Clients)
    181         NMT_FIELD(CStr8, m_GUID)
     182        NMT_FIELD(CStr, m_GUID)
    182183        NMT_FIELD_INT(m_MeanRTT, u32, 4)
    183184    NMT_END_ARRAY()
    184185END_NMT_CLASS()
     
    208209    NMT_END_ARRAY()
    209210END_NMT_CLASS()
    210211
     212START_NMT_CLASS_(ChangeSettings, NMT_CHANGE_SETTINGS)
     213    NMT_FIELD(CStr, m_GUID)
     214    NMT_FIELD(CStr, m_Settings)
     215END_NMT_CLASS()
     216
    211217END_NMTS()
    212218
    213219#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);
    652653    session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context);
    653654
    654655    session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context);
     
    11061107    return true;
    11071108}
    11081109
     1110bool CNetServerWorker::OnChangeSettings(void* context, CFsmEvent* event)
     1111{
     1112    ENSURE(event->GetType() == (uint)NMT_CHANGE_SETTINGS);
     1113    CNetServerSession* session = (CNetServerSession*)context;
     1114    CNetServerWorker& server = session->GetServer();
     1115
     1116    CChangeSettingsMessage* message = (CChangeSettingsMessage*)event->GetParamRef();
     1117    server.m_GameAttributesQueue.push_back(message->m_Settings);
     1118    return true;
     1119    /*JS::RootedValue gameAttributesVal(cx);
     1120    GetScriptInterface().ParseJSON(newGameAttributes.back(), &gameAttributesVal);
     1121    UpdateGameAttributes(&gameAttributesVal);*/
     1122
     1123    //UpdateGameAttributes(&(message->m_Settings));
     1124
     1125    /*
     1126    message->m_GUID = session->GetGUID();
     1127    PushGuiMessage??
     1128    server.SendMessage(m_Host, message);*/
     1129
     1130}
     1131
    11091132bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event)
    11101133{
    11111134    ENSURE(event->GetType() == (uint)NMT_LOADED_GAME);
  • source/network/NetServer.h

     
    188188    bool SendMessage(ENetPeer* peer, const CNetMessage* message);
    189189
    190190    /**
     191     * Send message to the host
     192    */
     193    bool SendMessageToHost(const CNetMessage* message);
     194
     195    /**
    191196     * Disconnects a player from gamesetup or session.
    192197     */
    193198    bool KickPlayer(const CStrW& playerName, const bool ban);
     
    270275    static bool OnInGame(void* context, CFsmEvent* event);
    271276    static bool OnChat(void* context, CFsmEvent* event);
    272277    static bool OnReady(void* context, CFsmEvent* event);
     278    static bool OnChangeSettings(void* context, CFsmEvent* event);
    273279    static bool OnLoadedGame(void* context, CFsmEvent* event);
    274280    static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event);
    275281    static bool OnRejoined(void* context, CFsmEvent* event);