1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-01-22 03:38:48 +02:00

Merge pull request #214 from ComfyFactory/minor_fixes

Minor changes
This commit is contained in:
Gerkiz 2022-02-14 00:28:19 +01:00 committed by GitHub
commit d7056ff82d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 417 additions and 84 deletions

View File

@ -644,7 +644,7 @@ local function on_gui_click(event)
local name = event.element.name 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') local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin tab_Admin')
if is_spamming then if is_spamming then
return return

View File

@ -3,6 +3,7 @@ local Event = require 'utils.event'
local Global = require 'utils.global' local Global = require 'utils.global'
local ComfyGui = require 'comfy_panel.main' local ComfyGui = require 'comfy_panel.main'
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local SpamProtection = require 'utils.spam_protection'
local this = { local this = {
players = {}, players = {},
@ -208,6 +209,10 @@ end
Gui.on_click( Gui.on_click(
clear_corpse_button_name, clear_corpse_button_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Clear Corpse')
if is_spamming then
return
end
Misc.clear_corpses(event) Misc.clear_corpses(event)
end end
) )

View File

@ -811,8 +811,35 @@ local function on_robot_built_entity(event)
spaghett_deny_building(event) spaghett_deny_building(event)
end 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}) 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_gui_switch_state_changed, on_gui_switch_state_changed)
Event.add(defines.events.on_force_created, on_force_created) Event.add(defines.events.on_force_created, on_force_created)
Event.add(defines.events.on_built_entity, on_built_entity) Event.add(defines.events.on_built_entity, on_built_entity)

View File

@ -235,7 +235,11 @@ local function on_gui_click(event)
local name = event.element.name 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') local is_spamming = SpamProtection.is_spamming(player, nil, 'Groups tab_Groups')
if is_spamming then if is_spamming then
return return

View File

@ -740,7 +740,7 @@ local function on_gui_click(event)
local name = element.name local name = element.name
local player = game.get_player(event.player_index) 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') local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList tab_Players')
if is_spamming then if is_spamming then
return return
@ -861,6 +861,10 @@ local function on_gui_click(event)
--Locate other players --Locate other players
local index = tonumber(element.name) local index = tonumber(element.name)
if index and game.players[index] and index == game.players[index].index then 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] local target = game.players[index]
if not target or not target.valid then if not target or not target.valid then
return return
@ -869,6 +873,10 @@ local function on_gui_click(event)
end end
--Poke other players --Poke other players
if string.sub(element.name, 1, 11) == 'poke_player' then 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)) local poked_player = string.sub(element.name, 13, string.len(element.name))
if player.name == poked_player then if player.name == poked_player then
return return

View File

@ -6,6 +6,7 @@ local Server = require 'utils.server'
local Tabs = require 'comfy_panel.main' local Tabs = require 'comfy_panel.main'
local session = require 'utils.datastore.session_data' local session = require 'utils.datastore.session_data'
local Config = require 'comfy_panel.config' local Config = require 'comfy_panel.config'
local SpamProtection = require 'utils.spam_protection'
local Class = {} local Class = {}
@ -391,6 +392,11 @@ local function remove_main_frame(main_frame, left, player)
end end
local function toggle(event) 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 left = event.player.gui.left
local main_frame = left[main_frame_name] local main_frame = left[main_frame_name]
@ -626,6 +632,10 @@ local function show_new_poll(poll_data)
end end
local function create_poll(event) 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 player = event.player
local data = Gui.get_data(event.element) local data = Gui.get_data(event.element)
@ -699,6 +709,10 @@ local function update_vote(answer, direction)
end end
local function vote(event) 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 player_index = event.player_index
local voted_button = event.element local voted_button = event.element
local button_data = Gui.get_data(voted_button) local button_data = Gui.get_data(voted_button)
@ -812,6 +826,10 @@ Gui.on_click(main_button_name, toggle)
Gui.on_click( Gui.on_click(
create_poll_button_name, create_poll_button_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Create Poll')
if is_spamming then
return
end
local player = event.player local player = event.player
local left = player.gui.left local left = player.gui.left
local frame = left[create_poll_frame_name] local frame = left[create_poll_frame_name]
@ -826,6 +844,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
poll_view_edit_name, poll_view_edit_name,
function(event) 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 player = event.player
local left = player.gui.left local left = player.gui.left
local frame = left[create_poll_frame_name] local frame = left[create_poll_frame_name]
@ -854,6 +876,10 @@ Gui.on_value_changed(
Gui.on_click( Gui.on_click(
create_poll_delete_answer_name, create_poll_delete_answer_name,
function(event) 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) local button_data = Gui.get_data(event.element)
if not button_data then if not button_data then
return return
@ -872,6 +898,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
create_poll_label_name, create_poll_label_name,
function(event) 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) local textfield = Gui.get_data(event.element)
if not textfield then if not textfield then
return return
@ -918,6 +948,10 @@ Gui.on_text_changed(
Gui.on_click( Gui.on_click(
create_poll_add_answer_name, create_poll_add_answer_name,
function(event) 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) local data = Gui.get_data(event.element)
if not data then if not data then
@ -936,6 +970,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
create_poll_close_name, create_poll_close_name,
function(event) 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) local frame = Gui.get_data(event.element)
if frame and frame.valid then if frame and frame.valid then
remove_create_poll_frame(frame, event.player_index) remove_create_poll_frame(frame, event.player_index)
@ -946,6 +984,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
create_poll_clear_name, create_poll_clear_name,
function(event) 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) local data = Gui.get_data(event.element)
if not data then if not data then
return return
@ -971,6 +1013,10 @@ Gui.on_click(create_poll_confirm_name, create_poll)
Gui.on_click( Gui.on_click(
create_poll_delete_name, create_poll_delete_name,
function(event) 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 player = event.player
local data = Gui.get_data(event.element) local data = Gui.get_data(event.element)
if not data then if not data then
@ -1024,6 +1070,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
create_poll_edit_name, create_poll_edit_name,
function(event) 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 player = event.player
local data = Gui.get_data(event.element) local data = Gui.get_data(event.element)
if not data then if not data then
@ -1175,6 +1225,10 @@ end
Gui.on_click( Gui.on_click(
poll_view_back_name, poll_view_back_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll View Back')
if is_spamming then
return
end
do_direction(event, -1) do_direction(event, -1)
end end
) )
@ -1182,6 +1236,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
poll_view_forward_name, poll_view_forward_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Poll View Forward')
if is_spamming then
return
end
do_direction(event, 1) do_direction(event, 1)
end end
) )

View File

@ -278,7 +278,7 @@ local function on_gui_click(event)
local player = game.get_player(event.player_index) local player = game.get_player(event.player_index)
local name = event.element.name 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') local is_spamming = SpamProtection.is_spamming(player, nil, 'Scoreboard tab_Scoreboard')
if is_spamming then if is_spamming then
return return
@ -293,11 +293,6 @@ local function on_gui_click(event)
return return
end end
local is_spamming = SpamProtection.is_spamming(player, nil, 'Score Gui Click')
if is_spamming then
return
end
-- Handles click on a score header -- Handles click on a score header
local element_to_column = { local element_to_column = {
['score_killscore'] = 'killscore', ['score_killscore'] = 'killscore',
@ -307,6 +302,10 @@ local function on_gui_click(event)
} }
local column = element_to_column[name] local column = element_to_column[name]
if column then 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] local sorting_pref = this.sort_by[player.name]
if sorting_pref.column == column and sorting_pref.method == 'descending' then if sorting_pref.column == column and sorting_pref.method == 'descending' then
sorting_pref.method = 'ascending' sorting_pref.method = 'ascending'

View File

@ -1,6 +1,7 @@
local Event = require 'utils.event' local Event = require 'utils.event'
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local Server = require 'utils.server' local Server = require 'utils.server'
local SpamProtection = require 'utils.spam_protection'
local main_frame_name = Gui.uid_name() local main_frame_name = Gui.uid_name()
local main_button_name = Gui.uid_name() local main_button_name = Gui.uid_name()
@ -164,6 +165,10 @@ end
Gui.on_click( Gui.on_click(
main_button_name, main_button_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Server Select Main')
if is_spamming then
return
end
local player = event.player local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -175,6 +180,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
discard_button_name, discard_button_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Server Select Discard')
if is_spamming then
return
end
local player = event.player local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -186,6 +195,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
instance_id_name, instance_id_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'Server Select Connect')
if is_spamming then
return
end
local player = event.player local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return

View File

@ -2,6 +2,7 @@ local Token = require 'utils.token'
local Task = require 'utils.task' local Task = require 'utils.task'
local Color = require 'utils.color_presets' local Color = require 'utils.color_presets'
local ICW = require 'maps.mountain_fortress_v3.icw.main' 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 Event = require 'utils.event'
local Global = require 'utils.global' local Global = require 'utils.global'
local Alert = require 'utils.alert' local Alert = require 'utils.alert'
@ -716,66 +717,72 @@ function Public.remove_offline_players()
local items = {} local items = {}
if #offline_players > 0 then if #offline_players > 0 then
for i = 1, #offline_players, 1 do 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 if offline_players[i] and offline_players[i].index then
offline_players[i] = nil local target = game.players[offline_players[i].index]
else if target and target.connected then
if offline_players[i] and game.players[offline_players[i].index] and offline_players[i].tick < game.tick - 108000 then offline_players[i] = nil
local name = offline_players[i].name else
player_inv[1] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_main) if target and offline_players[i].tick < game.tick - 108000 then
player_inv[2] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_armor) local name = offline_players[i].name
player_inv[3] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_guns) player_inv[1] = target.get_inventory(defines.inventory.character_main)
player_inv[4] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_ammo) player_inv[2] = target.get_inventory(defines.inventory.character_armor)
player_inv[5] = game.players[offline_players[i].index].get_inventory(defines.inventory.character_trash) player_inv[3] = target.get_inventory(defines.inventory.character_guns)
if not next(player_inv) then player_inv[4] = target.get_inventory(defines.inventory.character_ammo)
offline_players[i] = nil player_inv[5] = target.get_inventory(defines.inventory.character_trash)
break ICT_Functions.remove_surface(target) -- remove empty surface
end
local pos = game.forces.player.get_spawn_position(surface) if target.get_item_count() == 0 then -- if the player has zero items, don't do anything
local e = offline_players[i] = nil
surface.create_entity( goto final
{ end
name = 'character',
position = pos, local pos = game.forces.player.get_spawn_position(surface)
force = 'neutral' local e =
} surface.create_entity(
) {
local inv = e.get_inventory(defines.inventory.character_main) name = 'character',
e.character_inventory_slots_bonus = #player_inv[1] position = pos,
for ii = 1, 5, 1 do force = 'neutral'
if player_inv[ii].valid then }
for iii = 1, #player_inv[ii], 1 do )
if player_inv[ii][iii].valid then local inv = e.get_inventory(defines.inventory.character_main)
items[#items + 1] = player_inv[ii][iii] 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
end end
end if #items > 0 then
if #items > 0 then for item = 1, #items, 1 do
for item = 1, #items, 1 do if items[item].valid then
if items[item].valid then inv.insert(items[item])
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
end end
offline_players[i] = nil
local message = ({'main.cleaner', name}) break
local data = {
position = pos
}
Alert.alert_all_players_location(data, message)
e.die('neutral')
else
e.destroy()
end end
::final::
for ii = 1, 5, 1 do
if player_inv[ii].valid then
player_inv[ii].clear()
end
end
offline_players[i] = nil
break
end end
end end
end end

View File

@ -116,7 +116,7 @@ end
local function get_owner_car_object(cars, player) local function get_owner_car_object(cars, player)
for k, car in pairs(cars) do for k, car in pairs(cars) do
if car.owner == player.index then if car.owner == player.index then
return k return k, car
end end
end end
return false return false
@ -726,6 +726,71 @@ function Public.save_car(event)
end end
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) function Public.kill_car(entity)
if not validate_entity(entity) then if not validate_entity(entity) then
return return

View File

@ -6,6 +6,7 @@ local Tabs = require 'comfy_panel.main'
local Event = require 'utils.event' local Event = require 'utils.event'
local Token = require 'utils.token' local Token = require 'utils.token'
local Task = require 'utils.task' local Task = require 'utils.task'
local SpamProtection = require 'utils.spam_protection'
local Public = {} local Public = {}
local insert = table.insert local insert = table.insert
@ -518,6 +519,10 @@ end
Gui.on_click( Gui.on_click(
add_player_name, add_player_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -540,6 +545,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
transfer_car_name, transfer_car_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -562,6 +571,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
destroy_surface_name, destroy_surface_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -584,6 +597,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
allow_anyone_to_enter_name, allow_anyone_to_enter_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -613,6 +630,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
auto_upgrade_name, auto_upgrade_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -642,6 +663,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
save_add_player_button_name, save_add_player_button_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -689,6 +714,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
save_transfer_car_button_name, save_transfer_car_button_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -754,6 +783,10 @@ local clear_misc_settings =
Gui.on_click( Gui.on_click(
save_destroy_surface_button_name, save_destroy_surface_button_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -810,6 +843,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
kick_player_name, kick_player_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -856,6 +893,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
discard_add_player_name, discard_add_player_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -877,6 +918,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
discard_transfer_car_name, discard_transfer_car_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -898,6 +943,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
discard_destroy_surface_name, discard_destroy_surface_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -919,6 +968,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
main_toolbar_name, main_toolbar_name,
function(event) 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 local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return

View File

@ -124,6 +124,10 @@ Event.add(
return return
end end
if entity.name == 'entity-ghost' then
return
end
if not this.fullness_enabled then if not this.fullness_enabled then
return return
end end

View File

@ -108,7 +108,7 @@ local function on_gui_click(event)
if not event then if not event then
return return
end end
local player = game.players[event.player_index] local player = game.get_player(event.player_index)
if not (player and player.valid) then if not (player and player.valid) then
return return
end end
@ -120,12 +120,25 @@ local function on_gui_click(event)
return return
end end
if event.element.name == 'close_map_intro' then local name = event.element.name
local is_spamming = SpamProtection.is_spamming(player, nil, 'Map Info Gui Click')
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 if is_spamming then
return return
end 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 return
end end
end end

View File

@ -4,6 +4,7 @@ local Color = require 'utils.color_presets'
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local m_gui = require 'mod-gui' local m_gui = require 'mod-gui'
local mod = m_gui.get_button_flow local mod = m_gui.get_button_flow
local SpamProtection = require 'utils.spam_protection'
local this = { local this = {
inf_chests = {}, inf_chests = {},
@ -568,6 +569,10 @@ end
Gui.on_click( Gui.on_click(
main_button_name, main_button_name,
function(event) 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) local player = game.get_player(event.player_index)
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return

View File

@ -3,6 +3,7 @@ local Session = require 'utils.datastore.session_data'
local P = require 'utils.player_modifiers' local P = require 'utils.player_modifiers'
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local Color = require 'utils.color_presets' local Color = require 'utils.color_presets'
local SpamProtection = require 'utils.spam_protection'
--RPG Modules --RPG Modules
local Public = require 'modules.rpg.table' local Public = require 'modules.rpg.table'
@ -506,6 +507,10 @@ Public.remove_main_frame = remove_main_frame
Gui.on_click( Gui.on_click(
draw_main_frame_name, draw_main_frame_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Main Frame')
if is_spamming then
return
end
local player = event.player local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -518,6 +523,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
save_button_name, save_button_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'RPG Save Button')
if is_spamming then
return
end
local player = event.player local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -664,6 +673,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
discard_button_name, discard_button_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[settings_frame_name] local frame = screen[settings_frame_name]
@ -680,6 +693,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
settings_button_name, settings_button_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[settings_frame_name] local frame = screen[settings_frame_name]
@ -704,6 +721,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
enable_spawning_frame_name, enable_spawning_frame_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[spell_gui_frame_name] local frame = screen[spell_gui_frame_name]
@ -735,6 +756,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
spell_gui_button_name, spell_gui_button_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[spell_gui_frame_name] local frame = screen[spell_gui_frame_name]
@ -759,6 +784,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
spell1_button_name, spell1_button_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[spell_gui_frame_name] local frame = screen[spell_gui_frame_name]
@ -780,6 +809,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
spell2_button_name, spell2_button_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[spell_gui_frame_name] local frame = screen[spell_gui_frame_name]
@ -801,6 +834,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
spell3_button_name, spell3_button_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[spell_gui_frame_name] local frame = screen[spell_gui_frame_name]

View File

@ -4,6 +4,7 @@ local Public = require 'modules.wave_defense.table'
local Token = require 'utils.token' local Token = require 'utils.token'
local Task = require 'utils.task' local Task = require 'utils.task'
local Server = require 'utils.server' local Server = require 'utils.server'
local SpamProtection = require 'utils.spam_protection'
local main_frame_name = Gui.uid_name() local main_frame_name = Gui.uid_name()
local save_button_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( Gui.on_click(
save_button_name, save_button_name,
function(event) function(event)
local is_spamming = SpamProtection.is_spamming(event.player, nil, 'WD Save Button')
if is_spamming then
return
end
local player = event.player local player = event.player
if not player or not player.valid or not player.character then if not player or not player.valid or not player.character then
return return
@ -171,6 +176,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
discard_button_name, discard_button_name,
function(event) 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 player = event.player
local screen = player.gui.screen local screen = player.gui.screen
local frame = screen[main_frame_name] local frame = screen[main_frame_name]

View File

@ -3,6 +3,7 @@ local Global = require 'utils.global'
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local Token = require 'utils.token' local Token = require 'utils.token'
local Color = require 'utils.color_presets' local Color = require 'utils.color_presets'
local SpamProtection = require 'utils.spam_protection'
local pairs = pairs local pairs = pairs
local next = next local next = next
@ -123,6 +124,10 @@ local function alert_to(player, duration, sound, volume)
end end
local function zoom_to_pos(event) 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 player = event.player
local element = event.element local element = event.element
local position = Gui.get_data(element) local position = Gui.get_data(element)
@ -132,6 +137,10 @@ end
local close_alert = Public.close_alert local close_alert = Public.close_alert
local function on_click_close_alert(event) 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) close_alert(event.element)
end end

View File

@ -4,6 +4,7 @@ local Color = require 'utils.color_presets'
local Event = require 'utils.event' local Event = require 'utils.event'
local Global = require 'utils.global' local Global = require 'utils.global'
local Gui = require 'utils.gui' local Gui = require 'utils.gui'
local SpamProtection = require 'utils.spam_protection'
local this = { local this = {
players = {} players = {}
@ -175,6 +176,10 @@ end
Gui.on_click( Gui.on_click(
locate_player_frame_name, locate_player_frame_name,
function(event) 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) remove_camera_frame(event.player)
end end
) )
@ -182,6 +187,10 @@ Gui.on_click(
Gui.on_click( Gui.on_click(
player_frame_name, player_frame_name,
function(event) 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) remove_camera_frame(event.player)
end end
) )

View File

@ -1,7 +1,6 @@
local Token = require 'utils.token' local Token = require 'utils.token'
local Event = require 'utils.event' local Event = require 'utils.event'
local Global = require 'utils.global' local Global = require 'utils.global'
local SpamProtection = require 'utils.spam_protection'
local mod_gui = require('__core__/lualib/mod-gui') local mod_gui = require('__core__/lualib/mod-gui')
local tostring = tostring local tostring = tostring
@ -169,13 +168,6 @@ local function handler_factory(event_id)
return return
end 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 event.player = player
handler(event) handler(event)

View File

@ -4,10 +4,13 @@ local Public = {}
local this = { local this = {
prevent_spam = {}, -- the default table where all player indexes will be stored 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. default_tick = 10, -- this defines the default tick to check whether or not a user is spamming a button.
_DEBUG = false debug_text = false,
debug_spam = true
} }
local main_text = '[Spam Info] '
Global.register( Global.register(
this, this,
function(t) function(t)
@ -15,11 +18,18 @@ Global.register(
end end
) )
local function debug_str(str) local function debug_text(str)
if not this._DEBUG then if not this.debug_text then
return return
end 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 end
function Public.reset_spam_table() function Public.reset_spam_table()
@ -34,18 +44,20 @@ end
function Public.set_new_value(player) function Public.set_new_value(player)
if this.prevent_spam[player.index] then if this.prevent_spam[player.index] then
this.prevent_spam[player.index] = game.tick this.prevent_spam[player.index] = game.tick
return this.prevent_spam[player.index]
end end
return false
end end
function Public.is_spamming(player, value_to_compare, text) 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 if not this.prevent_spam[player.index] then
return false return false
end end
if text then if text then
debug_str('Frame: ' .. text) debug_text('Frame: ' .. text)
end end
if game.tick_paused then if game.tick_paused then
@ -59,7 +71,11 @@ function Public.is_spamming(player, value_to_compare, text)
Public.set_new_value(player) Public.set_new_value(player)
return false -- is not spamming return false -- is not spamming
else 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 return true -- is spamming
end end
end end