0ad/binaries/data/mods/public/gui/gamesetup/Controls/StartGameControl.js
wraitii 76c5263607 Rename GameAttributes to InitAttributes
The initial settings for a game, used to create the map in RM & tosetup
the simulation, are named InitAttributes in the C++, but generally
referred to as GameAttributes in the JS GUI. This renames the latter to
the former to avoid confusion, since these settings are immutable once
the map starts, so InitAttributes is more accurate.

Differential Revision: https://code.wildfiregames.com/D3705
This was SVN commit r25083.
2021-03-19 10:02:10 +00:00

53 lines
1.4 KiB
JavaScript

/**
* Cheat prevention:
*
* 1. Ensure that the host cannot start the game unless all clients agreed on the game settings using the ready system.
*
* TODO:
* 2. Ensure that the host cannot start the game with InitAttributes different from the agreed ones.
* This may be achieved by:
* - Determining the seed collectively.
* - passing the agreed game settings to the engine when starting the game instance
* - rejecting new game settings from the server after the game launch event
*/
class StartGameControl
{
constructor(netMessages)
{
this.gameLaunchHandlers = new Set();
// This may be read from publicly
this.gameStarted = false;
// In MP, the host launches the game and switches right away,
// clients switch when they receive the appropriate message.
netMessages.registerNetMessageHandler("start", this.switchToLoadingPage.bind(this));
}
registerLaunchGameHandler(handler)
{
this.gameLaunchHandlers.add(handler);
}
launchGame()
{
this.gameStarted = true;
for (let handler of this.gameLaunchHandlers)
handler();
g_GameSettings.launchGame(g_PlayerAssignments);
// Switch to the loading page right away,
// the GUI will otherwise show the unrandomised settings.
this.switchToLoadingPage();
}
switchToLoadingPage()
{
Engine.SwitchGuiPage("page_loading.xml", {
"attribs": g_GameSettings.toInitAttributes(),
"playerAssignments": g_PlayerAssignments
});
}
}