Skip to content

Commit

Permalink
Merge branch 'release/5.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
Cooldude2606 committed Mar 15, 2019
2 parents d64bf50 + 2982fc9 commit c735dd8
Show file tree
Hide file tree
Showing 13 changed files with 516 additions and 15 deletions.
File renamed without changes.
File renamed without changes.
135 changes: 135 additions & 0 deletions config/permission_groups.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
local Event = require 'utils.event'
local Game = require 'utils.game'
local Permission_Groups = require 'expcore.permission_groups'

Permission_Groups.new_group('Admin')
:allow_all()
:disallow{
'add_permission_group', -- admin
'delete_permission_group',
--'edit_permission_group', -- removed for admin till role script added
'import_permissions_string',
'map_editor_action',
'toggle_map_editor',
'change_multiplayer_config',
'set_heat_interface_mode',
'set_heat_interface_temperature',
'set_infinity_container_filter_item',
'set_infinity_container_remove_unfiltered_items',
'set_infinity_pipe_filter'
}

Permission_Groups.new_group('Trusted')
:allow_all()
:disallow{
'add_permission_group', -- admin
'delete_permission_group',
'edit_permission_group',
'import_permissions_string',
'map_editor_action',
'toggle_map_editor',
'change_multiplayer_config',
'set_heat_interface_mode',
'set_heat_interface_temperature',
'set_infinity_container_filter_item',
'set_infinity_container_remove_unfiltered_items',
'set_infinity_pipe_filter',
'admin_action' -- trusted
}

Permission_Groups.new_group('Standard')
:allow_all()
:disallow{
'add_permission_group', -- admin
'delete_permission_group',
'edit_permission_group',
'import_permissions_string',
'map_editor_action',
'toggle_map_editor',
'change_multiplayer_config',
'set_heat_interface_mode',
'set_heat_interface_temperature',
'set_infinity_container_filter_item',
'set_infinity_container_remove_unfiltered_items',
'set_infinity_pipe_filter',
'admin_action', -- trusted
'change_programmable_speaker_alert_parameters', -- standard
'drop_item',
'reset_assembling_machine',
'set_auto_launch_rocket',
'cancel_research'
}

Permission_Groups.new_group('Guest')
:allow_all()
:disallow{
'add_permission_group', -- admin
'delete_permission_group',
'edit_permission_group',
'import_permissions_string',
'map_editor_action',
'toggle_map_editor',
'change_multiplayer_config',
'set_heat_interface_mode',
'set_heat_interface_temperature',
'set_infinity_container_filter_item',
'set_infinity_container_remove_unfiltered_items',
'set_infinity_pipe_filter',
'admin_action', -- trusted
'change_programmable_speaker_alert_parameters', -- standard
'drop_item',
'reset_assembling_machine',
'set_auto_launch_rocket',
'cancel_research',
'change_programmable_speaker_parameters', -- guest
'change_train_stop_station',
'deconstruct',
'remove_cables',
'remove_train_station',
'reset_assembling_machine',
'rotate_entity',
'use_artillery_remote',
'launch_rocket'
}

Permission_Groups.new_group('Restricted')
:disallow_all()
:allow('write_to_console')

--- These events are used until a role system is added to make it easier for our admins

local trusted_time = 60*60*60*10 -- 10 hour
local standard_time = 60*60*60*3 -- 3 hour
local function assign_group(player)
if player.admin then
Permission_Groups.set_player_group(player,'Admin')
elseif player.online_time > trusted_time then
Permission_Groups.set_player_group(player,'Trusted')
elseif player.online_time > standard_time then
Permission_Groups.set_player_group(player,'Standard')
else
Permission_Groups.set_player_group(player,'Guest')
end
end

Event.add(defines.events.on_player_joined_game,function(event)
local player = Game.get_player_by_index(event.player_index)
assign_group(player)
end)

Event.add(defines.events.on_player_promoted,function(event)
local player = Game.get_player_by_index(event.player_index)
assign_group(player)
end)

Event.add(defines.events.on_player_demoted,function(event)
local player = Game.get_player_by_index(event.player_index)
assign_group(player)
end)

local check_interval = 60*60*15 -- 15 minutes
Event.on_nth_tick(check_interval,function(event)
for _,player in pairs(game.connected_players) do
assign_group(player)
end
end)
1 change: 1 addition & 0 deletions control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ local files = {
'modules.commands.cheat-mode',
'modules.commands.interface',
'modules.commands.help',
'config.permission_groups'
}

-- Loads all files in array above and logs progress
Expand Down
87 changes: 84 additions & 3 deletions expcore/common.lua
Original file line number Diff line number Diff line change
@@ -1,18 +1,76 @@
--- Adds some commonly used functions used in many modules
-- @author cooldude2606
-- @module Public
--[[
>>>>Functions List (see function for more detail):
Public.type_check(value,test_type) --- Compare types faster for faster validation of prams
Public.type_check_error(value,test_type,error_message,level) --- Raises an error if the value is of the incorrect type
Public.param_check(value,test_type,param_name,param_number) --- Raises an error when the value is the incorrect type, uses a consistent error message format
Public.extract_keys(tbl,...) --- Extracts certain keys from a table
Public.player_return(value,colour,player) --- Will return a value of any type to the player/server console, allows colour for in-game players
Public.opt_require(path) --- Calls a require that will not error if the file is not found
Public.ext_require(path,...) --- Calls a require and returns only the keys given, file must return a table
]]

local Colours = require 'resources.color_presets'
local Game = require 'utils.game'

local Public = {}

--- Compare types faster for faster validation of prams
-- @usage is_type('foo','string') -- return true
-- @usage is_type('foo') -- return false
--- Compare types faster for faster validation of params
-- @usage type_check('foo','string') -- return true
-- @usage type_check('foo') -- return false
-- @param v the value to be tested
-- @tparam[opt=nil] string test_type the type to test for if not given then it tests for nil
-- @treturn boolean is v of type test_type
function Public.type_check(value,test_type)
return test_type and value and type(value) == test_type or not test_type and not value or false
end

--- Raises an error if the value is of the wrong type
-- @usage type_check_error('foo','number','Value must be a number') -- will raise error "Value must be a number"
-- @tparam value any the value that you want to test the type of
-- @tparam test_type string the type that the value should be
-- @tparam error_message string the error message that is returned
-- @tparam level number the level to call the error on (level = 1 means the caller)
-- @treturn boolean true if no error was called
function Public.type_check_error(value,test_type,error_message,level)
level = level and level+1 or 2
return Public.test_type(value,test_type) or error(error_message,level)
end

--- Raises an error when the value is the incorrect type, uses a consistent error message format
-- @usage param_check('foo','number','repeat_count',2) -- will raise error "Invalid param #02 given to <anon>; repeat_count is not of type number"
-- @tparam value any the value that you want to test the type of
-- @tparam test_type string the type that the value should be
-- @tparam param_name string the name of the param
-- @tparam param_number number the number param it is
-- @treturn boolean true if no error was raised
function Public.param_check(value,test_type,param_name,param_number)
if not Public.test_type(value,test_type) then
local function_name = debug.getinfo(2,'n').name or '<anon>'
local error_message = string.format('Invalid param #%2d given to %s; %s is not of type %s',param_number,function_name,param_name,test_type)
return error(error_message,3)
end
return true
end

--- Extracts certain keys from a table
-- @usage local key_three, key_one = extract({key_one='foo',key_two='bar',key_three=true},'key_three','key_one')
-- @tparam tbl table the table which contains the keys
-- @tparam ... string the names of the keys you want extracted
-- @return the keys in the order given
function Public.extract_keys(tbl,...)
local values = {}
for _,key in pairs({...}) do
table.insert(values,tbl[key])
end
return unpack(values)
end

--- Will return a value of any type to the player/server console, allows colour for in-game players
-- @usage player_return('Hello, World!') -- returns 'Hello, World!' to game.player or server console
-- @usage player_return('Hello, World!','green') -- returns 'Hello, World!' to game.player with colour green or server console
Expand Down Expand Up @@ -54,4 +112,27 @@ function Public.player_return(value,colour,player)
else rcon.print(returnAsString) end
end

--- Calls a require that will not error if the file is not found
-- @usage local file = opt_require('file.not.present') -- will not cause any error
-- @tparam path string the path that you want to require
-- @return the returns from that file or nil, error if not loaded
function Public.opt_require(path)
local success, rtn = pcall(require,path)
if success then return rtn
else return nil,rtn end
end

--- Calls a require and returns only the keys given, file must return a table
-- @useage local extract, param_check = ext_require('expcore.common','extract','param_check')
-- @tparam path string the path that you want to require
-- @tparam ... string the name of the keys that you want returned
-- @return the keys in the order given
function Public.ext_require(path,...)
local rtn = require(path)
if type(rtn) ~= 'table' then
error('File did not return a table, can not extract keys.',2)
end
return Public.extract_keys(rtn,...)
end

return Public
Loading

0 comments on commit c735dd8

Please sign in to comment.