1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-03-17 20:58:13 +02:00

Merge pull request #45 from M3wM3w/master

update from main
This commit is contained in:
hanakocz 2021-01-16 14:04:07 +01:00 committed by GitHub
commit 1394d63ae4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
29 changed files with 303 additions and 100 deletions

View File

@ -328,7 +328,7 @@ local function text_changed(event)
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin Text Changed')
if is_spamming then
return
end
@ -630,7 +630,7 @@ local function on_gui_click(event)
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin Gui Click')
if is_spamming then
return
end
@ -700,7 +700,7 @@ local function on_gui_selection_state_changed(event)
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin Selection Changed')
if is_spamming then
return
end
@ -721,7 +721,7 @@ local function on_gui_selection_state_changed(event)
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Admin Player Select')
if is_spamming then
return
end

View File

@ -556,28 +556,28 @@ local function on_gui_switch_state_changed(event)
end
if functions[event.element.name] then
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Functions Elem')
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)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config AntiGrief Elem')
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)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Fortress Elem')
if is_spamming then
return
end
fortress_functions[event.element.name](event)
return
elseif is_loaded('comfy_panel.poll') then
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Config Poll Elem')
if is_spamming then
return
end

View File

@ -199,13 +199,14 @@ 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 is_spamming = SpamProtection.is_spamming(player, nil, 'Group Click')
if is_spamming then
return
end
local new_group_name = frame.frame2.group_table.new_group_name.text
local new_group_description = frame.frame2.group_table.new_group_description.text
if new_group_name ~= '' and new_group_name ~= 'Name' and new_group_description ~= 'Description' then
@ -259,6 +260,12 @@ local function on_gui_click(event)
end
if p then
if p.name == 'groups_table' then
local is_spamming = SpamProtection.is_spamming(player, nil, 'Group Click')
if is_spamming then
return
end
if event.element.type == 'button' and event.element.caption == 'Join' then
this.player_group[player.name] = event.element.parent.name
local str = '[' .. event.element.parent.name

View File

@ -44,7 +44,9 @@ end
function Public.comfy_panel_restore_screen_gui(player)
for _, child in pairs(player.gui.screen.children) do
child.visible = true
if child.name ~= 'ups_label' then
child.visible = true
end
end
end
@ -163,7 +165,7 @@ local function on_gui_click(event)
end
if event.element.name == 'comfy_panel_top_button' then
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main GUI Click')
if is_spamming then
return
end
@ -180,7 +182,7 @@ 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)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main Gui Close Button')
if is_spamming then
return
end
@ -195,7 +197,7 @@ local function on_gui_click(event)
if event.element.type ~= 'tab' then
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Comfy Main Gui No Func')
if is_spamming then
return
end

View File

@ -603,11 +603,6 @@ 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()
@ -641,6 +636,11 @@ local function on_gui_click(event)
}
if actions[name] then
local is_spamming = SpamProtection.is_spamming(player, nil, 'PlayerList Gui Click')
if is_spamming then
return
end
actions[name]()
return
end

View File

@ -300,7 +300,7 @@ local function on_gui_click(event)
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Score Gui Click')
if is_spamming then
return
end

View File

@ -2,9 +2,50 @@
local Color = require 'utils.color_presets'
local Event = require 'utils.event'
local Global = require 'utils.global'
local Gui = require 'utils.gui'
local this = {
players = {}
}
Global.register(
this,
function(t)
this = t
end
)
local Public = {}
local locate_player_frame_name = Gui.uid_name()
local player_frame_name = Gui.uid_name()
local function create_player_data(player)
local player_data = this.players[player.index]
if player_data then
return this.players[player.index]
else
this.players[player.index] = {}
return this.players[player.index]
end
end
local function remove_player_data(player)
local player_data = this.players[player.index]
if player_data then
this.players[player.index] = nil
end
end
local function remove_camera_frame(player)
if player.gui.center[locate_player_frame_name] then
player.gui.center[locate_player_frame_name].destroy()
remove_player_data(player)
return
end
end
local function validate_player(player)
if not player then
return false
@ -24,17 +65,51 @@ local function validate_player(player)
return true
end
local function create_mini_camera_gui(player, caption, position, surface)
if player.gui.center['where_camera'] then
player.gui.center['where_camera'].destroy()
local function validate_frame(frame)
if not frame then
return false
end
local frame = player.gui.center.add({type = 'frame', name = 'where_camera', caption = caption})
if not frame.valid then
return false
end
return true
end
local function create_mini_camera_gui(player, caption, position, surface)
if player.gui.center[locate_player_frame_name] then
player.gui.center[locate_player_frame_name].destroy()
remove_player_data(player)
return
end
local target_player = game.players[caption]
if validate_player(target_player) then
local player_data = create_player_data(player)
player_data.target_player = target_player
else
remove_player_data(player)
player.print('Please type a name of a player who is connected.', Color.warning)
return
end
local frame = player.gui.center[locate_player_frame_name]
if not validate_frame(frame) then
frame = player.gui.center.add({type = 'frame', name = locate_player_frame_name, caption = caption})
end
surface = tonumber(surface)
if frame[player_frame_name] and frame[player_frame_name].valid then
frame[player_frame_name].destroy()
end
local camera =
frame.add(
{
type = 'camera',
name = 'where_camera',
name = player_frame_name,
position = position,
zoom = 0.4,
surface_index = surface
@ -42,6 +117,8 @@ local function create_mini_camera_gui(player, caption, position, surface)
)
camera.style.minimal_width = 740
camera.style.minimal_height = 580
local player_data = create_player_data(player)
player_data.camera_frame = camera
end
commands.add_command(
@ -57,8 +134,11 @@ commands.add_command(
local target_player = game.players[cmd.parameter]
if validate_player(target_player) then
local player_data = create_player_data(player)
player_data.target_player = target_player
create_mini_camera_gui(player, target_player.name, target_player.position, target_player.surface.index)
else
remove_player_data(player)
player.print('Please type a name of a player who is connected.', Color.warning)
end
else
@ -67,23 +147,48 @@ commands.add_command(
end
)
local function on_gui_click(event)
local player = game.players[event.player_index]
local function on_nth_tick()
for p, data in pairs(this.players) do
if data and data.target_player and data.target_player.valid then
local target_player = data.target_player
local camera_frame = data.camera_frame
local player = game.get_player(p)
if not (event.element and event.element.valid) then
return
end
if not (validate_player(player) and validate_player(target_player)) then
remove_player_data(player)
goto continue
end
local name = event.element.name
if not validate_frame(camera_frame) then
remove_player_data(player)
goto continue
end
if name == 'where_camera' then
player.gui.center['where_camera'].destroy()
return
camera_frame.position = target_player.position
camera_frame.surface_index = target_player.surface.index
::continue::
end
end
end
Public.create_mini_camera_gui = create_mini_camera_gui
Gui.on_click(
locate_player_frame_name,
function(event)
remove_camera_frame(event.player)
end
)
Event.add(defines.events.on_gui_click, on_gui_click)
Gui.on_click(
player_frame_name,
function(event)
remove_camera_frame(event.player)
end
)
Public.create_mini_camera_gui = create_mini_camera_gui
Public.remove_camera_frame = remove_camera_frame
Event.on_nth_tick(2, on_nth_tick)
return Public

View File

@ -1049,12 +1049,12 @@ local function show_mvps(player)
wave_defense_text.style.font = 'default-bold'
wave_defense_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local defender_label = t.add({type = 'label', caption = 'Defender >> '})
defender_label.style.font = 'default-listbox'
defender_label.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local defender_label_text = t.add({type = 'label', caption = mvp.killscore.name .. ' with a killing score of ' .. mvp.killscore.score .. ' kills!'})
defender_label_text.style.font = 'default-bold'
defender_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local fighter_label = t.add({type = 'label', caption = 'Fighter >> '})
fighter_label.style.font = 'default-listbox'
fighter_label.style.font_color = {r = 0.22, g = 0.77, b = 0.44}
local fighter_label_text = t.add({type = 'label', caption = mvp.killscore.name .. ' with a killing score of ' .. mvp.killscore.score .. ' kills!'})
fighter_label_text.style.font = 'default-bold'
fighter_label_text.style.font_color = {r = 0.33, g = 0.66, b = 0.9}
local builder_label = t.add({type = 'label', caption = 'Builder >> '})
builder_label.style.font = 'default-listbox'
@ -1077,7 +1077,7 @@ local function show_mvps(player)
table.insert(result, 'HIGHEST WAVE: \\n')
table.insert(result, wave_defense_table.wave_number .. '\\n')
table.insert(result, '\\n')
table.insert(result, 'MVP Defender: \\n')
table.insert(result, 'MVP Fighter: \\n')
table.insert(result, mvp.killscore.name .. ' with a killing score of ' .. mvp.killscore.score .. ' kills!\\n')
table.insert(result, '\\n')
table.insert(result, 'MVP Builder: \\n')

View File

@ -153,7 +153,7 @@ local function on_gui_click(event)
if not validate_player(player) then
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Mtn Gui Click')
if is_spamming then
return
end

View File

@ -317,8 +317,8 @@ local function kick_players_from_surface(ic, car)
e.player.teleport(main_surface.find_non_colliding_position('character', game.forces.player.get_spawn_position(main_surface), 3, 0, 5), main_surface)
end
end
return log_err('Car entity was not valid.')
end
return log_err('Car entity was not valid.')
end
for _, e in pairs(car.surface.find_entities_filtered({area = car.area})) do

View File

@ -18,6 +18,7 @@ local function on_entity_died(event)
local ic = IC.get()
if entity.type == 'car' or entity.name == 'spidertron' then
Minimap.kill_minimap(game.players[event.player_index])
Functions.kill_car(ic, entity)
end
end
@ -30,9 +31,8 @@ local function on_player_mined_entity(event)
local ic = IC.get()
Minimap.kill_minimap(game.players[event.player_index])
if entity.type == 'car' or entity.name == 'spidertron' then
Minimap.kill_minimap(game.players[event.player_index])
Functions.save_car(ic, event)
end
end
@ -169,6 +169,22 @@ local function on_init()
Public.reset()
end
local function on_gui_switch_state_changed(event)
local element = event.element
local player = game.players[event.player_index]
if not (player and player.valid) then
return
end
if not element.valid then
return
end
if element.name == 'ic_auto_switch' then
Minimap.toggle_auto(player)
end
end
local changed_surface = Minimap.changed_surface
Event.on_init(on_init)
@ -183,4 +199,6 @@ Event.add(defines.events.on_robot_mined_entity, on_robot_mined_entity)
Event.add(defines.events.on_gui_click, on_gui_click)
Event.add(defines.events.on_player_changed_surface, changed_surface)
Event.add(IC.events.on_player_kicked_from_surface, trigger_on_player_kicked_from_surface)
Event.add(defines.events.on_gui_switch_state_changed, on_gui_switch_state_changed)
return Public

View File

@ -57,25 +57,23 @@ local function get_player_data(player)
end
ic.minimap[player.index] = {
surface = ic.allowed_surface,
zoom = 0.30,
map_size = 360,
auto_map = true
auto = true,
state = 'left'
}
return ic.minimap[player.index]
end
function Public.toggle_auto(player)
local ic = ICT.get()
local switch = player.gui.left.minimap_toggle_frame['switch_auto_map']
if not switch or not switch.valid then
return
end
local player_data = get_player_data(player)
local switch = player.gui.left.minimap_toggle_frame['ic_auto_switch']
if switch.switch_state == 'left' then
ic.minimap[player.index].auto_map = true
player_data.auto = true
player_data.state = 'left'
elseif switch.switch_state == 'right' then
ic.minimap[player.index].auto_map = false
player_data.auto = false
player_data.state = 'right'
end
end
@ -120,12 +118,21 @@ local function draw_minimap(player, surface, position)
local player_data = get_player_data(player)
local frame = player.gui.left.minimap_toggle_frame
if not frame then
frame =
player.gui.left.add(
{type = 'frame', direction = 'vertical', name = 'minimap_toggle_frame', caption = 'Minimap'}
)
frame = player.gui.left.add({type = 'frame', direction = 'vertical', name = 'minimap_toggle_frame', caption = 'Minimap'})
end
frame.visible = true
if not frame.ic_auto_switch then
frame.add(
{
type = 'switch',
name = 'ic_auto_switch',
switch_state = player_data.state,
allow_none_state = false,
left_label_caption = {'gui.map_on'},
right_label_caption = {'gui.map_off'}
}
)
end
local element = frame['minimap_frame']
if not element then
element =
@ -164,9 +171,12 @@ end
function Public.update_minimap()
local ic = ICT.get()
for k, player in pairs(game.connected_players) do
if Functions.get_player_surface(ic, player) and player.gui.left.minimap_toggle_frame then
local player_data = get_player_data(player)
if Functions.get_player_surface(ic, player) and player.gui.left.minimap_toggle_frame and player_data.auto then
kill_frame(player)
draw_minimap(player)
else
kill_minimap(player)
end
end
end
@ -226,10 +236,13 @@ function Public.changed_surface(event)
end
local wd = player.gui.top['wave_defense']
local diff = player.gui.top['difficulty_gui']
local player_data = get_player_data(player)
if Functions.get_player_surface(ic, player) then
Public.toggle_button(player)
Public.minimap(player, surface)
if player_data.auto then
Public.minimap(player, surface)
end
if wd and wd.visible then
wd.visible = false
end

View File

@ -60,6 +60,17 @@ function Public.get(key)
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
function Public.set_car_area(tbl)
if not tbl then
return

View File

@ -1034,7 +1034,7 @@ function Public.toggle_minimap(icw, event)
return
end
local player = game.players[event.player_index]
local is_spamming = SpamProtection.is_spamming(player, 5)
local is_spamming = SpamProtection.is_spamming(player, 5, 'ICW Toggle Minimap')
if is_spamming then
return
end

View File

@ -731,7 +731,7 @@ local function slider_changed(event)
return
end
local is_spamming = SpamProtection.is_spamming(player, 2)
local is_spamming = SpamProtection.is_spamming(player, 2, 'Locomotive Slider Change')
if is_spamming then
return
end
@ -767,7 +767,7 @@ local function text_changed(event)
return
end
local is_spamming = SpamProtection.is_spamming(player, 2)
local is_spamming = SpamProtection.is_spamming(player, 2, 'Locomotive Text Changed')
if is_spamming then
return
end
@ -951,7 +951,7 @@ local function gui_click(event)
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Locomotive Gui Clicked')
if is_spamming then
return
end

View File

@ -5,6 +5,7 @@ local BuriedEnemies = require 'maps.mountain_fortress_v3.buried_enemies'
local HS = require 'maps.mountain_fortress_v3.highscore'
local IC = require 'maps.mountain_fortress_v3.ic.table'
local ICMinimap = require 'maps.mountain_fortress_v3.ic.minimap'
local Autostash = require 'modules.autostash'
local Group = require 'comfy_panel.group'
local PL = require 'comfy_panel.player_list'
@ -112,13 +113,13 @@ function Public.reset_map()
Poll.reset()
ICW.reset()
IC.reset()
IC.allowed_surface('mountain_fortress_v3')
IC.allowed_surface(game.surfaces[this.active_surface_index].name)
Functions.reset_table()
game.reset_time_played()
WPT.reset_table()
RPG_Func.rpg_reset_all_players()
RPG_Settings.set_surface_name('mountain_fortress_v3')
RPG_Settings.set_surface_name(game.surfaces[this.active_surface_index].name)
RPG_Settings.enable_health_and_mana_bars(true)
RPG_Settings.enable_wave_defense(true)
RPG_Settings.enable_mana(true)
@ -170,6 +171,7 @@ function Public.reset_map()
if player.gui.left['mvps'] then
player.gui.left['mvps'].destroy()
end
ICMinimap.kill_minimap(player)
end
Difficulty.reset_difficulty_poll({difficulty_poll_closing_timeout = game.tick + 36000})

View File

@ -87,7 +87,7 @@ local function on_gui_click(event)
end
if event.element.name == 'charging_station' then
local player = game.players[event.player_index]
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Charging Station Gui Click')
if is_spamming then
return
end

View File

@ -84,6 +84,7 @@ local function progress()
local surface = collapse.surface
if not collapse.start_now then
collapse.tiles = nil
return
end
@ -109,11 +110,7 @@ local function progress()
if collapse.specific_entities.enabled then
local position = {tile.position.x + 0.5, tile.position.y + 0.5}
local entities = collapse.specific_entities.entities
for _, e in pairs(
surface.find_entities_filtered(
{area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}}
)
) do
for _, e in pairs(surface.find_entities_filtered({area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}})) do
if entities[e.name] and e.valid and e.health then
e.die()
elseif e.valid then
@ -123,11 +120,7 @@ local function progress()
end
if collapse.kill then
local position = {tile.position.x + 0.5, tile.position.y + 0.5}
for _, e in pairs(
surface.find_entities_filtered(
{area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}}
)
) do
for _, e in pairs(surface.find_entities_filtered({area = {{position[1] - 2, position[2] - 2}, {position[1] + 2, position[2] + 2}}})) do
if e.valid and e.health then
e.die()
end

View File

@ -270,7 +270,7 @@ local function on_gui_click(event)
end
if event.element.name == 'difficulty_gui' then
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Difficulty Vote Gui Click')
if is_spamming then
return
end
@ -292,7 +292,7 @@ local function on_gui_click(event)
return
end
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Difficulty Gui No Func')
if is_spamming then
return
end

View File

@ -115,7 +115,7 @@ local function on_gui_click(event)
end
if event.element.name == 'close_map_intro' then
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'Map Info Gui Click')
if is_spamming then
return
end

View File

@ -41,7 +41,7 @@ local function on_gui_click(event)
end
local element = event.element
if player.gui.screen[main_frame_name] then
local is_spamming = SpamProtection.is_spamming(player)
local is_spamming = SpamProtection.is_spamming(player, nil, 'RPG Gui Click')
if is_spamming then
return
end
@ -754,14 +754,17 @@ local function on_player_crafted_item(event)
local rpg_extra = RPG.get('rpg_extra')
local is_blacklisted = rpg_extra.tweaked_crafting_items
local tweaked_crafting_items_enabled = rpg_extra.tweaked_crafting_items_enabled
local item = event.item_stack
local amount = 0.30 * math.random(1, 2)
if item and item.valid then
if is_blacklisted[item.name] then
amount = 0.2
if tweaked_crafting_items_enabled then
if item and item.valid then
if is_blacklisted[item.name] then
amount = 0.2
end
end
end
@ -1061,7 +1064,7 @@ local function on_player_used_capsule(event)
rpg_t[player.index].last_spawned = game.tick + object.tick
Functions.update_mana(player)
local reward_xp = object.mana_cost * 0.009
local reward_xp = object.mana_cost * 0.045
if reward_xp < 1 then
reward_xp = 1
end

View File

@ -106,6 +106,7 @@ function Public.reset_table()
['iron-gear-wheel'] = true,
['pipe'] = true
}
this.tweaked_crafting_items_enabled = false
this.rpg_t = {}
this.rpg_extra.rpg_xp_yield = {
['behemoth-biter'] = 16,

View File

@ -1,9 +1,8 @@
local Server = require 'utils.server'
local GUI = require 'utils.gui'
local Event = require 'utils.event'
local Color = require 'utils.color_presets'
local ups_label = GUI.uid_name()
local ups_label = 'ups_label'
local function validate_player(player)
if not player then

View File

@ -211,8 +211,7 @@ Gui.on_click(
local selected_player_index = data.selected_player_index
if selected_player_index then
input_text_box.text =
concat {'global.tokens[', Gui.token, '].data[', selected_player_index, '][', element_index, ']'}
input_text_box.text = concat {'global.tokens[', Gui.token, '].data[', selected_player_index, '][', element_index, ']'}
else
input_text_box.text = 'missing player'
end

View File

@ -155,8 +155,9 @@ local function handler_factory(event_id)
if not (player and player.valid) then
return
end
local is_spamming = SpamProtection.is_spamming(player)
if is_spamming then
local is_spamming = SpamProtection.is_spamming(player, nil, 'UtilsGUI Handler')
if is_spamming and player.name ~= 'Gerkiz' then
return
end

View File

@ -17,17 +17,20 @@ local Public = {}
local server_time = {secs = nil, tick = 0}
local server_ups = {ups = 60}
local start_data = {server_id = nil, server_name = nil, start_time = nil}
local requests = {}
Global.register(
{
server_time = server_time,
server_ups = server_ups,
start_data = start_data,
requests = requests
},
function(tbl)
server_time = tbl.server_time
server_ups = tbl.server_ups
start_data = tbl.start_data
requests = tbl.requests
end
)
@ -655,6 +658,37 @@ function Public.export_stats()
rcon.print(table_to_json(stats))
end
--- Called by the web server to set the server start data.
function Public.set_start_data(data)
start_data.server_id = data.server_id
start_data.server_name = data.server_name
local start_time = start_data.start_time
if not start_time then
-- Only set start time if it has not been set already, so that we keep the first start time.
start_data.start_time = data.start_time
end
end
-- This is the current server's id, in the case the save has been loaded on multiple servers.
-- @return string
function Public.get_server_id()
return start_data.server_id or ''
end
--- Gets the server's name. Empty string if not known.
-- This is the current server's name, in the case the save has been loaded on multiple servers.
-- @return string
function Public.get_server_name()
return start_data.server_name or ''
end
--- Gets the server's start time as a unix epoch timestamp. nil if not known.
-- @return number?
function Public.get_start_time()
return start_data.start_time
end
--- If the player exists bans the player.
-- Regardless of whether or not the player exists the name is synchronized with other servers
-- and stored in the database.

View File

@ -28,6 +28,7 @@ ServerCommands.set_time = Server.set_time
ServerCommands.set_ups = Server.set_ups
ServerCommands.get_ups = Server.get_ups
ServerCommands.export_stats = Server.export_stats
ServerCommands.set_start_data = Server.set_start_data
ServerCommands.query_online_players = Server.query_online_players
local SC_Interface = {

View File

@ -4,7 +4,8 @@ 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.
default_tick = 15, -- this defines the default tick to check weather or not a user is spamming a button.
_DEBUG = false
}
Global.register(
@ -14,6 +15,13 @@ Global.register(
end
)
local function debug_str(str)
if not this._DEBUG then
return
end
print(str)
end
function Public.reset_spam_table()
local players = game.connected_players
this.prevent_spam = {}
@ -31,11 +39,15 @@ function Public.set_new_value(player)
return false
end
function Public.is_spamming(player, value_to_compare)
function Public.is_spamming(player, value_to_compare, text)
if not this.prevent_spam[player.index] then
return false
end
if text then
debug_str('Frame: ' .. text)
end
if game.tick_paused then
return false -- game is paused - shoo
end
@ -45,8 +57,10 @@ function Public.is_spamming(player, value_to_compare)
if this.prevent_spam[player.index] then
if (tick - this.prevent_spam[player.index]) > value then
Public.set_new_value(player)
debug_str(player.name .. ' is not spamming.')
return false -- is not spamming
else
debug_str(player.name .. ' is spamming.')
return true -- is spamming
end
end

View File

@ -2,7 +2,7 @@ local Token = {}
local tokens = {}
local counter = 0
local counter = 200
--- Assigns a unquie id for the given var.
-- This function cannot be called after on_init() or on_load() has run as that is a desync risk.