Converted Modules To Use Roles

This commit is contained in:
Cooldude2606
2018-09-29 17:28:07 +01:00
parent 96784009b6
commit e50bd509f8
48 changed files with 277 additions and 1146 deletions

View File

@@ -6,14 +6,14 @@
-- Module Require
local Game = require('FactorioStdLib.Game@^0.8.0')
local Ranking -- ExpGamingCore.Ranking@^4.0.0
local Role -- ExpGamingCore.Role@^4.0.0
local Sync -- ExpGamingCore.Sync@^4.0.0
-- Module Define
local module_verbose = false
local Admin = {
on_init=function()
if loaded_modules['ExpGamingCore.Ranking@^4.0.0'] then Ranking = require('ExpGamingCore.Ranking@^4.0.0') end
if loaded_modules['ExpGamingCore.Role@^4.0.0'] then Role = require('ExpGamingCore.Role@^4.0.0') end
if loaded_modules['ExpGamingCore.Sync@^4.0.0'] then Sync = require('ExpGamingCore.Sync@^4.0.0') end
if loaded_modules['ExpGamingCore.Server@^4.0.0'] then require('ExpGamingCore.Server@^4.0.0').add_module_to_interface('Admin','ExpGamingAdmin.AdminLib') end
end,
@@ -41,9 +41,8 @@ end
function Admin.allowed(player)
local player = Game.get_player(player)
if Ranking then
local lowest_admin_power = Ranking.get_group('Admin').lowest.power
return lowest_admin_power >= Ranking.get_rank(player).power
if Role then
return Role.allowed(player,'admin-commands')
else return player.admin end
end
@@ -79,7 +78,7 @@ function Admin.clear_player(player,by_player)
if Admin.is_banned(player,true) == true then Server.interface(game.unban_player,true,player,by_player) end
if Admin.clear_warings then Admin.clear_warings(player,by_player,true) end
if Admin.clear_reports then Admin.clear_reports(player,by_player,true) end
if Ranking.get_rank(player).group.name == 'Jail' then Server.interface(Ranking.revert,true,player,by_player) end
if Role.has_flag(player,'is_jail') then Server.interface(Role.revert,true,player,by_player,2) end
if Sync then Sync.emit_embeded{
title='Player Clear',
color=Color.to_hex(defines.textcolor.low),

View File

@@ -1,5 +1,5 @@
local Admin = Admin
local Ranking = require('ExpGamingCore.Ranking')
local Role = require('ExpGamingCore.Role')
--- Used to jail a player which stops them from moving
-- @command jail
@@ -11,8 +11,8 @@ commands.add_command('jail', 'Jails a player', {
}, function(event,args)
local player = args.player
local reason = args.reason
if Ranking.get_rank(player):allowed('no-report') then player_return({'ExpGamingAdmin.cant-report',args.player}) return commands.error end
if Admin.is_banned(player) then player_return({'commands.cant-report-ban',args.player}) return commands.error end
if Role.allowed(player,'no-report') then player_return{'ExpGamingAdmin.cant-report',args.player} return commands.error end
if Admin.is_banned(player) then player_return{'commands.cant-report-ban',args.player} return commands.error end
Admin.jail(player,event.player_index,reason)
end)
@@ -24,5 +24,5 @@ commands.add_command('unjail', 'Returns a player\'s old rank', {
}, function(event,args)
local player = args.player
if Admin.is_banned(player) then player_return({'commands.cant-report-ban',args.player}) return commands.error end
Server.interface(Ranking.revert,true,player,event.player_index)
Server.interface(Role.revert,true,player,event.player_index,2)
end)

View File

@@ -1,5 +1,5 @@
local Admin = Admin
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
local Role = require('ExpGamingCore.Role@^4.0.0')
--- Reports a player
-- @command report
@@ -13,7 +13,7 @@ commands.add_command('report', 'Reports a player', {
local player = args.player
local reason = args.reason
if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player}) return commands.error end
if Ranking.get_rank(player):allowed('no-report') then player_return({'ExpGamingAdmin.cant-report',args.player}) return commands.error end
if Role.allowed(player,'no-report') then player_return({'ExpGamingAdmin.cant-report',args.player}) return commands.error end
for _,report in pairs(global.addons.reports.reports) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player}) return commands.error end end
for _,report in pairs(global.addons.reports.varified) do if report[1] == _player.name then player_return({'ExpGamingAdmin.cant-report',args.player}) return commands.error end end
Admin.report(player,event.player_index,reason)

View File

@@ -1,5 +1,5 @@
local Admin = Admin
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
local Role = require('ExpGamingCore.Role@^4.0.0')
--- Gives a warning to a player
-- @command warn
@@ -11,8 +11,8 @@ commands.add_command('warn', 'Gives a player a warning', {
}, function(event,args)
local player = args.player
local reason = args.reason
if Admin.is_banned(player) then player_return({'ExpGamingAdmin.cant-report-ban',args.player}) return commands.error end
if Ranking.get_rank(player):allowed('no-report') then player_return({'ExpGamingAdmin.cant-report',args.player}) return commands.error end
if Admin.is_banned(player) then player_return{'ExpGamingAdmin.cant-report-ban',args.player} return commands.error end
if Role.allowed(player,'no-report') then player_return{'ExpGamingAdmin.cant-report',args.player} return commands.error end
Admin.give_warning(player,event.player_index,reason)
end)

View File

@@ -7,7 +7,7 @@
-- Module Require
local Admin = require('ExpGamingAdmin.AdminLib@^4.0.0')
local Gui = require('ExpGamingCore.Gui@^4.0.0')
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
local Role = require('ExpGamingCore.Role@^4.0.0')
local Game = require('FactorioStdLib.Game@^0.8.0')
local playerInfo -- ExpGamingPlayer@^4.0.0
@@ -89,9 +89,9 @@ local player_drop_down = Gui.inputs.add_drop_down('player-drop-down-admin-comman
player_info_flow.clear()
if selected == 'Select Player' then return
else get_player_info(selected,player_info_flow,true) end
local rank = Ranking.get_rank(player)
local _rank = Ranking.get_rank(selected)
if rank.power >= _rank.power then element.parent.warning.caption = {'ExpGamingAdmin.warning'}
local role = Role.get_highest(player)
local _role = Role.get(selected)
if role.index >= _role.index then element.parent.warning.caption = {'ExpGamingAdmin.warning'}
else element.parent.warning.caption = '' end
end)
@@ -118,12 +118,12 @@ local take_action = Gui.inputs.add{
caption={'ExpGamingAdmin.take-action'}
}:on_event('click',function(event)
local dropdowns = event.element.parent
local rank = Ranking.get_rank(event.player_index)
local role = Role.get_highest(event.player_index)
local _action= dropdowns.parent.action.caption ~= 'Select Action' and dropdowns.parent.action.caption or nil
local _player = Game.get_player(dropdowns.parent.player.caption)
if not _player or not _action then dropdowns.warning.caption = {'ExpGamingAdmin.invalid'} return end
local _rank = Ranking.get_rank(_player)
if rank.power >= _rank.power then dropdowns.warning.caption = {'ExpGamingAdmin.rank-high'} return end
local _role = Role.get_highest(_player)
if role.index >= _role.index then dropdowns.warning.caption = {'ExpGamingAdmin.rank-high'} return end
local _reason = dropdowns['reason-input-admin-commands'] and dropdowns['reason-input-admin-commands'].text
if (_action == 'Jail' or _action == 'Kick' or _action == 'Ban' or _action == 'Temp Ban') and (_reason == 'Enter Reason' or string.len(_reason) < 20) then return end
Admin.take_action(_action,_player,event.player_index,_reason)

View File

@@ -1,4 +1,4 @@
--- Adds a jail function to the admin set, require ExpGamingRanking to work.
--- Adds a jail function to the admin set, require ExpGamingRole to work.
-- @module ExpGamingAdmin.Jail@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
@@ -8,7 +8,7 @@
local Admin = require('ExpGamingAdmin.AdminLib@^4.0.0')
local AdminGui = require('ExpGamingAdmin.Gui@^4.0.0')
local Server = require('ExpGamingCore.Server@^4.0.0')
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
local Role = require('ExpGamingCore.Role@^4.0.0')
local Game = require('FactorioStdLib.Game@^0.8.0')
local Color -- FactorioStdLib.Color@^0.8.0
local Sync -- ExpGamingCore.Sync@^4.0.0
@@ -40,8 +40,9 @@ function Admin.jail(player,by_player,reason)
['Reason:']=reason
} end
if Admin.move_inventory then Admin.move_inventory(player) end
Ranking.meta.last_jail = player.name
Server.interface(Ranking.give_rank,true,player,'Jail',by_player_name)
Role.meta.last_jail = player.name
Server.interface(Role.unassign,true,player,Role.get(player),by_player_name)
Server.interface(Role.assign,true,player,'Jail',by_player_name)
end
Admin.add_action('Jail',Admin.jail)

View File

@@ -7,7 +7,7 @@
-- Module Require
local Admin = require('ExpGamingAdmin.AdminLib@^4.0.0')
local Server = require('ExpGamingCore.Server@^4.0.0')
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
local Role = require('ExpGamingCore.Role@^4.0.0')
local Gui = require('ExpGamingCore.Gui@^4.0.0')
local Game = require('FactorioStdLib.Game@^0.8.0')
local Color = require('FactorioStdLib.Color@^0.8.0')
@@ -40,13 +40,11 @@ local function valid_players(player,by_player)
end
local function report_message(player,by_player,reason)
local low_rank = Ranking.get_group('User').highest
local high_rank = Ranking.get_group('Admin').lowest
local player, by_player_name = valid_players(player,by_player)
if not player then return end
if Admin.is_banned(player,true) == 'report' then return end
Ranking.print(low_rank,{'ExpGamingAdmin.low-print',player.name,reason},defines.textcolor.info,true)
Ranking.print(high_rank,{'ExpGamingAdmin.high-print',player.name,by_player_name,reason},defines.textcolor.med)
Role.print(Role.meta.groups.User.lowest,{'ExpGamingAdmin.low-print',player.name,reason},defines.textcolor.info,true)
Role.print(Role.meta.groups.Admin.lowest,{'ExpGamingAdmin.high-print',player.name,by_player_name,reason},defines.textcolor.med)
if Sync then Sync.emit_embeded{
title='Player Report',
color=Color.to_hex(defines.textcolor.med),
@@ -61,7 +59,7 @@ local function cheak_reports(player)
local player = Game.get_player(player)
if not player then return end
local reports = Admin.count_reports(player)
if reports >= reports_needed_for_jail and global.actions[player.name] ~= 'report-jail' and Ranking.get_rank(player).group.name ~= 'Jail' then
if reports >= reports_needed_for_jail and global.actions[player.name] ~= 'report-jail' and Role.get_highest(player).group.name ~= 'Jail' then
global.actions[player.name] = actions.report
Admin.jail(player,'<server>','Too many user reports. Contact an Admin to be unjailed.')
end
@@ -86,9 +84,9 @@ end
function Admin.report(player,by_player,reason)
local player, by_player_name = valid_players(player,by_player)
if not player or Ranking.get_rank(player):allowed('no-report') then return end
if Admin.is_banned(by_player) or Ranking.get_group(by_player).name == 'Jail' then return end
if Ranking.get_rank(by_player):allowed('varified') then
if not player or Role.allowed(player,'no-report') then return end
if Admin.is_banned(by_player) or Role.has_flag(by_player,'is_jail') then return end
if Role.has_flag(by_player,'is_varified') then
global.varified[player.name] = global.varified[player.name] or {}
local reports = global.varified[player.name]
for _,value in pairs(reports) do

View File

@@ -1,4 +1,4 @@
--- Adds a temp ban function to the admin set, requires ExpGamingCore.Ranking to work.
--- Adds a temp ban function to the admin set, requires ExpGamingCore.Role to work.
-- @module ExpGamingAdmin.KicTempBan@4.0.0
-- @author Cooldude2606
-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE
@@ -7,7 +7,7 @@
-- Module Require
local Admin = require('ExpGamingAdmin.AdminLib@^4.0.0')
local Server = require('ExpGamingCore.Server@^4.0.0')
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
local Role = require('ExpGamingCore.Role@^4.0.0')
local Game = require('FactorioStdLib.Game@^0.8.0')
local Color = require('FactorioStdLib.Color@^0.8.0')
local Sync -- ExpGamingCore.Sync@^4.0.0
@@ -36,8 +36,9 @@ function Admin.temp_ban(player,by_player,reason)
} end
game.print({'ExpGamingAdmin.temp-ban',player.name,by_player_name,reason},defines.textcolor.info)
if Admin.move_inventory then Admin.move_inventory(player) end
Ranking.meta.last_jail = player.name
Server.interface(Ranking.give_rank,true,player,'Jail',by_player_name)
Role.meta.last_jail = player.name
Server.interface(Role.unassign,true,player,Role.get(player),by_player_name)
Server.interface(Role.assign,true,player,'Jail',by_player_name)
end
Admin.add_action('Temp Ban',Admin.temp_ban)

View File

@@ -7,7 +7,7 @@
-- Module Require
local Admin = require('ExpGamingAdmin.AdminLib@^4.0.0')
local Server = require('ExpGamingCore.Server@^4.0.0')
local Ranking = require('ExpGamingCore.Ranking@^4.0.0')
local Role = require('ExpGamingCore.Role@^4.0.0')
local Game = require('FactorioStdLib.Game@^0.8.0')
local Color = require('FactorioStdLib.Color@^0.8.0')
local Sync -- ExpGamingCore.Sync@^4.0.0
@@ -45,11 +45,11 @@ local ThisModule = {
end,
on_post=function()
local highest = nil
for _,rank in pairs(Ranking.ranks) do
local power = rank.power
if not highest and not rank:allowed('no-report') then highest = power-1 end
for _,role in pairs(Role.roles) do
local power = role.index
if not highest and not role.not_reportable then highest = power-1 end
local _power = power; if highest then _power = power-highest end
if rank:allowed('no-report') then remove_warnings_time[power] = 0
if role.not_reportable then remove_warnings_time[power] = 0
else remove_warnings_time[power] = min_time_to_remove_warning*_power end
end
end
@@ -131,8 +131,8 @@ script.on_event(defines.events.on_tick,function(event)
if (game.tick % min_time_to_remove_warning) == 0 then
for name,warnings in pairs(global) do
if warnings > 0 then
local rank = Ranking.get_rank(name)
local time_to_remove = remove_warnings_time[rank.power]
local role = Role.get(name)
local time_to_remove = remove_warnings_time[role.index]
if (game.tick % time_to_remove) == 0 then
global[name]=warnings-1
if global.warnings[name] > 5 then