forked from mirrors/0ad
Session cleanup and bugfix.
Rename "hosts" following 903803ceec in session and join dialog.
Move join/leave code to new functions OnClientJoin and OnClientLeave.
This was SVN commit r18315.
This commit is contained in:
@@ -124,7 +124,7 @@ function pollAndHandleNetworkClient()
|
||||
break;
|
||||
|
||||
case "players":
|
||||
g_PlayerAssignments = message.hosts;
|
||||
g_PlayerAssignments = message.newAssignments;
|
||||
break;
|
||||
|
||||
case "start":
|
||||
|
||||
@@ -461,37 +461,16 @@ function handleNetStatusMessage(message)
|
||||
|
||||
function handlePlayerAssignmentsMessage(message)
|
||||
{
|
||||
// Find and report all leavings
|
||||
for (let guid in g_PlayerAssignments)
|
||||
{
|
||||
if (message.hosts[guid])
|
||||
continue;
|
||||
if (!message.newAssignments[guid])
|
||||
onClientLeave(guid);
|
||||
|
||||
setClientPauseState(guid, false);
|
||||
let joins = Object.keys(message.newAssignments).filter(guid => !g_PlayerAssignments[guid]);
|
||||
|
||||
addChatMessage({ "type": "disconnect", "guid": guid });
|
||||
g_PlayerAssignments = message.newAssignments;
|
||||
|
||||
for (let id in g_Players)
|
||||
if (g_Players[id].guid == guid)
|
||||
g_Players[id].offline = true;
|
||||
}
|
||||
|
||||
let joins = Object.keys(message.hosts).filter(guid => !g_PlayerAssignments[guid]);
|
||||
|
||||
g_PlayerAssignments = message.hosts;
|
||||
|
||||
// Report all joinings
|
||||
joins.forEach(guid => {
|
||||
|
||||
let playerID = g_PlayerAssignments[guid].player;
|
||||
if (g_Players[playerID])
|
||||
{
|
||||
g_Players[playerID].guid = guid;
|
||||
g_Players[playerID].name = g_PlayerAssignments[guid].name;
|
||||
g_Players[playerID].offline = false;
|
||||
}
|
||||
|
||||
addChatMessage({ "type": "connect", "guid": guid });
|
||||
onClientJoin(guid);
|
||||
});
|
||||
|
||||
updateChatAddressees();
|
||||
@@ -504,6 +483,37 @@ function handlePlayerAssignmentsMessage(message)
|
||||
}
|
||||
}
|
||||
|
||||
function onClientJoin(guid)
|
||||
{
|
||||
let playerID = g_PlayerAssignments[guid].player;
|
||||
|
||||
if (g_Players[playerID])
|
||||
{
|
||||
g_Players[playerID].guid = guid;
|
||||
g_Players[playerID].name = g_PlayerAssignments[guid].name;
|
||||
g_Players[playerID].offline = false;
|
||||
}
|
||||
|
||||
addChatMessage({
|
||||
"type": "connect",
|
||||
"guid": guid
|
||||
});
|
||||
}
|
||||
|
||||
function onClientLeave(guid)
|
||||
{
|
||||
setClientPauseState(guid, false);
|
||||
|
||||
for (let id in g_Players)
|
||||
if (g_Players[id].guid == guid)
|
||||
g_Players[id].offline = true;
|
||||
|
||||
addChatMessage({
|
||||
"type": "disconnect",
|
||||
"guid": guid
|
||||
});
|
||||
}
|
||||
|
||||
function updateChatAddressees()
|
||||
{
|
||||
let addressees = [
|
||||
|
||||
Reference in New Issue
Block a user