mirror of
https://github.com/Refactorio/RedMew.git
synced 2025-01-03 22:52:13 +02:00
Add permissions module for DO (#1391)
* Enable 'no-blueprints' for all DO maps.
This commit is contained in:
parent
d598d9f208
commit
579dad4453
@ -1355,6 +1355,7 @@ stds.factorio_defines = {
|
||||
'gui_value_changed',
|
||||
'import_blueprint',
|
||||
'import_blueprint_string',
|
||||
'import_blueprints_filtered',
|
||||
'import_permissions_string',
|
||||
'inventory_split',
|
||||
'inventory_transfer',
|
||||
@ -1448,6 +1449,7 @@ stds.factorio_defines = {
|
||||
'undo',
|
||||
'upgrade',
|
||||
'upgrade_opened_blueprint',
|
||||
'upgrade_opened_blueprint_by_record',
|
||||
'use_artillery_remote',
|
||||
'use_item',
|
||||
'wire_dragging',
|
||||
|
@ -441,6 +441,14 @@ global.config = {
|
||||
donator_perks = {
|
||||
enabled = true
|
||||
}
|
||||
},
|
||||
permissions = {
|
||||
enabled = true,
|
||||
presets = {
|
||||
no_blueprints = false,
|
||||
no_handcraft = false,
|
||||
},
|
||||
modes = {},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -117,6 +117,9 @@ end
|
||||
if config.spidertron_group_control.enabled then
|
||||
require 'features.spidertron_group_control'
|
||||
end
|
||||
if config.permissions.enabled then
|
||||
require 'features.permissions'
|
||||
end
|
||||
|
||||
-- GUIs
|
||||
-- The order determines the order they appear from left to right.
|
||||
|
120
features/permissions.lua
Normal file
120
features/permissions.lua
Normal file
@ -0,0 +1,120 @@
|
||||
local Command = require 'utils.command'
|
||||
local Event = require 'utils.event'
|
||||
local Ranks = require 'resources.ranks'
|
||||
local Global = require 'utils.global'
|
||||
|
||||
local data = {
|
||||
initialized_permissions = false,
|
||||
}
|
||||
|
||||
Global.register(data, function(tbl)
|
||||
data = tbl
|
||||
end)
|
||||
|
||||
local config = global.config.permissions
|
||||
local Public = {}
|
||||
|
||||
-- defines.input_action listed at https://lua-api.factorio.com/latest/defines.html#defines.input_action
|
||||
local DEFAULT_PRESETS_ACTIONS = {
|
||||
no_blueprints = {
|
||||
[defines.input_action.import_blueprint] = false,
|
||||
[defines.input_action.import_blueprint_string] = false,
|
||||
[defines.input_action.import_blueprints_filtered] = false,
|
||||
[defines.input_action.import_permissions_string] = false,
|
||||
[defines.input_action.open_blueprint_library_gui] = false,
|
||||
[defines.input_action.open_blueprint_record] = false,
|
||||
[defines.input_action.upgrade_opened_blueprint_by_record] = false,
|
||||
},
|
||||
no_handcraft= {
|
||||
[defines.input_action.craft] = false,
|
||||
}
|
||||
}
|
||||
|
||||
for preset_name, preset_actions in pairs(DEFAULT_PRESETS_ACTIONS) do
|
||||
config.modes[preset_name] = config.modes[preset_name] or preset_actions
|
||||
end
|
||||
|
||||
---Returns config.preset.any(true)
|
||||
---@return boolean
|
||||
function Public.any_preset()
|
||||
for preset_name, is_enabled in pairs(config.presets or {}) do
|
||||
if is_enabled and config.modes[preset_name] ~= nil then return true end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
---Sets all permissions for the "Default" group to true
|
||||
function Public.reset_all_permissions()
|
||||
local Default = game.permissions.get_group("Default")
|
||||
|
||||
for _, action_ID in pairs(defines.input_action) do
|
||||
Default.set_allows_action(action_ID, true)
|
||||
end
|
||||
end
|
||||
|
||||
---Sets permissions for the "Default" group
|
||||
---@param params config.permissions
|
||||
function Public.set_permissions(params)
|
||||
if params then
|
||||
for name, actions in pairs(params.modes or {}) do
|
||||
config.modes[name] = actions
|
||||
end
|
||||
|
||||
for name, is_enabled in pairs(params.presets or {}) do
|
||||
config.presets[name] = is_enabled
|
||||
end
|
||||
end
|
||||
|
||||
local Default = game.permissions.get_group("Default")
|
||||
|
||||
for name, actions in pairs(config.modes or {}) do
|
||||
if config.presets[name] then
|
||||
for action, is_allowed in pairs(actions or {}) do
|
||||
Default.set_allows_action(action, is_allowed)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Init permissions for multiplayer servers
|
||||
--- 'game.is_multiplayer()' is not available on 'on_init'
|
||||
Event.add(defines.events.on_player_joined_game, function()
|
||||
if config.enabled
|
||||
and not data.initialized_permissions
|
||||
and game.is_multiplayer()
|
||||
and Public.any_preset()
|
||||
then
|
||||
Public.set_permissions()
|
||||
data.initialized_permissions = true
|
||||
end
|
||||
end)
|
||||
|
||||
---Use "/permissions-reset" to reset all players' permissions to default for the "Default" group (admin/server only)
|
||||
Command.add(
|
||||
'permissions-reset',
|
||||
{
|
||||
description = {'command_description.permissions_reset'},
|
||||
arguments = {},
|
||||
required_rank = Ranks.admin,
|
||||
allowed_by_server = true
|
||||
},
|
||||
function()
|
||||
Public.reset_all_permissions()
|
||||
end
|
||||
)
|
||||
|
||||
---Use "/permissions-set-scenario" to reapply scenario's permissions, if any, for the "Default" group (admin/server only)
|
||||
Command.add(
|
||||
'permissions-set-scenario',
|
||||
{
|
||||
description = {'command_description.permissions_set_scenario'},
|
||||
arguments = {},
|
||||
required_rank = Ranks.admin,
|
||||
allowed_by_server = true
|
||||
},
|
||||
function()
|
||||
Public.set_permissions()
|
||||
end
|
||||
)
|
||||
|
||||
return Public
|
@ -68,6 +68,8 @@ meltdown_set=Sets the status of meltdown.
|
||||
redmew_color=Set will save your current color for future maps. Reset will erase your saved color. Random will give you a random color.
|
||||
performance_scale_set=Sets the performance scale between 0.05 and 1. Will alter the game speed, manual mining speed, manual crafting speed and character running speed per force.
|
||||
performance_scale_get=Shows the current performance scale.
|
||||
permissions_reset=Use "/permissions-reset" to reset all players' permissions to default
|
||||
permissions_set_scenario=Use "/permissions-set-scenario" to reapply scenario's permissions, if any
|
||||
market=Places a market near you. Use /market removeall to remove all markets on a map
|
||||
lazy_bastard_bootstrap=Puts down the minimum requirements to get started
|
||||
toast=Sends a toast to all players
|
||||
|
@ -111,6 +111,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30, -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(
|
||||
function()
|
||||
|
@ -114,6 +114,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.forces.player.technologies['mining-productivity-1'].enabled = false
|
||||
|
@ -95,6 +95,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
if script.active_mods['early_construction'] then
|
||||
table.insert(Config.player_create.starting_items, { count = 1, name = 'early-construction-light-armor' })
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
--game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -92,6 +92,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
if script.active_mods['early_construction'] then
|
||||
table.insert(Config.player_create.starting_items, { count = 1, name = 'early-construction-light-armor' })
|
||||
|
@ -93,6 +93,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
if script.active_mods['early_construction'] then
|
||||
table.insert(Config.player_create.starting_items, { count = 1, name = 'early-construction-light-armor' })
|
||||
|
@ -92,6 +92,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -96,6 +96,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -103,6 +103,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
if script.active_mods['early_construction'] then
|
||||
table.insert(Config.player_create.starting_items, { count = 1, name = 'early-construction-light-armor' })
|
||||
|
@ -103,6 +103,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
if script.active_mods['early_construction'] then
|
||||
table.insert(Config.player_create.starting_items, { count = 1, name = 'early-construction-light-armor' })
|
||||
|
@ -115,6 +115,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
local kr_remote = Token.register(function()
|
||||
-- enable creep on Redmew surface
|
||||
|
@ -86,6 +86,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -108,6 +108,8 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
Config.permissions.presets.no_handcraft = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.permissions.get_group("Default").set_allows_action(defines.input_action.craft, false)
|
||||
|
@ -85,6 +85,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.draw_resource_selection = false
|
||||
|
@ -86,6 +86,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.draw_resource_selection = false
|
||||
|
@ -88,6 +88,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.forces.player.technologies['mining-productivity-1'].enabled = false
|
||||
|
@ -88,6 +88,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.forces.player.technologies['mining-productivity-1'].enabled = false
|
||||
|
@ -88,6 +88,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
game.forces.player.technologies['mining-productivity-1'].enabled = false
|
||||
|
@ -89,6 +89,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -89,6 +89,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -92,6 +92,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -91,6 +91,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
if script.active_mods['early_construction'] then
|
||||
table.insert(Config.player_create.starting_items, { count = 1, name = 'early-construction-light-armor' })
|
||||
|
@ -86,6 +86,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -87,6 +87,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -92,6 +92,7 @@ Config.dump_offline_inventories = {
|
||||
offline_timout_mins = 30 -- time after which a player logs off that their inventory is provided to the team
|
||||
}
|
||||
Config.paint.enabled = false
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
@ -90,6 +90,7 @@ Config.paint.enabled = false
|
||||
Config.day_night.enabled = true
|
||||
Config.day_night.use_fixed_brightness = true
|
||||
Config.day_night.fixed_brightness = 0.70
|
||||
Config.permissions.presets.no_blueprints = true
|
||||
|
||||
Event.on_init(function()
|
||||
-- game.draw_resource_selection = false
|
||||
|
Loading…
Reference in New Issue
Block a user