Fixed more bugs in Admin

This commit is contained in:
Cooldude2606
2018-11-09 16:20:36 +00:00
parent 2877c4fc5f
commit f6c1ea7c32
4 changed files with 25 additions and 31 deletions

View File

@@ -28,6 +28,12 @@ local global = global{
} }
-- Function Define -- Function Define
function Admin.valid_players(player,by_player)
local player = Game.get_player(player)
local by_player = Game.get_player(by_player) or SERVER
return player, by_player
end
function Admin.create_reason(reason,name) function Admin.create_reason(reason,name)
local reason = reason or 'No Reason' local reason = reason or 'No Reason'
if not string.find(string.lower(reason),string.lower(name)) then reason = reason..' - '..name end if not string.find(string.lower(reason),string.lower(name)) then reason = reason..' - '..name end
@@ -71,7 +77,7 @@ function Admin.take_action(action,player,by_player,reason)
end end
function Admin.clear_player(player,by_player) function Admin.clear_player(player,by_player)
local player, by_player_name = valid_players(player,by_player) local player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
if Admin.is_banned(player,true) == true then Server.interface(game.unban_player,true,player,by_player) end 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_warings then Admin.clear_warings(player,by_player,true) end
@@ -82,7 +88,7 @@ function Admin.clear_player(player,by_player)
color=Color.to_hex(defines.textcolor.low), color=Color.to_hex(defines.textcolor.low),
description='A player had their reports and warnings cleared.', description='A player had their reports and warnings cleared.',
['Player:']='<<inline>>'..player.name, ['Player:']='<<inline>>'..player.name,
['By:']='<<inline>>'..by_player_name, ['By:']='<<inline>>'..by_player.name,
} end } end
Admin.set_banned(player,false) Admin.set_banned(player,false)
end end

View File

@@ -18,7 +18,7 @@ local module_verbose = false
local ThisModule = { local ThisModule = {
on_init=function() on_init=function()
if loaded_modules['ExpGamingCore.Sync@^4.0.0'] then Sync = require('ExpGamingCore.Sync@^4.0.0') end if loaded_modules['ExpGamingCore.Sync@^4.0.0'] then Sync = require('ExpGamingCore.Sync@^4.0.0') end
if loaded_modules['FactorioStdLib.Color@^0.8.0'] then Sync = require('FactorioStdLib.Color@^0.8.0') end if loaded_modules['FactorioStdLib.Color@^0.8.0'] then Color = require('FactorioStdLib.Color@^0.8.0') end
end end
} }

View File

@@ -33,24 +33,18 @@ local varified_to_warings = 3 -- used in count_reports
local reports_needed_for_jail = 6 local reports_needed_for_jail = 6
-- Function Define -- Function Define
local function valid_players(player,by_player)
local player = Game.get_player(player)
local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>'
return player, by_player_name
end
local function report_message(player,by_player,reason) local function report_message(player,by_player,reason)
local player, by_player_name = valid_players(player,by_player) local player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
if Admin.is_banned(player,true) == 'report' then return end if Admin.is_banned(player,true) == 'report' then return end
Role.print(Role.meta.groups.User.lowest,{'ExpGamingAdmin.low-print',player.name,reason},defines.textcolor.info,true) 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) 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{ if Sync then Sync.emit_embeded{
title='Player Report', title='Player Report',
color=Color.to_hex(defines.textcolor.med), color=Color.to_hex(defines.textcolor.med),
description='A player was reported.', description='A player was reported.',
['Player:']='<<inline>>'..player.name, ['Player:']='<<inline>>'..player.name,
['By:']='<<inline>>'..by_player_name, ['By:']='<<inline>>'..by_player.name,
['Reason:']=reason ['Reason:']=reason
} end } end
end end
@@ -82,30 +76,30 @@ function Admin.count_reports(player)
end end
function Admin.report(player,by_player,reason) function Admin.report(player,by_player,reason)
local player, by_player_name = valid_players(player,by_player) local player, by_player = Admin.valid_players(player,by_player)
if not player or Role.has_flag(player,'not_reportable') then return end if not player or Role.has_flag(player,'not_reportable') then return end
if Admin.is_banned(by_player) or Role.has_flag(by_player,'is_jail') 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 if Role.has_flag(by_player,'is_varified') then
global.varified[player.name] = global.varified[player.name] or {} global.varified[player.name] = global.varified[player.name] or {}
local reports = global.varified[player.name] local reports = global.varified[player.name]
for _,value in pairs(reports) do for _,value in pairs(reports) do
if value[1] == by_player_name then return end if value[1] == by_player.name then return end
end end
table.insert(reports,{by_player_name,reason}) table.insert(reports,{by_player.name,reason})
else else
global.reports[player.name] = global.reports[player.name] or {} global.reports[player.name] = global.reports[player.name] or {}
local reports = global.reports[player.name] local reports = global.reports[player.name]
for _,value in pairs(reports) do for _,value in pairs(reports) do
if value[1] == by_player_name then return end if value[1] == by_player.name then return end
end end
table.insert(reports,{by_player_name,reason}) table.insert(reports,{by_player.name,reason})
end end
report_message(player,by_player,reason) report_message(player,by_player,reason)
cheak_reports(player) cheak_reports(player)
end end
function Admin.clear_reports(player,by_player,no_emit) function Admin.clear_reports(player,by_player,no_emit)
local player, by_player_name = valid_players(player,by_player) local player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
global.reports[player.name]={} global.reports[player.name]={}
global.varified[player.name]={} global.varified[player.name]={}
@@ -115,7 +109,7 @@ function Admin.clear_reports(player,by_player,no_emit)
color=Color.to_hex(defines.textcolor.low), color=Color.to_hex(defines.textcolor.low),
description='A player had their reports cleared.', description='A player had their reports cleared.',
['Player:']='<<inline>>'..player.name, ['Player:']='<<inline>>'..player.name,
['By:']='<<inline>>'..by_player_name, ['By:']='<<inline>>'..by_player.name,
} }
end end
end end

View File

@@ -59,14 +59,8 @@ local ThisModule = {
local global = global{} local global = global{}
-- Function Define -- Function Define
local function valid_players(player,by_player)
local player = Game.get_player(player)
local by_player_name = Game.get_player(by_player) and Game.get_player(by_player).name or '<server>'
return player, by_player_name
end
local function give_punishment(player,by_player,reason) local function give_punishment(player,by_player,reason)
local player, by_player_name = valid_players(player,by_player) local player, by_player = Admin.valid_players(player,by_player)
local warnings = Admin.get_warnings(player) local warnings = Admin.get_warnings(player)
local punishment = punishments[warnings] local punishment = punishments[warnings]
local reason = reason or 'No Other Reason' local reason = reason or 'No Other Reason'
@@ -95,7 +89,7 @@ function Admin.get_warnings(player)
end end
function Admin.give_warning(player,by_player,reason,min) function Admin.give_warning(player,by_player,reason,min)
local player, by_player_name = valid_players(player,by_player) local player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
local min = Game.get_player(by_player) and take_action or min or 0 local min = Game.get_player(by_player) and take_action or min or 0
local warnings = Admin.get_warnings(player) local warnings = Admin.get_warnings(player)
@@ -103,14 +97,14 @@ function Admin.give_warning(player,by_player,reason,min)
warnings = warnings+1 warnings = warnings+1
global[player.name] = warnings global[player.name] = warnings
if warnings > take_action then if warnings > take_action then
player_return({'ExpGamingAdmin-Warnings@4-0-0.warning-given-by',by_player_name},defines.textcolor.info,player) player_return({'ExpGamingAdmin-Warnings@4-0-0.warning-given-by',by_player.name},defines.textcolor.info,player)
game.print({'ExpGamingAdmin-Warnings@4-0-0.player-warning',player.name,by_player_name,reason}) game.print({'ExpGamingAdmin-Warnings@4-0-0.player-warning',player.name,by_player.name,reason})
end end
give_punishment(player,by_player,reason) give_punishment(player,by_player,reason)
end end
function Admin.clear_warings(player,by_player,no_emit) function Admin.clear_warings(player,by_player,no_emit)
local player, by_player_name = valid_players(player,by_player) local player, by_player = Admin.valid_players(player,by_player)
if not player then return end if not player then return end
global[player.name]=nil global[player.name]=nil
if not no_emit and Sync then if not no_emit and Sync then
@@ -119,7 +113,7 @@ function Admin.clear_warings(player,by_player,no_emit)
color=Color.to_hex(defines.textcolor.low), color=Color.to_hex(defines.textcolor.low),
description='A player had their warnings cleared.', description='A player had their warnings cleared.',
['Player:']='<<inline>>'..player.name, ['Player:']='<<inline>>'..player.name,
['By:']='<<inline>>'..by_player_name, ['By:']='<<inline>>'..by_player.name,
} }
end end
end end