Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/binaries/data/mods/public/gui/session/messages.js
Show All 18 Lines | |||||
var g_PlayerAssignmentsChangeHandlers = new Set(); | var g_PlayerAssignmentsChangeHandlers = new Set(); | ||||
/** | /** | ||||
* These handlers are called when the ceasefire time has run out. | * These handlers are called when the ceasefire time has run out. | ||||
*/ | */ | ||||
var g_CeasefireEndedHandlers = new Set(); | var g_CeasefireEndedHandlers = new Set(); | ||||
/** | /** | ||||
* These handlers are fired if the server informed the players that the networked game is out of sync. | |||||
*/ | |||||
var g_NetworkOutOfSyncHandlers = new Set(); | |||||
/** | |||||
* Handle all netmessage types that can occur. | * Handle all netmessage types that can occur. | ||||
*/ | */ | ||||
var g_NetMessageTypes = { | var g_NetMessageTypes = { | ||||
"netstatus": msg => { | "netstatus": msg => { | ||||
handleNetStatusMessage(msg); | handleNetStatusMessage(msg); | ||||
}, | }, | ||||
"netwarn": msg => { | "netwarn": msg => { | ||||
addNetworkWarning(msg); | addNetworkWarning(msg); | ||||
}, | }, | ||||
"out-of-sync": msg => { | "out-of-sync": msg => { | ||||
onNetworkOutOfSync(msg); | for (let handler of g_NetworkOutOfSyncHandlers) | ||||
handler(msg); | |||||
}, | }, | ||||
"players": msg => { | "players": msg => { | ||||
handlePlayerAssignmentsMessage(msg); | handlePlayerAssignmentsMessage(msg); | ||||
}, | }, | ||||
"paused": msg => { | "paused": msg => { | ||||
g_PauseControl.setClientPauseState(msg.guid, msg.pause); | g_PauseControl.setClientPauseState(msg.guid, msg.pause); | ||||
}, | }, | ||||
"clients-loading": msg => { | "clients-loading": msg => { | ||||
▲ Show 20 Lines • Show All 251 Lines • ▼ Show 20 Lines | function registerPlayerAssignmentsChangeHandler(handler) | ||||
g_PlayerAssignmentsChangeHandlers.add(handler); | g_PlayerAssignmentsChangeHandlers.add(handler); | ||||
} | } | ||||
function registerCeasefireEndedHandler(handler) | function registerCeasefireEndedHandler(handler) | ||||
{ | { | ||||
g_CeasefireEndedHandlers.add(handler); | g_CeasefireEndedHandlers.add(handler); | ||||
} | } | ||||
function registerNetworkOutOfSyncHandler(handler) | |||||
{ | |||||
g_NetworkOutOfSyncHandlers.add(handler); | |||||
} | |||||
/** | /** | ||||
* Loads all known cheat commands. | * Loads all known cheat commands. | ||||
*/ | */ | ||||
function getCheatsData() | function getCheatsData() | ||||
{ | { | ||||
let cheats = {}; | let cheats = {}; | ||||
for (let fileName of Engine.ListDirectoryFiles("simulation/data/cheats/", "*.json", false)) | for (let fileName of Engine.ListDirectoryFiles("simulation/data/cheats/", "*.json", false)) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 198 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
function handleClientsLoadingMessage(guids) | function handleClientsLoadingMessage(guids) | ||||
{ | { | ||||
let loadingClientsText = Engine.GetGUIObjectByName("loadingClientsText"); | let loadingClientsText = Engine.GetGUIObjectByName("loadingClientsText"); | ||||
loadingClientsText.caption = guids.map(guid => colorizePlayernameByGUID(guid)).join(translateWithContext("Separator for a list of client loading messages", ", ")); | loadingClientsText.caption = guids.map(guid => colorizePlayernameByGUID(guid)).join(translateWithContext("Separator for a list of client loading messages", ", ")); | ||||
} | } | ||||
function onNetworkOutOfSync(msg) | |||||
{ | |||||
let txt = [ | |||||
sprintf(translate("Out-Of-Sync error on turn %(turn)s."), { | |||||
"turn": msg.turn | |||||
}), | |||||
sprintf(translateWithContext("Out-Of-Sync", "Players: %(players)s"), { | |||||
"players": msg.players.join(translateWithContext("Separator for a list of players", ", ")) | |||||
}), | |||||
msg.hash == msg.expectedHash ? | |||||
translateWithContext("Out-Of-Sync", "Your game state is identical to the hosts game state.") : | |||||
translateWithContext("Out-Of-Sync", "Your game state differs from the hosts game state."), | |||||
"" | |||||
]; | |||||
if (msg.turn > 1 && g_GameAttributes.settings.PlayerData.some(pData => pData && pData.AI)) | |||||
txt.push(translateWithContext("Out-Of-Sync", "Rejoining Multiplayer games with AIs is not supported yet!")); | |||||
else | |||||
txt.push( | |||||
translateWithContext("Out-Of-Sync", "Ensure all players use the same mods."), | |||||
translateWithContext("Out-Of-Sync", 'Click on "Report a Bug" in the main menu to help fix this.'), | |||||
sprintf(translateWithContext("Out-Of-Sync", "Replay saved to %(filepath)s"), { | |||||
"filepath": escapeText(msg.path_replay) | |||||
}), | |||||
sprintf(translateWithContext("Out-Of-Sync", "Dumping current state to %(filepath)s"), { | |||||
"filepath": escapeText(msg.path_oos_dump) | |||||
}) | |||||
); | |||||
messageBox( | |||||
600, 280, | |||||
txt.join("\n"), | |||||
translate("Out of Sync") | |||||
); | |||||
} | |||||
function onReplayOutOfSync(turn, hash, expectedHash) | |||||
{ | |||||
messageBox( | |||||
500, 140, | |||||
sprintf(translate("Out-Of-Sync error on turn %(turn)s."), { | |||||
"turn": turn | |||||
}) + "\n" + | |||||
// Translation: This is shown if replay is out of sync | |||||
translateWithContext("Out-Of-Sync", "The current game state is different from the original game state."), | |||||
translate("Out of Sync") | |||||
); | |||||
} | |||||
function handlePlayerAssignmentsMessage(message) | function handlePlayerAssignmentsMessage(message) | ||||
{ | { | ||||
for (let guid in g_PlayerAssignments) | for (let guid in g_PlayerAssignments) | ||||
if (!message.newAssignments[guid]) | if (!message.newAssignments[guid]) | ||||
onClientLeave(guid); | onClientLeave(guid); | ||||
let joins = Object.keys(message.newAssignments).filter(guid => !g_PlayerAssignments[guid]); | let joins = Object.keys(message.newAssignments).filter(guid => !g_PlayerAssignments[guid]); | ||||
▲ Show 20 Lines • Show All 144 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator