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

fix blueprints always disabled

This commit is contained in:
danielmartin0 2024-09-16 14:29:15 +01:00
parent d02a4beb56
commit 4014340e89
4 changed files with 217 additions and 214 deletions

View File

@ -16,6 +16,7 @@ local Surfaces = require 'maps.pirates.surfaces.surfaces'
-- local Progression = require 'maps.pirates.progression'
local IslandEnum = require 'maps.pirates.surfaces.islands.island_enum'
local Roles = require 'maps.pirates.roles.roles'
local Permissions = require 'maps.pirates.permissions'
-- local Gui = require 'maps.pirates.gui.gui'
-- local Sea = require 'maps.pirates.surfaces.sea.sea'
-- local Hold = require 'maps.pirates.surfaces.hold'
@ -1483,7 +1484,7 @@ local function event_on_player_joined_game(event)
local surface = game.surfaces[CoreData.lobby_surface_name]
player.teleport(surface.find_non_colliding_position('character', spawnpoint, 32, 0.5) or spawnpoint, surface)
Roles.update_privileges(player)
Permissions.update_privileges(player)
if not player.name then return end
@ -1672,7 +1673,7 @@ local function on_player_changed_surface(event)
end
end
Roles.update_privileges(player)
Permissions.update_privileges(player)
GuiWelcome.close_welcome_window(player)
end

View File

@ -9,9 +9,6 @@ local Public = {}
Public.scenario_id_name = 'pirates'
Public.version_string = '1.6.3' --major.minor.patch versioning, to match factorio mod portal
-- Public.blueprint_library_allowed = true
-- Public.blueprint_importing_allowed = true
Public.rocket_silo_death_causes_loss = false
Public.victory_x = 1000

View File

@ -0,0 +1,209 @@
-- This file is part of thesixthroc's Pirate Ship softmod, licensed under GPLv3 and stored at https://github.com/ComfyFactory/ComfyFactorio and https://github.com/danielmartin0/ComfyFactorio-Pirates.
local Session = require 'utils.datastore.session_data'
local Antigrief = require 'utils.antigrief'
-- local Balance = require 'maps.pirates.balance'
local _inspect = require 'utils.inspect'.inspect
local Memory = require 'maps.pirates.memory'
local Common = require 'maps.pirates.common'
local CoreData = require 'maps.pirates.coredata'
local Public = {}
local function set_normal_permissions(group)
if not _DEBUG then
group.set_allows_action(defines.input_action.edit_permission_group, false)
end
group.set_allows_action(defines.input_action.import_permissions_string, false)
group.set_allows_action(defines.input_action.delete_permission_group, false)
group.set_allows_action(defines.input_action.add_permission_group, false)
group.set_allows_action(defines.input_action.admin_action, false)
end
local function set_restricted_permissions(group)
set_normal_permissions(group)
group.set_allows_action(defines.input_action.cancel_craft, false)
group.set_allows_action(defines.input_action.drop_item, false)
group.set_allows_action(defines.input_action.drop_blueprint_record, false)
group.set_allows_action(defines.input_action.build, false)
group.set_allows_action(defines.input_action.build_rail, false)
group.set_allows_action(defines.input_action.build_terrain, false)
group.set_allows_action(defines.input_action.begin_mining, false)
group.set_allows_action(defines.input_action.begin_mining_terrain, false)
group.set_allows_action(defines.input_action.activate_copy, false)
group.set_allows_action(defines.input_action.activate_cut, false)
group.set_allows_action(defines.input_action.activate_paste, false)
group.set_allows_action(defines.input_action.upgrade, false)
group.set_allows_action(defines.input_action.deconstruct, false)
group.set_allows_action(defines.input_action.open_gui, false)
group.set_allows_action(defines.input_action.fast_entity_transfer, false)
group.set_allows_action(defines.input_action.fast_entity_split, false)
end
function Public.try_create_permissions_groups()
if not game.permissions.get_group('lobby') then
local group = game.permissions.create_group('lobby')
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
group.set_allows_action(defines.input_action.grab_blueprint_record, false)
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
end
if not game.permissions.get_group('crowsnest') then
local group = game.permissions.create_group('crowsnest')
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
end
if not game.permissions.get_group('crowsnest_privileged') then
local group = game.permissions.create_group('crowsnest_privileged')
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
group.set_allows_action(defines.input_action.open_gui, true)
group.set_allows_action(defines.input_action.fast_entity_transfer, true)
group.set_allows_action(defines.input_action.fast_entity_split, true)
end
if not game.permissions.get_group('cabin') then
local group = game.permissions.create_group('cabin')
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.open_gui, true) -- We want you to open the market, but there is other code to prevent you from opening certain chests
end
if not game.permissions.get_group('cabin_privileged') then
local group = game.permissions.create_group('cabin_privileged')
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.open_gui, true) -- We want you to open the market, but there is other code to prevent you from opening certain chests
end
if not game.permissions.get_group('plebs') then
local group = game.permissions.create_group('plebs')
set_normal_permissions(group)
end
if not game.permissions.get_group('not_trusted') then
local group = game.permissions.create_group('not_trusted')
set_normal_permissions(group)
-- not_trusted.set_allows_action(defines.input_action.cancel_craft, false)
-- not_trusted.set_allows_action(defines.input_action.drop_item, false)
group.set_allows_action(defines.input_action.disconnect_rolling_stock, false)
group.set_allows_action(defines.input_action.connect_rolling_stock, false)
group.set_allows_action(defines.input_action.open_train_gui, false)
group.set_allows_action(defines.input_action.open_train_station_gui, false)
group.set_allows_action(defines.input_action.open_trains_gui, false)
group.set_allows_action(defines.input_action.change_train_stop_station, false)
group.set_allows_action(defines.input_action.change_train_wait_condition, false)
group.set_allows_action(defines.input_action.change_train_wait_condition_data, false)
group.set_allows_action(defines.input_action.drag_train_schedule, false)
group.set_allows_action(defines.input_action.drag_train_wait_condition, false)
group.set_allows_action(defines.input_action.go_to_train_station, false)
group.set_allows_action(defines.input_action.remove_train_station, false)
group.set_allows_action(defines.input_action.set_trains_limit, false)
group.set_allows_action(defines.input_action.set_train_stopped, false)
end
local blueprint_disabled_groups = {
'crowsnest_bps_disabled',
'crowsnest_privileged_bps_disabled',
'cabin_bps_disabled',
'cabin_privileged_bps_disabled',
'plebs_bps_disabled',
'not_trusted_bps_disabled'
}
for _, group_name in ipairs(blueprint_disabled_groups) do
if not game.permissions.get_group(group_name) then
local group = game.permissions.create_group(group_name)
local base_group_name = group_name:gsub('_bps_disabled', '')
local base_group = game.permissions.get_group(base_group_name)
for _, action in pairs(defines.input_action) do
group.set_allows_action(action, base_group.allows_action(action))
end
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
group.set_allows_action(defines.input_action.grab_blueprint_record, false)
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
end
end
end
local function add_player_to_permission_group(player, group_override)
Public.try_create_permissions_groups()
-- local jailed = Jailed.get_jailed_table()
-- local enable_permission_group_disconnect = WPT.get('disconnect_wagon')
local gulag = game.permissions.get_group('gulag')
local tbl = gulag and gulag.players
for i = 1, #tbl do
if tbl[i].index == player.index then
return
end
end
-- if player.admin then
-- return
-- end
-- if jailed[player.name] then
-- return
-- end
local group = game.permissions.get_group(group_override)
group.add_player(player)
end
function Public.update_privileges(player)
Public.try_create_permissions_groups()
if not Common.validate_player_and_character(player) then
return
end
local memory = Memory.get_crew_memory()
local bps_disabled_suffix = memory.run_has_blueprints_disabled and '_bps_disabled' or ''
if string.sub(player.surface.name, 9, 17) == 'Crowsnest' then
if Public.player_privilege_level(player) >= Public.privilege_levels.OFFICER then
return add_player_to_permission_group(player, 'crowsnest_privileged' .. bps_disabled_suffix)
else
return add_player_to_permission_group(player, 'crowsnest' .. bps_disabled_suffix)
end
elseif string.sub(player.surface.name, 9, 13) == 'Cabin' then
if Public.player_privilege_level(player) >= Public.privilege_levels.OFFICER then
return add_player_to_permission_group(player, 'cabin_privileged' .. bps_disabled_suffix)
else
return add_player_to_permission_group(player, 'cabin' .. bps_disabled_suffix)
end
elseif player.surface.name == CoreData.lobby_surface_name then
return add_player_to_permission_group(player, 'lobby')
else
local session = Session.get_session_table()
local AG = Antigrief.get()
local playtime = player.online_time
if session and session[player.name] then
playtime = player.online_time + session[player.name]
end
if AG and AG.enabled and not player.admin and playtime < 5184000 then -- 24 hours
add_player_to_permission_group(player, 'not_trusted' .. bps_disabled_suffix)
else
add_player_to_permission_group(player, 'plebs' .. bps_disabled_suffix)
end
end
end
return Public

View File

@ -11,6 +11,7 @@ local Utils = require 'maps.pirates.utils_local'
local CoreData = require 'maps.pirates.coredata'
local Server = require 'utils.server'
local Classes = require 'maps.pirates.roles.classes'
local Permissions = require 'maps.pirates.permissions'
local Public = {}
local privilege_levels = {
@ -38,7 +39,7 @@ function Public.make_officer(captain, player)
memory.officers_table[player.index] = true
Common.notify_force_light(force, { 'pirates.roles_make_officer', captain.name, player.name })
Public.update_privileges(player)
Permissions.update_privileges(player)
else
Common.notify_player_error(captain, { 'pirates.roles_make_officer_error_1' })
return false
@ -62,7 +63,7 @@ function Public.unmake_officer(captain, player)
memory.officers_table[player.index] = nil
Common.notify_force_light(force, { 'pirates.roles_unmake_officer', captain.name, player.name })
Public.update_privileges(player)
Permissions.update_privileges(player)
return true
else
Common.notify_player_error(captain, { 'pirates.roles_unmake_officer_error_1' })
@ -177,7 +178,7 @@ function Public.make_captain(player)
end
if memory.playerindex_captain then
Public.update_privileges(game.players[memory.playerindex_captain])
Permissions.update_privileges(game.players[memory.playerindex_captain])
end
memory.playerindex_captain = player.index
@ -192,7 +193,7 @@ function Public.make_captain(player)
-- don't use "unmake_officer" as it prints additional messages
memory.officers_table[player.index] = nil
Public.update_privileges(player)
Permissions.update_privileges(player)
local force = player.force
if force and force.valid then
@ -562,209 +563,4 @@ function Public.captain_tax(captain_index)
end
end
local function set_normal_permissions(group)
if not _DEBUG then
group.set_allows_action(defines.input_action.edit_permission_group, false)
end
group.set_allows_action(defines.input_action.import_permissions_string, false)
group.set_allows_action(defines.input_action.delete_permission_group, false)
group.set_allows_action(defines.input_action.add_permission_group, false)
group.set_allows_action(defines.input_action.admin_action, false)
if not CoreData.blueprint_library_allowed then
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
group.set_allows_action(defines.input_action.grab_blueprint_record, false)
end
if not CoreData.blueprint_importing_allowed then
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
end
end
local function set_restricted_permissions(group)
set_normal_permissions(group)
group.set_allows_action(defines.input_action.cancel_craft, false)
group.set_allows_action(defines.input_action.drop_item, false)
group.set_allows_action(defines.input_action.drop_blueprint_record, false)
group.set_allows_action(defines.input_action.build, false)
group.set_allows_action(defines.input_action.build_rail, false)
group.set_allows_action(defines.input_action.build_terrain, false)
group.set_allows_action(defines.input_action.begin_mining, false)
group.set_allows_action(defines.input_action.begin_mining_terrain, false)
group.set_allows_action(defines.input_action.activate_copy, false)
group.set_allows_action(defines.input_action.activate_cut, false)
group.set_allows_action(defines.input_action.activate_paste, false)
group.set_allows_action(defines.input_action.upgrade, false)
group.set_allows_action(defines.input_action.deconstruct, false)
group.set_allows_action(defines.input_action.open_gui, false)
group.set_allows_action(defines.input_action.fast_entity_transfer, false)
group.set_allows_action(defines.input_action.fast_entity_split, false)
end
function Public.try_create_permissions_groups()
if not game.permissions.get_group('lobby') then
local group = game.permissions.create_group('lobby')
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
group.set_allows_action(defines.input_action.grab_blueprint_record, false)
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
end
if not game.permissions.get_group('crowsnest') then
local group = game.permissions.create_group('crowsnest')
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
end
if not game.permissions.get_group('crowsnest_privileged') then
local group = game.permissions.create_group('crowsnest_privileged')
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
group.set_allows_action(defines.input_action.open_gui, true)
group.set_allows_action(defines.input_action.fast_entity_transfer, true)
group.set_allows_action(defines.input_action.fast_entity_split, true)
end
if not game.permissions.get_group('cabin') then
local group = game.permissions.create_group('cabin')
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.open_gui, true) -- We want you to open the market, but there is other code to prevent you from opening certain chests
end
if not game.permissions.get_group('cabin_privileged') then
local group = game.permissions.create_group('cabin_privileged')
group.set_allows_action(defines.input_action.deconstruct, true) --pick up dead players
set_restricted_permissions(group)
group.set_allows_action(defines.input_action.open_gui, true) -- We want you to open the market, but there is other code to prevent you from opening certain chests
end
if not game.permissions.get_group('plebs') then
local group = game.permissions.create_group('plebs')
set_normal_permissions(group)
end
if not game.permissions.get_group('not_trusted') then
local group = game.permissions.create_group('not_trusted')
set_normal_permissions(group)
-- not_trusted.set_allows_action(defines.input_action.cancel_craft, false)
-- not_trusted.set_allows_action(defines.input_action.drop_item, false)
group.set_allows_action(defines.input_action.disconnect_rolling_stock, false)
group.set_allows_action(defines.input_action.connect_rolling_stock, false)
group.set_allows_action(defines.input_action.open_train_gui, false)
group.set_allows_action(defines.input_action.open_train_station_gui, false)
group.set_allows_action(defines.input_action.open_trains_gui, false)
group.set_allows_action(defines.input_action.change_train_stop_station, false)
group.set_allows_action(defines.input_action.change_train_wait_condition, false)
group.set_allows_action(defines.input_action.change_train_wait_condition_data, false)
group.set_allows_action(defines.input_action.drag_train_schedule, false)
group.set_allows_action(defines.input_action.drag_train_wait_condition, false)
group.set_allows_action(defines.input_action.go_to_train_station, false)
group.set_allows_action(defines.input_action.remove_train_station, false)
group.set_allows_action(defines.input_action.set_trains_limit, false)
group.set_allows_action(defines.input_action.set_train_stopped, false)
end
local blueprint_disabled_groups = {
'crowsnest_bps_disabled',
'crowsnest_privileged_bps_disabled',
'cabin_bps_disabled',
'cabin_privileged_bps_disabled',
'plebs_bps_disabled',
'not_trusted_bps_disabled'
}
for _, group_name in ipairs(blueprint_disabled_groups) do
if not game.permissions.get_group(group_name) then
local group = game.permissions.create_group(group_name)
local base_group_name = group_name:gsub('_bps_disabled', '')
local base_group = game.permissions.get_group(base_group_name)
for _, action in pairs(defines.input_action) do
group.set_allows_action(action, base_group.allows_action(action))
end
group.set_allows_action(defines.input_action.open_blueprint_library_gui, false)
group.set_allows_action(defines.input_action.grab_blueprint_record, false)
group.set_allows_action(defines.input_action.import_blueprint_string, false)
group.set_allows_action(defines.input_action.import_blueprint, false)
end
end
end
function Public.add_player_to_permission_group(player, group_override)
Public.try_create_permissions_groups()
-- local jailed = Jailed.get_jailed_table()
-- local enable_permission_group_disconnect = WPT.get('disconnect_wagon')
local gulag = game.permissions.get_group('gulag')
local tbl = gulag and gulag.players
for i = 1, #tbl do
if tbl[i].index == player.index then
return
end
end
-- if player.admin then
-- return
-- end
-- if jailed[player.name] then
-- return
-- end
local group = game.permissions.get_group(group_override)
group.add_player(player)
end
function Public.update_privileges(player)
Public.try_create_permissions_groups()
if not Common.validate_player_and_character(player) then
return
end
local memory = Memory.get_crew_memory()
local bps_disabled_suffix = memory.run_has_blueprints_disabled and '_bps_disabled' or ''
if string.sub(player.surface.name, 9, 17) == 'Crowsnest' then
if Public.player_privilege_level(player) >= Public.privilege_levels.OFFICER then
return Public.add_player_to_permission_group(player, 'crowsnest_privileged' .. bps_disabled_suffix)
else
return Public.add_player_to_permission_group(player, 'crowsnest' .. bps_disabled_suffix)
end
elseif string.sub(player.surface.name, 9, 13) == 'Cabin' then
if Public.player_privilege_level(player) >= Public.privilege_levels.OFFICER then
return Public.add_player_to_permission_group(player, 'cabin_privileged' .. bps_disabled_suffix)
else
return Public.add_player_to_permission_group(player, 'cabin' .. bps_disabled_suffix)
end
elseif player.surface.name == CoreData.lobby_surface_name then
return Public.add_player_to_permission_group(player, 'lobby')
else
local session = Session.get_session_table()
local AG = Antigrief.get()
local playtime = player.online_time
if session and session[player.name] then
playtime = player.online_time + session[player.name]
end
if AG and AG.enabled and not player.admin and playtime < 5184000 then -- 24 hours
Public.add_player_to_permission_group(player, 'not_trusted' .. bps_disabled_suffix)
else
Public.add_player_to_permission_group(player, 'plebs' .. bps_disabled_suffix)
end
end
end
return Public