From 5d163ceeebd28d506d23586204e3f5b17bfd658d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Fri, 22 Mar 2019 21:56:34 +0000 Subject: [PATCH] Cleaned Config Files --- config/command_auth_admin.lua | 3 +++ config/command_parse_general.lua | 7 +++++- config/file_loader.lua | 20 ++++++++++++++++ config/permission_groups.lua | 4 ++++ control.lua | 41 ++++++++++++++++++-------------- expcore/commands.lua | 2 +- modules/commands/admin-chat.lua | 1 - modules/commands/cheat-mode.lua | 1 - modules/commands/interface.lua | 1 - modules/commands/kill.lua | 1 - modules/commands/teleport.lua | 1 - 11 files changed, 57 insertions(+), 25 deletions(-) create mode 100644 config/file_loader.lua diff --git a/config/command_auth_admin.lua b/config/command_auth_admin.lua index e5b5baf1..4817e643 100644 --- a/config/command_auth_admin.lua +++ b/config/command_auth_admin.lua @@ -1,3 +1,6 @@ +--- This is a very simple config file which adds a admin only auth function +-- not much to change here its more so it can be enabled and disabled from ./config/file_loader.lua +-- either way you can change the requirements to be "admin" if you wanted to local Commands = require 'expcore.commands' Commands.add_authenticator(function(player,command,tags,reject) diff --git a/config/command_parse_general.lua b/config/command_parse_general.lua index 8c719996..513aa845 100644 --- a/config/command_parse_general.lua +++ b/config/command_parse_general.lua @@ -1,8 +1,13 @@ +--- This file contains some common command param parse functions +-- this file is less of a config and more of a requirement but you may wish to change how some behave +-- as such you need to be confident with lua but you edit this config file +-- use Commands.add_parse('name',function(input,player,reject) end) to add a parse +-- see ./expcore/commands.lua for more details local Commands = require 'expcore.commands' local Game = require 'utils.game' --[[ ->>>>Adds parses: +>>>>Adds Parses: boolean string-options - options: array string-max-length - max_length: number diff --git a/config/file_loader.lua b/config/file_loader.lua new file mode 100644 index 00000000..56005d6a --- /dev/null +++ b/config/file_loader.lua @@ -0,0 +1,20 @@ +--- This contains a list of all files that will be loaded and the order they are loaded in +-- to stop a file from loading add "--" in front of it, remove the "--" to have the file be loaded +-- config files should be loaded after all modules are loaded +-- core files should be required by modules and not be present in this list +return { + --'example.file_not_loaded', + 'modules.factorio-control', -- base factorio free play scenario + -- Game Commands + 'modules.commands.me', + 'modules.commands.kill', + 'modules.commands.admin-chat', + 'modules.commands.tag', + 'modules.commands.teleport', + 'modules.commands.cheat-mode', + 'modules.commands.interface', + 'modules.commands.help', + -- Config Files + 'config.command_auth_admin', -- commands tags with admin_only are blocked for non admins + 'config.permission_groups', -- loads some predefined permission groups +} \ No newline at end of file diff --git a/config/permission_groups.lua b/config/permission_groups.lua index 90216487..b14fa9e9 100644 --- a/config/permission_groups.lua +++ b/config/permission_groups.lua @@ -1,3 +1,7 @@ +--- Use this file to add new permission groups to the game +-- start with Permission_Groups.new_group('name') +-- then use either :allow_all() or :disallow_all() to set the default for non specified actions +-- then use :allow{} and :disallow{} to specify certain actions to allow/disallow local Event = require 'utils.event' local Game = require 'utils.game' local Permission_Groups = require 'expcore.permission_groups' diff --git a/control.lua b/control.lua index aff18c15..02ff8cec 100644 --- a/control.lua +++ b/control.lua @@ -1,4 +1,8 @@ --- If you're looking to configure anything, you want config.lua. Nearly everything in this file is dictated by the config. + +--- Please go to ./config if you want to change settings, each file is commented with what it does +-- if it is not in ./config then you should not attempt to change it unless you know what you are doing +-- all files which are loaded (including the config files) are present in ./config/file_loader.lua +-- this file is the landing point for all scenarios please DO NOT edit directly, further comments are to aid development -- Info on the data lifecycle and how we use it: https://github.com/Refactorio/RedMew/wiki/The-data-lifecycle require 'resources.data_stages' @@ -14,34 +18,35 @@ require 'utils.math' Debug = require 'utils.debug' require 'resources.version' -local files = { - 'modules.factorio-control', - 'modules.commands.me', - 'modules.commands.kill', - 'modules.commands.admin-chat', - 'modules.commands.tag', - 'modules.commands.teleport', - 'modules.commands.cheat-mode', - 'modules.commands.interface', - 'modules.commands.help', - 'config.permission_groups' -} +-- Global require function used to extract parts of a module, because simply being in common is not good enough +ext_require = require('expcore.common').ext_require --- Loads all files in array above and logs progress -local total_files = string.format('%3d',#files) +-- Please go to config/file_loader.lua to edit the files that are loaded +local files = require 'config.file_loader' + +-- Loads all files from the config and logs that they are loaded +local total_file_count = string.format('%3d',#files) local errors = {} for index,path in pairs(files) do - log(string.format('[INFO] Loading files %3d/%s',index,total_files)) + + -- Loads the next file in the list + log(string.format('[INFO] Loading files %3d/%s',index,total_file_count)) local success,file = pcall(require,path) - -- error checking + + -- Error Checking if not success then + -- Failed to load a file log('[ERROR] Failed to load file: '..path) log('[ERROR] '..file) table.insert(errors,'[ERROR] '..path..' :: '..file) elseif type(file) == 'string' and file:find('not found') then + -- Returned a file not found message log('[ERROR] File not found: '..path) table.insert(errors,'[ERROR] '..path..' :: Not Found') end + end + +-- Logs all errors again to make it make it easy to find log('[INFO] All files loaded with '..#errors..' errors:') -for _,error in pairs(errors) do log(error) end -- logs all errors again to make it make it easy to find \ No newline at end of file +for _,error in pairs(errors) do log(error) end \ No newline at end of file diff --git a/expcore/commands.lua b/expcore/commands.lua index dbfc9b06..a3c90991 100644 --- a/expcore/commands.lua +++ b/expcore/commands.lua @@ -162,7 +162,7 @@ ]] local Game = require 'utils.game' -local player_return = require('expcore.common').player_return +local player_return = ext_require('expcore.common','player_return') local Commands = { defines={ -- common values are stored error like signals diff --git a/modules/commands/admin-chat.lua b/modules/commands/admin-chat.lua index 6df5a58b..2f9df730 100644 --- a/modules/commands/admin-chat.lua +++ b/modules/commands/admin-chat.lua @@ -1,6 +1,5 @@ local Commands = require 'expcore.commands' require 'config.command_parse_general' -require 'config.command_auth_admin' Commands.new_command('admin-chat','Sends a message in chat that only admins can see.') :add_param('message',false) -- the message to send in the admin chat diff --git a/modules/commands/cheat-mode.lua b/modules/commands/cheat-mode.lua index 71ea9d15..dbbdc54d 100644 --- a/modules/commands/cheat-mode.lua +++ b/modules/commands/cheat-mode.lua @@ -1,6 +1,5 @@ local Commands = require 'expcore.commands' require 'config.command_parse_general' -require 'config.command_auth_admin' Commands.new_command('toggle-cheat-mode','Toggles cheat mode for your player, or another player.') :add_param('player',true,'player') -- player to toggle chest mode of, can be nil for self diff --git a/modules/commands/interface.lua b/modules/commands/interface.lua index a2eff255..24424ebf 100644 --- a/modules/commands/interface.lua +++ b/modules/commands/interface.lua @@ -1,7 +1,6 @@ local Commands = require 'expcore.commands' local Global = require 'utils.global' local Common = require 'expcore.common' -require 'config.command_auth_admin' -- modules that are loaded into the interface env to be accessed local interface_modules = { diff --git a/modules/commands/kill.lua b/modules/commands/kill.lua index 7ecb5c90..d1e4de25 100644 --- a/modules/commands/kill.lua +++ b/modules/commands/kill.lua @@ -1,6 +1,5 @@ local Commands = require 'expcore.commands' require 'config.command_parse_general' -require 'config.command_auth_admin' Commands.new_command('kill','Kills yourself or another player.') :add_param('player',true,'player-alive') -- the player to kill, must be alive to be valid diff --git a/modules/commands/teleport.lua b/modules/commands/teleport.lua index ed02fc0d..7275f56a 100644 --- a/modules/commands/teleport.lua +++ b/modules/commands/teleport.lua @@ -1,6 +1,5 @@ local Commands = require 'expcore.commands' require 'config.command_parse_general' -require 'config.command_auth_admin' local function teleport(from_player,to_player) local surface = to_player.surface