From 3eed4b1d8d1e18d80a869d5dbe949edb31282b29 Mon Sep 17 00:00:00 2001 From: Cooldude2606 Date: Sun, 24 Jun 2018 20:59:28 +0100 Subject: [PATCH] Added ExpGamingCommands.admin --- modules/ExpGamingCommands/admin/control.lua | 18 +++++ modules/ExpGamingCommands/admin/softmod.json | 29 +++++++ modules/ExpGamingCommands/admin/src/clear.lua | 12 +++ modules/ExpGamingCommands/admin/src/jail.lua | 28 +++++++ .../ExpGamingCommands/admin/src/report.lua | 29 +++++++ .../ExpGamingCommands/admin/src/tempban.lua | 24 ++++++ .../ExpGamingCommands/admin/src/warnings.lua | 28 +++++++ modules/ExpGamingCommands/repair/control.lua | 12 +-- modules/ExpGamingCore/Commands/control.lua | 8 +- to convert/Addons/Commands/admin.lua | 81 ------------------- 10 files changed, 176 insertions(+), 93 deletions(-) create mode 100644 modules/ExpGamingCommands/admin/control.lua create mode 100644 modules/ExpGamingCommands/admin/softmod.json create mode 100644 modules/ExpGamingCommands/admin/src/clear.lua create mode 100644 modules/ExpGamingCommands/admin/src/jail.lua create mode 100644 modules/ExpGamingCommands/admin/src/report.lua create mode 100644 modules/ExpGamingCommands/admin/src/tempban.lua create mode 100644 modules/ExpGamingCommands/admin/src/warnings.lua delete mode 100644 to convert/Addons/Commands/admin.lua diff --git a/modules/ExpGamingCommands/admin/control.lua b/modules/ExpGamingCommands/admin/control.lua new file mode 100644 index 00000000..b5b01f45 --- /dev/null +++ b/modules/ExpGamingCommands/admin/control.lua @@ -0,0 +1,18 @@ +--- A full ranking system for factorio. +-- @module ExpGamingCommands.kill +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE + +-- this file should be replaced with a collection but idk if fsm can hanndle collections in a collection + +local Admin = require('ExpGamingAdmin') + +return { + on_init = function(self) + if loaded_modules['ExpGamingAdmin.TempBan'] then verbose('ExpGamingAdmin.TempBan is installed; Loading tempban src') require(module_path..'/src/tempban',{Admin=Admin}) end + if loaded_modules['ExpGamingAdmin.Jail'] then verbose('ExpGamingAdmin.Jail is installed; Loading tempban src') require(module_path..'/src/jail',{Admin=Admin}) end + if loaded_modules['ExpGamingAdmin.Warnings'] then verbose('ExpGamingAdmin.Warnings is installed; Loading tempban src') require(module_path..'/src/warnings',{Admin=Admin}) end + if loaded_modules['ExpGamingAdmin.Reports'] then verbose('ExpGamingAdmin.Reports is installed; Loading tempban src') require(module_path..'/src/reprots',{Admin=Admin}) end + if loaded_modules['ExpGamingAdmin.ClearInventory'] then verbose('ExpGamingAdmin.ClearInventory is installed; Loading tempban src') require(module_path..'/src/clear',{Admin=Admin}) end + end +} \ No newline at end of file diff --git a/modules/ExpGamingCommands/admin/softmod.json b/modules/ExpGamingCommands/admin/softmod.json new file mode 100644 index 00000000..9b56868d --- /dev/null +++ b/modules/ExpGamingCommands/admin/softmod.json @@ -0,0 +1,29 @@ +{ + "name": "admin", + "version": "4.0.0", + "type": "Module", + "description": "Admins many of the admin featues which the script can use as in game commands.", + "location": "", + "keywords": [ + "ExpGaming", + "Admin", + "Tools", + "Commands", + "Temp ban", + "Jail", + "Clear Inventory", + "Report", + "Warnings" + ], + "author": "", + "contact": "", + "license": "", + "dependencies": { + "ExpGamingCore.Commands": "^4.0.0", + "ExpGamingAdmin.TempBan": "?^4.0.0", + "ExpGamingAdmin.Jail": "?^4.0.0", + "ExpGamingAdmin.Warnings": "?^4.0.0", + "ExpGamingAdmin.Reports": "^?4.0.0", + "ExpGamingAdmin.ClearInventory": "?^4.0.0" + } +} \ No newline at end of file diff --git a/modules/ExpGamingCommands/admin/src/clear.lua b/modules/ExpGamingCommands/admin/src/clear.lua new file mode 100644 index 00000000..81d2441a --- /dev/null +++ b/modules/ExpGamingCommands/admin/src/clear.lua @@ -0,0 +1,12 @@ +local Admin = Admin + +--- Clears a players inventory and moves it to chests in spawn +-- @command clear-inv +-- @param player the player to clear the inventory of +commands.add_command('clear-inv', 'Clears a player\'s invetory', { + ['player'] = {true,'player-rank'} +}, function(event,args) + local player = args.player + if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end + Admin.move_inventory(player) +end) diff --git a/modules/ExpGamingCommands/admin/src/jail.lua b/modules/ExpGamingCommands/admin/src/jail.lua new file mode 100644 index 00000000..5a4c8831 --- /dev/null +++ b/modules/ExpGamingCommands/admin/src/jail.lua @@ -0,0 +1,28 @@ +local Admin = Admin +local Ranking = require('ExpGamingCore.Ranking') + +--- Used to jail a player which stops them from moving +-- @command jail +-- @param player the player to be jailed +-- @param[opt] reason the reason the player was jailed +commands.add_command('jail', 'Jails a player', { + ['player']={true,'player-rank'}, + ['reason']={false,'string-inf'} +}, function(event,args) + local player = args.player + local reason = args.reason + if Ranking.get_rank(player):allowed('no-report') then player_return({'reports.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) + +--- Used to unjail a player +-- @command unjail +-- @param player the player to unjail +commands.add_command('unjail', 'Returns a player\'s old rank', { + ['player']={true,'player'} +}, 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) +end) \ No newline at end of file diff --git a/modules/ExpGamingCommands/admin/src/report.lua b/modules/ExpGamingCommands/admin/src/report.lua new file mode 100644 index 00000000..8a300243 --- /dev/null +++ b/modules/ExpGamingCommands/admin/src/report.lua @@ -0,0 +1,29 @@ +local Admin = Admin +local Ranking = require('ExpGamingCore.Ranking') + +--- Reports a player +-- @command report +-- @param player the player to report +-- @param[opt] reason the reason why the player was reported +commands.add_command('report', 'Reports a player', { + ['player']={true,'player-rank'}, + ['reason']={false,'string-inf'} +}, function(event,args) + local _player = Game.get_player(event) + local player = args.player + local reason = args.reason + if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end + if Ranking.get_rank(player):allowed('no-report') then player_return({'reports.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({'reports.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({'reports.cant-report',args.player}) return commands.error end end + Admin.report(player,event.player_index,reason) +end) + +--- Clears the reports of the player +-- @command clear-reports +-- @param player the player to clear the reports of +commands.add_command('clear-reports', 'Clears a player\'s reports', { + ['player'] = {true,Admin.is_not_banned} +}, function(event,args) + Admin.clear_reports(args.player,event.player_index) +end) \ No newline at end of file diff --git a/modules/ExpGamingCommands/admin/src/tempban.lua b/modules/ExpGamingCommands/admin/src/tempban.lua new file mode 100644 index 00000000..1a55c690 --- /dev/null +++ b/modules/ExpGamingCommands/admin/src/tempban.lua @@ -0,0 +1,24 @@ +local Admin = Admin + +--- Used to temp ban a player and give a reason +-- @command temp-ban +-- @param player the player to temp ban +-- @param[opt] reason the reason for the ban +commands.add_command('temp-ban', 'Temporarily ban a player', { + ['player']={true,'player-rank'}, + ['reason']={false,'string-inf'} +}, function(event,args) + local player = args.player + local reason = args.reason + if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end + Admin.temp_ban(player,event.player_index,reason) +end) + +--- Used to clear all parts of a player, removing warnings, reports, jail and temp ban +-- @command clear-all +-- @param player the player to clear +commands.add_command('clear-all', 'Clears a player of any temp-ban, reports or warnings', { + ['player']={true,'player'} +}, function(event,args) + Admin.clear_player(args.player,event.player_index) +end) \ No newline at end of file diff --git a/modules/ExpGamingCommands/admin/src/warnings.lua b/modules/ExpGamingCommands/admin/src/warnings.lua new file mode 100644 index 00000000..2a389eb9 --- /dev/null +++ b/modules/ExpGamingCommands/admin/src/warnings.lua @@ -0,0 +1,28 @@ +local Admin = Admin +local Ranking = require('ExpGamingCore.Ranking') + +--- Gives a warning to a player +-- @command warn +-- @param player the player to give a warning to +-- @param[opt] reason the reason the player was given a warning +commands.add_command('warn', 'Gives a player a warning', { + ['player']={true,'player-rank'}, + ['reason']={false,'string-inf'} +}, function(event,args) + local player = args.player + local reason = args.reason + if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end + if Ranking.get_rank(player):allowed('no-report') then player_return({'reports.cant-report',args.player}) return commands.error end + Admin.give_warning(player,event.player_index,reason) +end) + +--- Clears the warning of a player +-- @command clear-warnings +-- @param player the player to clear the warning of +commands.add_command('clear-warnings', 'Clears a player\'s warnings', { + ['player'] = {true,'player'} +}, function(event,args) + local player = args.player + if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end + Admin.clear_warings(player,event.player_index) +end) \ No newline at end of file diff --git a/modules/ExpGamingCommands/repair/control.lua b/modules/ExpGamingCommands/repair/control.lua index 778c9fde..a266d3f5 100644 --- a/modules/ExpGamingCommands/repair/control.lua +++ b/modules/ExpGamingCommands/repair/control.lua @@ -1,12 +1,8 @@ ---[[ -Explosive Gaming +--- A full ranking system for factorio. +-- @module ExpGamingCommands.kill +-- @author Cooldude2606 +-- @license https://github.com/explosivegaming/scenario/blob/master/LICENSE -This file can be used with permission but this and the credit below must remain in the file. -Contact a member of management on our discord to seek permission to use our code. -Any changes that you may make to the code are yours but that does not make the script yours. -Discord: https://discord.gg/r6dC2uK -]] ---Please Only Edit Below This Line----------------------------------------------------------- local Game = require('FactorioStdLib.Game') local Ranking = require('ExpGamingCore.Ranking') diff --git a/modules/ExpGamingCore/Commands/control.lua b/modules/ExpGamingCore/Commands/control.lua index 45737aec..8f5d6583 100644 --- a/modules/ExpGamingCore/Commands/control.lua +++ b/modules/ExpGamingCore/Commands/control.lua @@ -46,7 +46,7 @@ setmetatable(commands,{ -- @field player converts the input into a valid player -- @field player_online converts the input to a player if the player is online -- @field player_alive converts the input to a player if the player is online and alive --- @field player_rank converts the input to a player if the player is a lower rank than the user +-- @field player_rank converts the input to a player if the player is a lower rank than the user or if the person is not admin and the user is -- @field player_rank-online converts the input to a player if the player is a lower rank than the user and online -- @field player_rank_alive converts the input to a player if the player is a lower rank than the user and online and alive commands.validate = { @@ -60,9 +60,9 @@ commands.validate = { ['player']=function(value,event) return Game.get_player(player) or commands.error{'commands.error-player'} end, ['player-online']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or player.conected and player or commands.error{'commands.error-player-online'} end, ['player-alive']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or player.character and player.character.health > 0 and player or commands.error{'commands.error-player-alive'} end, - ['player-rank']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin or commands.error{'commands.error-player-rank'} end, - ['player-rank-online']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin or commands.error{'commands.error-player-rank'} end, - ['player-rank-alive']=function(value,event) local player,err = commands.validate['player-alive'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin or commands.error{'commands.error-player-rank'} end + ['player-rank']=function(value,event) local player,err = commands.validate['player'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin and Game.get_player(event).admin or commands.error{'commands.error-player-rank'} end, + ['player-rank-online']=function(value,event) local player,err = commands.validate['player-online'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin and Game.get_player(event).admin or commands.error{'commands.error-player-rank'} end, + ['player-rank-alive']=function(value,event) local player,err = commands.validate['player-alive'](value) return err and commands.error(err) or Ranking and Ranking.get_rank(player).power > Ranking.get_rank(event).power or not player.admin and Game.get_player(event).admin or commands.error{'commands.error-player-rank'} end } --- Returns the inputs of this command as a formated string diff --git a/to convert/Addons/Commands/admin.lua b/to convert/Addons/Commands/admin.lua deleted file mode 100644 index 775df6d1..00000000 --- a/to convert/Addons/Commands/admin.lua +++ /dev/null @@ -1,81 +0,0 @@ ---[[ -Explosive Gaming - -This file can be used with permission but this and the credit below must remain in the file. -Contact a member of management on our discord to seek permission to use our code. -Any changes that you may make to the code are yours but that does not make the script yours. -Discord: https://discord.gg/r6dC2uK -]] ---Please Only Edit Below This Line----------------------------------------------------------- - -commands.add_command('report', 'Reports a player', {'player','reason',true}, function(event,args) - local _player = Game.get_player(event) - local player = Game.get_player(args.player) - local reason = args.reason - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end - if Ranking.get_rank(player):allowed('no-report') then player_return({'reports.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({'reports.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({'reports.cant-report',args.player}) return commands.error end end - Admin.report(player,event.player_index,reason) -end) - -commands.add_command('warn', 'Gives a player a warning', {'player','reason',true}, function(event,args) - local player = Game.get_player(args.player) - local reason = args.reason - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end - if Ranking.get_rank(player):allowed('no-report') then player_return({'reports.cant-report',args.player}) return commands.error end - Admin.give_warning(player,event.player_index,reason) -end) - -commands.add_command('jail', 'Jails a player', {'player','reason',true}, function(event,args) - local player = Game.get_player(args.player) - local reason = args.reason - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - if Ranking.get_rank(player):allowed('no-report') then player_return({'reports.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) - -commands.add_command('unjail', 'Returns a player\'s old rank', {'player',true}, function(event,args) - local player = Game.get_player(args.player) - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - 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) -end) - -commands.add_command('temp-ban', 'Temporarily ban a player', {'player','reason',true}, function(event,args) - local player = Game.get_player(args.player) - local reason = args.reason - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end - Admin.temp_ban(player,event.player_index,reason) -end) - -commands.add_command('clear-inv', 'Clears a player\'s invetory', {'player'}, function(event,args) - local player = Game.get_player(args.player) - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end - Admin.move_inventory(player) -end) - -commands.add_command('clear-warnings', 'Clears a player\'s warnings', {'player'}, function(event,args) - local player = Game.get_player(args.player) - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end - Admin.clear_warings(player,event.player_index) -end) - -commands.add_command('clear-reports', 'Clears a player\'s reports', {'player'}, function(event,args) - local player = Game.get_player(args.player) - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - if Admin.is_banned(player) then player_return({'reports.cant-report-ban',args.player}) return commands.error end - Admin.clear_reports(player,event.player_index) -end) - -commands.add_command('clear-all', 'Clears a player of any temp-ban, reports or warnings', {'player'}, function(event,args) - local player = Game.get_player(args.player) - if not player then player_return({'commands.invalid-player',args.player}) return commands.error end - Admin.clear_player(player,event.player_index) -end)