Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mitigate a crash in crudeplayerlist caused by AI host leaving #5368

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion LuaRules/Gadgets/start_teamnames.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,15 @@ function gadget:Initialize()
local teamList = Spring.GetTeamList()
for i = 1, #teamList do
local teamID = teamList[i]
local _, leaderID = Spring.GetTeamInfo(teamID, false)
local _, leaderID, _, isAI = Spring.GetTeamInfo(teamID, false)
if leaderID >= 0 then
Spring.SetTeamRulesParam(teamID, "initLeaderID", leaderID, PUBLIC_VISIBLE)
Spring.SetTeamRulesParam(teamID, "initAI", isAI, PUBLIC_VISIBLE) -- NB: NEEDED OR CRUDEPLAYERLIST WILL CRASH UPON RELOAD WHEN AN SKIRMISH AI HOST LEAVES!!!
if isAI then
local _, name, host = Spring.GetAIInfo(teamID) -- store these for later when https://github.com/beyond-all-reason/spring/issues/1727 is fixed.
Spring.SetTeamRulesParam(teamID, "initAIHost", host, PUBLIC_VISIBLE) -- This will allow users to re-host AI and gives widgets a fallback.
Spring.SetTeamRulesParam(teamID, "initAIName", name, PUBLIC_VISIBLE) -- Note: ShortName and Version are not available to sync. This can be derived via initAIName.
end
end
end
end
Expand Down
17 changes: 15 additions & 2 deletions LuaUI/Widgets/gui_chili_crudeplayerlist.lua
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ local fallbackAllyTeamID = Spring.GetMyAllyTeamID()

local Chili

local function GetAIName(teamID)
local _, name = Spring.GetAIInfo(teamID)
local fallbackName = Spring.GetTeamRulesParam(teamID, "initAIName") or "Unknown AI"
return name or "<Broken> " .. fallbackName
end

local function IsTeamAI(teamID) -- Creates a fallback. Probably should be a Utility function
local _, _, _, isAiTeam = Spring.GetTeamInfo(teamID, false)
return isAiTeam or Spring.GetTeamRulesParam(teamID, "initAI")
end


local function GetColorChar(colorTable)
if colorTable == nil then return string.char(255,255,255,255) end
local col = {}
Expand Down Expand Up @@ -280,7 +292,7 @@ local function GetEntryData(playerID, teamID, allyTeamID, isAiTeam, isDead)
end

if isAiTeam then
local _, name = Spring.GetAIInfo(teamID)
name = GetAIName(teamID)
entryData.name = name
end

Expand Down Expand Up @@ -599,7 +611,8 @@ local function InitializePlayerlist()
for i = 1, #teamList do
local teamID = teamList[i]
if teamID ~= gaiaTeamID then
local _, leaderID, isDead, isAiTeam, _, allyTeamID = Spring.GetTeamInfo(teamID, false)
local _, leaderID, isDead, _, _, allyTeamID = Spring.GetTeamInfo(teamID, false)
local isAiTeam = IsTeamAI(teamID)
if leaderID < 0 then
leaderID = Spring.GetTeamRulesParam(teamID, "initLeaderID") or leaderID
end
Expand Down