Fixed create, disband, and chown commands

This commit is contained in:
Alden Peeters 2019-09-09 18:20:58 -04:00
parent f9ce04c4c4
commit 9adfb56b3b
No known key found for this signature in database
GPG Key ID: CDAD63AE9DA934BE

@ -26,7 +26,13 @@ function factions.get_player_faction(name)
if faction == "" then if faction == "" then
return nil return nil
else else
return faction -- Check that faction still exists
if facts[faction] == nil then
factions.leave_faction(name)
return nil
else
return faction
end
end end
end end
end end
@ -39,6 +45,10 @@ function factions.get_owner(name)
end end
end end
function factions.chown(name, owner)
facts[name].owner = owner
end
function factions.register_faction(fname, founder, pw) function factions.register_faction(fname, founder, pw)
facts[fname] = { facts[fname] = {
name = fname, name = fname,
@ -46,6 +56,7 @@ function factions.register_faction(fname, founder, pw)
password = pw password = pw
} }
save_factions() save_factions()
factions.join_faction(fname, founder)
end end
function factions.disband_faction(name) function factions.disband_faction(name)
@ -71,7 +82,6 @@ end
-- Chat commands -- Chat commands
local function handle_command(name, param) local function handle_command(name, param)
--local params = {string.match(param, "^([^ ]+)%s?(.*)")}
local params = {} local params = {}
for p in string.gmatch(param, "[^%s]+") do for p in string.gmatch(param, "[^%s]+") do
table.insert(params, p) table.insert(params, p)
@ -95,7 +105,7 @@ local function handle_command(name, param)
minetest.chat_send_player(name, S("Registered @1", faction_name)) minetest.chat_send_player(name, S("Registered @1", faction_name))
return true return true
end end
elseif action == "factions.disband" then elseif action == "disband" then
local faction_name = factions.get_player_faction(name) local faction_name = factions.get_player_faction(name)
local password = params[2] local password = params[2]
if faction_name == nil then if faction_name == nil then
@ -105,6 +115,7 @@ local function handle_command(name, param)
elseif password == nil then elseif password == nil then
minetest.chat_send_player(name, S("WARNING! This cannot be reversed! Run again with the password if you're absolutely certain")) minetest.chat_send_player(name, S("WARNING! This cannot be reversed! Run again with the password if you're absolutely certain"))
elseif password ~= factions.get_password(faction_name) then elseif password ~= factions.get_password(faction_name) then
print("wrong password")
minetest.chat_send_player(name, S("Permission denied")) minetest.chat_send_player(name, S("Permission denied"))
else else
factions.disband_faction(faction_name, name, name) factions.disband_faction(faction_name, name, name)
@ -196,8 +207,10 @@ local function handle_command(name, param)
local password = params[3] local password = params[3]
if faction_name == nil then if faction_name == nil then
minetest.chat_send_player(name, S("You are not in a faction")) minetest.chat_send_player(name, S("You are not in a faction"))
elseif factions.get_player_faction(name) ~= faction_name then elseif target == nil then
minetest.chat_send_player(name, S("@1 isn't in your faction", name)) minetest.chat_send_player(name, S("Missing player name"))
elseif factions.get_player_faction(target) ~= faction_name then
minetest.chat_send_player(name, S("@1 isn't in your faction", target))
elseif factions.get_owner(faction_name) ~= name then elseif factions.get_owner(faction_name) ~= name then
minetest.chat_send_player(name, S("Permission denied")) minetest.chat_send_player(name, S("Permission denied"))
elseif password == nil then elseif password == nil then
@ -205,7 +218,8 @@ local function handle_command(name, param)
elseif password ~= factions.get_password(faction_name) then elseif password ~= factions.get_password(faction_name) then
minetest.chat_send_player(name, S("Permission denied")) minetest.chat_send_player(name, S("Permission denied"))
else else
minetest.chat_send_player(name, S("Ownership has been transferred to @1", name)) factions.chown(faction_name, target)
minetest.chat_send_player(name, S("Ownership has been transferred to @1", target))
return true return true
end end
end end