Differential D3243 Diff 16503 binaries/data/mods/public/gui/gamesetup/NetMessages/GameRegisterStanza.js
Changeset View
Changeset View
Standalone View
Standalone View
binaries/data/mods/public/gui/gamesetup/NetMessages/GameRegisterStanza.js
Show All 14 Lines | constructor(initData, setupWindow, netMessages, gameSettingsControl, mapCache) | ||||
this.mods = JSON.stringify(Engine.GetEngineInfo().mods); | this.mods = JSON.stringify(Engine.GetEngineInfo().mods); | ||||
this.timer = undefined; | this.timer = undefined; | ||||
// Only send a lobby update when its data changed | // Only send a lobby update when its data changed | ||||
this.lastStanza = undefined; | this.lastStanza = undefined; | ||||
// Events | // Events | ||||
setupWindow.registerClosePageHandler(this.onClosePage.bind(this)); | setupWindow.registerClosePageHandler(this.onClosePage.bind(this)); | ||||
gameSettingsControl.registerGameAttributesBatchChangeHandler(this.onGameAttributesBatchChange.bind(this)); | |||||
netMessages.registerNetMessageHandler("start", this.onGameStart.bind(this)); | netMessages.registerNetMessageHandler("start", this.onGameStart.bind(this)); | ||||
g_NewGameSettings.map.watch(() => this.onSettingsChange(), ["map", "type"]); | |||||
g_NewGameSettings.mapSize.watch(() => this.onSettingsChange(), ["size"]); | |||||
g_NewGameSettings.victoryConditions.watch(() => this.onSettingsChange(), ["active"]); | |||||
g_NewGameSettings.playerCount.watch(() => this.onSettingsChange(), ["nbPlayers"]); | |||||
} | } | ||||
onGameAttributesBatchChange() | onSettingsChange() | ||||
{ | { | ||||
if (this.lastStanza) | if (this.lastStanza) | ||||
this.sendDelayed(); | this.sendDelayed(); | ||||
else | else | ||||
this.sendImmediately(); | this.sendImmediately(); | ||||
} | } | ||||
onGameStart() | onGameStart() | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | if (this.timer !== undefined) | ||||
this.timer = undefined; | this.timer = undefined; | ||||
} | } | ||||
let clients = this.formatClientsForStanza(); | let clients = this.formatClientsForStanza(); | ||||
let stanza = { | let stanza = { | ||||
"name": this.serverName, | "name": this.serverName, | ||||
"hostUsername": Engine.LobbyGetNick(), | "hostUsername": Engine.LobbyGetNick(), | ||||
"mapName": g_GameAttributes.map, | "mapName": g_NewGameSettings.map.map, | ||||
"niceMapName": this.mapCache.getTranslatableMapName(g_GameAttributes.mapType, g_GameAttributes.map), | "niceMapName": this.mapCache.getTranslatableMapName(g_NewGameSettings.map.type, g_NewGameSettings.map.map), | ||||
"mapSize": g_GameAttributes.mapType == "random" ? g_GameAttributes.settings.Size : "Default", | "mapSize": g_NewGameSettings.map.type == "random" ? g_NewGameSettings.mapSize.size : "Default", | ||||
"mapType": g_GameAttributes.mapType, | "mapType": g_NewGameSettings.map.type, | ||||
"victoryConditions": g_GameAttributes.settings.VictoryConditions.join(","), | "victoryConditions": Array.from(g_NewGameSettings.victoryConditions.active).join(","), | ||||
"nbp": clients.connectedPlayers, | "nbp": clients.connectedPlayers, | ||||
"maxnbp": g_GameAttributes.settings.PlayerData.length, | "maxnbp": g_NewGameSettings.playerCount.nbPlayers, | ||||
"players": clients.list, | "players": clients.list, | ||||
"mods": this.mods, | "mods": this.mods, | ||||
"hasPassword": this.hasPassword || "" | "hasPassword": this.hasPassword || "" | ||||
}; | }; | ||||
// Only send the stanza if one of these properties changed | // Only send the stanza if one of these properties changed | ||||
if (this.lastStanza && Object.keys(stanza).every(prop => this.lastStanza[prop] == stanza[prop])) | if (this.lastStanza && Object.keys(stanza).every(prop => this.lastStanza[prop] == stanza[prop])) | ||||
return; | return; | ||||
this.lastStanza = stanza; | this.lastStanza = stanza; | ||||
Engine.SendRegisterGame(stanza); | Engine.SendRegisterGame(stanza); | ||||
Engine.ProfileStop(); | Engine.ProfileStop(); | ||||
} | } | ||||
/** | /** | ||||
* Send a list of playernames and distinct between players and observers. | * Send a list of playernames and distinct between players and observers. | ||||
* Don't send teams, AIs or anything else until the game was started. | * Don't send teams, AIs or anything else until the game was started. | ||||
* The playerData format from g_GameAttributes is kept to reuse the GUI function presenting the data. | |||||
*/ | */ | ||||
formatClientsForStanza() | formatClientsForStanza() | ||||
{ | { | ||||
let connectedPlayers = 0; | let connectedPlayers = 0; | ||||
let playerData = []; | let playerData = []; | ||||
for (let guid in g_PlayerAssignments) | for (let guid in g_PlayerAssignments) | ||||
{ | { | ||||
let pData = { "Name": g_PlayerAssignments[guid].name }; | let pData = { "Name": g_PlayerAssignments[guid].name }; | ||||
if (g_GameAttributes.settings.PlayerData[g_PlayerAssignments[guid].player - 1]) | if (g_PlayerAssignments[guid].player <= g_NewGameSettings.playerCount.nbPlayers) | ||||
++connectedPlayers; | ++connectedPlayers; | ||||
else | else | ||||
pData.Team = "observer"; | pData.Team = "observer"; | ||||
playerData.push(pData); | playerData.push(pData); | ||||
} | } | ||||
return { | return { | ||||
Show All 10 Lines |
Wildfire Games · Phabricator