mirror of
https://github.com/ComfyFactory/ComfyFactorio.git
synced 2025-01-08 00:39:30 +02:00
commit
990015ba2e
16
.luacheckrc
16
.luacheckrc
@ -48,7 +48,7 @@ local STD_BASE_CONTROL = 'lua52c+factorio+factorio_control+factorio_defines+fact
|
||||
--[Assume Factorio Control stage as default]--
|
||||
-------------------------------------------------------------------------------
|
||||
std = STD_CONTROL
|
||||
globals = {'print', '_DEBUG', '_CHEATS', '_DUMP_ENV', 'ServerCommands', 'Debug', '_LIFECYCLE', '_STAGE'}
|
||||
globals = {'print', '_DEBUG', '_CHEATS', '_DUMP_ENV', 'ServerCommands', 'Debug', '_LIFECYCLE', '_STAGE', 'get_game_version'}
|
||||
max_line_length = LINE_LENGTH
|
||||
|
||||
not_globals = NOT_GLOBALS
|
||||
@ -199,8 +199,10 @@ stds.factorio_control = {
|
||||
-- (http://lua-api.factorio.com/latest/LuaBootstrap.html)
|
||||
script = {
|
||||
fields = {
|
||||
"on_nth_tick", "on_event", "on_init", "on_load",
|
||||
"on_configuration_changed", "raise_event",
|
||||
"get_event_handler", "mod_name", "get_event_order"
|
||||
"get_event_handler", "mod_name", "get_event_order",
|
||||
"generate_event_name",
|
||||
},
|
||||
other_fields = false,
|
||||
},
|
||||
@ -1076,7 +1078,13 @@ stds.factorio_defines = {
|
||||
'on_pre_robot_exploded_cliff',
|
||||
'on_pre_surface_cleared',
|
||||
'on_pre_surface_deleted',
|
||||
'on_pre_build',
|
||||
'on_put_item',
|
||||
'on_permission_group_added',
|
||||
'on_permission_group_deleted',
|
||||
'on_permission_group_edited',
|
||||
'on_permission_string_imported',
|
||||
'on_pre_permission_group_deleted',
|
||||
'on_pre_permission_string_imported',
|
||||
'on_research_finished',
|
||||
'on_research_started',
|
||||
'on_resource_depleted',
|
||||
@ -1196,7 +1204,7 @@ stds.factorio_defines = {
|
||||
'change_train_stop_station',
|
||||
'change_train_wait_condition',
|
||||
'change_train_wait_condition_data',
|
||||
'clear_cursor_stack',
|
||||
'clean_cursor_stack',
|
||||
'clear_selected_blueprint',
|
||||
'clear_selected_deconstruction_item',
|
||||
'clear_selected_upgrade_item',
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -305,8 +312,12 @@ function Public.alphanumeric_only(value)
|
||||
end
|
||||
|
||||
function Public.reset_groups()
|
||||
this.player_group = {}
|
||||
this.join_spam_protection = {}
|
||||
local players = game.connected_players
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
this.player_group[player.name] = '[Group]'
|
||||
this.join_spam_protection[player.name] = game.tick
|
||||
end
|
||||
this.tag_groups = {}
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -317,50 +317,50 @@ Public.mining_events = {
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "wooden-chest", player_index)
|
||||
end, 2048, "Treasure_Tier_1"},
|
||||
end, 1024, "Treasure_Tier_1"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "iron-chest", player_index)
|
||||
end, 1024, "Treasure_Tier_2"},
|
||||
end, 512, "Treasure_Tier_2"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "steel-chest", player_index)
|
||||
end, 512, "Treasure_Tier_3"},
|
||||
end, 256, "Treasure_Tier_3"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "crash-site-spaceship-wreck-medium-" .. math_random(1,3), player_index)
|
||||
end, 256, "Treasure_Tier_4"},
|
||||
end, 128, "Treasure_Tier_4"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "crash-site-spaceship-wreck-big-" .. math_random(1,2), player_index)
|
||||
end, 128, "Treasure_Tier_5"},
|
||||
end, 64, "Treasure_Tier_5"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "big-ship-wreck-" .. math_random(1,3), player_index)
|
||||
end, 64, "Treasure_Tier_6"},
|
||||
end, 32, "Treasure_Tier_6"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "crash-site-chest-" .. math_random(1,2), player_index)
|
||||
end, 32, "Treasure_Tier_7"},
|
||||
end, 16, "Treasure_Tier_7"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
Public.loot_crate(surface, position, "crash-site-spaceship", player_index)
|
||||
Public.unstuck_player(player_index)
|
||||
end, 16, "Treasure_Tier_8"},
|
||||
end, 8, "Treasure_Tier_8"},
|
||||
|
||||
{function(cave_miner, entity, player_index)
|
||||
local position = entity.position
|
||||
@ -478,7 +478,7 @@ Public.on_entity_died = {
|
||||
end,
|
||||
["container"] = function(cave_miner, entity)
|
||||
local position = entity.position
|
||||
Public.reveal(cave_miner, game.surfaces.nauvis, game.surfaces.cave_miner_source, position, 16)
|
||||
Public.reveal(cave_miner, game.surfaces.nauvis, game.surfaces.cave_miner_source, position, 20)
|
||||
end,
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ local function init(cave_miner)
|
||||
surface.brightness_visual_weights = {0.92, 0.92, 0.92}
|
||||
surface.daytime = 0.43
|
||||
surface.freeze_daytime = true
|
||||
surface.solar_power_multiplier = 5
|
||||
surface.solar_power_multiplier = 3
|
||||
|
||||
cave_miner.last_reroll_player_name = ""
|
||||
cave_miner.reveal_queue = {}
|
||||
|
@ -140,7 +140,7 @@ function Public.spawn_random_cave_market(surface, position)
|
||||
end
|
||||
end
|
||||
for name, value in pairs(items) do
|
||||
local value = value * math_random(16, 32) * 0.01
|
||||
local value = value * math_random(20, 36) * 0.01
|
||||
local count = 1
|
||||
if value < 1 then
|
||||
count = math_floor(1 / value)
|
||||
@ -150,8 +150,6 @@ function Public.spawn_random_cave_market(surface, position)
|
||||
market.add_market_item({price = {{"raw-fish", value}}, offer = {type = 'give-item', item = name, count = count}})
|
||||
end
|
||||
|
||||
blacklist["railgun"] = true
|
||||
blacklist["railgun-dart"] = true
|
||||
blacklist["wood"] = true
|
||||
blacklist["express-loader"] = true
|
||||
blacklist["fast-loader"] = true
|
||||
@ -165,7 +163,7 @@ function Public.spawn_random_cave_market(surface, position)
|
||||
end
|
||||
end
|
||||
for name, value in pairs(items) do
|
||||
local value = value * math_random(5, 10) * 0.01
|
||||
local value = value * math_random(4, 8) * 0.01
|
||||
local count = 1
|
||||
if value < 1 then
|
||||
count = math_floor(1 / value)
|
||||
|
@ -12,8 +12,6 @@ function Public.init_enemy_weapon_damage()
|
||||
['bullet'] = 0,
|
||||
['cannon-shell'] = 0,
|
||||
['capsule'] = 0,
|
||||
['beam'] = 0,
|
||||
['laser'] = 0,
|
||||
['electric'] = 0,
|
||||
['flamethrower'] = 0,
|
||||
['grenade'] = 0,
|
||||
@ -23,6 +21,17 @@ function Public.init_enemy_weapon_damage()
|
||||
['shotgun-shell'] = 0
|
||||
}
|
||||
|
||||
local experimental = get_game_version()
|
||||
if experimental then
|
||||
data['beam'] = 0
|
||||
data['laser'] = 0
|
||||
else
|
||||
data['railgun'] = 0
|
||||
data['combat-robot-beam'] = 0
|
||||
data['combat-robot-laser'] = 0
|
||||
data['laser-turret'] = 0
|
||||
end
|
||||
|
||||
local e = game.forces.enemy
|
||||
|
||||
e.technologies['refined-flammables-1'].researched = true
|
||||
@ -42,8 +51,6 @@ local function enemy_weapon_damage()
|
||||
['biological'] = 0.08,
|
||||
['bullet'] = 0.08,
|
||||
['capsule'] = 0.08,
|
||||
['beam'] = 0.08,
|
||||
['laser'] = 0.08,
|
||||
['electric'] = 0.08,
|
||||
['flamethrower'] = 0.08,
|
||||
--['grenade'] = 0.08,
|
||||
@ -53,6 +60,16 @@ local function enemy_weapon_damage()
|
||||
--['shotgun-shell'] = 0.08
|
||||
}
|
||||
|
||||
local experimental = get_game_version()
|
||||
if experimental then
|
||||
data['beam'] = 0.08
|
||||
data['laser'] = 0.08
|
||||
else
|
||||
data['combat-robot-beam'] = 0.08
|
||||
data['combat-robot-laser'] = 0.08
|
||||
data['laser-turret'] = 0.08
|
||||
end
|
||||
|
||||
for k, v in pairs(data) do
|
||||
local new = Difficulty.get().difficulty_vote_value * v
|
||||
|
||||
|
@ -622,11 +622,6 @@ local mining_events = {
|
||||
},
|
||||
{
|
||||
function(entity, index)
|
||||
if Locomotive.is_around_train(entity) then
|
||||
entity.destroy()
|
||||
return
|
||||
end
|
||||
|
||||
local position = entity.position
|
||||
local surface = entity.surface
|
||||
surface.create_entity({name = 'car', position = position, force = 'player'})
|
||||
@ -920,7 +915,6 @@ local function on_entity_died(event)
|
||||
biters.amount = 0
|
||||
end
|
||||
if Locomotive.is_around_train(entity) then
|
||||
entity.destroy()
|
||||
return
|
||||
end
|
||||
if random(1, 512) == 1 then
|
||||
@ -947,7 +941,6 @@ local function on_entity_died(event)
|
||||
end
|
||||
end
|
||||
if Locomotive.is_around_train(entity) then
|
||||
entity.destroy()
|
||||
return
|
||||
end
|
||||
angry_tree(entity, cause, player)
|
||||
|
@ -592,9 +592,11 @@ Public.magic_item_crafting_callback_weighted =
|
||||
|
||||
local tech = stack.tech
|
||||
if tech then
|
||||
if not force.technologies[tech].researched then
|
||||
entity.destroy()
|
||||
return
|
||||
if force.technologies[tech] then
|
||||
if not force.technologies[tech].researched then
|
||||
entity.destroy()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -790,12 +792,9 @@ function Public.set_difficulty()
|
||||
amount = 20
|
||||
end
|
||||
|
||||
if wave_defense_table.threat <= 0 then
|
||||
wave_defense_table.wave_interval = 1000
|
||||
end
|
||||
|
||||
wave_defense_table.wave_interval = 3600 - player_count * 60
|
||||
if wave_defense_table.wave_interval < 1800 then
|
||||
|
||||
if wave_defense_table.wave_interval < 1800 or wave_defense_table.threat <= 0 then
|
||||
wave_defense_table.wave_interval = 1800
|
||||
end
|
||||
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
@ -220,7 +221,7 @@ local function output_cargo(wagon, passive_chest)
|
||||
if t and t.valid then
|
||||
local c = chest2.insert(t)
|
||||
if (c > 0) then
|
||||
chest1.remove(t)
|
||||
chest1[i].count = chest1[i].count - c
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -830,10 +831,69 @@ local function move_room_to_train(icw, train, wagon)
|
||||
end
|
||||
end
|
||||
|
||||
local function get_connected_rolling_stock(entity, direction, carriages)
|
||||
--thanks Boskid
|
||||
local first_stock, second_stock
|
||||
for k, v in pairs(carriages) do
|
||||
if v == entity then
|
||||
first_stock = carriages[k - 1]
|
||||
second_stock = carriages[k + 1]
|
||||
break
|
||||
end
|
||||
end
|
||||
if not first_stock then
|
||||
first_stock, second_stock = second_stock, nil
|
||||
end
|
||||
if not first_stock then
|
||||
return nil
|
||||
end
|
||||
|
||||
local angle = math.atan2(-(entity.position.x - first_stock.position.x), entity.position.y - first_stock.position.y) / (2 * math.pi) - entity.orientation
|
||||
if direction == defines.rail_direction.back then
|
||||
angle = angle + 0.5
|
||||
end
|
||||
while angle < -0.5 do
|
||||
angle = angle + 1
|
||||
end
|
||||
while angle > 0.5 do
|
||||
angle = angle - 1
|
||||
end
|
||||
local connected_stock
|
||||
if angle > -0.25 and angle < 0.25 then
|
||||
connected_stock = first_stock
|
||||
else
|
||||
connected_stock = second_stock
|
||||
end
|
||||
if not connected_stock then
|
||||
return nil
|
||||
end
|
||||
|
||||
angle = math.atan2(-(connected_stock.position.x - entity.position.x), connected_stock.position.y - entity.position.y) / (2 * math.pi) - connected_stock.orientation
|
||||
while angle < -0.5 do
|
||||
angle = angle + 1
|
||||
end
|
||||
while angle > 0.5 do
|
||||
angle = angle - 1
|
||||
end
|
||||
local joint_of_connected_stock
|
||||
if angle > -0.25 and angle < 0.25 then
|
||||
joint_of_connected_stock = defines.rail_direction.front
|
||||
else
|
||||
joint_of_connected_stock = defines.rail_direction.back
|
||||
end
|
||||
return connected_stock, joint_of_connected_stock
|
||||
end
|
||||
|
||||
function Public.construct_train(icw, locomotive, carriages)
|
||||
for i, carriage in pairs(carriages) do
|
||||
if carriage == locomotive then
|
||||
local stock = locomotive.get_connected_rolling_stock(defines.rail_direction.front)
|
||||
local stock
|
||||
local experimental = get_game_version()
|
||||
if experimental then
|
||||
stock = locomotive.get_connected_rolling_stock(defines.rail_direction.front)
|
||||
else
|
||||
stock = get_connected_rolling_stock(locomotive, defines.rail_direction.front, carriages)
|
||||
end
|
||||
if stock ~= carriages[i - 1] then
|
||||
local n = 1
|
||||
local m = #carriages
|
||||
@ -953,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
|
||||
|
@ -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
|
||||
|
@ -168,7 +168,7 @@ local resource_loot = {
|
||||
{
|
||||
stack = {
|
||||
recipe = 'stone-wall',
|
||||
tech = 'stone-wall',
|
||||
tech = 'stone-walls',
|
||||
output = {item = 'stone-wall', min_rate = 0.6 / 60, distance_factor = 1 / 6 / 60 / 512}
|
||||
},
|
||||
weight = 10
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -44,13 +45,13 @@ local this = {
|
||||
[3] = ''
|
||||
},
|
||||
difficulty_vote_value = 1,
|
||||
difficulty_vote_index = 1,
|
||||
difficulty_vote_index = 2,
|
||||
fair_vote = false,
|
||||
difficulty_poll_closing_timeout = 54000,
|
||||
difficulty_player_votes = {},
|
||||
gui_width = 108,
|
||||
name = "I'm too young to die",
|
||||
strength_modifier = 1.00,
|
||||
name = 'Hurt me plenty',
|
||||
strength_modifier = 1.25,
|
||||
button_tooltip = nil
|
||||
}
|
||||
|
||||
@ -192,7 +193,7 @@ end
|
||||
function Public.reset_difficulty_poll(tbl)
|
||||
if tbl then
|
||||
this.difficulty_vote_value = tbl.difficulty_vote_value or 1
|
||||
this.difficulty_vote_index = tbl.difficulty_vote_index or 1
|
||||
this.difficulty_vote_index = tbl.difficulty_vote_index or 2
|
||||
this.difficulty_player_votes = {}
|
||||
this.difficulty_poll_closing_timeout = tbl.difficulty_poll_closing_timeout or game.tick + 54000
|
||||
for _, p in pairs(game.connected_players) do
|
||||
@ -207,7 +208,7 @@ function Public.reset_difficulty_poll(tbl)
|
||||
Public.difficulty_gui()
|
||||
else
|
||||
this.difficulty_vote_value = 1
|
||||
this.difficulty_vote_index = 1
|
||||
this.difficulty_vote_index = 2
|
||||
this.difficulty_player_votes = {}
|
||||
this.difficulty_poll_closing_timeout = game.tick + 54000
|
||||
for _, p in pairs(game.connected_players) do
|
||||
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -16,11 +16,18 @@ local function create_gui(player)
|
||||
label.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
|
||||
|
||||
local progressbar = frame.add({type = 'progressbar', name = 'progressbar', value = 0})
|
||||
progressbar.style = 'achievement_progressbar'
|
||||
progressbar.style.minimal_width = 96
|
||||
progressbar.style.maximal_width = 96
|
||||
progressbar.style.padding = -1
|
||||
progressbar.style.top_padding = 1
|
||||
local experimental = get_game_version()
|
||||
if experimental then
|
||||
progressbar.style = 'achievement_progressbar'
|
||||
progressbar.style.minimal_width = 96
|
||||
progressbar.style.maximal_width = 96
|
||||
progressbar.style.padding = -1
|
||||
progressbar.style.top_padding = 1
|
||||
else
|
||||
progressbar.style.minimal_width = 96
|
||||
progressbar.style.maximal_width = 96
|
||||
progressbar.style.top_padding = 10
|
||||
end
|
||||
|
||||
local line = frame.add({type = 'line', direction = 'vertical'})
|
||||
line.style.left_padding = 4
|
||||
|
@ -1,3 +1,7 @@
|
||||
--luacheck: ignore
|
||||
local branch_version = '1.1' -- define what game version we're using
|
||||
local sub = string.sub
|
||||
|
||||
-- Non-applicable stages are commented out.
|
||||
_STAGE = {
|
||||
--settings = 1,
|
||||
@ -9,3 +13,13 @@ _STAGE = {
|
||||
--config_change = 7,
|
||||
runtime = 8
|
||||
}
|
||||
|
||||
function get_game_version()
|
||||
local get_active_branch = sub(game.active_mods.base, 3, 4)
|
||||
local is_branch_experimental = sub(branch_version, 3, 4)
|
||||
if get_active_branch >= is_branch_experimental then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
@ -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)
|
||||
|
87
utils/spam_protection.lua
Normal file
87
utils/spam_protection.lua
Normal file
@ -0,0 +1,87 @@
|
||||
local Event = require 'utils.event'
|
||||
local Global = require 'utils.global'
|
||||
local Public = {}
|
||||
|
||||
local this = {
|
||||
prevent_spam = {}, -- the default table where all player indexes will be stored
|
||||
default_tick = 15 -- this defines the default tick to check weather or not a user is spamming a button.
|
||||
}
|
||||
|
||||
Global.register(
|
||||
this,
|
||||
function(t)
|
||||
this = t
|
||||
end
|
||||
)
|
||||
|
||||
function Public.reset_spam_table()
|
||||
local players = game.connected_players
|
||||
this.prevent_spam = {}
|
||||
for i = 1, #players do
|
||||
local player = players[i]
|
||||
this.prevent_spam[player.index] = game.tick
|
||||
end
|
||||
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)
|
||||
if not this.prevent_spam[player.index] then
|
||||
return
|
||||
end
|
||||
|
||||
local tick = game.tick
|
||||
local value = value_to_compare or this.default_tick
|
||||
if this.prevent_spam[player.index] then
|
||||
if (tick - this.prevent_spam[player.index]) > value then
|
||||
Public.set_new_value(player)
|
||||
return false -- is not spamming
|
||||
else
|
||||
return true -- is spamming
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
function Public.get(key)
|
||||
if key then
|
||||
return this[key]
|
||||
else
|
||||
return this
|
||||
end
|
||||
end
|
||||
|
||||
function Public.set(key, value)
|
||||
if key and (value or value == false) then
|
||||
this[key] = value
|
||||
return this[key]
|
||||
elseif key then
|
||||
return this[key]
|
||||
else
|
||||
return this
|
||||
end
|
||||
end
|
||||
|
||||
Event.add(
|
||||
defines.events.on_player_joined_game,
|
||||
function(event)
|
||||
local player = game.get_player(event.player_index)
|
||||
|
||||
if not this.prevent_spam[player.index] then
|
||||
this.prevent_spam[player.index] = game.tick
|
||||
end
|
||||
end
|
||||
)
|
||||
Event.on_init(
|
||||
function()
|
||||
Public.reset_spam_table()
|
||||
end
|
||||
)
|
||||
|
||||
return Public
|
Loading…
Reference in New Issue
Block a user