From baa07a8da645ef4d5eb81c83c63f2dbb3552831d Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Wed, 19 Sep 2018 22:51:19 +0100 Subject: [PATCH] Fixed some bugs in ExpGamingCore.Group --- modules/ExpGamingCore/Group/config.lua | 32 +++++++++++++++++++++++++ modules/ExpGamingCore/Group/control.lua | 19 +++++++++------ modules/ExpGamingLib/control.lua | 2 +- modules/index.lua | 5 ++-- 4 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 modules/ExpGamingCore/Group/config.lua diff --git a/modules/ExpGamingCore/Group/config.lua b/modules/ExpGamingCore/Group/config.lua new file mode 100644 index 00000000..c7f6bbc6 --- /dev/null +++ b/modules/ExpGamingCore/Group/config.lua @@ -0,0 +1,32 @@ +-- defines for groups +Group{ + name='_root', + disallow={} +} + +Group{ + name='_admin', + disallow={ + 'edit_permission_group', + 'delete_permission_group', + 'add_permission_group' + } +} + +Group{ + name='_member', + disallow={ + 'edit_permission_group', + 'delete_permission_group', + 'add_permission_group' + } +} + +Group{ + name='_guest', + disallow={ + 'edit_permission_group', + 'delete_permission_group', + 'add_permission_group' + } +} \ No newline at end of file diff --git a/modules/ExpGamingCore/Group/control.lua b/modules/ExpGamingCore/Group/control.lua index 9bbda1b5..672edfec 100644 --- a/modules/ExpGamingCore/Group/control.lua +++ b/modules/ExpGamingCore/Group/control.lua @@ -17,15 +17,20 @@ local module_verbose = false -- @field _prototype the prototype of this class -- @field groups a table of all groups, includes auto complete on the indexing local Group = { - _prototype = setmetatable({},{ - __index=function(tbl,key) return rawget(rawget(tbl,'_raw_group'),key) end - }), + _prototype = {}, groups = setmetatable({},{ __index=table.autokey, __newindex=function(tbl,key,value) rawset(tbl,key,Group.define(obj)) end - }) + }), + on_init = function() + if loaded_modules['ExpGamingCore.Server@^4.0.0'] then require('ExpGamingCore.Server@^4.0.0').add_module_to_interface('Group','ExpGamingCore.Group') end + end, + on_post = function(self) + -- loads the groups in config + require(module_path..'/config',{Group=self}) + end } -- Function Define @@ -40,7 +45,7 @@ function Group.define(obj) if not type_error(obj.name,'string','Group creation is invalid: group.name is not a string') then return end if not type_error(obj.disallow,'table','Group creation is invalid: group.disallow is not a table') then return end verbose('Created Group: '..obj.name) - setmetatable(obj,{__index=Group._prototype}) + setmetatable(obj,{__index=function(tbl,key) return Group._prototype[key] or rawget(tbl,'_raw_group') and rawget(tbl,'_raw_group')[key] or nil end}) rawset(Group.groups,obj.name,obj) return obj end @@ -62,8 +67,8 @@ end -- @treturn LuaPermissionGroup the factorio group linked to this group function Group._prototype:get_raw() if not self_test(self,'group','get_raw') then return end - if not group._raw_group then error('No permissions group found, please to not remove groups with /permissions',2) return end - return setmetatable({},{__index=group._raw_group}) + if not self._raw_group then error('No permissions group found, please to not remove groups with /permissions',2) return end + return setmetatable({},{__index=self._raw_group}) end --- Used to add a player to this group diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index ed43577b..a424cbac 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -85,7 +85,7 @@ end -- @tparam string prototype_name the name of the class -- @tparam string function_name the name of the function function ExpLib.self_test(self,prototype_name,function_name) - return ExpLib.is_type(value,'table') or error('Call to prototype without context, either supply a '..prototype_name..' or use '..prototype_name..':'..function_name,3) + return ExpLib.is_type(self,'table') or error('Call to prototype without context, either supply a '..prototype_name..' or use '..prototype_name..':'..function_name,3) end --- Will return a value of any type to the player/server console, allows colour for in-game players diff --git a/modules/index.lua b/modules/index.lua index 1963314b..d9548eaf 100644 --- a/modules/index.lua +++ b/modules/index.lua @@ -11,14 +11,14 @@ return { ['FactorioStdLib.Color@0.8.0']='./modules/FactorioStdLib/Color', ['ExpGamingLib@^4.0.0']='./modules/ExpGamingLib', ['ExpGamingLib@4.0.0']='./modules/ExpGamingLib', - ['ExpGamingCore.Command@4.0.0']='./modules/ExpGamingCore/Commands', + ['ExpGamingCore.Command@4.0.0']='./modules/ExpGamingCore/Command', ['ExpGamingCore.Server@4.0.0']='./modules/ExpGamingCore/Server', ['ExpGamingCore.Ranking@^4.0.0']='./modules/ExpGamingCore/Ranking', ['ExpGamingCore.Ranking@4.0.0']='./modules/ExpGamingCore/Ranking', ['ExpGamingBot.autoChat@4.0.0']='./modules/ExpGamingBot/autoChat', ['ExpGamingCore.Server@^4.0.0']='./modules/ExpGamingCore/Server', ['ExpGamingCommands.tags@4.0.0']='./modules/ExpGamingCommands/tags', - ['ExpGamingCore.Command@^4.0.0']='./modules/ExpGamingCore/Commands', + ['ExpGamingCore.Command@^4.0.0']='./modules/ExpGamingCore/Command', ['ExpGamingCommands.home@4.0.0']='./modules/ExpGamingCommands/home', ['ExpGamingCommands.cheatMode@4.0.0']='./modules/ExpGamingCommands/cheatMode', ['ExpGamingCommands.bonus@4.0.0']='./modules/ExpGamingCommands/bonus', @@ -47,4 +47,5 @@ return { ['ExpGamingAdmin.Jail@4.0.0']='./modules/ExpGamingAdmin/Jail', ['ExpGamingAdmin.Commands@4.0.0']='./modules/ExpGamingAdmin/Commands', ['ExpGamingAdmin.Ban@4.0.0']='./modules/ExpGamingAdmin/Ban', + ['ExpGamingCore.Group@4.0.0']='./modules/ExpGamingCore/Group', } \ No newline at end of file