mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-02-09 13:37:05 +02:00
commit
129b6b031b
@ -3,8 +3,7 @@ local Global = require 'utils.global'
|
||||
local Task = require 'utils.task'
|
||||
local Token = require 'utils.token'
|
||||
local Game = require 'utils.game'
|
||||
local Server = require 'features.server'
|
||||
local Color = require 'resources.color_presets'
|
||||
local Utils = require 'utils.core'
|
||||
|
||||
local player_corpses = {}
|
||||
|
||||
@ -119,10 +118,7 @@ local function mined_entity(event)
|
||||
|
||||
if player and corpse_owner then
|
||||
local message = table.concat {'## - ', player.name, ' has looted ', corpse_owner.name, "'s corpse"}
|
||||
|
||||
game.print(message, Color.yellow)
|
||||
log('[Corpse] ' .. message)
|
||||
Server.to_discord_bold(message)
|
||||
Utils.action_warning('[Corpse]', message)
|
||||
end
|
||||
end
|
||||
|
||||
@ -143,11 +139,8 @@ local function on_gui_opened(event)
|
||||
local corpse_owner = Game.get_player_by_index(corpse_owner_index)
|
||||
|
||||
if player and corpse_owner then
|
||||
local message = table.concat {'## - ', player.name, ' is looting ', corpse_owner.name, "'s corpse"}
|
||||
|
||||
game.print(message, Color.yellow)
|
||||
log('[Corpse] ' .. message)
|
||||
Server.to_discord_bold(message)
|
||||
local message = table.concat {player.name, ' is looting ', corpse_owner.name, "'s corpse"}
|
||||
Utils.action_warning('[Corpse]', message)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,9 +4,11 @@ local Utils = require 'utils.core'
|
||||
local Game = require 'utils.game'
|
||||
local Server = require 'features.server'
|
||||
|
||||
local format = string.format
|
||||
local match = string.match
|
||||
|
||||
local function allowed_to_nuke(player)
|
||||
return player.admin or UserGroups.is_regular(player.name) or
|
||||
((player.online_time / 216000) > global.config.nuke_control.nuke_min_time_hours)
|
||||
return player.admin or UserGroups.is_regular(player.name) or ((player.online_time / 216000) > global.config.nuke_control.nuke_min_time_hours)
|
||||
end
|
||||
|
||||
local function ammo_changed(event)
|
||||
@ -16,7 +18,7 @@ local function ammo_changed(event)
|
||||
end
|
||||
local nukes = player.remove_item({name = 'atomic-bomb', count = 1000})
|
||||
if nukes > 0 then
|
||||
game.print(player.name .. ' tried to use a nuke, but instead dropped it on his foot.')
|
||||
Utils.action_warning('[Nuke]', player.name .. ' tried to use a nuke, but instead dropped it on his foot.')
|
||||
|
||||
local character = player.character
|
||||
if character and character.valid then
|
||||
@ -38,10 +40,8 @@ local function on_player_deconstructed_area(event)
|
||||
player.remove_item({name = 'deconstruction-planner', count = 1000})
|
||||
|
||||
--Make them think they arent noticed
|
||||
Utils.print_except(player.name .. ' tried to deconstruct something, but instead deconstructed themself.', player)
|
||||
player.print(
|
||||
'Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.'
|
||||
)
|
||||
Utils.silent_action_warning('[Deconstruct]', player.name .. ' tried to deconstruct something, but instead deconstructed themself.', player)
|
||||
player.print('Only regulars can mark things for deconstruction, if you want to deconstruct something you may ask an admin to promote you.')
|
||||
|
||||
local character = player.character
|
||||
if character and character.valid then
|
||||
@ -61,10 +61,7 @@ local function on_player_deconstructed_area(event)
|
||||
|
||||
local entities = player.surface.find_entities_filtered {area = area, force = player.force}
|
||||
if #entities > 1000 then
|
||||
Utils.print_admins(
|
||||
'Warning! ' .. player.name .. ' just tried to deconstruct ' .. tostring(#entities) .. ' entities!',
|
||||
nil
|
||||
)
|
||||
Utils.print_admins('Warning! ' .. player.name .. ' just tried to deconstruct ' .. tostring(#entities) .. ' entities!', nil)
|
||||
end
|
||||
for _, entity in pairs(entities) do
|
||||
if entity.valid and entity.to_be_deconstructed(Game.get_player_by_index(event.player_index).force) then
|
||||
@ -75,8 +72,7 @@ end
|
||||
|
||||
local function item_not_sanctioned(item)
|
||||
local name = item.name
|
||||
return (name:find('capsule') or name == 'cliff-explosives' or name == 'raw-fish' or
|
||||
name == 'discharge-defense-remote')
|
||||
return (name:find('capsule') or name == 'cliff-explosives' or name == 'raw-fish' or name == 'discharge-defense-remote')
|
||||
end
|
||||
|
||||
global.entities_allowed_to_bomb = {
|
||||
@ -149,20 +145,12 @@ local function on_capsule_used(event)
|
||||
if count > 8 then
|
||||
if global.players_warned[event.player_index] then
|
||||
if nuke_control.enable_autoban then
|
||||
Server.ban_sync(
|
||||
player.name,
|
||||
string.format(
|
||||
'Damaged %i entities with %s. This action was performed automatically. If you want to contest this ban please visit redmew.com/discord.',
|
||||
count,
|
||||
item.name
|
||||
),
|
||||
'<script>'
|
||||
)
|
||||
Server.ban_sync(player.name, format('Damaged %i entities with %s. This action was performed automatically. If you want to contest this ban please visit redmew.com/discord.', count, item.name), '<script>')
|
||||
end
|
||||
else
|
||||
global.players_warned[event.player_index] = true
|
||||
if nuke_control.enable_autokick then
|
||||
game.kick_player(player, string.format('Damaged %i entities with %s -Antigrief', count, item.name))
|
||||
game.kick_player(player, format('Damaged %i entities with %s -Antigrief', count, item.name))
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -171,7 +159,7 @@ end
|
||||
|
||||
local function on_player_joined(event)
|
||||
local player = game.players[event.player_index]
|
||||
if string.match(player.name, '^[Ili1|]+$') then
|
||||
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
|
||||
|
@ -3,9 +3,16 @@
|
||||
-- Dependencies
|
||||
local Game = require 'utils.game'
|
||||
local Color = require 'resources.color_presets'
|
||||
local Server = require 'features.server'
|
||||
|
||||
-- localized functions
|
||||
local random = math.random
|
||||
local sqrt = math.sqrt
|
||||
local floor = math.floor
|
||||
local format = string.format
|
||||
local match = string.match
|
||||
local insert = table.insert
|
||||
local concat = table.concat
|
||||
|
||||
-- local constants
|
||||
local prefix = '## - '
|
||||
@ -21,14 +28,21 @@ local Module = {}
|
||||
function Module.distance(pos1, pos2)
|
||||
local dx = pos2.x - pos1.x
|
||||
local dy = pos2.y - pos1.y
|
||||
return math.sqrt(dx * dx + dy * dy)
|
||||
return sqrt(dx * dx + dy * dy)
|
||||
end
|
||||
|
||||
--- Takes msg and prints it to all players except provided player
|
||||
function Module.print_except(msg, player)
|
||||
-- @param msg <string> The message to print
|
||||
-- @param color <table> the color to use for the message
|
||||
-- @param player <LuaPlayer> the player not to send the message to
|
||||
function Module.print_except(msg, color, player)
|
||||
if not color then
|
||||
color = Color.white
|
||||
end
|
||||
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if p ~= player then
|
||||
p.print(msg)
|
||||
p.print(msg, color)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -51,7 +65,7 @@ function Module.print_admins(msg, source)
|
||||
source_name = 'Server'
|
||||
chat_color = Color.yellow
|
||||
end
|
||||
local formatted_msg = string.format('%s(ADMIN) %s: %s', prefix, source_name, msg) -- to the server
|
||||
local formatted_msg = format('%s(ADMIN) %s: %s', prefix, source_name, msg) -- to the server
|
||||
print(formatted_msg)
|
||||
for _, p in pairs(game.connected_players) do
|
||||
if p.admin then
|
||||
@ -96,7 +110,7 @@ function Module.find_entities_by_last_user(player, surface, filters)
|
||||
filter.force = player.force.name
|
||||
for _, e in pairs(surface.find_entities_filtered(filter)) do
|
||||
if e.last_user == player then
|
||||
table.insert(entities, e)
|
||||
insert(entities, e)
|
||||
end
|
||||
end
|
||||
return entities
|
||||
@ -114,26 +128,26 @@ end
|
||||
function Module.format_time(ticks)
|
||||
local result = {}
|
||||
|
||||
local hours = math.floor(ticks * ticks_to_hours)
|
||||
local hours = floor(ticks * ticks_to_hours)
|
||||
if hours > 0 then
|
||||
ticks = ticks - hours * hours_to_ticks
|
||||
table.insert(result, hours)
|
||||
insert(result, hours)
|
||||
if hours == 1 then
|
||||
table.insert(result, 'hour')
|
||||
insert(result, 'hour')
|
||||
else
|
||||
table.insert(result, 'hours')
|
||||
insert(result, 'hours')
|
||||
end
|
||||
end
|
||||
|
||||
local minutes = math.floor(ticks * ticks_to_minutes)
|
||||
table.insert(result, minutes)
|
||||
local minutes = floor(ticks * ticks_to_minutes)
|
||||
insert(result, minutes)
|
||||
if minutes == 1 then
|
||||
table.insert(result, 'minute')
|
||||
insert(result, 'minute')
|
||||
else
|
||||
table.insert(result, 'minutes')
|
||||
insert(result, 'minutes')
|
||||
end
|
||||
|
||||
return table.concat(result, ' ')
|
||||
return concat(result, ' ')
|
||||
end
|
||||
|
||||
--- Prints a message letting the player know they cannot run a command
|
||||
@ -147,15 +161,15 @@ end
|
||||
-- @param command the command's name as table element
|
||||
-- @param parameters the command's parameters as a table (optional)
|
||||
function Module.log_command(actor, command, parameters)
|
||||
local action = table.concat {'[Admin-Command] ', actor, ' used: ', command}
|
||||
local action = concat {'[Admin-Command] ', actor, ' used: ', command}
|
||||
if parameters then
|
||||
action = table.concat {action, ' ', parameters}
|
||||
action = concat {action, ' ', parameters}
|
||||
end
|
||||
log(action)
|
||||
end
|
||||
|
||||
function Module.comma_value(n) -- credit http://richard.warburton.it
|
||||
local left, num, right = string.match(n, '^([^%d]*%d)(%d*)(.-)$')
|
||||
local left, num, right = match(n, '^([^%d]*%d)(%d*)(.-)$')
|
||||
return left .. (num:reverse():gsub('(%d%d%d)', '%1,'):reverse()) .. right
|
||||
end
|
||||
|
||||
@ -187,6 +201,27 @@ function Module.set_and_return(tbl, key, value)
|
||||
return value
|
||||
end
|
||||
|
||||
--- Takes msg and prints it to all players. Also prints to the log and discord
|
||||
-- @param msg <string> The message to print
|
||||
-- @param warning_prefix <string> The name of the module/warning
|
||||
function Module.action_warning(warning_prefix, msg)
|
||||
game.print(prefix .. msg, Color.yellow)
|
||||
msg = format('%s %s', warning_prefix, msg)
|
||||
log(msg)
|
||||
Server.to_discord_bold(msg)
|
||||
end
|
||||
|
||||
--- Takes msg and prints it to all players except provided player. Also prints to the log and discord
|
||||
-- @param msg <string> The message to print
|
||||
-- @param warning_prefix <string> The name of the module/warning
|
||||
-- @param player <LuaPlayer> the player not to send the message to
|
||||
function Module.silent_action_warning(warning_prefix, msg, player)
|
||||
Module.print_except(prefix .. msg, Color.yellow, player)
|
||||
msg = format('%s %s', warning_prefix, msg)
|
||||
log(msg)
|
||||
Server.to_discord_bold(msg)
|
||||
end
|
||||
|
||||
-- add utility functions that exist in base factorio/util
|
||||
require 'util'
|
||||
|
||||
@ -198,7 +233,6 @@ require 'util'
|
||||
-- @return <table> modified position
|
||||
Module.move_position = util.moveposition
|
||||
|
||||
|
||||
--- Takes a direction and gives you the opposite
|
||||
-- @param direction <defines.direction> north, east, south, west, northeast, northwest, southeast, southwest
|
||||
-- @return <number> representing the direction
|
||||
|
Loading…
x
Reference in New Issue
Block a user