Ticket #3607: t3607_assign_the_unassigned_v1.patch

File t3607_assign_the_unassigned_v1.patch, 1.6 KB (added by elexis, 9 years ago)
  • binaries/data/mods/public/gui/gamesetup/gamesetup.js

    function handleNetMessage(message)  
    455455        var resetReady = false;
    456456        var newPlayer = "";
    457457        // Find and report all joinings/leavings
    458458        for (var host in message.hosts)
    459459        {
    460             if (!g_PlayerAssignments[host])
     460            if (g_PlayerAssignments[host])
     461                continue;
     462
     463            // If we have extra player slots and we are the controller, give the player an ID.
     464            if (g_IsController && message.hosts[host].player === -1 && g_AssignedCount < g_GameAttributes.settings.PlayerData.length)
    461465            {
    462                 // If we have extra player slots and we are the controller, give the player an ID.
    463                 if (g_IsController && message.hosts[host].player === -1 && g_AssignedCount < g_GameAttributes.settings.PlayerData.length)
    464                     Engine.AssignNetworkPlayer(g_AssignedCount + 1, host);
    465                 addChatMessage({ "type": "connect", "username": message.hosts[host].name });
    466                 newPlayer = host;
     466                // Find an index of the playerdata array which is not assigned to any player
     467                let freeSlot = 1 + g_GameAttributes.settings.PlayerData.findIndex((v,i) =>
     468                    Object.keys(g_PlayerAssignments).every(guid => g_PlayerAssignments[guid].player != i + 1)
     469                );
     470                Engine.AssignNetworkPlayer(freeSlot, host);
    467471            }
     472
     473            addChatMessage({ "type": "connect", "username": message.hosts[host].name });
     474            newPlayer = host;
    468475        }
    469476
    470477        for (var host in g_PlayerAssignments)
    471478        {
    472479            if (!message.hosts[host])