1
0
mirror of https://github.com/ComfyFactory/ComfyFactorio.git synced 2025-02-09 13:37:02 +02:00

antigrief - added more logging

This commit is contained in:
Gerkiz 2020-07-07 16:30:17 +02:00
parent e24dc9ee92
commit 7f2cbcfb4f

View File

@ -4,10 +4,12 @@
local Event = require 'utils.event'
local session = require 'utils.session_data'
local Server = require 'utils.server'
local Global = require 'utils.global'
local Utils = require 'utils.core'
local Server = require 'utils.server'
local Public = {}
local match = string.match
local this = {
landfill_history = {
@ -50,7 +52,8 @@ local ammo_names = {
['cluster-grenade'] = true,
['grenade'] = true,
['atomic-bomb'] = true,
['cliff-explosives'] = true
['cliff-explosives'] = true,
['rocket'] = true
}
Global.register(
@ -60,6 +63,24 @@ Global.register(
end
)
local function damage_player(player)
if player.character then
player.character.health = player.character.health - math.random(50, 100)
player.character.surface.create_entity({name = 'water-splash', position = player.position})
local messages = {
'Ouch.. That hurt! Better be careful now.',
'Just a fleshwound.',
'Better keep those hands to yourself or you might loose them.'
}
player.print(messages[math.random(1, #messages)], {r = 0.75, g = 0.0, b = 0.0})
if player.character.health <= 0 then
player.character.die('enemy')
game.print(player.name .. ' should have obeyed the law.', {r = 0.75, g = 0.0, b = 0.0})
return
end
end
end
local function on_marked_for_deconstruction(event)
local tracker = session.get_session_table()
local trusted = session.get_trusted_table()
@ -102,19 +123,19 @@ local function on_player_ammo_inventory_changed(event)
if playtime < 1296000 then
local nukes = player.remove_item({name = 'atomic-bomb', count = 1000})
if nukes > 0 then
player.print('You have not grown accustomed to this technology yet.', {r = 0.22, g = 0.99, b = 0.99})
Server.to_discord_bold(
table.concat {'** [Nuke] ' .. player.name .. ' tried to equip nukes but was not trusted. **'}
)
game.print(
'[Nuke] ' .. player.name .. ' tried to equip nukes but was not trusted.',
{r = 0.22, g = 0.99, b = 0.99}
)
player.character.health = 0
Utils.action_warning('{Nuke}', player.name .. ' tried to equip nukes but was not trusted.')
damage_player(player)
end
end
end
local function on_player_joined_game(event)
local player = game.players[event.player_index]
if match(player.name, '^[Ili1|]+$') then
Server.ban_sync(player.name, '', '<script>') -- No reason given, to not give them any hints to change their name
end
end
local function on_player_built_tile(event)
local placed_tiles = event.tiles
if
@ -127,6 +148,10 @@ local function on_player_built_tile(event)
--landfill history--
if not this.landfill_history[player.index] then
this.landfill_history[player.index] = {}
end
if #this.landfill_history[player.index] > 100 then
this.landfill_history[player.index] = {}
end
@ -191,6 +216,9 @@ local function on_player_used_capsule(event)
local name = item.name
if ammo_names[name] then
if not this.capsule_history[player.index] then
this.capsule_history[player.index] = {}
end
if #this.capsule_history[player.index] > 100 then
this.capsule_history[player.index] = {}
end
@ -220,6 +248,10 @@ local function on_entity_died(event)
local player = cause.player
name = player.name
if not this.friendly_fire_history[player.index] then
this.friendly_fire_history[player.index] = {}
end
if #this.friendly_fire_history[cause.player.index] > 100 then
this.friendly_fire_history[cause.player.index] = {}
end
@ -258,11 +290,17 @@ local function on_entity_died(event)
str = str .. 'surface:' .. event.entity.surface.index
if cause and cause.name == 'character' and cause.player then
if not this.friendly_fire_history[cause.player.index] then
this.friendly_fire_history[cause.player.index] = {}
end
if #this.friendly_fire_history[cause.player.index] > 100 then
this.friendly_fire_history[cause.player.index] = {}
end
this.friendly_fire_history[cause.player.index][#this.friendly_fire_history[cause.player.index] + 1] = str
else
if not this.friendly_fire_history['unknown'] then
this.friendly_fire_history['unknown'] = {}
end
if #this.friendly_fire_history['unknown'] > 100 then
this.friendly_fire_history['unknown'] = {}
end
@ -280,6 +318,9 @@ local function on_player_mined_entity(event)
end
if this.whitelist_types[event.entity.type] then
if not this.mining_history[player.index] then
this.mining_history[player.index] = {}
end
if #this.mining_history[player.index] > 100 then
this.mining_history[player.index] = {}
end
@ -309,6 +350,9 @@ local function on_player_mined_entity(event)
if blacklisted_types[event.entity.type] then
return
end
if not this.mining_history[player.index] then
this.mining_history[player.index] = {}
end
if #this.mining_history[player.index] > 100 then
this.mining_history[player.index] = {}
@ -351,10 +395,10 @@ local function on_gui_opened(event)
end
if player.name ~= corpse_owner.name then
game.print(player.name .. ' is looting ' .. corpse_owner.name .. '´s body.', {r = 0.85, g = 0.85, b = 0.85})
Server.to_discord_bold(
table.concat {'** [Corpse] ' .. player.name .. ' is looting ' .. corpse_owner.name .. '´s body. **'}
)
Utils.action_warning('{Corpse}', player.name .. ' is looting ' .. corpse_owner.name .. '´s body.')
if not this.corpse_history[player.index] then
this.corpse_history[player.index] = {}
end
if #this.corpse_history[player.index] > 100 then
this.corpse_history[player.index] = {}
end
@ -395,10 +439,10 @@ local function on_pre_player_mined_item(event)
return
end
if player.name ~= corpse_owner.name then
game.print(player.name .. ' has looted ' .. corpse_owner.name .. '´s body.', {r = 0.85, g = 0.85, b = 0.85})
Server.to_discord_bold(
table.concat {'[Corpse] ' .. player.name .. ' has looted ' .. corpse_owner.name .. '´s body.'}
)
Utils.action_warning('{Corpse}', player.name .. ' has looted ' .. corpse_owner.name .. '´s body.')
if not this.corpse_history[player.index] then
this.corpse_history[player.index] = {}
end
if #this.corpse_history[player.index] > 100 then
this.corpse_history[player.index] = {}
end
@ -418,31 +462,6 @@ local function on_pre_player_mined_item(event)
end
end
local function on_player_joined_game(event)
local player = game.get_player(event.player_index)
if not player then
return
end
if not this.mining_history[player.index] then
this.mining_history[player.index] = {}
end
if not this.capsule_history[player.index] then
this.capsule_history[player.index] = {}
end
if not this.friendly_fire_history[player.index] then
this.friendly_fire_history[player.index] = {}
end
if not this.landfill_history[player.index] then
this.landfill_history[player.index] = {}
end
if not this.corpse_history[player.index] then
this.corpse_history[player.index] = {}
end
if not this.cancel_crafting_history[player.index] then
this.cancel_crafting_history[player.index] = {}
end
end
local function on_player_cursor_stack_changed(event)
local tracker = session.get_session_table()
local trusted = session.get_trusted_table()
@ -475,17 +494,8 @@ local function on_player_cursor_stack_changed(event)
if ammo_names[name] then
local item_to_remove = player.remove_item({name = name, count = 1000})
if item_to_remove > 0 then
player.print('You have not grown accustomed to this technology yet.', {r = 0.22, g = 0.99, b = 0.99})
Server.to_discord_bold(
table.concat {
'** [Capsule] ' .. player.name .. ' equipped ' .. name .. ' but was not trusted. **'
}
)
game.print(
'[Capsule] ' .. player.name .. ' equipped ' .. name .. ' but was not trusted.',
{r = 0.22, g = 0.99, b = 0.99}
)
player.character.health = 0
Utils.action_warning('{Capsule}', player.name .. ' equipped ' .. name .. ' but was not trusted.')
damage_player(player)
end
end
end
@ -499,24 +509,18 @@ local function on_player_cancelled_crafting(event)
playtime = player.online_time + tracker[player.name]
end
game.print(serpent.block(#event.items))
local count = #event.items
if playtime < 1296000 then
if count > 40 then
game.print(
Utils.action_warning(
'{Crafting}',
player.name ..
' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. count .. '.',
{r = 0.85, g = 0.85, b = 0.85}
)
Server.to_discord_bold(
table.concat {
'[Crafting] ' ..
player.name ..
' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. count .. '.'
}
' canceled their craft of item ' .. event.recipe.name .. ' of total count ' .. count .. '.'
)
if not this.cancel_crafting_history[player.index] then
this.cancel_crafting_history[player.index] = {}
end
if #this.cancel_crafting_history[player.index] > 100 then
this.cancel_crafting_history[player.index] = {}
end
@ -538,6 +542,25 @@ local function on_player_cancelled_crafting(event)
end
end
function Public.reset_tables()
this.landfill_history = {
['unknown'] = {}
}
this.capsule_history = {
['unknown'] = {}
}
this.friendly_fire_history = {
['unknown'] = {}
}
this.mining_history = {
['unknown'] = {}
}
this.corpse_history = {
['unknown'] = {}
}
this.cancel_crafting_history = {}
end
function Public.cursor_stack(event, pattern)
local player = game.get_player(event.player_index)
local stack = player.cursor_stack
@ -579,7 +602,6 @@ function Public.get(key)
end
end
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
Event.add(defines.events.on_player_mined_entity, on_player_mined_entity)
Event.add(defines.events.on_entity_died, on_entity_died)
Event.add(defines.events.on_built_entity, on_built_entity)
@ -591,5 +613,6 @@ Event.add(defines.events.on_pre_player_mined_item, on_pre_player_mined_item)
Event.add(defines.events.on_player_used_capsule, on_player_used_capsule)
Event.add(defines.events.on_player_cursor_stack_changed, on_player_cursor_stack_changed)
Event.add(defines.events.on_player_cancelled_crafting, on_player_cancelled_crafting)
Event.add(defines.events.on_player_joined_game, on_player_joined_game)
return Public