From b213ef8f7f07e7399db18067aa0e1d7b5ec4d435 Mon Sep 17 00:00:00 2001 From: Fireball <32598847+FIr3baL@users.noreply.github.com> Date: Fri, 6 Dec 2024 12:44:42 +0100 Subject: [PATCH] Fix parsing of avoids --- libs/chiliui/chili/headers/util.lua | 9 +++++++++ libs/liblobby/lobby/interface.lua | 11 ++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/libs/chiliui/chili/headers/util.lua b/libs/chiliui/chili/headers/util.lua index aaa8abc42..f9fa9a7d7 100644 --- a/libs/chiliui/chili/headers/util.lua +++ b/libs/chiliui/chili/headers/util.lua @@ -397,6 +397,15 @@ function table:ifind(element) return false end +function table:ifindByKey(element, key) + for i = 1, #self do + if self[i][key] and self[i][key] == element then + return i + end + end + return false +end + function table:sum() local r = 0 for i = 1, #self do diff --git a/libs/liblobby/lobby/interface.lua b/libs/liblobby/lobby/interface.lua index ce8c134fe..de7112731 100644 --- a/libs/liblobby/lobby/interface.lua +++ b/libs/liblobby/lobby/interface.lua @@ -2148,18 +2148,15 @@ local function buildDisregardListID(ignores, avoids, blocks) for _, userID in ipairs(blocks) do table.insert(disregardListID, {userID = userID, status = Configuration.BLOCK}) end + for _, userID in ipairs(avoids) do - if table.ifind(disregardListID, userID) then - Spring.Log(LOG_SECTION, LOG.ERROR, string.format("Found same user in 2 disregard lists (%s and %s):%s", "blocks", "avoids", userID)) - else + if not table.ifindByKey(disregardListID, userID, "userID") then table.insert(disregardListID, {userID = userID, status = Configuration.AVOID}) end end + for _, userID in ipairs(ignores) do - local i = table.ifind(disregardListID, userID) - if i then - Spring.Log(LOG_SECTION, LOG.ERROR, string.format("Found same user in 2 disregard lists (%s and %s):%s", disregardListID[i].status == Configuration.BLOCK and "blocks" or "avoids", "ignores" , userID)) - else + if not table.ifindByKey(disregardListID, userID, "userID") then table.insert(disregardListID, {userID = userID, status = Configuration.IGNORE}) end end