mirror of
https://github.com/mt-mods/playerfactions.git
synced 2025-02-16 16:32:24 +01:00
disband: allow admin
- permit admin to disband a faction without having any factions himself - permit admin to skip password check (he can supply any placeholder) - permit admin to disband his own single faction - don't call get_owner or valid_password if is admin - streamline duplicate code
This commit is contained in:
16
init.lua
16
init.lua
@ -221,34 +221,30 @@ local function handle_command(name, param)
|
|||||||
return true, S("Registered @1.", faction_name)
|
return true, S("Registered @1.", faction_name)
|
||||||
end
|
end
|
||||||
elseif action == "disband" then
|
elseif action == "disband" then
|
||||||
local password = nil
|
local password = params[2]
|
||||||
local faction_name = nil
|
local faction_name = nil
|
||||||
local own_factions = factions.get_administered_factions(name)
|
local own_factions = factions.get_administered_factions(name)
|
||||||
local number_factions = own_factions and #own_factions or 0
|
local number_factions = own_factions and #own_factions or 0
|
||||||
if number_factions == 0 then
|
if not is_admin and number_factions == 0 then
|
||||||
return false, S("You don't own any factions.")
|
return false, S("You don't own any factions.")
|
||||||
elseif #params == 1 then
|
elseif #params == 1 or not password then
|
||||||
return false, S("Missing password.")
|
return false, S("Missing password.")
|
||||||
elseif #params == 2 and number_factions == 1 then
|
elseif #params == 2 and number_factions == 1 then
|
||||||
password = params[2]
|
|
||||||
faction_name = own_factions[1]
|
faction_name = own_factions[1]
|
||||||
elseif #params >= 3 then
|
elseif #params >= 3 then
|
||||||
faction_name = params[3]
|
faction_name = params[3]
|
||||||
password = params[2]
|
|
||||||
end
|
end
|
||||||
if password == nil then
|
if faction_name == nil then
|
||||||
return false, S("Missing password.")
|
|
||||||
elseif faction_name == nil then
|
|
||||||
return false, S(
|
return false, S(
|
||||||
"You are the owner of multiple factions, you have to choose one of them: @1.",
|
"You are the owner of multiple factions, you have to choose one of them: @1.",
|
||||||
table.concat(own_factions, ", ")
|
table.concat(own_factions, ", ")
|
||||||
)
|
)
|
||||||
elseif not facts[faction_name] then
|
elseif not facts[faction_name] then
|
||||||
return false, S("Faction @1 doesn't exist.", faction_name)
|
return false, S("Faction @1 doesn't exist.", faction_name)
|
||||||
elseif name ~= factions.get_owner(faction_name) and not is_admin then
|
elseif not is_admin and name ~= factions.get_owner(faction_name) then
|
||||||
return false, S("Permission denied: You are not the owner of that faction, " ..
|
return false, S("Permission denied: You are not the owner of that faction, " ..
|
||||||
"and don't have the @1 privilege.", factions.priv)
|
"and don't have the @1 privilege.", factions.priv)
|
||||||
elseif not factions.valid_password(faction_name, password) then
|
elseif not is_admin and factions.valid_password(faction_name, password) then
|
||||||
return false, S("Permission denied: Wrong password.")
|
return false, S("Permission denied: Wrong password.")
|
||||||
else
|
else
|
||||||
factions.disband_faction(faction_name)
|
factions.disband_faction(faction_name)
|
||||||
|
Reference in New Issue
Block a user