From 3a13d261e29d833b07a83377900bc34c0779c4d7 Mon Sep 17 00:00:00 2001 From: Gerkiz Date: Mon, 14 Dec 2020 19:36:37 +0100 Subject: [PATCH] make gui handlers utilize anti-spam --- comfy_panel/admin.lua | 52 +++--- comfy_panel/config.lua | 197 +++++++++----------- comfy_panel/group.lua | 9 +- comfy_panel/main.lua | 26 ++- comfy_panel/player_list.lua | 15 +- comfy_panel/poll.lua | 2 +- comfy_panel/score.lua | 9 +- maps/mountain_fortress_v3/gui.lua | 18 +- maps/mountain_fortress_v3/icw/functions.lua | 5 + maps/mountain_fortress_v3/locomotive.lua | 17 ++ modules/charging_station.lua | 7 +- modules/difficulty_vote_by_amount.lua | 14 +- modules/map_info.lua | 17 +- modules/rpg/main.lua | 22 ++- utils/gui.lua | 8 +- 15 files changed, 253 insertions(+), 165 deletions(-) diff --git a/comfy_panel/admin.lua b/comfy_panel/admin.lua index 8917095a..a959a583 100644 --- a/comfy_panel/admin.lua +++ b/comfy_panel/admin.lua @@ -4,6 +4,7 @@ local Event = require 'utils.event' local Jailed = require 'utils.datastore.jail_data' local Tabs = require 'comfy_panel.main' local AntiGrief = require 'antigrief' +local SpamProtection = require 'utils.spam_protection' local lower = string.lower @@ -47,9 +48,7 @@ local function bring_player(player, source_player) if pos then player.teleport(pos, source_player.surface) game.print( - player.name .. - ' has been teleported to ' .. - source_player.name .. '. ' .. bring_player_messages[math.random(1, #bring_player_messages)], + player.name .. ' has been teleported to ' .. source_player.name .. '. ' .. bring_player_messages[math.random(1, #bring_player_messages)], {r = 0.98, g = 0.66, b = 0.22} ) end @@ -66,11 +65,7 @@ local function go_to_player(player, source_player) local pos = player.surface.find_non_colliding_position('character', player.position, 50, 1) if pos then source_player.teleport(pos, player.surface) - game.print( - source_player.name .. - ' is visiting ' .. player.name .. '. ' .. go_to_player_messages[math.random(1, #go_to_player_messages)], - {r = 0.98, g = 0.66, b = 0.22} - ) + game.print(source_player.name .. ' is visiting ' .. player.name .. '. ' .. go_to_player_messages[math.random(1, #go_to_player_messages)], {r = 0.98, g = 0.66, b = 0.22}) end end @@ -102,10 +97,7 @@ local function damage(player, source_player) end player.character.health = player.character.health - 125 player.surface.create_entity({name = 'big-explosion', position = player.position}) - game.print( - player.name .. damage_messages[math.random(1, #damage_messages)] .. source_player.name, - {r = 0.98, g = 0.66, b = 0.22} - ) + game.print(player.name .. damage_messages[math.random(1, #damage_messages)] .. source_player.name, {r = 0.98, g = 0.66, b = 0.22}) end end @@ -139,10 +131,7 @@ local function enemy(player, source_player) game.create_force('enemy_players') end player.force = game.forces.enemy_players - game.print( - player.name .. ' is now an enemy! ' .. enemy_messages[math.random(1, #enemy_messages)], - {r = 0.95, g = 0.15, b = 0.15} - ) + game.print(player.name .. ' is now an enemy! ' .. enemy_messages[math.random(1, #enemy_messages)], {r = 0.95, g = 0.15, b = 0.15}) admin_only_message(source_player.name .. ' has turned ' .. player.name .. ' into an enemy') end @@ -339,6 +328,11 @@ local function text_changed(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + local data = { frame = frame, antigrief = antigrief, @@ -367,10 +361,7 @@ local create_admin_panel = (function(player, frame) end end - local drop_down = - frame.add( - {type = 'drop-down', name = 'admin_player_select', items = player_names, selected_index = selected_index} - ) + local drop_down = frame.add({type = 'drop-down', name = 'admin_player_select', items = player_names, selected_index = selected_index}) drop_down.style.minimal_width = 326 drop_down.style.right_padding = 12 drop_down.style.left_padding = 12 @@ -518,10 +509,7 @@ local create_admin_panel = (function(player, frame) end end - local drop_down_2 = - frame.add( - {type = 'drop-down', name = 'admin_history_select', items = histories, selected_index = selected_index_2} - ) + local drop_down_2 = frame.add({type = 'drop-down', name = 'admin_history_select', items = histories, selected_index = selected_index_2}) drop_down_2.style.right_padding = 12 drop_down_2.style.left_padding = 12 @@ -621,6 +609,7 @@ end local function on_gui_click(event) local player = game.players[event.player_index] + local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return @@ -641,6 +630,11 @@ local function on_gui_click(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + if admin_functions[name] then local target_player_name = frame['admin_player_select'].items[frame['admin_player_select'].selected_index] if not target_player_name then @@ -706,6 +700,11 @@ local function on_gui_selection_state_changed(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + create_admin_panel(player, frame) end if name == 'admin_player_select' then @@ -722,6 +721,11 @@ local function on_gui_selection_state_changed(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + create_admin_panel(player, frame) end end diff --git a/comfy_panel/config.lua b/comfy_panel/config.lua index d0ee7aee..3bbcd2d9 100644 --- a/comfy_panel/config.lua +++ b/comfy_panel/config.lua @@ -4,6 +4,7 @@ local Antigrief = require 'antigrief' local Color = require 'utils.color_presets' local SessionData = require 'utils.datastore.session_data' local Utils = require 'utils.core' +local SpamProtection = require 'utils.spam_protection' local spaghett_entity_blacklist = { ['logistic-chest-requester'] = true, @@ -108,17 +109,11 @@ local functions = { end, ['comfy_panel_blueprint_toggle'] = function(event) if event.element.switch_state == 'left' then - game.permissions.get_group('Default').set_allows_action( - defines.input_action.open_blueprint_library_gui, - true - ) + game.permissions.get_group('Default').set_allows_action(defines.input_action.open_blueprint_library_gui, true) game.permissions.get_group('Default').set_allows_action(defines.input_action.import_blueprint_string, true) get_actor(event, '{Blueprints}', 'has enabled blueprints!') else - game.permissions.get_group('Default').set_allows_action( - defines.input_action.open_blueprint_library_gui, - false - ) + game.permissions.get_group('Default').set_allows_action(defines.input_action.open_blueprint_library_gui, false) game.permissions.get_group('Default').set_allows_action(defines.input_action.import_blueprint_string, false) get_actor(event, '{Blueprints}', 'has disabled blueprints!') end @@ -133,26 +128,25 @@ local functions = { end spaghett() end, - ["bb_team_balancing_toggle"] = function(event) - if event.element.switch_state == "left" then - global.bb_settings.team_balancing = true - game.print("Team balancing has been enabled!") - else - global.bb_settings.team_balancing = false - game.print("Team balancing has been disabled!") - end - end, - - ["bb_only_admins_vote"] = function(event) - if event.element.switch_state == "left" then - global.bb_settings.only_admins_vote = true - global.difficulty_player_votes = {} - game.print("Admin-only difficulty voting has been enabled!") - else - global.bb_settings.only_admins_vote = false - game.print("Admin-only difficulty voting has been disabled!") - end - end, + ['bb_team_balancing_toggle'] = function(event) + if event.element.switch_state == 'left' then + global.bb_settings.team_balancing = true + game.print('Team balancing has been enabled!') + else + global.bb_settings.team_balancing = false + game.print('Team balancing has been disabled!') + end + end, + ['bb_only_admins_vote'] = function(event) + if event.element.switch_state == 'left' then + global.bb_settings.only_admins_vote = true + global.difficulty_player_votes = {} + game.print('Admin-only difficulty voting has been enabled!') + else + global.bb_settings.only_admins_vote = false + game.print('Admin-only difficulty voting has been disabled!') + end + end } local poll_function = { @@ -221,11 +215,7 @@ local fortress_functions = { get_actor(event, '{Collapse}', 'has enabled the collapse function. Collapse will occur after wave 100!') else this.collapse_grace = false - get_actor( - event, - '{Collapse}', - 'has disabled the collapse function. You must reach zone 2 for collapse to occur!' - ) + get_actor(event, '{Collapse}', 'has disabled the collapse function. You must reach zone 2 for collapse to occur!') end end, ['comfy_panel_spill_items_to_surface'] = function(event) @@ -233,18 +223,10 @@ local fortress_functions = { local this = WPT.get() if event.element.switch_state == 'left' then this.spill_items_to_surface = true - get_actor( - event, - '{Item Spill}', - 'has enabled the ore spillage function. Ores now drop to surface when mining.' - ) + get_actor(event, '{Item Spill}', 'has enabled the ore spillage function. Ores now drop to surface when mining.') else this.spill_items_to_surface = false - get_actor( - event, - '{Item Spill}', - 'has disabled the item spillage function. Ores no longer drop to surface when mining.' - ) + get_actor(event, '{Item Spill}', 'has disabled the item spillage function. Ores no longer drop to surface when mining.') end end, ['comfy_panel_void_or_tile'] = function(event) @@ -351,13 +333,7 @@ local build_config_gui = (function(player, frame) if global.auto_hotbar_enabled[player.index] then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_auto_hotbar_switch', - 'AutoHotbar', - 'Automatically fills your hotbar with placeable items.' - ) + add_switch(scroll_pane, switch_state, 'comfy_panel_auto_hotbar_switch', 'AutoHotbar', 'Automatically fills your hotbar with placeable items.') scroll_pane.add({type = 'line'}) end @@ -368,13 +344,7 @@ local build_config_gui = (function(player, frame) if not poll_table[player.index] then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_poll_no_notify_toggle', - 'Notify on polls', - 'Receive a message when new polls are created and popup the poll.' - ) + add_switch(scroll_pane, switch_state, 'comfy_panel_poll_no_notify_toggle', 'Notify on polls', 'Receive a message when new polls are created and popup the poll.') scroll_pane.add({type = 'line'}) end @@ -394,13 +364,7 @@ local build_config_gui = (function(player, frame) if game.permissions.get_group('Default').allows_action(defines.input_action.open_blueprint_library_gui) then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_blueprint_toggle', - 'Blueprint Library', - 'Toggles the usage of blueprint strings and the library.' - ) + add_switch(scroll_pane, switch_state, 'comfy_panel_blueprint_toggle', 'Blueprint Library', 'Toggles the usage of blueprint strings and the library.') scroll_pane.add({type = 'line'}) @@ -422,13 +386,7 @@ local build_config_gui = (function(player, frame) if global.comfy_panel_config.poll_trusted then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_poll_trusted_toggle', - 'Poll mode', - 'Disables non-trusted plebs to create polls.' - ) + add_switch(scroll_pane, switch_state, 'comfy_panel_poll_trusted_toggle', 'Poll mode', 'Disables non-trusted plebs to create polls.') end scroll_pane.add({type = 'line'}) @@ -446,16 +404,9 @@ local build_config_gui = (function(player, frame) if AG.enabled then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_disable_antigrief', - 'Antigrief', - 'Left = Enables antigrief / Right = Disables antigrief' - ) + add_switch(scroll_pane, switch_state, 'comfy_panel_disable_antigrief', 'Antigrief', 'Left = Enables antigrief / Right = Disables antigrief') scroll_pane.add({type = 'line'}) - - + if package.loaded['maps.biter_battles_v2.main'] then label = scroll_pane.add({type = 'label', caption = 'Biter Battles Settings'}) label.style.font = 'default-bold' @@ -467,22 +418,38 @@ local build_config_gui = (function(player, frame) label.style.font_color = Color.green scroll_pane.add({type = 'line'}) - - local switch_state = "right" - if global.bb_settings.team_balancing then switch_state = "left" end - local switch = add_switch(scroll_pane, switch_state, "bb_team_balancing_toggle", "Team Balancing", "Players can only join a team that has less or equal players than the opposing.") - if not admin then switch.ignored_by_interaction = true end - - scroll_pane.add({type = 'line'}) - - local switch_state = "right" - if global.bb_settings.only_admins_vote then switch_state = "left" end - local switch = add_switch(scroll_pane, switch_state, "bb_only_admins_vote", "Admin Vote", "Only admins can vote for map difficulty. Clears all currently existing votes.") - if not admin then switch.ignored_by_interaction = true end - - scroll_pane.add({type = 'line'}) - end - + + local switch_state = 'right' + if global.bb_settings.team_balancing then + switch_state = 'left' + end + local switch = + add_switch( + scroll_pane, + switch_state, + 'bb_team_balancing_toggle', + 'Team Balancing', + 'Players can only join a team that has less or equal players than the opposing.' + ) + if not admin then + switch.ignored_by_interaction = true + end + + scroll_pane.add({type = 'line'}) + + local switch_state = 'right' + if global.bb_settings.only_admins_vote then + switch_state = 'left' + end + local switch = + add_switch(scroll_pane, switch_state, 'bb_only_admins_vote', 'Admin Vote', 'Only admins can vote for map difficulty. Clears all currently existing votes.') + if not admin then + switch.ignored_by_interaction = true + end + + scroll_pane.add({type = 'line'}) + end + if package.loaded['maps.mountain_fortress_v3.main'] then label = scroll_pane.add({type = 'label', caption = 'Mountain Fortress Settings'}) label.style.font = 'default-bold' @@ -499,13 +466,7 @@ local build_config_gui = (function(player, frame) if full.fullness_enabled then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_disable_fullness', - 'Inventory Fullness', - 'Left = Enables inventory fullness.\nRight = Disables inventory fullness.' - ) + add_switch(scroll_pane, switch_state, 'comfy_panel_disable_fullness', 'Inventory Fullness', 'Left = Enables inventory fullness.\nRight = Disables inventory fullness.') scroll_pane.add({type = 'line'}) @@ -556,13 +517,7 @@ local build_config_gui = (function(player, frame) if this.void_or_tile then switch_state = 'left' end - add_switch( - scroll_pane, - switch_state, - 'comfy_panel_void_or_tile', - 'Void Tiles', - 'Left = Changes the tiles to out-of-map.\nRight = Changes the tiles to lab-dark-2' - ) + add_switch(scroll_pane, switch_state, 'comfy_panel_void_or_tile', 'Void Tiles', 'Left = Changes the tiles to out-of-map.\nRight = Changes the tiles to lab-dark-2') scroll_pane.add({type = 'line'}) switch_state = 'right' @@ -588,22 +543,44 @@ local build_config_gui = (function(player, frame) end) local function on_gui_switch_state_changed(event) + local player = game.players[event.player_index] + if not (player and player.valid) then + return + end + if not event.element then return end if not event.element.valid then return end + if functions[event.element.name] then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end functions[event.element.name](event) return elseif antigrief_functions[event.element.name] then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end antigrief_functions[event.element.name](event) return elseif fortress_functions[event.element.name] then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end fortress_functions[event.element.name](event) return elseif package.loaded['comfy_panel.poll'] then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end if poll_function[event.element.name] then poll_function[event.element.name](event) return diff --git a/comfy_panel/group.lua b/comfy_panel/group.lua index 834cecd2..3067a579 100644 --- a/comfy_panel/group.lua +++ b/comfy_panel/group.lua @@ -2,6 +2,7 @@ local Tabs = require 'comfy_panel.main' local Global = require 'utils.global' +local SpamProtection = require 'utils.spam_protection' local this = { player_group = {}, @@ -181,6 +182,7 @@ local function on_gui_click(event) if not event then return end + if not event.element then return end @@ -188,8 +190,8 @@ local function on_gui_click(event) return end - local player = game.players[event.element.player_index] local name = event.element.name + local player = game.players[event.player_index] local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return @@ -197,6 +199,11 @@ local function on_gui_click(event) if frame.name ~= 'Groups' then return end + local is_spamming = SpamProtection.is_spamming(player) + + if is_spamming then + return + end if name == 'create_new_group' then local new_group_name = frame.frame2.group_table.new_group_name.text diff --git a/comfy_panel/main.lua b/comfy_panel/main.lua index f4dff0a6..cd0eaf01 100644 --- a/comfy_panel/main.lua +++ b/comfy_panel/main.lua @@ -9,7 +9,8 @@ if admin = true, then tab is visible only for admins (usable for map-specific se draw_map_scores would be a function with the player and the frame as arguments ]] -local event = require 'utils.event' +local Event = require 'utils.event' +local SpamProtection = require 'utils.spam_protection' comfy_panel_tabs = {} @@ -133,15 +134,24 @@ local function on_player_joined_game(event) end local function on_gui_click(event) + if not event then + return + end + + local player = game.players[event.player_index] + if not event.element then return end if not event.element.valid then return end - local player = game.players[event.player_index] if event.element.name == 'comfy_panel_top_button' then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end if player.gui.left.comfy_panel then player.gui.left.comfy_panel.destroy() Public.comfy_panel_restore_left_gui(player) @@ -154,6 +164,10 @@ local function on_gui_click(event) end if event.element.caption == 'X' and event.element.name == 'comfy_panel_close' then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end player.gui.left.comfy_panel.destroy() Public.comfy_panel_restore_left_gui(player) return @@ -165,10 +179,14 @@ local function on_gui_click(event) if event.element.type ~= 'tab' then return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end Public.comfy_panel_refresh_active_tab(player) end -event.add(defines.events.on_player_joined_game, on_player_joined_game) -event.add(defines.events.on_gui_click, on_gui_click) +Event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.add(defines.events.on_gui_click, on_gui_click) return Public diff --git a/comfy_panel/player_list.lua b/comfy_panel/player_list.lua index 12fb9058..3f786457 100644 --- a/comfy_panel/player_list.lua +++ b/comfy_panel/player_list.lua @@ -18,6 +18,7 @@ local Session = require 'utils.datastore.session_data' local Jailed = require 'utils.datastore.jail_data' local Tabs = require 'comfy_panel.main' local Global = require 'utils.global' +local SpamProtection = require 'utils.spam_protection' local Public = {} @@ -477,8 +478,7 @@ local function player_list_show(player, frame, sort_by) } player_list_panel_table.style.maximal_height = 530 - player_list_panel_table = - player_list_panel_table.add {type = 'table', name = 'player_list_panel_table', column_count = 5} + player_list_panel_table = player_list_panel_table.add {type = 'table', name = 'player_list_panel_table', column_count = 5} local player_list = get_sorted_list(sort_by) for i = 1, #player_list, 1 do @@ -564,8 +564,7 @@ local function player_list_show(player, frame, sort_by) -- Poke local flow = player_list_panel_table.add {type = 'flow', name = 'button_flow_' .. i, direction = 'horizontal'} flow.add {type = 'label', name = 'button_spacer_' .. i, caption = ''} - local button = - flow.add {type = 'button', name = 'poke_player_' .. player_list[i].name, caption = player_list[i].pokes} + local button = flow.add {type = 'button', name = 'poke_player_' .. player_list[i].name, caption = player_list[i].pokes} button.style.font = 'default' button.tooltip = 'Poke ' .. player_list[i].name .. ' with a random message!' label.style.font_color = {r = 0.83, g = 0.83, b = 0.83} @@ -584,6 +583,7 @@ local function on_gui_click(event) if not event then return end + if not event.element then return end @@ -593,8 +593,8 @@ local function on_gui_click(event) if not event.element.name then return end - local player = game.players[event.element.player_index] + local player = game.players[event.player_index] local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return @@ -603,6 +603,11 @@ local function on_gui_click(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + local name = event.element.name local actions = { ['player_list_panel_header_2'] = function() diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index c4ccb238..aa10ea5f 100644 --- a/comfy_panel/poll.lua +++ b/comfy_panel/poll.lua @@ -6,6 +6,7 @@ local Server = require 'utils.server' local Tabs = require 'comfy_panel.main' local session = require 'utils.datastore.session_data' + local Class = {} local insert = table.insert @@ -1206,7 +1207,6 @@ function Class.reset() local main_frame = p.gui.left[main_frame_name] if main_frame and main_frame.valid then local main_frame_data = Gui.get_data(main_frame) - local poll_index = main_frame_data.poll_index update_poll_viewer(main_frame_data) remove_main_frame(main_frame, p.gui.left, p) end diff --git a/comfy_panel/score.lua b/comfy_panel/score.lua index 68d32672..a2140ba5 100644 --- a/comfy_panel/score.lua +++ b/comfy_panel/score.lua @@ -3,6 +3,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' local Tabs = require 'comfy_panel.main' +local SpamProtection = require 'utils.spam_protection' local Public = {} local this = { @@ -265,6 +266,7 @@ local function on_gui_click(event) if not event then return end + if not event.element then return end @@ -272,7 +274,7 @@ local function on_gui_click(event) return end - local player = game.players[event.element.player_index] + local player = game.players[event.player_index] local frame = Tabs.comfy_panel_get_active_frame(player) if not frame then return @@ -281,6 +283,11 @@ local function on_gui_click(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + local name = event.element.name -- Handles click on the checkbox, for floating score diff --git a/maps/mountain_fortress_v3/gui.lua b/maps/mountain_fortress_v3/gui.lua index ca4f3a04..1c8cae7c 100644 --- a/maps/mountain_fortress_v3/gui.lua +++ b/maps/mountain_fortress_v3/gui.lua @@ -2,6 +2,8 @@ local Event = require 'utils.event' local RPG_Settings = require 'modules.rpg.table' local WPT = require 'maps.mountain_fortress_v3.table' local Gui = require 'utils.gui' +local SpamProtection = require 'utils.spam_protection' + local format_number = require 'util'.format_number local Public = {} @@ -140,19 +142,23 @@ end local function on_gui_click(event) local element = event.element - local player = game.players[event.player_index] - if not validate_player(player) then - return - end if not element.valid then return end - local locomotive = WPT.get('locomotive') - local name = element.name if name == main_button_name then + local player = game.players[event.player_index] + if not validate_player(player) then + return + end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + + local locomotive = WPT.get('locomotive') if not player or not player.valid then return end diff --git a/maps/mountain_fortress_v3/icw/functions.lua b/maps/mountain_fortress_v3/icw/functions.lua index a943d9ce..d1e07738 100644 --- a/maps/mountain_fortress_v3/icw/functions.lua +++ b/maps/mountain_fortress_v3/icw/functions.lua @@ -2,6 +2,7 @@ local Public = {} local ICW = require 'maps.mountain_fortress_v3.icw.table' local WPT = require 'maps.mountain_fortress_v3.table' +local SpamProtection = require 'utils.spam_protection' local main_tile_name = 'tutorial-grid' function Public.request_reconstruction(icw) @@ -1012,6 +1013,10 @@ function Public.toggle_minimap(icw, event) return end local player = game.players[event.player_index] + local is_spamming = SpamProtection.is_spamming(player, 5) + if is_spamming then + return + end local player_data = get_player_data(icw, player) if event.button == defines.mouse_button_type.right then player_data.zoom = player_data.zoom - 0.07 diff --git a/maps/mountain_fortress_v3/locomotive.lua b/maps/mountain_fortress_v3/locomotive.lua index 263cf570..a1ce0cec 100644 --- a/maps/mountain_fortress_v3/locomotive.lua +++ b/maps/mountain_fortress_v3/locomotive.lua @@ -17,6 +17,8 @@ local Antigrief = require 'antigrief' local Task = require 'utils.task' local Token = require 'utils.token' local MapFunctions = require 'tools.map_functions' +local SpamProtection = require 'utils.spam_protection' + local format_number = require 'util'.format_number local Public = {} @@ -717,6 +719,11 @@ local function slider_changed(event) if not slider_value then return end + + local is_spamming = SpamProtection.is_spamming(player, 2) + if is_spamming then + return + end slider_value = slider_value.slider if not slider_value then return @@ -749,6 +756,11 @@ local function text_changed(event) return end + local is_spamming = SpamProtection.is_spamming(player, 2) + if is_spamming then + return + end + if not data.text_input or not data.text_input.valid then return end @@ -928,6 +940,11 @@ local function gui_click(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + if not data then return end diff --git a/modules/charging_station.lua b/modules/charging_station.lua index b7996f0e..1fc3a0c0 100644 --- a/modules/charging_station.lua +++ b/modules/charging_station.lua @@ -2,6 +2,7 @@ --charge your armor equipment from nearby accumulators! --change global.charging_station_multiplier if you want different conversion rate than 1:1. local Event = require 'utils.event' +local SpamProtection = require 'utils.spam_protection' local function draw_charging_gui() for _, player in pairs(game.connected_players) do @@ -84,8 +85,12 @@ local function on_gui_click(event) if not event.element.valid then return end - local player = game.players[event.element.player_index] if event.element.name == 'charging_station' then + local player = game.players[event.player_index] + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end charge(player) return end diff --git a/modules/difficulty_vote_by_amount.lua b/modules/difficulty_vote_by_amount.lua index 82f66a79..b8cf9d8d 100644 --- a/modules/difficulty_vote_by_amount.lua +++ b/modules/difficulty_vote_by_amount.lua @@ -1,6 +1,7 @@ local Event = require 'utils.event' local Server = require 'utils.server' local Global = require 'utils.global' +local SpamProtection = require 'utils.spam_protection' local max = math.max local round = math.round @@ -259,14 +260,20 @@ local function on_gui_click(event) if not event then return end + local player = game.players[event.player_index] + if not event.element then return end if not event.element.valid then return end - local player = game.players[event.element.player_index] + if event.element.name == 'difficulty_gui' then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end poll_difficulty(player) return end @@ -285,6 +292,11 @@ local function on_gui_click(event) return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + local i = tonumber(event.element.name) if this.difficulty_player_votes[player.name] and this.difficulty_player_votes[player.name].index == i then diff --git a/modules/map_info.lua b/modules/map_info.lua index 1907875a..d5f4afca 100644 --- a/modules/map_info.lua +++ b/modules/map_info.lua @@ -1,5 +1,7 @@ +local Event = require 'utils.event' local Global = require 'utils.global' local Tabs = require 'comfy_panel.main' +local SpamProtection = require 'utils.spam_protection' local map_info = { localised_category = false, @@ -100,13 +102,23 @@ local function on_gui_click(event) if not event then return end + local player = game.players[event.player_index] + if not (player and player.valid) then + return + end + if not event.element then return end if not event.element.valid then return end + if event.element.name == 'close_map_intro' then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end game.players[event.player_index].gui.left.comfy_panel.destroy() return end @@ -114,8 +126,7 @@ end comfy_panel_tabs['Map Info'] = {gui = create_map_intro, admin = false} -local event = require 'utils.event' -event.add(defines.events.on_player_joined_game, on_player_joined_game) -event.add(defines.events.on_gui_click, on_gui_click) +Event.add(defines.events.on_player_joined_game, on_player_joined_game) +Event.add(defines.events.on_gui_click, on_gui_click) return Public diff --git a/modules/rpg/main.lua b/modules/rpg/main.lua index 694a6c96..fe8ccc7d 100644 --- a/modules/rpg/main.lua +++ b/modules/rpg/main.lua @@ -2,6 +2,7 @@ local Gui = require 'utils.gui' local Event = require 'utils.event' local AntiGrief = require 'antigrief' local Color = require 'utils.color_presets' +local SpamProtection = require 'utils.spam_protection' local WD = require 'modules.wave_defense.table' local Math2D = require 'math2d' @@ -24,6 +25,14 @@ local main_frame_name = RPG.main_frame_name local sub = string.sub local function on_gui_click(event) + if not event then + return + end + local player = game.players[event.player_index] + if not (player and player.valid) then + return + end + if not event.element then return end @@ -31,9 +40,11 @@ local function on_gui_click(event) return end local element = event.element - local player = game.players[event.player_index] - if not player or not player.valid then - return + if player.gui.screen[main_frame_name] then + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end end local surface_name = RPG.get('rpg_extra').surface_name @@ -701,10 +712,7 @@ local function on_pre_player_mined_item(event) end local rpg_t = RPG.get('rpg_t') - if - rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and - rpg_t[player.index].last_mined_entity_position.y == event.entity.position.y - then + if rpg_t[player.index].last_mined_entity_position.x == event.entity.position.x and rpg_t[player.index].last_mined_entity_position.y == event.entity.position.y then return end rpg_t[player.index].last_mined_entity_position.x = entity.position.x diff --git a/utils/gui.lua b/utils/gui.lua index 4dbbbdd6..f406146b 100644 --- a/utils/gui.lua +++ b/utils/gui.lua @@ -1,6 +1,7 @@ local Token = require 'utils.token' local Event = require 'utils.event' local Global = require 'utils.global' +local SpamProtection = require 'utils.spam_protection' local tostring = tostring local next = next @@ -151,9 +152,14 @@ local function handler_factory(event_id) end local player = game.get_player(event.player_index) - if not player or not player.valid then + if not (player and player.valid) then return end + local is_spamming = SpamProtection.is_spamming(player) + if is_spamming then + return + end + event.player = player handler(event)