diff --git a/comfy_panel/admin.lua b/comfy_panel/admin.lua index 944c725c..6037f234 100644 --- a/comfy_panel/admin.lua +++ b/comfy_panel/admin.lua @@ -644,7 +644,7 @@ local function on_gui_click(event) local name = event.element.name - if name == 'tab_Admin' then + if name == 'tab_' .. module_name then local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin tab_Admin') if is_spamming then return diff --git a/comfy_panel/bottom_frame.lua b/comfy_panel/bottom_frame.lua index ef86ac97..d8faef51 100644 --- a/comfy_panel/bottom_frame.lua +++ b/comfy_panel/bottom_frame.lua @@ -3,6 +3,7 @@ local Event = require 'utils.event' local Global = require 'utils.global' local ComfyGui = require 'comfy_panel.main' local Gui = require 'utils.gui' +local SpamProtection = require 'utils.spam_protection' local this = { players = {}, @@ -208,6 +209,10 @@ end Gui.on_click( clear_corpse_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Clear Corpse') + if is_spamming then + return + end Misc.clear_corpses(event) end ) diff --git a/comfy_panel/config.lua b/comfy_panel/config.lua index 05c53a6a..2d8b886e 100644 --- a/comfy_panel/config.lua +++ b/comfy_panel/config.lua @@ -811,8 +811,35 @@ local function on_robot_built_entity(event) spaghett_deny_building(event) end +local function on_gui_click(event) + if not event then + return + end + local player = game.get_player(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 + + local name = event.element.name + + if name == 'tab_' .. module_name then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Main Button') + if is_spamming then + return + end + end +end + Tabs.add_tab_to_gui({name = module_name, id = build_config_gui_token, admin = false}) +Event.add(defines.events.on_gui_click, on_gui_click) Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed) Event.add(defines.events.on_force_created, on_force_created) Event.add(defines.events.on_built_entity, on_built_entity) diff --git a/comfy_panel/group.lua b/comfy_panel/group.lua index dd8aa7d2..f9cbc0c6 100644 --- a/comfy_panel/group.lua +++ b/comfy_panel/group.lua @@ -235,7 +235,11 @@ local function on_gui_click(event) local name = event.element.name - if name == 'tab_Groups' then + if not name then + return + end + + if name == 'tab_' .. module_name then local is_spamming = SpamProtection.is_spamming(player, nil, 'Groups tab_Groups') if is_spamming then return diff --git a/comfy_panel/player_list.lua b/comfy_panel/player_list.lua index 06f07765..08c0b645 100644 --- a/comfy_panel/player_list.lua +++ b/comfy_panel/player_list.lua @@ -740,7 +740,7 @@ local function on_gui_click(event) local name = element.name local player = game.get_player(event.player_index) - if name == 'tab_Players' then + if name == 'tab_' .. module_name then local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList tab_Players') if is_spamming then return @@ -861,6 +861,10 @@ local function on_gui_click(event) --Locate other players local index = tonumber(element.name) if index and game.players[index] and index == game.players[index].index then + local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Locate Player') + if is_spamming then + return + end local target = game.players[index] if not target or not target.valid then return @@ -869,6 +873,10 @@ local function on_gui_click(event) end --Poke other players if string.sub(element.name, 1, 11) == 'poke_player' then + local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Poke Player') + if is_spamming then + return + end local poked_player = string.sub(element.name, 13, string.len(element.name)) if player.name == poked_player then return diff --git a/comfy_panel/poll.lua b/comfy_panel/poll.lua index 919cec47..b9a3758f 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 Config = require 'comfy_panel.config' +local SpamProtection = require 'utils.spam_protection' local Class = {} @@ -391,6 +392,11 @@ local function remove_main_frame(main_frame, left, player) end local function toggle(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Toggle Poll') + if is_spamming then + return + end + local left = event.player.gui.left local main_frame = left[main_frame_name] @@ -626,6 +632,10 @@ local function show_new_poll(poll_data) end local function create_poll(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Confirm') + if is_spamming then + return + end local player = event.player local data = Gui.get_data(event.element) @@ -699,6 +709,10 @@ local function update_vote(answer, direction) end local function vote(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll Vote') + if is_spamming then + return + end local player_index = event.player_index local voted_button = event.element local button_data = Gui.get_data(voted_button) @@ -812,6 +826,10 @@ Gui.on_click(main_button_name, toggle) Gui.on_click( create_poll_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll') + if is_spamming then + return + end local player = event.player local left = player.gui.left local frame = left[create_poll_frame_name] @@ -826,6 +844,10 @@ Gui.on_click( Gui.on_click( poll_view_edit_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll View Edit') + if is_spamming then + return + end local player = event.player local left = player.gui.left local frame = left[create_poll_frame_name] @@ -854,6 +876,10 @@ Gui.on_value_changed( Gui.on_click( create_poll_delete_answer_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Delete Answer') + if is_spamming then + return + end local button_data = Gui.get_data(event.element) if not button_data then return @@ -872,6 +898,10 @@ Gui.on_click( Gui.on_click( create_poll_label_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Label Name') + if is_spamming then + return + end local textfield = Gui.get_data(event.element) if not textfield then return @@ -918,6 +948,10 @@ Gui.on_text_changed( Gui.on_click( create_poll_add_answer_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Add Answer') + if is_spamming then + return + end local data = Gui.get_data(event.element) if not data then @@ -936,6 +970,10 @@ Gui.on_click( Gui.on_click( create_poll_close_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Close') + if is_spamming then + return + end local frame = Gui.get_data(event.element) if frame and frame.valid then remove_create_poll_frame(frame, event.player_index) @@ -946,6 +984,10 @@ Gui.on_click( Gui.on_click( create_poll_clear_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Clear') + if is_spamming then + return + end local data = Gui.get_data(event.element) if not data then return @@ -971,6 +1013,10 @@ Gui.on_click(create_poll_confirm_name, create_poll) Gui.on_click( create_poll_delete_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Delete') + if is_spamming then + return + end local player = event.player local data = Gui.get_data(event.element) if not data then @@ -1024,6 +1070,10 @@ Gui.on_click( Gui.on_click( create_poll_edit_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll Edit') + if is_spamming then + return + end local player = event.player local data = Gui.get_data(event.element) if not data then @@ -1175,6 +1225,10 @@ end Gui.on_click( poll_view_back_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll View Back') + if is_spamming then + return + end do_direction(event, -1) end ) @@ -1182,6 +1236,10 @@ Gui.on_click( Gui.on_click( poll_view_forward_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll View Forward') + if is_spamming then + return + end do_direction(event, 1) end ) diff --git a/comfy_panel/score.lua b/comfy_panel/score.lua index db21b74f..b6465e9c 100644 --- a/comfy_panel/score.lua +++ b/comfy_panel/score.lua @@ -278,7 +278,7 @@ local function on_gui_click(event) local player = game.get_player(event.player_index) local name = event.element.name - if name == 'tab_Scoreboard' then + if name == 'tab_' .. module_name then local is_spamming = SpamProtection.is_spamming(player, nil, 'Scoreboard tab_Scoreboard') if is_spamming then return @@ -293,11 +293,6 @@ local function on_gui_click(event) return end - local is_spamming = SpamProtection.is_spamming(player, nil, 'Score Gui Click') - if is_spamming then - return - end - -- Handles click on a score header local element_to_column = { ['score_killscore'] = 'killscore', @@ -307,6 +302,10 @@ local function on_gui_click(event) } local column = element_to_column[name] if column then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Score Gui Column Click') + if is_spamming then + return + end local sorting_pref = this.sort_by[player.name] if sorting_pref.column == column and sorting_pref.method == 'descending' then sorting_pref.method = 'ascending' diff --git a/comfy_panel/server_select.lua b/comfy_panel/server_select.lua index e021712f..1ec5c592 100644 --- a/comfy_panel/server_select.lua +++ b/comfy_panel/server_select.lua @@ -1,6 +1,7 @@ local Event = require 'utils.event' local Gui = require 'utils.gui' local Server = require 'utils.server' +local SpamProtection = require 'utils.spam_protection' local main_frame_name = Gui.uid_name() local main_button_name = Gui.uid_name() @@ -164,6 +165,10 @@ end Gui.on_click( main_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Server Select Main') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -175,6 +180,10 @@ Gui.on_click( Gui.on_click( discard_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Server Select Discard') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -186,6 +195,10 @@ Gui.on_click( Gui.on_click( instance_id_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Server Select Connect') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return diff --git a/maps/mountain_fortress_v3/functions.lua b/maps/mountain_fortress_v3/functions.lua index c8cde557..a0dde834 100644 --- a/maps/mountain_fortress_v3/functions.lua +++ b/maps/mountain_fortress_v3/functions.lua @@ -2,6 +2,7 @@ local Token = require 'utils.token' local Task = require 'utils.task' local Color = require 'utils.color_presets' local ICW = require 'maps.mountain_fortress_v3.icw.main' +local ICT_Functions = require 'maps.mountain_fortress_v3.ic.functions' local Event = require 'utils.event' local Global = require 'utils.global' local Alert = require 'utils.alert' @@ -716,66 +717,72 @@ function Public.remove_offline_players() local items = {} if #offline_players > 0 then for i = 1, #offline_players, 1 do - if offline_players[i] and game.players[offline_players[i].index] and game.players[offline_players[i].index].connected then - offline_players[i] = nil - else - if offline_players[i] and game.players[offline_players[i].index] and offline_players[i].tick < game.tick - 108000 then - local name = offline_players[i].name - player_inv[1] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_main) - player_inv[2] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_armor) - player_inv[3] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_guns) - player_inv[4] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_ammo) - player_inv[5] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_trash) - if not next(player_inv) then - offline_players[i] = nil - break - end + if offline_players[i] and offline_players[i].index then + local target = game.players[offline_players[i].index] + if target and target.connected then + offline_players[i] = nil + else + if target and offline_players[i].tick < game.tick - 108000 then + local name = offline_players[i].name + player_inv[1] = target.get_inventory(defines.inventory.character_main) + player_inv[2] = target.get_inventory(defines.inventory.character_armor) + player_inv[3] = target.get_inventory(defines.inventory.character_guns) + player_inv[4] = target.get_inventory(defines.inventory.character_ammo) + player_inv[5] = target.get_inventory(defines.inventory.character_trash) + ICT_Functions.remove_surface(target) -- remove empty surface - local pos = game.forces.player.get_spawn_position(surface) - local e = - surface.create_entity( - { - name = 'character', - position = pos, - force = 'neutral' - } - ) - local inv = e.get_inventory(defines.inventory.character_main) - e.character_inventory_slots_bonus = #player_inv[1] - for ii = 1, 5, 1 do - if player_inv[ii].valid then - for iii = 1, #player_inv[ii], 1 do - if player_inv[ii][iii].valid then - items[#items + 1] = player_inv[ii][iii] + if target.get_item_count() == 0 then -- if the player has zero items, don't do anything + offline_players[i] = nil + goto final + end + + local pos = game.forces.player.get_spawn_position(surface) + local e = + surface.create_entity( + { + name = 'character', + position = pos, + force = 'neutral' + } + ) + local inv = e.get_inventory(defines.inventory.character_main) + e.character_inventory_slots_bonus = #player_inv[1] + for ii = 1, 5, 1 do + if player_inv[ii].valid then + for iii = 1, #player_inv[ii], 1 do + if player_inv[ii][iii].valid then + items[#items + 1] = player_inv[ii][iii] + end end end end - end - if #items > 0 then - for item = 1, #items, 1 do - if items[item].valid then - inv.insert(items[item]) + if #items > 0 then + for item = 1, #items, 1 do + if items[item].valid then + inv.insert(items[item]) + end + end + + local message = ({'main.cleaner', name}) + local data = { + position = pos + } + Alert.alert_all_players_location(data, message) + + e.die('neutral') + else + e.destroy() + end + + for ii = 1, 5, 1 do + if player_inv[ii].valid then + player_inv[ii].clear() end end - - local message = ({'main.cleaner', name}) - local data = { - position = pos - } - Alert.alert_all_players_location(data, message) - - e.die('neutral') - else - e.destroy() + offline_players[i] = nil + break end - - for ii = 1, 5, 1 do - if player_inv[ii].valid then - player_inv[ii].clear() - end - end - offline_players[i] = nil - break + ::final:: end end end diff --git a/maps/mountain_fortress_v3/ic/functions.lua b/maps/mountain_fortress_v3/ic/functions.lua index 2987eb12..f36e7fb0 100644 --- a/maps/mountain_fortress_v3/ic/functions.lua +++ b/maps/mountain_fortress_v3/ic/functions.lua @@ -116,7 +116,7 @@ end local function get_owner_car_object(cars, player) for k, car in pairs(cars) do if car.owner == player.index then - return k + return k, car end end return false @@ -726,6 +726,71 @@ function Public.save_car(event) end end +function Public.remove_surface(player) + local surfaces = IC.get('surfaces') + local cars = IC.get('cars') + local _, car = get_owner_car_object(cars, player) + if not car then + return + end + + if not car.saved_entity then + return + end + + kick_players_out_of_vehicles(car) + kick_players_from_surface(car) + + local trust_system = IC.get('trust_system') + local owner = car.owner + + if owner then + owner = game.get_player(owner) + if owner and owner.valid then + if trust_system[owner.index] then + trust_system[owner.index] = nil + end + end + end + + local renders = IC.get('renders') + + if renders[owner.index] then + rendering.destroy(renders[owner.index]) + renders[owner.index] = nil + end + + local player_gui_data = IC.get('player_gui_data') + if player_gui_data[owner.name] then + player_gui_data[owner.name] = nil + end + + local players = IC.get('players') + if players[owner.index] then + players[owner.index] = nil + end + + local misc_settings = IC.get('misc_settings') + if misc_settings[owner.index] then + misc_settings[owner.index] = nil + end + + local surface_index = car.surface + local surface = game.surfaces[surface_index] + kill_doors(car) + for _, tile in pairs(surface.find_tiles_filtered({area = car.area})) do + surface.set_tiles({{name = 'out-of-map', position = tile.position}}, true) + end + for _, x in pairs({car.area.left_top.x - 1.5, car.area.right_bottom.x + 1.5}) do + local p = {x = x, y = car.area.left_top.y + ((car.area.right_bottom.y - car.area.left_top.y) * 0.5)} + surface.set_tiles({{name = 'out-of-map', position = {x = p.x + 0.5, y = p.y}}}, true) + surface.set_tiles({{name = 'out-of-map', position = {x = p.x - 1, y = p.y}}}, true) + end + game.delete_surface(surface) + surfaces[car.saved_entity] = nil + cars[car.saved_entity] = nil +end + function Public.kill_car(entity) if not validate_entity(entity) then return diff --git a/maps/mountain_fortress_v3/ic/gui.lua b/maps/mountain_fortress_v3/ic/gui.lua index e08b35f8..9c8cec1a 100644 --- a/maps/mountain_fortress_v3/ic/gui.lua +++ b/maps/mountain_fortress_v3/ic/gui.lua @@ -6,6 +6,7 @@ local Tabs = require 'comfy_panel.main' local Event = require 'utils.event' local Token = require 'utils.token' local Task = require 'utils.task' +local SpamProtection = require 'utils.spam_protection' local Public = {} local insert = table.insert @@ -518,6 +519,10 @@ end Gui.on_click( add_player_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Add Player') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -540,6 +545,10 @@ Gui.on_click( Gui.on_click( transfer_car_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Transfer Car') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -562,6 +571,10 @@ Gui.on_click( Gui.on_click( destroy_surface_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Destroy Surface') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -584,6 +597,10 @@ Gui.on_click( Gui.on_click( allow_anyone_to_enter_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Allow Anyone To Enter') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -613,6 +630,10 @@ Gui.on_click( Gui.on_click( auto_upgrade_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Auto Upgrade') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -642,6 +663,10 @@ Gui.on_click( Gui.on_click( save_add_player_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Save Add Player') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -689,6 +714,10 @@ Gui.on_click( Gui.on_click( save_transfer_car_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Save Transfer Car') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -754,6 +783,10 @@ local clear_misc_settings = Gui.on_click( save_destroy_surface_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Save Destroy Car') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -810,6 +843,10 @@ Gui.on_click( Gui.on_click( kick_player_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Kick Player') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -856,6 +893,10 @@ Gui.on_click( Gui.on_click( discard_add_player_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Discard Add Player') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -877,6 +918,10 @@ Gui.on_click( Gui.on_click( discard_transfer_car_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Discard Transfer Car') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -898,6 +943,10 @@ Gui.on_click( Gui.on_click( discard_destroy_surface_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Discard Destroy Surface') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -919,6 +968,10 @@ Gui.on_click( Gui.on_click( main_toolbar_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Ic Gui Main Toolbar') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return diff --git a/modules/check_fullness.lua b/modules/check_fullness.lua index 32c69bd5..aa3f7281 100644 --- a/modules/check_fullness.lua +++ b/modules/check_fullness.lua @@ -124,6 +124,10 @@ Event.add( return end + if entity.name == 'entity-ghost' then + return + end + if not this.fullness_enabled then return end diff --git a/modules/map_info.lua b/modules/map_info.lua index 3ed5c235..00d5823f 100644 --- a/modules/map_info.lua +++ b/modules/map_info.lua @@ -108,7 +108,7 @@ local function on_gui_click(event) if not event then return end - local player = game.players[event.player_index] + local player = game.get_player(event.player_index) if not (player and player.valid) then return end @@ -120,12 +120,25 @@ local function on_gui_click(event) return end - if event.element.name == 'close_map_intro' then - local is_spamming = SpamProtection.is_spamming(player, nil, 'Map Info Gui Click') + local name = event.element.name + + if not name then + return + end + + if name == 'tab_' .. module_name then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Map Info Main Button') if is_spamming then return end - game.players[event.player_index].gui.left.comfy_panel.destroy() + end + + if name == 'close_map_intro' then + local is_spamming = SpamProtection.is_spamming(player, nil, 'Map Info Close Button') + if is_spamming then + return + end + player.gui.left.comfy_panel.destroy() return end end diff --git a/modules/portable_chest.lua b/modules/portable_chest.lua index 1ed77621..367b3ba4 100644 --- a/modules/portable_chest.lua +++ b/modules/portable_chest.lua @@ -4,6 +4,7 @@ local Color = require 'utils.color_presets' local Gui = require 'utils.gui' local m_gui = require 'mod-gui' local mod = m_gui.get_button_flow +local SpamProtection = require 'utils.spam_protection' local this = { inf_chests = {}, @@ -568,6 +569,10 @@ end Gui.on_click( main_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Portable Chest Main Button') + if is_spamming then + return + end local player = game.get_player(event.player_index) if not player or not player.valid or not player.character then return diff --git a/modules/rpg/gui.lua b/modules/rpg/gui.lua index a8f1d422..0d54ba62 100644 --- a/modules/rpg/gui.lua +++ b/modules/rpg/gui.lua @@ -3,6 +3,7 @@ local Session = require 'utils.datastore.session_data' local P = require 'utils.player_modifiers' local Gui = require 'utils.gui' local Color = require 'utils.color_presets' +local SpamProtection = require 'utils.spam_protection' --RPG Modules local Public = require 'modules.rpg.table' @@ -506,6 +507,10 @@ Public.remove_main_frame = remove_main_frame Gui.on_click( draw_main_frame_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Main Frame') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -518,6 +523,10 @@ Gui.on_click( Gui.on_click( save_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Save Button') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -664,6 +673,10 @@ Gui.on_click( Gui.on_click( discard_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Discard Button') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[settings_frame_name] @@ -680,6 +693,10 @@ Gui.on_click( Gui.on_click( settings_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Settings Button') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[settings_frame_name] @@ -704,6 +721,10 @@ Gui.on_click( Gui.on_click( enable_spawning_frame_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Enable Spawning') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[spell_gui_frame_name] @@ -735,6 +756,10 @@ Gui.on_click( Gui.on_click( spell_gui_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Spell Gui') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[spell_gui_frame_name] @@ -759,6 +784,10 @@ Gui.on_click( Gui.on_click( spell1_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Spell_1 Button') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[spell_gui_frame_name] @@ -780,6 +809,10 @@ Gui.on_click( Gui.on_click( spell2_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Spell_2 Button') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[spell_gui_frame_name] @@ -801,6 +834,10 @@ Gui.on_click( Gui.on_click( spell3_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Spell_3 Button') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[spell_gui_frame_name] diff --git a/modules/wave_defense/pause_waves.lua b/modules/wave_defense/pause_waves.lua index 9e51beda..b27c8b51 100644 --- a/modules/wave_defense/pause_waves.lua +++ b/modules/wave_defense/pause_waves.lua @@ -4,6 +4,7 @@ local Public = require 'modules.wave_defense.table' local Token = require 'utils.token' local Task = require 'utils.task' local Server = require 'utils.server' +local SpamProtection = require 'utils.spam_protection' local main_frame_name = Gui.uid_name() local save_button_name = Gui.uid_name() @@ -125,6 +126,10 @@ local pause_waves_state_token = Token.register(pause_waves_state) Gui.on_click( save_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'WD Save Button') + if is_spamming then + return + end local player = event.player if not player or not player.valid or not player.character then return @@ -171,6 +176,10 @@ Gui.on_click( Gui.on_click( discard_button_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'WD Discard Button') + if is_spamming then + return + end local player = event.player local screen = player.gui.screen local frame = screen[main_frame_name] diff --git a/utils/alert.lua b/utils/alert.lua index 48b005b3..1ad9233a 100644 --- a/utils/alert.lua +++ b/utils/alert.lua @@ -3,6 +3,7 @@ local Global = require 'utils.global' local Gui = require 'utils.gui' local Token = require 'utils.token' local Color = require 'utils.color_presets' +local SpamProtection = require 'utils.spam_protection' local pairs = pairs local next = next @@ -123,6 +124,10 @@ local function alert_to(player, duration, sound, volume) end local function zoom_to_pos(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Alert Zoom to Pos') + if is_spamming then + return + end local player = event.player local element = event.element local position = Gui.get_data(element) @@ -132,6 +137,10 @@ end local close_alert = Public.close_alert local function on_click_close_alert(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Alert Close') + if is_spamming then + return + end close_alert(event.element) end diff --git a/utils/commands/where.lua b/utils/commands/where.lua index 2d08a9be..27d49091 100644 --- a/utils/commands/where.lua +++ b/utils/commands/where.lua @@ -4,6 +4,7 @@ local Color = require 'utils.color_presets' local Event = require 'utils.event' local Global = require 'utils.global' local Gui = require 'utils.gui' +local SpamProtection = require 'utils.spam_protection' local this = { players = {} @@ -175,6 +176,10 @@ end Gui.on_click( locate_player_frame_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Where Locate Player') + if is_spamming then + return + end remove_camera_frame(event.player) end ) @@ -182,6 +187,10 @@ Gui.on_click( Gui.on_click( player_frame_name, function(event) + local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Where Player Frame') + if is_spamming then + return + end remove_camera_frame(event.player) end ) diff --git a/utils/gui.lua b/utils/gui.lua index 8086d05c..4a644e0e 100644 --- a/utils/gui.lua +++ b/utils/gui.lua @@ -1,7 +1,6 @@ local Token = require 'utils.token' local Event = require 'utils.event' local Global = require 'utils.global' -local SpamProtection = require 'utils.spam_protection' local mod_gui = require('__core__/lualib/mod-gui') local tostring = tostring @@ -169,13 +168,6 @@ local function handler_factory(event_id) return end - if not event.text then - local is_spamming = SpamProtection.is_spamming(player, nil, 'UtilsGUI Handler') - if is_spamming then - return - end - end - event.player = player handler(event) diff --git a/utils/spam_protection.lua b/utils/spam_protection.lua index c3204e77..3721e58f 100644 --- a/utils/spam_protection.lua +++ b/utils/spam_protection.lua @@ -4,10 +4,13 @@ local Public = {} local this = { prevent_spam = {}, -- the default table where all player indexes will be stored - default_tick = 7, -- this defines the default tick to check whether or not a user is spamming a button. - _DEBUG = false + default_tick = 10, -- this defines the default tick to check whether or not a user is spamming a button. + debug_text = false, + debug_spam = true } +local main_text = '[Spam Info] ' + Global.register( this, function(t) @@ -15,11 +18,18 @@ Global.register( end ) -local function debug_str(str) - if not this._DEBUG then +local function debug_text(str) + if not this.debug_text then return end - print(str) + print(main_text .. str) +end + +local function debug_spam(str) + if not this.debug_spam then + return + end + print(main_text .. str) end function Public.reset_spam_table() @@ -34,18 +44,20 @@ end function Public.set_new_value(player) if this.prevent_spam[player.index] then this.prevent_spam[player.index] = game.tick - return this.prevent_spam[player.index] end - return false end function Public.is_spamming(player, value_to_compare, text) + if not player or not player.valid then + player = game.get_player(player) + end + if not this.prevent_spam[player.index] then return false end if text then - debug_str('Frame: ' .. text) + debug_text('Frame: ' .. text) end if game.tick_paused then @@ -59,7 +71,11 @@ function Public.is_spamming(player, value_to_compare, text) Public.set_new_value(player) return false -- is not spamming else - debug_str(player.name .. ' is spamming.') + if text then + debug_spam(player.name .. ' is spamming: ' .. text) + else + debug_spam(player.name .. ' is spamming.') + end return true -- is spamming end end