diff --git a/FactorioSoftmodManager.lua b/FactorioSoftmodManager.lua index 52cbab0b..1657bde6 100644 --- a/FactorioSoftmodManager.lua +++ b/FactorioSoftmodManager.lua @@ -542,8 +542,9 @@ Manager.event = setmetatable({ Manager.event[event_name] = new_callback return end -- other wise raise the event and call every callback; no use of script.raise_event due to override - if type(tbl[event_name]) == 'table' then - for module_name,callback in pairs(tbl[event_name]) do + local event_functions = tbl.__events[event_name] + if type(event_functions) == 'table' then + for module_name,callback in pairs(event_functions) do -- loops over the call backs and which module it is from if type(callback) ~= 'function' then error('Invalid Event Callback: "'..event_name..'/'..module_name..'"') end local sandbox, success, err = Manager.sandbox(callback,{module_name=setupModuleName(module_name),module_path=moduleIndex[tostring(module_name)]},new_callback,...) @@ -557,7 +558,7 @@ Manager.event = setmetatable({ else chache[error_message] = nil end if chache[error_message] and chache[error_message][2] > 100 then Manager.verbose('There was an error happening every tick for 100 ticks, the event handler has been removed!','errorCaught') - tbl[event_name][module_name] = nil + event_functions[module_name] = nil end end end diff --git a/modules/ExpGamingCore/Group/config.lua b/modules/ExpGamingCore/Group/config.lua index 09285a4a..438fd3c8 100644 --- a/modules/ExpGamingCore/Group/config.lua +++ b/modules/ExpGamingCore/Group/config.lua @@ -14,7 +14,7 @@ Group{ } Group{ - name='Member', + name='HiMember', disallow={ 'edit_permission_group', 'delete_permission_group', @@ -22,11 +22,65 @@ Group{ } } +Group{ + name='Member', + disallow={ + 'edit_permission_group', + 'delete_permission_group', + 'add_permission_group', + 'set_auto_launch_rocket', + 'change_programmable_speaker_alert_parameters', + 'drop_item' + } +} + Group{ name='Guest', disallow={ 'edit_permission_group', 'delete_permission_group', - 'add_permission_group' + 'add_permission_group', + 'set_auto_launch_rocket', + 'change_programmable_speaker_alert_parameters', + 'drop_item', + 'build_terrain', + 'remove_cables', + 'launch_rocket', + 'reset_assembling_machine', + 'cancel_research' + } +} + +Group{ + name='Jail', + disallow={ + 'set_allow_commands', + 'edit_permission_group', + 'delete_permission_group', + 'add_permission_group', + 'open_character_gui', + 'begin_mining', + 'start_walking', + 'player_leave_game', + 'open_blueprint_library_gui', + 'build_item', + 'use_item', + 'select_item', + 'rotate_entity', + 'open_train_gui', + 'open_train_station_gui', + 'open_gui', + 'open_item', + 'deconstruct', + 'build_rail', + 'cancel_research', + 'start_research', + 'set_train_stopped', + 'select_gun', + 'open_technology_gui', + 'open_trains_gui', + 'edit_custom_tag', + 'craft', + 'setup_assembling_machine', } } \ No newline at end of file diff --git a/modules/ExpGamingCore/Role/config.lua b/modules/ExpGamingCore/Role/config.lua index 05e3dca4..3ad720ce 100644 --- a/modules/ExpGamingCore/Role/config.lua +++ b/modules/ExpGamingCore/Role/config.lua @@ -1,9 +1,12 @@ Role.add_flag('is_default') -- this must be included in atleast one role -Role.add_flag('is_root',function(player,state) player.character.destructible = not state end) -Role.add_flag('is_admin',function(player,state) player.admin = state end) +Role.add_flag('is_root',function(player,state) player.character.destructible = not state end) -- not required but setting true will allow everythin for that role +Role.add_flag('is_admin',function(player,state) player.admin = state end) -- highly recomented but not required Role.add_flag('is_spectator',function(player,state) player.spectator = state end) Role.add_flag('is_jail',function(player,state) player.character.active = not state end) +Role.add_flag('is_donator') +Role.add_flag('is_timed') +-- Root Role{ name='Root', short_hand='Root', @@ -13,10 +16,234 @@ Role{ is_root=true, is_admin=true, is_spectator=true, + allow={} +} +Role{ + name='Community Manager', + short_hand='Com Mngr', + tag='[Com Mngr]', + group='Root', + colour={r=150,g=68,b=161}, + is_admin=true, + is_spectator=true, + is_donator=true, + allow={} +} +Role{ + name='Developer', + short_hand='Dev', + tag='[Dev]', + group='Root', + colour={r=179,g=125,b=46}, + is_admin=true, + is_spectator=true, + is_donator=true, + allow={ + ['interface']=true, + ['cheat-mode']=true + } +} + +-- Admin +Role{ + name='Administrator', + short_hand='Admin', + tag='[Admin]', + group='Admin', + colour={r=233,g=63,b=233}, + is_admin=true, + is_spectator=true, + allow={ + ['game-settings']=true, + ['always-warp']=true, + ['admin-items']=true + } +} +Role{ + name='Moderator', + short_hand='Mod', + tag='[Mod]', + group='Admin', + colour={r=0,g=170,b=0}, + is_admin=true, + is_spectator=true, + allow={ + ['set-home']=true, + ['home']=true, + ['return']=true, + ['announcements']=true, + ['rank-changer']=true, + } +} +Role{ + name='Trainee', + short_hand='TrMod', + tag='[TrMod]', + group='Admin', + colour={r=0,g=196,b=137}, + is_spectator=true, + allow={ + ['go-to']=true, + ['bring']=true, + ['no-report']=true, + ['set-home']=false, + ['home']=false, + ['return']=false, + ['bonus']=false, + ['admin-commands']=true, + ['warn']=true, + ['temp-ban']=true, + ['clear-warings']=true, + ['clear-reports']=true, + ['clear-all']=true, + ['clear-inv']=true, + } +} + +-- High Member +Role{ + name='Sponsor', + short_hand='Spon', + tag='[Sponsor]', + group='HiMember', + colour={r=247,g=246,b=54}, + is_spectator=true, + is_donator=true, + allow={} +} +Role{ + name='Pay to Win', + short_hand='P2W', + tag='[P2W]', + group='HiMember', + colour={r=238,g=172,b=44}, + is_donator=true, + allow={ + ['jail']=true, + ['unjail']=true, + ['bonus']=true, + ['bonus-respawn']=true + } +} +Role{ + name='Donator', + short_hand='Don', + tag='[Donator]', + group='HiMember', + colour={r=230,g=99,b=34}, + is_donator=true, + allow={ + ['set-home']=true, + ['home']=true, + ['return']=true, + } +} +Role{ + name='Partner', + short_hand='Part', + tag='[Partner]', + group='HiMember', + colour={r=140,g=120,b=200}, + allow={} +} +Role{ + name='Veteran', + short_hand='Vet', + tag='[Veteran]', + group='HiMember', + colour={r=140,g=120,b=200}, + is_timed=true, + time=600, -- 10 hours + allow={ + ['global-chat']=true, + ['tree-decon']=true, + ['create-poll']=true, + ['repair']=true + } +} + +-- Member +Role{ + name='Member', + short_hand='Mem', + tag='[Member]', + group='Member', + colour={r=24,g=172,b=188}, + allow={ + ['edit-tasklist']=true, + ['make-warp']=true, + ['nuke']=true, + ['base-damage']=true, + ['varified']=true + } +} +Role{ + name='Regular', + short_hand='Reg', + tag='[Regular]', + group='Member', + colour={r=79,g=155,b=163}, + is_timed=true, + time=180, -- 3 hours + allow={ + ['kill']=true, + ['decon']=true, + ['capsules']=true + } +} + +-- Guest +Role{ + name='Guest', + short_hand='', + tag='', + group='Guest', + colour={r=185,g=187,b=160}, is_default=true, + allow={ + ['player-list']=true, + ['readme']=true, + ['rockets']=true, + ['science']=true, + ['tasklist']=true, + ['report']=true, + ['warp-list']=true, + ['polls']=true, + ['tag']=true, + ['tag-clear']=true, + ['report']=true + } +} + +-- Jail +Role{ + name='Jail', + short_hand='Jail', + tag='[Jail]', + group='Jail', + colour={r=50,g=50,b=50}, + is_jail=true, allow={} } Role.order = { - 'Root' + 'Root', + 'Community Manager', + 'Developer', + 'Administrator', + 'Moderator', + 'Trainee', + 'Sponsor', + 'Pay to Win', + 'Donator', + 'Partner', + 'Veteran', + 'Member', + 'Regular', + 'Guest', + 'Jail' +} + +Role.set_preassign{ + cooldude2606={'Root','Developer','Administrator','Moderator'} } \ No newline at end of file diff --git a/modules/ExpGamingCore/Role/control.lua b/modules/ExpGamingCore/Role/control.lua index 683bd204..eb6012da 100644 --- a/modules/ExpGamingCore/Role/control.lua +++ b/modules/ExpGamingCore/Role/control.lua @@ -18,7 +18,7 @@ local Role = { order={}, flags={}, actions={}, - meta={}, + meta={times={}}, roles=setmetatable({},{ __index=table.autokey, __newindex=function(tbl,key,value) @@ -27,6 +27,7 @@ local Role = { }), on_init=function() if loaded_modules['ExpGamingCore.Server@^4.0.0'] then require('ExpGamingCore.Server@^4.0.0').add_module_to_interface('Role','ExpGamingCore.Role') end + if loaded_modules['ExpGamingCore.Commands@^4.0.0'] then require(module_path..'/src/commands',{Role=Role}) end end, on_post=function(self) -- loads the roles in config @@ -37,6 +38,7 @@ local Role = { local role = self.get(role_name) if not role then error('Invalid role name in order listing: '..role_name) return end if role.is_default then self.meta.default = role end + if role.is_timed then self.meta.times[role.name] = {index,role.time} end if previous then setmetatable(previous.allow,{__index=role.allow}) end role.index = index previous = role @@ -50,12 +52,17 @@ local Role = { local global = global{ change_chache_length=15, changes={}, + preassign={}, players={}, roles={} } -- Function Define +--- Used to set default roles for players who join +-- @usage Role.set_preassign{name={roles}} +function Role.set_preassign(tbl) global.preassign = tbl end + --- Defines a new instance of a role -- @usage Role.define{name='Root',short_hand='Root',tag='[Root]',group='Root',colour={r=255,b=255,g=255},is_root=true,allow={}} -- returns new role -- @usage Role{name='Root',short_hand='Root',tag='[Root]',group='Root',colour={r=255,b=255,g=255},is_root=true,allow={}} -- returns new role @@ -211,7 +218,7 @@ function Role.has_flag(mixed,flag) if not type_error(flag,'string','Invalid argument #2 to Role.has_flag, flag is not a string.') then return end local roles = Role.get(mixed) if not type_error(roles,'table','Invalid argument #1 to Role.has_flag, mixed is not a role or player.') then return end - if #roles then for _,role in pairs(roles) do + if #roles > 0 then for _,role in pairs(roles) do if role:has_flag(flag) then return true end end elseif roles:has_flag(flag) then return true end return false @@ -235,7 +242,7 @@ function Role.allowed(mixed,action) if not type_error(action,'string','Invalid argument #2 to Role.allowed, action is not a string.') then return end local roles = Role.get(mixed) if not type_error(roles,'table','Invalid argument #1 to Role.allowed, mixed is not a role or player.') then return end - if #roles then for _,role in pairs(roles) do + if #roles > 0 then for _,role in pairs(roles) do if role:allowed(action) then return true end end elseif roles:allowed(action) then return true end return false @@ -430,7 +437,7 @@ script.on_event(role_change_event_id,function(event) -- assign new tag and group of highest role if highest.__faild then Group.get(player):remove_player(player) else Group.assign(player,highest.group) end - if not player.tag == highest.tag then player.tag = highest.tag player.print{'ExpGamingCore-Role.tag-reset'} end + if player.tag ~= highest.tag then player.tag = highest.tag player.print{'ExpGamingCore-Role.tag-reset'} end -- play a sound to the player if event.effect == 'assign' and not role.is_jail then player.play_sound{path='utility/achievement_unlocked'} else player.play_sound{path='utility/game_lost'} end @@ -439,7 +446,7 @@ script.on_event(role_change_event_id,function(event) if event.effect == 'assign' then game.print{'ExpGamingCore-Role.default-print',{'ExpGamingCore-Role.assign',player.name,role.name,by_player.name}} else game.print{'ExpGamingCore-Role.default-print',{'ExpGamingCore-Role.unassign',player.name,role.name,by_player.name}} end -- log change to file - game.write_file('ranking-change.json', + game.write_file('role-change.json', table.json({ tick=game.tick, play_time=player.online_time, @@ -453,5 +460,23 @@ script.on_event(role_change_event_id,function(event) end end) +script.on_event(defines.events.on_player_joined_game,function(event) + local player = Game.get_player(event) + local highest = Role.get_highest(player) or Role.meta.default + Group.assign(player,highest.group) + player.tag=highest.tag + if global.preassign[player.name:lower()] then Role.assign(player,global.preassign[player.name:lower()]) end +end) + +script.on_event(defines.events.on_tick,function(event) + if game.tick%(3600*5) ~= 0 then return end -- every 5 minutes + for role_name, time in pairs(Role.meta.times) do + for _,player in pairs(game.connected_players) do + local highest = Role.get_highest(player) + if highest.index > time[1] and (player.online_time) > time[2] then Role.assign(player,role_name) end + end + end +end) + -- Module Return return setmetatable(Role,{__call=function(tbl,...) tbl.define(...) end}) \ No newline at end of file diff --git a/modules/ExpGamingCore/Role/locale/en.cfg b/modules/ExpGamingCore/Role/locale/en.cfg index 80ba94f8..4cb41594 100644 --- a/modules/ExpGamingCore/Role/locale/en.cfg +++ b/modules/ExpGamingCore/Role/locale/en.cfg @@ -3,4 +3,4 @@ default-print=[Everyone]: __1__ print=[__1__]: __2__ assign=__1__ was assigned to __2__ by __3__ unassign=__1__ was unassigned from __2__ by __3__ -tag-reset=Your Tag was reset due to a Rank change \ No newline at end of file +tag-reset=Your Tag was reset due to a role change \ No newline at end of file diff --git a/modules/ExpGamingCore/Role/src/commands.lua b/modules/ExpGamingCore/Role/src/commands.lua new file mode 100644 index 00000000..0b6d9c09 --- /dev/null +++ b/modules/ExpGamingCore/Role/src/commands.lua @@ -0,0 +1,28 @@ +local Role = Role + +commands.add_validation('player-rank',function(value,event) + local player,err = commands.validate['player'](value) + return err and commands.error(err) + or Role.get_highest(player).index > Role.get_highest(event).index and player + or commands.error{'commands.error-player-rank'} +end) + +commands.add_validation('player-rank-online',function(value,event) + local player,err = commands.validate['player-online'](value) + if err then return commands.error(err) end + local player,err = commands.validate['player-rank'](player) + if err then return commands.error(err) end + return player +end) + +commands.add_validation('player-rank-alive',function(value,event) + local player,err = commands.validate['player-alive'](value) + if err then return commands.error(err) end + local player,err = commands.validate['player-rank'](player) + if err then return commands.error(err) end + return player +end) + +commands.add_middleware(function(player_name,command_name,event) + return Role.allowed(player_name,command_name) +end) \ No newline at end of file diff --git a/modules/ExpGamingCore/Server/control.lua b/modules/ExpGamingCore/Server/control.lua index 66dbf1bd..24171890 100644 --- a/modules/ExpGamingCore/Server/control.lua +++ b/modules/ExpGamingCore/Server/control.lua @@ -38,7 +38,8 @@ local global = global{ -- @treturn string the new uuid Server.uuid = add_metatable({},function() -- when it is called as a function - return global.uuid + 1 + global.uuid=global.uuid+1 + return global.uuid end,function() -- when it is treated as a string return string.to_hex(tostring(Server.uuid())) @@ -457,6 +458,7 @@ script.on_event(defines.events.on_tick,function(event) if #global.timeout > 0 then Server.check_timeouts() end -- timeout checks if #global.queue > 0 then -- resolve one thread local current_thread = global.all[global.queue[1]] + game.print(current_thread.uuid) if current_thread and current_thread:valid() then current_thread:resolve() end end end) diff --git a/modules/ExpGamingLib/control.lua b/modules/ExpGamingLib/control.lua index a424cbac..ce382909 100644 --- a/modules/ExpGamingLib/control.lua +++ b/modules/ExpGamingLib/control.lua @@ -36,7 +36,7 @@ function ExpLib.get_env() i=i+1 end level=level+1 - if debug.getinfo(level-1).namewhat == 'global' then break end + if debug.getinfo(level-2).namewhat == 'global' then break end end return env end