Ticket #3806: 3806_player_gamesetup_v2.3.patch
File 3806_player_gamesetup_v2.3.patch, 44.7 KB (added by , 8 years ago) |
---|
-
binaries/data/mods/public/gui/aiconfig/aiconfig.js
16 16 let aiSelection = Engine.GetGUIObjectByName("aiSelection"); 17 17 aiSelection.list = g_AIDescriptions.map(ai => ai.data.name); 18 18 aiSelection.selected = g_AIDescriptions.findIndex(ai => ai.id == settings.id); 19 aiSelection.hidden = !settings. isController;19 aiSelection.hidden = !settings.canBeChanged; 20 20 21 21 let aiSelectionText = Engine.GetGUIObjectByName("aiSelectionText"); 22 22 aiSelectionText.caption = aiSelection.list[aiSelection.selected]; 23 aiSelectionText.hidden = settings. isController;23 aiSelectionText.hidden = settings.canBeChanged; 24 24 25 25 let aiDiff = Engine.GetGUIObjectByName("aiDifficulty"); 26 26 aiDiff.list = prepareForDropdown(g_Settings.AIDifficulties).Title; 27 27 aiDiff.selected = settings.difficulty; 28 aiDiff.hidden = !settings. isController;28 aiDiff.hidden = !settings.canBeChanged; 29 29 30 30 let aiDiffText = Engine.GetGUIObjectByName("aiDifficultyText"); 31 31 aiDiffText.caption = aiDiff.list[aiDiff.selected]; 32 aiDiffText.hidden = settings. isController;32 aiDiffText.hidden = settings.canBeChanged; 33 33 } 34 34 35 35 function selectAI(idx) -
binaries/data/mods/public/gui/common/settings.js
37 37 "MapTypes": loadMapTypes(), 38 38 "MapSizes": loadSettingValuesFile("map_sizes.json"), 39 39 "PlayerDefaults": loadPlayerDefaults(), 40 "GuestSettings": loadSettingValuesFile("guest_settings.json"), 40 41 "PopulationCapacities": loadPopulationCapacities(), 41 42 "StartingResources": loadSettingValuesFile("starting_resources.json"), 42 43 "VictoryConditions": loadVictoryConditions() -
binaries/data/mods/public/gui/gamesetup/gamesetup.js
5 5 const g_GameSpeeds = prepareForDropdown(g_Settings && g_Settings.GameSpeeds.filter(speed => !speed.ReplayOnly)); 6 6 const g_MapSizes = prepareForDropdown(g_Settings && g_Settings.MapSizes); 7 7 const g_MapTypes = prepareForDropdown(g_Settings && g_Settings.MapTypes); 8 const g_GuestSettings = prepareForDropdown(g_Settings && g_Settings.GuestSettings); 8 9 const g_PopulationCapacities = prepareForDropdown(g_Settings && g_Settings.PopulationCapacities); 9 10 const g_StartingResources = prepareForDropdown(g_Settings && g_Settings.StartingResources); 10 11 const g_VictoryConditions = prepareForDropdown(g_Settings && g_Settings.VictoryConditions); … … 31 32 "netstatus": msg => handleNetStatusMessage(msg), 32 33 "netwarn": msg => addNetworkWarning(msg), 33 34 "gamesetup": msg => handleGamesetupMessage(msg), 35 "changesetting": msg => handleChangeSettingMessage(msg), 34 36 "players": msg => handlePlayerAssignmentMessage(msg), 35 37 "ready": msg => handleReadyMessage(msg), 36 38 "start": msg => handleGamestartMessage(msg), … … 270 272 initCivNameList(); 271 273 initMapTypes(); 272 274 initMapFilters(); 275 initDropdowns(); 273 276 274 277 if (g_IsController) 275 278 { … … 277 280 g_GameAttributes.matchID = Engine.GetMatchID(); 278 281 g_GameAttributes.settings.CheatsEnabled = !g_IsNetworked; 279 282 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();291 283 } 292 284 else 293 285 hideControls(); … … 309 301 } 310 302 } 311 303 304 function initDropdowns() 305 { 306 initMapNameList(); 307 initNumberOfPlayers(); 308 initGameSpeed(); 309 initGuestSettings(); 310 initPopulationCaps(); 311 initStartingResources(); 312 initCeasefire(); 313 initWonderDurations(); 314 initVictoryConditions(); 315 initMapSizes(); 316 initRadioButtons(); 317 } 318 312 319 function initMapTypes() 313 320 { 314 321 let mapTypes = Engine.GetGUIObjectByName("mapType"); … … 316 323 mapTypes.list_data = g_MapTypes.Name; 317 324 mapTypes.onSelectionChange = function() { 318 325 if (this.selected != -1) 326 { 327 if (!g_IsController) 328 { 329 changeSetting("mapType", this.list_data[this.selected]); 330 return; 331 } 319 332 selectMapType(this.list_data[this.selected]); 333 } 320 334 }; 321 if (g_IsController) 322 mapTypes.selected = g_MapTypes.Default; 335 mapTypes.selected = g_MapTypes.Default; 323 336 } 324 337 325 338 function initMapFilters() … … 329 342 mapFilters.list_data = g_MapFilters.map(mapFilter => mapFilter.id); 330 343 mapFilters.onSelectionChange = function() { 331 344 if (this.selected != -1) 345 { 346 if (!g_IsController) 347 { 348 changeSetting("mapFilter", this.list_data[this.selected]); 349 return; 350 } 332 351 selectMapFilter(this.list_data[this.selected]); 352 } 333 353 }; 334 if (g_IsController) 335 mapFilters.selected = 0; 354 mapFilters.selected = 0; 336 355 g_GameAttributes.mapFilter = "default"; 337 356 } 338 357 … … 349 368 "optionPopulationCap", 350 369 "optionStartingResources", 351 370 "optionCeasefire", 371 "optionGuestSettings", 352 372 "optionRevealMap", 353 373 "optionExploreMap", 354 374 "optionDisableTreasures", … … 390 410 numPlayers.list_data = playersArray; 391 411 numPlayers.onSelectionChange = function() { 392 412 if (this.selected != -1) 413 { 414 if (!g_IsController) 415 { 416 changeSetting("numPlayers", this.list_data[this.selected]); 417 return; 418 } 393 419 selectNumPlayers(this.list_data[this.selected]); 420 } 394 421 }; 395 422 numPlayers.selected = g_MaxPlayers - 1; 396 423 } … … 398 425 function initGameSpeed() 399 426 { 400 427 let gameSpeed = Engine.GetGUIObjectByName("gameSpeed"); 401 gameSpeed.hidden = false;402 Engine.GetGUIObjectByName("gameSpeedText").hidden = true;403 428 gameSpeed.list = g_GameSpeeds.Title; 404 429 gameSpeed.list_data = g_GameSpeeds.Speed; 405 430 gameSpeed.onSelectionChange = function() { 406 431 if (this.selected != -1) 432 { 433 if (!g_IsController) 434 { 435 changeSetting("gameSpeed", this.list_data[this.selected]); 436 return; 437 } 407 438 g_GameAttributes.gameSpeed = g_GameSpeeds.Speed[this.selected]; 408 439 } 409 440 updateGameAttributes(); 410 441 }; 411 442 gameSpeed.selected = g_GameSpeeds.Default; … … 419 450 populationCaps.selected = g_PopulationCapacities.Default; 420 451 populationCaps.onSelectionChange = function() { 421 452 if (this.selected != -1) 453 { 454 if (!g_IsController) 455 { 456 changeSetting("populationCap", this.list_data[this.selected]); 457 return; 458 } 422 459 g_GameAttributes.settings.PopulationCap = g_PopulationCapacities.Population[this.selected]; 460 } 423 461 424 462 updateGameAttributes(); 425 463 }; … … 433 471 startingResourcesL.selected = g_StartingResources.Default; 434 472 startingResourcesL.onSelectionChange = function() { 435 473 if (this.selected != -1) 474 { 475 if (!g_IsController) 476 { 477 changeSetting("startingResources", this.list_data[this.selected]); 478 return; 479 } 436 480 g_GameAttributes.settings.StartingResources = g_StartingResources.Resources[this.selected]; 481 } 437 482 438 483 updateGameAttributes(); 439 484 }; … … 447 492 ceasefireL.selected = g_Ceasefire.Default; 448 493 ceasefireL.onSelectionChange = function() { 449 494 if (this.selected != -1) 495 { 496 if (!g_IsController) 497 { 498 changeSetting("ceasefire", this.list_data[this.selected]); 499 return; 500 } 450 501 g_GameAttributes.settings.Ceasefire = g_Ceasefire.Duration[this.selected]; 502 } 451 503 452 504 updateGameAttributes(); 453 505 }; 454 506 } 455 507 508 function initGuestSettings() 509 { 510 let guestSettings = Engine.GetGUIObjectByName("guestSettings"); 511 guestSettings.list = g_GuestSettings.Title; 512 guestSettings.list_data = g_GuestSettings.Data; 513 guestSettings.onSelectionChange = function() { 514 if (this.selected != -1) 515 { 516 if (!g_IsController) 517 { 518 changeSetting("guestSettings", this.list_data[this.selected]); 519 return; 520 } 521 g_GameAttributes.GuestSettings = g_GuestSettings.Data[this.selected]; 522 } 523 524 updateGameAttributes(); 525 }; 526 if (guestSettings.selected == -1) 527 guestSettings.selected = g_GuestSettings.Default; 528 } 529 456 530 function initVictoryConditions() 457 531 { 458 532 let victoryConditions = Engine.GetGUIObjectByName("victoryCondition"); … … 461 535 victoryConditions.onSelectionChange = function() { 462 536 if (this.selected != -1) 463 537 { 538 if (!g_IsController) 539 { 540 changeSetting("victoryCondition", this.list_data[this.selected]); 541 return; 542 } 464 543 g_GameAttributes.settings.GameType = g_VictoryConditions.Name[this.selected]; 465 544 g_GameAttributes.settings.VictoryScripts = g_VictoryConditions.Scripts[this.selected]; 466 545 } … … 478 557 wonderConditions.onSelectionChange = function() 479 558 { 480 559 if (this.selected != -1) 560 { 561 if (!g_IsController) 562 { 563 changeSetting("wonderDuration", this.list_data[this.selected]); 564 return; 565 } 481 566 g_GameAttributes.settings.WonderDuration = g_WonderDurations.Duration[this.selected]; 567 } 482 568 483 569 updateGameAttributes(); 484 570 }; … … 492 578 mapSize.list_data = g_MapSizes.Tiles; 493 579 mapSize.onSelectionChange = function() { 494 580 if (this.selected != -1) 581 { 582 if (!g_IsController) 583 { 584 changeSetting("mapSice", this.list_data[this.selected]); 585 return; 586 } 495 587 g_GameAttributes.settings.Size = g_MapSizes.Tiles[this.selected]; 588 } 496 589 updateGameAttributes(); 497 590 }; 498 591 mapSize.selected = 0; … … 513 606 514 607 Object.keys(options).forEach(attribute => { 515 608 Engine.GetGUIObjectByName(options[attribute]).onPress = function() { 609 if (!g_IsController) 610 { 611 changeSetting(attribute, this.checked); 612 return; 613 } 516 614 g_GameAttributes.settings[attribute] = this.checked; 517 615 updateGameAttributes(); 518 616 }; … … 519 617 }); 520 618 521 619 Engine.GetGUIObjectByName("enableRating").onPress = function() { 620 if (!g_IsController) 621 { 622 changeSetting("enableRating", this.checked); 623 return; 624 } 522 625 g_GameAttributes.settings.RatingEnabled = this.checked; 523 626 Engine.SetRankedGame(this.checked); 524 627 Engine.GetGUIObjectByName("enableCheats").enabled = !this.checked; … … 533 636 function hideControls() 534 637 { 535 638 for (let ctrl of ["mapType", "mapFilter", "mapSelection", "victoryCondition", "gameSpeed", "numPlayers"]) 536 hideControl(ctrl, ctrl + "Text" );639 hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl)); 537 640 538 // TODO: Shouldn't players be able to choose their own assignment?539 641 for (let i = 0; i < g_MaxPlayers; ++i) 540 642 { 541 Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = true;542 Engine.GetGUIObjectByName("playerCiv["+i+"]").hidden = true;543 Engine.GetGUIObjectByName("playerTeam["+i+"]").hidden = true;643 Engine.GetGUIObjectByName("playerAssignment["+i+"]").hidden = !canPlayerChange("playerAssignment", i); 644 Engine.GetGUIObjectByName("playerCiv["+i+"]").hidden = !canPlayerChange("playerCiv", i); 645 Engine.GetGUIObjectByName("playerTeam["+i+"]").hidden = !canPlayerChange("playerTeam", i); 544 646 } 545 647 546 648 Engine.GetGUIObjectByName("startGame").enabled = true; … … 573 675 } 574 676 575 677 /** 678 * Returns if the player is allowed to change this setting 679 */ 680 function canPlayerChange(setting, index = -1) 681 { 682 if (g_GameAttributes.mapType == "scenario" && 683 ["victoryCondition", "wonderDuration", "populationCap", 684 "startingResources", "ceasefire", "revealMap", "exploreMap", 685 "disableTreasures", "lockTeams", "playerCiv", "playerTeam", "playerColor"].indexOf(setting) >= 0) 686 return false; 687 688 if (g_GameAttributes.mapType != "random" && setting == "numPlayers") 689 return false; 690 691 if (g_IsController) 692 return true; 693 694 if (setting == "guestSettings") 695 return false; 696 697 if (g_GuestSettings.Data.indexOf(setting) == -1) 698 return g_GameAttributes.GuestSettings == "all"; 699 700 if (index >= 0 && g_PlayerAssignments[Engine.GetPlayerGUID()] !== undefined && index != g_PlayerAssignments[Engine.GetPlayerGUID()].player-1) 701 return g_GameAttributes.GuestSettings == "all"; 702 703 return g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) >= g_GuestSettings.Data.indexOf(setting); 704 } 705 /** 706 * helper function for Engine.NetworkChangeSetting 707 */ 708 function changeSetting(setting, value) 709 { 710 Engine.NetworkChangeSetting({"setting": setting, "value": value}); 711 } 712 713 /** 576 714 * Hide and set some elements depending on whether we play single- or multiplayer. 577 715 */ 578 716 function initMultiplayerSettings() … … 579 717 { 580 718 Engine.GetGUIObjectByName("chatPanel").hidden = !g_IsNetworked; 581 719 Engine.GetGUIObjectByName("optionCheats").hidden = !g_IsNetworked; 720 Engine.GetGUIObjectByName("optionGuestSettings").hidden = !g_IsNetworked; 582 721 Engine.GetGUIObjectByName("optionRating").hidden = !Engine.HasXmppClient(); 583 722 584 723 Engine.GetGUIObjectByName("enableCheats").enabled = !Engine.IsRankedGame(); … … 615 754 let playerSlot = i; // declare for inner function use 616 755 team.onSelectionChange = function() { 617 756 if (this.selected != -1) 618 g_GameAttributes.settings.PlayerData[playerSlot].Team = this.selected - 1; 757 { 758 if (!g_IsController) 759 { 760 changeSetting("playerTeam["+i+"]", this.list_data[this.selected]); 761 return; 762 } 763 g_GameAttributes.settings.PlayerData[playerSlot].Team = this.selected - 1; 764 } 619 765 620 766 updateGameAttributes(); 621 767 }; … … 624 770 colorPicker.list = g_PlayerColors.map(color => ' ' + '[color="' + rgbToGuiColor(color) + '"]■[/color]'); 625 771 colorPicker.list_data = g_PlayerColors.map((color, index) => index); 626 772 colorPicker.selected = -1; 627 colorPicker.onSelectionChange = function() { selectPlayerColor(playerSlot, this.selected); }; 773 colorPicker.onSelectionChange = function() { 774 if (!g_IsController) 775 { 776 changeSetting("playerColorPicker["+i+"]", this.list_data[this.selected]); 777 return; 778 } 779 selectPlayerColor(playerSlot, this.selected); 780 }; 628 781 629 782 Engine.GetGUIObjectByName("playerCiv["+i+"]").onSelectionChange = function() { 630 783 if ((this.selected != -1)&&(g_GameAttributes.mapType !== "scenario")) 784 { 785 if (!g_IsController) 786 { 787 changeSetting("playerCiv["+i+"]", this.list_data[this.selected]); 788 return; 789 } 631 790 g_GameAttributes.settings.PlayerData[playerSlot].Civ = this.list_data[this.selected]; 791 } 632 792 633 793 updateGameAttributes(); 634 794 }; … … 695 855 } 696 856 697 857 /** 698 * Called whenever the host changed any setting.858 * Called whenever the host sent new game attributes. 699 859 * @param {Object} message 700 860 */ 701 861 function handleGamesetupMessage(message) … … 717 877 } 718 878 719 879 /** 880 * Called whenever a client changes a setting. 881 * @param {Object} message 882 */ 883 function handleChangeSettingMessage(message) 884 { 885 if (!message.guid || !message.data || !message.data.setting || message.data.value === undefined) 886 return; 887 888 warn("The player with guid " + message.guid + " has changed the setting " + 889 message.data.setting + " to the value " + message.data.value + ". Type is " + typeof message.data.value); 890 updateGUIObjects(); 891 } 892 893 /** 720 894 * Called whenever a client joins/leaves or any gamesetting is changed. 721 895 * @param {Object} message 722 896 */ … … 869 1043 mapSelectionBox.list_data = mapListFiles; 870 1044 mapSelectionBox.onSelectionChange = function() { 871 1045 if (this.selected != -1) 1046 { 1047 if (!g_IsController) 1048 { 1049 changeSetting("mapSelection", this.list_data[this.selected]); 1050 return; 1051 } 872 1052 selectMap(this.list_data[this.selected]); 1053 } 873 1054 }; 874 1055 mapSelectionBox.selected = Math.max(0, mapListFiles.indexOf(g_GameAttributes.map || "")); 875 1056 } … … 1046 1227 function selectNumPlayers(num) 1047 1228 { 1048 1229 // Avoid recursion 1049 if (g_IsInGuiUpdate || ! g_IsController|| g_GameAttributes.mapType != "random")1230 if (g_IsInGuiUpdate || !canPlayerChange("numPlayers") || g_GameAttributes.mapType != "random") 1050 1231 return; 1051 1232 1052 1233 // Unassign players from nonexistent slots … … 1110 1291 function selectMapType(type) 1111 1292 { 1112 1293 // Avoid recursion 1113 if (g_IsInGuiUpdate || !g_IsController)1294 if (g_IsInGuiUpdate) 1114 1295 return; 1115 1296 1116 1297 if (!g_MapPath[type]) … … 1140 1321 function selectMapFilter(id) 1141 1322 { 1142 1323 // Avoid recursion 1143 if (g_IsInGuiUpdate || !g_IsController)1324 if (g_IsInGuiUpdate) 1144 1325 return; 1145 1326 1146 1327 g_GameAttributes.mapFilter = id; … … 1153 1334 function selectMap(name) 1154 1335 { 1155 1336 // Avoid recursion 1156 if (g_IsInGuiUpdate || ! g_IsController || !name)1337 if (g_IsInGuiUpdate || !name) 1157 1338 return; 1158 1339 1159 1340 // Reset some map specific properties which are not necessarily redefined on each map … … 1285 1466 1286 1467 if (g_IsNetworked) 1287 1468 { 1288 Engine. SetNetworkGameAttributes(g_GameAttributes);1469 Engine.NetworkSetGameAttributes(g_GameAttributes); 1289 1470 Engine.StartNetworkGame(); 1290 1471 } 1291 1472 else … … 1324 1505 let mapFilterIdx = g_MapFilters.findIndex(mapFilter => mapFilter.id == (g_GameAttributes.mapFilter || "default")); 1325 1506 let mapTypeIdx = g_GameAttributes.mapType !== undefined ? g_MapTypes.Name.indexOf(g_GameAttributes.mapType) : g_MapTypes.Default; 1326 1507 let gameSpeedIdx = g_GameAttributes.gameSpeed !== undefined ? g_GameSpeeds.Speed.indexOf(g_GameAttributes.gameSpeed) : g_GameSpeeds.Default; 1508 let guestSettingsIdx = g_GameAttributes.GuestSettings !== undefined ? g_GuestSettings.Data.indexOf(g_GameAttributes.GuestSettings) : g_GuestSettings.Default; 1327 1509 1328 1510 // These dropdowns might set the default (as they ignore g_IsInGuiUpdate) 1329 1511 let mapSizeIdx = mapSettings.Size !== undefined ? g_MapSizes.Tiles.indexOf(mapSettings.Size) : g_MapSizes.Default; … … 1334 1516 let ceasefireIdx = mapSettings.Ceasefire !== undefined ? g_Ceasefire.Duration.indexOf(mapSettings.Ceasefire) : g_Ceasefire.Default; 1335 1517 let numPlayers = mapSettings.PlayerData ? mapSettings.PlayerData.length : g_MaxPlayers; 1336 1518 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 } 1519 Engine.GetGUIObjectByName("mapType").selected = mapTypeIdx; 1520 Engine.GetGUIObjectByName("mapFilter").selected = mapFilterIdx; 1521 Engine.GetGUIObjectByName("mapSelection").selected = Engine.GetGUIObjectByName("mapSelection").list_data.indexOf(mapName); 1522 Engine.GetGUIObjectByName("mapSize").selected = mapSizeIdx; 1523 Engine.GetGUIObjectByName("numPlayers").selected = numPlayers - 1; 1524 Engine.GetGUIObjectByName("victoryCondition").selected = victoryIdx; 1525 Engine.GetGUIObjectByName("wonderDuration").selected = wonderDurationIdx; 1526 Engine.GetGUIObjectByName("populationCap").selected = popIdx; 1527 Engine.GetGUIObjectByName("gameSpeed").selected = gameSpeedIdx; 1528 Engine.GetGUIObjectByName("ceasefire").selected = ceasefireIdx; 1529 Engine.GetGUIObjectByName("startingResources").selected = startingResIdx; 1530 Engine.GetGUIObjectByName("guestSettings").selected = guestSettingsIdx; 1358 1531 1532 1533 initMapNameList(); 1534 1359 1535 // Can be visible to both host and clients 1360 1536 Engine.GetGUIObjectByName("mapSizeText").caption = g_GameAttributes.mapType == "random" ? g_MapSizes.LongName[mapSizeIdx] : translate("Default"); 1361 1537 Engine.GetGUIObjectByName("numPlayersText").caption = numPlayers; 1362 1538 Engine.GetGUIObjectByName("victoryConditionText").caption = g_VictoryConditions.Title[victoryIdx]; 1363 1539 Engine.GetGUIObjectByName("wonderDurationText").caption = g_WonderDurations.Title[wonderDurationIdx]; 1540 Engine.GetGUIObjectByName("guestSettingsText").caption = g_GuestSettings.Title[guestSettingsIdx]; 1364 1541 Engine.GetGUIObjectByName("populationCapText").caption = g_PopulationCapacities.Title[popIdx]; 1365 1542 Engine.GetGUIObjectByName("startingResourcesText").caption = g_StartingResources.Title[startingResIdx]; 1366 1543 Engine.GetGUIObjectByName("ceasefireText").caption = g_Ceasefire.Title[ceasefireIdx]; 1367 1544 Engine.GetGUIObjectByName("gameSpeedText").caption = g_GameSpeeds.Title[gameSpeedIdx]; 1545 Engine.GetGUIObjectByName("mapTypeText").caption = g_MapTypes.Title[mapTypeIdx]; 1546 Engine.GetGUIObjectByName("mapFilterText").caption = g_MapFilters[mapFilterIdx].name; 1547 Engine.GetGUIObjectByName("mapSelectionText").caption = mapName == "random" ? g_RandomMap : translate(getMapDisplayName(mapName)); 1368 1548 1369 1549 setGUIBoolean("enableCheats", "enableCheatsText", !!mapSettings.CheatsEnabled); 1370 1550 setGUIBoolean("disableTreasures", "disableTreasuresText", !!mapSettings.DisableTreasures); … … 1387 1567 Engine.GetGUIObjectByName("mapSizeDesc").hidden = !isRandom; 1388 1568 Engine.GetGUIObjectByName("mapSize").hidden = !isRandom || !g_IsController; 1389 1569 Engine.GetGUIObjectByName("mapSizeText").hidden = !isRandom || g_IsController; 1390 hideControl("numPlayers", "numPlayersText", isRandom && g_IsController);1391 1570 1392 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ;1393 1394 1571 for (let ctrl of ["victoryCondition", "wonderDuration", "populationCap", 1395 1572 "startingResources", "ceasefire", "revealMap", 1396 "exploreMap", "disableTreasures", "lockTeams"]) 1397 hideControl(ctrl, ctrl + "Text", notScenario); 1573 "exploreMap", "disableTreasures", "lockTeams", 1574 "gameSpeed", "guestSettings", "enableCheats", 1575 "mapSelection", "numPlayers", "mapType", "mapFilter"]) 1576 hideControl(ctrl, ctrl + "Text", canPlayerChange(ctrl)); 1398 1577 1578 let notScenario = g_GameAttributes.mapType != "scenario" && g_IsController ; 1399 1579 Engine.GetGUIObjectByName("civResetButton").hidden = !notScenario; 1400 1580 1401 1581 for (let i = 0; i < g_MaxPlayers; ++i) … … 1431 1611 pCiv.selected = civ ? pCiv.list_data.indexOf(civ) : 0; 1432 1612 pTeam.selected = team !== undefined && team >= 0 ? team+1 : 0; 1433 1613 1434 hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", g_IsController);1435 hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", notScenario);1436 hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", notScenario);1614 hideControl("playerAssignment["+i+"]", "playerAssignmentText["+i+"]", canPlayerChange("playerAssignment", i)); 1615 hideControl("playerCiv["+i+"]", "playerCivText["+i+"]", canPlayerChange("playerCiv", i)); 1616 hideControl("playerTeam["+i+"]", "playerTeamText["+i+"]", canPlayerChange("playerTeam", i)); 1437 1617 1438 1618 // Allow host to chose player colors on non-scenario maps 1439 1619 let pColorPicker = Engine.GetGUIObjectByName("playerColorPicker["+i+"]"); 1440 1620 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) 1621 pColorPicker.hidden = !canPlayerChange("playerColor", i); 1622 pColorPickerHeading.hidden = !canPlayerChange("playerColor", i); 1623 if (canPlayerChange("playerColor", i)) 1445 1624 pColorPicker.selected = g_PlayerColors.findIndex(col => sameColor(col, color)); 1446 1625 } 1447 1626 … … 1532 1711 1533 1712 if (g_IsNetworked) 1534 1713 { 1535 Engine. SetNetworkGameAttributes(g_GameAttributes);1714 Engine.NetworkSetGameAttributes(g_GameAttributes); 1536 1715 if (g_LoadingState >= 2) 1537 1716 sendRegisterGameStanza(); 1538 1717 } … … 1546 1725 1547 1726 Engine.PushGuiPage("page_aiconfig.xml", { 1548 1727 "callback": "AIConfigCallback", 1549 " isController": g_IsController,1728 "canBeChanged": canPlayerChange("playerConfig"), 1550 1729 "playerSlot": playerSlot, 1551 1730 "id": g_GameAttributes.settings.PlayerData[playerSlot].AI, 1552 1731 "difficulty": g_GameAttributes.settings.PlayerData[playerSlot].AIDiff … … 1560 1739 { 1561 1740 g_LastViewedAIPlayer = -1; 1562 1741 1563 if (!ai.save || !g_IsController)1742 if (!ai.save) 1564 1743 return; 1565 1744 1566 1745 g_GameAttributes.settings.PlayerData[ai.playerSlot].AI = ai.id; 1567 1746 g_GameAttributes.settings.PlayerData[ai.playerSlot].AIDiff = ai.difficulty; 1568 1747 1748 if (!g_IsController) 1749 { 1750 changeSetting("playerConfig["+i+"]", JSON.stringify(ai)); 1751 return; 1752 } 1569 1753 if (g_IsNetworked) 1570 Engine. SetNetworkGameAttributes(g_GameAttributes);1754 Engine.NetworkSetGameAttributes(g_GameAttributes); 1571 1755 else 1572 1756 updatePlayerList(); 1573 1757 } … … 1663 1847 { 1664 1848 g_GameAttributes.settings.PlayerData[playerSlot].AI = ""; 1665 1849 if (g_IsNetworked) 1666 Engine. SetNetworkGameAttributes(g_GameAttributes);1850 Engine.NetworkSetGameAttributes(g_GameAttributes); 1667 1851 } 1668 1852 1669 1853 let assignBox = Engine.GetGUIObjectByName("playerAssignment["+i+"]"); … … 1674 1858 assignBox.selected = selection; 1675 1859 assignBoxText.caption = hostNameList[selection]; 1676 1860 1677 if (g_IsController) 1678 assignBox.onselectionchange = function() { 1679 if (g_IsInGuiUpdate) 1680 return; 1861 assignBox.onSelectionChange = function() { 1862 if (g_IsInGuiUpdate) 1863 return; 1864 if (!g_IsController) 1865 { 1866 changeSetting("playerAssignment["+i+"]", this.list_data[this.selected]); 1867 return; 1868 } 1681 1869 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1870 let guid = hostGuidList[this.selected]; 1871 if (!guid) 1872 { 1873 if (g_IsNetworked) 1874 // Unassign any host from this player slot 1875 Engine.AssignNetworkPlayer(playerID, ""); 1876 // Remove AI from this player slot 1877 g_GameAttributes.settings.PlayerData[playerSlot].AI = ""; 1878 } 1879 else if (guid.substr(0, 3) == "ai:") 1880 { 1881 if (g_IsNetworked) 1882 // Unassign any host from this player slot 1883 Engine.AssignNetworkPlayer(playerID, ""); 1884 // Set the AI for this player slot 1885 g_GameAttributes.settings.PlayerData[playerSlot].AI = guid.substr(3); 1886 } 1887 else 1888 swapPlayers(guid, playerSlot); 1701 1889 1702 1703 Engine.SetNetworkGameAttributes(g_GameAttributes);1704 1705 1706 1707 1890 if (g_IsNetworked) 1891 Engine.NetworkSetGameAttributes(g_GameAttributes); 1892 else 1893 updatePlayerList(); 1894 updateReadyUI(); 1895 }; 1708 1896 } 1709 1897 1710 1898 g_IsInGuiUpdate = false; -
binaries/data/mods/public/gui/gamesetup/gamesetup.xml
90 90 <object name="playerAssignment[n]" type="dropdown" style="ModernDropDown" size="22%+37 2 50%+35 30" tooltip_style="onscreenToolTip"> 91 91 <translatableAttribute id="tooltip">Select player.</translatableAttribute> 92 92 </object> 93 <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+ 50 50%+35 30"/>93 <object name="playerAssignmentText[n]" type="text" style="ModernLabelText" size="22%+33 0 50%+35 30"/> 94 94 <object name="playerConfig[n]" type="button" style="StoneButton" size="50%+40 4 50%+64 28" 95 95 tooltip_style="onscreenToolTip" 96 96 font="sans-bold-stroke-12" … … 346 346 </object> 347 347 </object> 348 348 349 <object name="optionGuestSettings" size="14 188 94% 206"> 350 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 351 <translatableAttribute id="caption">Guest Settings:</translatableAttribute> 352 </object> 353 <object name="guestSettingsText" size="40% 0 100% 100%" type="text" style="ModernLeftLabelText"/> 354 <object name="guestSettings" size="40%+10 0 100% 28" type="dropdown" style="ModernDropDown" hidden="true" tooltip_style="onscreenToolTip"> 355 <translatableAttribute id="tooltip">Set which settings can be changed by every player.</translatableAttribute> 356 </object> 357 </object> 358 349 359 <object name="optionRevealMap" size="14 218 94% 246"> 350 360 <object size="0 0 40% 28" type="text" style="ModernRightLabelText"> 351 361 <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": "playerColor", 13 "Default": true 14 }, 15 { 16 "Title": "Color & Civilization", 17 "Data": "playerCiv" 18 }, 19 { 20 "Title": "Color, Civilization & Team", 21 "Data": "playerTeam" 22 }, 23 { 24 "Title": "All", 25 "Data": "all" 26 } 27 ] 28 } -
source/gui/scripting/ScriptFunctions.cpp
330 330 LOGERROR("Failed to save game"); 331 331 } 332 332 333 void SetNetworkGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1)333 void NetworkChangeSetting(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue keyValuePair1) 334 334 { 335 ENSURE(g_Net Server);335 ENSURE(g_NetClient); 336 336 //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere 337 337 // (with no obvious reason). 338 338 JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); 339 339 JSAutoRequest rq(cx); 340 JS::RootedValue keyValuePair(cx, keyValuePair1); 341 342 g_NetClient->SendChangeSettingMessage(&keyValuePair, *(pCxPrivate->pScriptInterface)); 343 } 344 345 void NetworkSetGameAttributes(ScriptInterface::CxPrivate* pCxPrivate, JS::HandleValue attribs1) 346 { 347 ENSURE(g_NetClient); 348 //TODO: This is a workaround because we need to pass a MutableHandle to a JSAPI functions somewhere 349 // (with no obvious reason). 350 JSContext* cx = pCxPrivate->pScriptInterface->GetContext(); 351 JSAutoRequest rq(cx); 340 352 JS::RootedValue attribs(cx, attribs1); 341 353 342 g_Net Server->UpdateGameAttributes(&attribs, *(pCxPrivate->pScriptInterface));354 g_NetClient->SendGameSetupMessage(&attribs, *(pCxPrivate->pScriptInterface)); 343 355 } 344 356 345 357 void StartNetworkHost(ScriptInterface::CxPrivate* pCxPrivate, const std::wstring& playerName) … … 425 437 426 438 void AssignNetworkPlayer(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), int playerID, const std::string& guid) 427 439 { 428 ENSURE(g_Net Server);440 ENSURE(g_NetClient); 429 441 430 g_Net Server->AssignPlayer(playerID, guid);442 g_NetClient->SendAssignPlayerMessage(playerID, guid); 431 443 } 432 444 433 445 void SetNetworkPlayerStatus(ScriptInterface::CxPrivate* UNUSED(pCxPrivate), const std::string& guid, int ready) … … 1042 1054 scriptInterface.RegisterFunction<std::string, &GetPlayerGUID>("GetPlayerGUID"); 1043 1055 scriptInterface.RegisterFunction<bool, CStrW, bool, &KickPlayer>("KickPlayer"); 1044 1056 scriptInterface.RegisterFunction<JS::Value, &PollNetworkClient>("PollNetworkClient"); 1045 scriptInterface.RegisterFunction<void, JS::HandleValue, &SetNetworkGameAttributes>("SetNetworkGameAttributes"); 1057 scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkChangeSetting>("NetworkChangeSetting"); 1058 scriptInterface.RegisterFunction<void, JS::HandleValue, &NetworkSetGameAttributes>("NetworkSetGameAttributes"); 1046 1059 scriptInterface.RegisterFunction<void, int, std::string, &AssignNetworkPlayer>("AssignNetworkPlayer"); 1047 1060 scriptInterface.RegisterFunction<void, std::string, int, &SetNetworkPlayerStatus>("SetNetworkPlayerStatus"); 1048 1061 scriptInterface.RegisterFunction<void, &ClearAllPlayerReady>("ClearAllPlayerReady"); -
source/network/NetClient.cpp
96 96 AddTransition(NCS_PREGAME, (uint)NMT_READY, NCS_PREGAME, (void*)&OnReady, context); 97 97 AddTransition(NCS_PREGAME, (uint)NMT_GAME_SETUP, NCS_PREGAME, (void*)&OnGameSetup, context); 98 98 AddTransition(NCS_PREGAME, (uint)NMT_PLAYER_ASSIGNMENT, NCS_PREGAME, (void*)&OnPlayerAssignment, context); 99 AddTransition(NCS_PREGAME, (uint)NMT_CHANGE_SETTING, NCS_PREGAME, (void*)&OnChangeSetting, context); 99 100 AddTransition(NCS_PREGAME, (uint)NMT_KICKED, NCS_PREGAME, (void*)&OnKicked, context); 100 101 AddTransition(NCS_PREGAME, (uint)NMT_CLIENT_TIMEOUT, NCS_PREGAME, (void*)&OnClientTimeout, context); 101 102 AddTransition(NCS_PREGAME, (uint)NMT_CLIENT_PERFORMANCE, NCS_PREGAME, (void*)&OnClientPerformance, context); … … 323 324 SetCurrState(NCS_UNCONNECTED); 324 325 } 325 326 327 void CNetClient::SendChangeSettingMessage(JS::MutableHandleValue keyValuePair, ScriptInterface& scriptInterface) 328 { 329 JSContext* cx = scriptInterface.GetContext(); 330 JS::RootedValue keyValuePairRooted(cx); 331 keyValuePairRooted = keyValuePair; 332 333 CChangeSettingMessage changeSetting(GetScriptInterface()); 334 changeSetting.m_Data.set(keyValuePairRooted); 335 SendMessage(&changeSetting); 336 } 337 338 void CNetClient::SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface) 339 { 340 JSContext* cx = scriptInterface.GetContext(); 341 JS::RootedValue attrsRooted(cx); 342 attrsRooted = attrs; 343 344 CGameSetupMessage gameSetup(scriptInterface); 345 gameSetup.m_Data = attrsRooted; 346 SendMessage(&gameSetup); 347 } 348 349 void CNetClient::SendAssignPlayerMessage(const int playerID, const std::string& guid) 350 { 351 CAssignPlayerMessage assignPlayer; 352 assignPlayer.m_PlayerID = playerID; 353 assignPlayer.m_GUIDToAssign = guid; 354 SendMessage(&assignPlayer); 355 } 356 326 357 void CNetClient::SendChatMessage(const std::wstring& text) 327 358 { 328 359 CChatMessage chat; … … 592 623 return true; 593 624 } 594 625 626 bool CNetClient::OnChangeSetting(void* context, CFsmEvent* event) 627 { 628 ENSURE(event->GetType() == (uint)NMT_CHANGE_SETTING); 629 630 CNetClient* client = (CNetClient*)context; 631 JSContext* cx = client->GetScriptInterface().GetContext(); 632 JSAutoRequest rq(cx); 633 634 CChangeSettingMessage* message = (CChangeSettingMessage*)event->GetParamRef(); 635 636 JS::RootedValue msg(cx); 637 client->GetScriptInterface().Eval("({'type':'changesetting'})", &msg); 638 client->GetScriptInterface().SetProperty(msg, "guid", std::string(message->m_GUID), false); 639 client->GetScriptInterface().SetProperty(msg, "data", message->m_Data, false); 640 client->PushGuiMessage(msg); 641 642 return true; 643 } 644 595 645 bool CNetClient::OnGameStart(void* context, CFsmEvent* event) 596 646 { 597 647 ENSURE(event->GetType() == (uint)NMT_GAME_START); -
source/network/NetClient.h
187 187 */ 188 188 void LoadFinished(); 189 189 190 void SendChangeSettingMessage(JS::MutableHandleValue keyValuePair, ScriptInterface& scriptInterface); 191 192 void SendGameSetupMessage(JS::MutableHandleValue attrs, ScriptInterface& scriptInterface); 193 194 void SendAssignPlayerMessage(const int playerID, const std::string& guid); 195 190 196 void SendChatMessage(const std::wstring& text); 191 197 192 198 void SendReadyMessage(const int status); … … 212 218 static bool OnReady(void* context, CFsmEvent* event); 213 219 static bool OnGameSetup(void* context, CFsmEvent* event); 214 220 static bool OnPlayerAssignment(void* context, CFsmEvent* event); 221 static bool OnChangeSetting(void* context, CFsmEvent* event); 215 222 static bool OnInGame(void* context, CFsmEvent* event); 216 223 static bool OnGameStart(void* context, CFsmEvent* event); 217 224 static bool OnJoinSyncStart(void* context, CFsmEvent* event); -
source/network/NetMessage.cpp
103 103 104 104 switch (header.GetType()) 105 105 { 106 case NMT_CHANGE_SETTING: 107 pNewMessage = new CChangeSettingMessage(scriptInterface); 108 break; 109 106 110 case NMT_GAME_SETUP: 107 111 pNewMessage = new CGameSetupMessage(scriptInterface); 108 112 break; … … 203 207 pNewMessage = new CSimulationMessage(scriptInterface); 204 208 break; 205 209 210 case NMT_ASSIGN_PLAYER: 211 pNewMessage = new CAssignPlayerMessage; 212 break; 213 206 214 default: 207 215 LOGERROR("CNetMessageFactory::CreateMessage(): Unknown message type '%d' received", header.GetType()); 208 216 break; -
source/network/NetMessage.h
1 /* Copyright (C) 201 5Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 154 154 ScriptInterface& m_ScriptInterface; 155 155 }; 156 156 157 /** 158 * Special message type to send single setting changes. 159 */ 160 class CChangeSettingMessage : public CNetMessage 161 { 162 NONCOPYABLE(CChangeSettingMessage); 163 public: 164 CChangeSettingMessage(ScriptInterface& scriptInterface); 165 CChangeSettingMessage(ScriptInterface& scriptInterface, CStr& guid, JS::HandleValue data); 166 virtual u8* Serialize(u8* pBuffer) const; 167 virtual const u8* Deserialize(const u8* pStart, const u8* pEnd); 168 virtual size_t GetSerializedLength() const; 169 virtual CStr ToString() const; 170 171 CStr m_GUID; 172 JS::PersistentRootedValue m_Data; 173 private: 174 ScriptInterface& m_ScriptInterface; 175 }; 176 157 177 // This time, the classes are created 158 178 #include "NetMessages.h" 159 179 -
source/network/NetMessages.h
28 28 29 29 #define PS_PROTOCOL_MAGIC 0x5073013f // 'P', 's', 0x01, '?' 30 30 #define PS_PROTOCOL_MAGIC_RESPONSE 0x50630121 // 'P', 'c', 0x01, '!' 31 #define PS_PROTOCOL_VERSION 0x0101001 3// Arbitrary protocol31 #define PS_PROTOCOL_VERSION 0x01010014 // Arbitrary protocol 32 32 #define PS_DEFAULT_PORT 0x5073 // 'P', 's' 33 33 34 34 // Defines the list of message types. The order of the list must not change. … … 51 51 NMT_CHAT, 52 52 NMT_READY, 53 53 NMT_GAME_SETUP, 54 NMT_CHANGE_SETTING, 55 NMT_ASSIGN_PLAYER, 54 56 NMT_PLAYER_ASSIGNMENT, 55 57 56 58 NMT_FILE_TRANSFER_REQUEST, … … 218 220 NMT_END_ARRAY() 219 221 END_NMT_CLASS() 220 222 223 START_NMT_CLASS_(AssignPlayer, NMT_ASSIGN_PLAYER) 224 NMT_FIELD_INT(m_PlayerID, i8, 1) 225 NMT_FIELD(CStr, m_GUIDToAssign) 226 END_NMT_CLASS() 227 221 228 END_NMTS() 222 229 223 230 #else -
source/network/NetMessageSim.cpp
1 /* Copyright (C) 201 1Wildfire Games.1 /* Copyright (C) 2016 Wildfire Games. 2 2 * This file is part of 0 A.D. 3 3 * 4 4 * 0 A.D. is free software: you can redistribute it and/or modify … … 229 229 stream << "CGameSetupMessage { m_Data: " << source << " }"; 230 230 return CStr(stream.str()); 231 231 } 232 233 234 CChangeSettingMessage::CChangeSettingMessage(ScriptInterface& scriptInterface) : 235 CNetMessage(NMT_CHANGE_SETTING), m_ScriptInterface(scriptInterface), m_Data(scriptInterface.GetJSRuntime()) 236 { 237 } 238 239 CChangeSettingMessage::CChangeSettingMessage(ScriptInterface& scriptInterface, CStr& guid, JS::HandleValue data) : 240 CNetMessage(NMT_CHANGE_SETTING), m_ScriptInterface(scriptInterface), 241 m_GUID(guid), m_Data(scriptInterface.GetJSRuntime(), data) 242 { 243 } 244 245 u8* CChangeSettingMessage::Serialize(u8* pBuffer) const 246 { 247 // TODO: ought to handle serialization exceptions 248 u8* pos = CNetMessage::Serialize(pBuffer); 249 CBufferBinarySerializer serializer(m_ScriptInterface, pos); 250 serializer.StringASCII("guid", m_GUID, 0, UINT32_MAX); 251 serializer.ScriptVal("command", const_cast<JS::PersistentRootedValue*>(&m_Data)); 252 return serializer.GetBuffer(); 253 } 254 255 const u8* CChangeSettingMessage::Deserialize(const u8* pStart, const u8* pEnd) 256 { 257 // TODO: ought to handle serialization exceptions 258 const u8* pos = CNetMessage::Deserialize(pStart, pEnd); 259 std::istringstream stream(std::string(pos, pEnd)); 260 CStdDeserializer deserializer(m_ScriptInterface, stream); 261 deserializer.StringASCII("guid", m_GUID, 0, UINT32_MAX); 262 deserializer.ScriptVal("command", const_cast<JS::PersistentRootedValue*>(&m_Data)); 263 return pEnd; 264 } 265 266 size_t CChangeSettingMessage::GetSerializedLength() const 267 { 268 CLengthBinarySerializer serializer(m_ScriptInterface); 269 serializer.StringASCII("guid", m_GUID, 0, UINT32_MAX); 270 serializer.ScriptVal("command", const_cast<JS::PersistentRootedValue*>(&m_Data)); 271 return CNetMessage::GetSerializedLength() + serializer.GetLength(); 272 } 273 274 CStr CChangeSettingMessage::ToString() const 275 { 276 std::string source = m_ScriptInterface.ToString(const_cast<JS::PersistentRootedValue*>(&m_Data)); 277 278 std::stringstream stream; 279 stream << "CChangeSettingMessage { m_GUID: " << m_GUID << ", m_Data: " << source << " }"; 280 return CStr(stream.str()); 281 } -
source/network/NetServer.cpp
649 649 session->AddTransition(NSS_PREGAME, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context); 650 650 session->AddTransition(NSS_PREGAME, (uint)NMT_CHAT, NSS_PREGAME, (void*)&OnChat, context); 651 651 session->AddTransition(NSS_PREGAME, (uint)NMT_READY, NSS_PREGAME, (void*)&OnReady, context); 652 session->AddTransition(NSS_PREGAME, (uint)NMT_CHANGE_SETTING, NSS_PREGAME, (void*)&OnChangeSetting, context); 653 session->AddTransition(NSS_PREGAME, (uint)NMT_GAME_SETUP, NSS_PREGAME, (void*)&OnGameSetup, context); 654 session->AddTransition(NSS_PREGAME, (uint)NMT_ASSIGN_PLAYER, NSS_PREGAME, (void*)&OnAssignPlayer, context); 652 655 session->AddTransition(NSS_PREGAME, (uint)NMT_LOADED_GAME, NSS_INGAME, (void*)&OnLoadedGame, context); 653 656 654 657 session->AddTransition(NSS_JOIN_SYNCING, (uint)NMT_CONNECTION_LOST, NSS_UNCONNECTED, (void*)&OnDisconnect, context); … … 1111 1114 return true; 1112 1115 } 1113 1116 1117 bool CNetServerWorker::OnChangeSetting(void* context, CFsmEvent* event) 1118 { 1119 ENSURE(event->GetType() == (uint)NMT_CHANGE_SETTING); 1120 1121 CNetServerSession* session = (CNetServerSession*)context; 1122 CNetServerWorker& server = session->GetServer(); 1123 1124 CChangeSettingMessage* message = (CChangeSettingMessage*)event->GetParamRef(); 1125 message->m_GUID = session->GetGUID(); 1126 // Forward message to host 1127 for (CNetServerSession* session : server.m_Sessions) 1128 if (session->GetGUID() == server.m_HostGUID) 1129 return session->SendMessage(message); 1130 LOGERROR("No host found to send the ChaneSettingMessage to."); 1131 } 1132 1133 bool CNetServerWorker::OnGameSetup(void* context, CFsmEvent* event) 1134 { 1135 ENSURE(event->GetType() == (uint)NMT_GAME_SETUP); 1136 1137 CNetServerSession* session = (CNetServerSession*)context; 1138 CNetServerWorker& server = session->GetServer(); 1139 1140 if (session->GetGUID() != server.m_HostGUID) // Client wasn't allowed to send new attributes 1141 return true; 1142 1143 CGameSetupMessage* message = (CGameSetupMessage*)event->GetParamRef(); 1144 1145 server.UpdateGameAttributes(&(message->m_Data)); 1146 return true; 1147 } 1148 1149 bool CNetServerWorker::OnAssignPlayer(void* context, CFsmEvent* event) 1150 { 1151 ENSURE(event->GetType() == (uint)NMT_ASSIGN_PLAYER); 1152 CNetServerSession* session = (CNetServerSession*)context; 1153 CNetServerWorker& server = session->GetServer(); 1154 1155 if (session->GetGUID() != server.m_HostGUID) // Client wasn't allowed to assign a player 1156 return true; 1157 1158 CAssignPlayerMessage* message = (CAssignPlayerMessage*)event->GetParamRef(); 1159 server.m_AssignPlayerQueue.emplace_back(message->m_PlayerID, message->m_GUIDToAssign); 1160 return true; 1161 } 1162 1114 1163 bool CNetServerWorker::OnLoadedGame(void* context, CFsmEvent* event) 1115 1164 { 1116 1165 ENSURE(event->GetType() == (uint)NMT_LOADED_GAME); -
source/network/NetServer.h
270 270 static bool OnInGame(void* context, CFsmEvent* event); 271 271 static bool OnChat(void* context, CFsmEvent* event); 272 272 static bool OnReady(void* context, CFsmEvent* event); 273 static bool OnChangeSetting(void* context, CFsmEvent* event); 274 static bool OnGameSetup(void* context, CFsmEvent* event); 275 static bool OnAssignPlayer(void* context, CFsmEvent* event); 273 276 static bool OnLoadedGame(void* context, CFsmEvent* event); 274 277 static bool OnJoinSyncingLoadedGame(void* context, CFsmEvent* event); 275 278 static bool OnRejoined(void* context, CFsmEvent* event);