From 8b8764c5a5a8c35b5fea10aa5361e272b0fcfa07 Mon Sep 17 00:00:00 2001 From: Earu Date: Sat, 8 Oct 2022 19:01:20 +0200 Subject: [PATCH] steam block list syncing convar --- lua/easychat/client/settings.lua | 4 +++- lua/easychat/easychat.lua | 1 + lua/easychat/networking.lua | 19 +++++++++++++------ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lua/easychat/client/settings.lua b/lua/easychat/client/settings.lua index bd1b130..abd7a57 100644 --- a/lua/easychat/client/settings.lua +++ b/lua/easychat/client/settings.lua @@ -32,7 +32,8 @@ local EC_NICK_COMPLETE = get_cvar("easychat_nick_complete") local EC_NICK_PRIORITIZE = get_cvar("easychat_nick_prioritize") local EC_OUT_CLICK_CLOSE = get_cvar("easychat_out_click_close") local EC_SERVER_MSG = get_cvar("easychat_server_msg") -local EC_SKIP_STARTUP_MSG = GetConVar("easychat_skip_startup_msg") +local EC_SKIP_STARTUP_MSG = get_cvar("easychat_skip_startup_msg") +local EC_SYNC_STEAM_BLOCKS = get_cvar("easychat_sync_steam_blocks") -- timestamps local EC_TIMESTAMPS = get_cvar("easychat_timestamps") @@ -99,6 +100,7 @@ local function create_default_settings() [EC_OUT_CLICK_CLOSE] = "Close the chat when clicking away", [EC_SERVER_MSG] = "Show changes made to the server cvars", [EC_SKIP_STARTUP_MSG] = "Skips annoying addon startup messages (displays in console)", + [EC_SYNC_STEAM_BLOCKS] = "Synchronize your steam block list with EasyChat", }) settings:AddSpacer(category_name) diff --git a/lua/easychat/easychat.lua b/lua/easychat/easychat.lua index 9296a21..b296b3c 100644 --- a/lua/easychat/easychat.lua +++ b/lua/easychat/easychat.lua @@ -460,6 +460,7 @@ if CLIENT then local EC_OUT_CLICK_CLOSE = CreateConVar("easychat_out_click_close", "1", FCVAR_ARCHIVE, "Clicking outside the chatbox closes it") local EC_SERVER_MSG = CreateConVar("easychat_server_msg", "1", FCVAR_ARCHIVE, "Shows convars being changed on the server") local EC_SKIP_STARTUP_MSG = CreateConVar("easychat_skip_startup_msg", "1", FCVAR_ARCHIVE, "Displays random addons startup messages in the console") + local _ = CreateConVar("easychat_sync_steam_blocks", "1", FCVAR_ARCHIVE, "Sync Steam blocked users with EasyChat") -- timestamps local EC_TIMESTAMPS = CreateConVar("easychat_timestamps", "0", FCVAR_ARCHIVE, "Display timestamps in the chatbox") diff --git a/lua/easychat/networking.lua b/lua/easychat/networking.lua index 2ebc993..b6c2937 100644 --- a/lua/easychat/networking.lua +++ b/lua/easychat/networking.lua @@ -497,9 +497,12 @@ if CLIENT then EasyChat.BlockedPlayers = util.JSONToTable(BLOCKED_PLAYERS) or {} local lookup = {} - for _, ply in ipairs(player.GetAll()) do - if ply:GetFriendStatus() == "blocked" then - table.insert(lookup, ply:SteamID()) + + if GetConVar("easychat_sync_steam_blocks"):GetBool() then + for _, ply in ipairs(player.GetAll()) do + if ply:GetFriendStatus() == "blocked" then + table.insert(lookup, ply:SteamID()) + end end end @@ -515,7 +518,7 @@ if CLIENT then end) end - EasyChat.LoadBlockedPlayers() + hook.Add("Initialize", "EasyChatBlockListInit", EasyChat.LoadBlockedPlayers) function EasyChat.BlockPlayer(steam_id) EasyChat.BlockedPlayers[steam_id] = true @@ -549,8 +552,10 @@ if CLIENT then if not IsValid(ply) then return false end if not ply:IsPlayer() then return false end - local steam_blocked = (ply:GetFriendStatus() or "") == "blocked" - if steam_blocked then return true end + if GetConVar("easychat_sync_steam_blocks"):GetBool() then + local steam_blocked = (ply:GetFriendStatus() or "") == "blocked" + if steam_blocked then return true end + end local steam_id = ply:SteamID() or "" if LocalPlayer():SteamID() == steam_id then return false end @@ -561,6 +566,8 @@ if CLIENT then -- sync up data for players joining, we dont want a funny steam blocked person to avoid blocking gameevent.Listen("player_spawn") hook.Add("player_spawn", TAG, function(data) + if not GetConVar("easychat_sync_steam_blocks"):GetBool() then return end + timer.Simple(10, function() local ply = Player(data.userid) if not IsValid(ply) then return end