2016-07-30 05:02:22 +02:00
|
|
|
-------------------------------------------------------------------------------
|
2016-08-07 19:31:11 +02:00
|
|
|
-- factions Mod by Sapier
|
2016-07-30 05:02:22 +02:00
|
|
|
--
|
|
|
|
-- License WTFPL
|
|
|
|
--
|
|
|
|
--! @file chatcommnd.lua
|
2016-08-07 19:31:11 +02:00
|
|
|
--! @brief factions chat interface
|
2016-08-12 11:34:39 +02:00
|
|
|
--! @copyright Sapier, agrecascino, shamoanjac
|
|
|
|
--! @author Sapier, agrecascino, shamoanjac
|
|
|
|
--! @date 2016-08-12
|
2016-07-30 05:02:22 +02:00
|
|
|
--
|
|
|
|
-- Contact sapier a t gmx net
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
2016-08-08 01:10:47 +02:00
|
|
|
local send_error = function(player, message)
|
|
|
|
minetest.chat_send_player(player, message)
|
|
|
|
end
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions_chat = {}
|
2016-07-30 05:02:22 +02:00
|
|
|
|
2016-08-07 19:36:56 +02:00
|
|
|
factions.commands = {}
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command = function(cmd_name, cmd)
|
|
|
|
factions.commands[cmd_name] = { -- default command
|
2016-08-07 15:17:33 +02:00
|
|
|
name = cmd_name,
|
|
|
|
faction_permissions = {},
|
|
|
|
global_privileges = {},
|
|
|
|
format = {},
|
2016-08-07 19:22:31 +02:00
|
|
|
infaction = true,
|
2016-08-07 15:17:33 +02:00
|
|
|
description = "This command has no description.",
|
|
|
|
run = function(self, player, argv)
|
2016-08-08 01:10:47 +02:00
|
|
|
if self.global_privileges then
|
2016-08-08 13:46:42 +02:00
|
|
|
local tmp = {}
|
|
|
|
for i in ipairs(self.global_privileges) do
|
|
|
|
tmp[self.global_privileges[i]] = true
|
|
|
|
end
|
|
|
|
local bool, missing_privs = minetest.check_player_privs(player, tmp)
|
2016-08-08 01:10:47 +02:00
|
|
|
if not bool then
|
2016-08-08 13:46:42 +02:00
|
|
|
send_error(player, "Unauthorized.")
|
2016-08-08 01:10:47 +02:00
|
|
|
end
|
2016-08-08 13:46:42 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
-- checks argument formats
|
|
|
|
local args = {
|
|
|
|
factions = {},
|
|
|
|
players = {},
|
|
|
|
strings = {},
|
|
|
|
other = {}
|
|
|
|
}
|
2016-08-08 01:10:47 +02:00
|
|
|
if #argv < #(self.format) then
|
|
|
|
send_error(player, "Not enough parameters.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
for i in ipairs(self.format) do
|
|
|
|
local argtype = self.format[i]
|
2016-08-07 15:17:33 +02:00
|
|
|
local arg = argv[i]
|
|
|
|
if argtype == "faction" then
|
2016-08-20 00:47:35 +02:00
|
|
|
local fac = factions.get_faction(arg)
|
2016-08-07 15:17:33 +02:00
|
|
|
if not fac then
|
2016-08-08 01:10:47 +02:00
|
|
|
send_error(player, "Specified faction "..arg.." does not exist")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
|
|
|
else
|
|
|
|
table.insert(args.factions, fac)
|
|
|
|
end
|
|
|
|
elseif argtype == "player" then
|
|
|
|
local pl = minetest.get_player_by_name(arg)
|
2016-08-25 18:31:02 +02:00
|
|
|
if not pl and not factions.players[arg] then
|
2016-08-08 13:46:42 +02:00
|
|
|
send_error(player, "Player is not online.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
|
|
|
else
|
|
|
|
table.insert(args.players, pl)
|
|
|
|
end
|
|
|
|
elseif argtype == "string" then
|
|
|
|
table.insert(args.strings, arg)
|
|
|
|
else
|
2016-08-08 01:10:47 +02:00
|
|
|
minetest.log("error", "Bad format definition for function "..self.name)
|
|
|
|
send_error(player, "Internal server error")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2016-08-08 01:10:47 +02:00
|
|
|
for i=#self.format, #argv, 1 do
|
2016-08-07 15:17:33 +02:00
|
|
|
table.insert(args.other, argv[i])
|
|
|
|
end
|
|
|
|
|
2016-08-07 19:22:31 +02:00
|
|
|
-- checks permissions
|
2016-08-20 00:47:35 +02:00
|
|
|
local player_faction = factions.get_player_faction(player)
|
2016-08-08 01:10:47 +02:00
|
|
|
if self.infaction and not player_faction then
|
|
|
|
minetest.chat_send_player(player, "This command is only available within a faction.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
2016-08-08 01:10:47 +02:00
|
|
|
end
|
2016-08-08 13:46:42 +02:00
|
|
|
if self.faction_permissions then
|
2016-08-08 01:10:47 +02:00
|
|
|
for i in ipairs(self.faction_permissions) do
|
|
|
|
if not player_faction:has_permission(player, self.faction_permissions[i]) then
|
|
|
|
send_error(player, "You don't have permissions to do that.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-- get some more data
|
|
|
|
local pos = minetest.get_player_by_name(player):getpos()
|
2016-08-14 15:53:40 +02:00
|
|
|
local parcelpos = factions.get_parcel_pos(pos)
|
|
|
|
return self.on_success(player, player_faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
end,
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
minetest.chat_send_player(player, "Not implemented yet!")
|
|
|
|
end
|
|
|
|
}
|
|
|
|
-- override defaults
|
|
|
|
for k, v in pairs(cmd) do
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.commands[cmd_name][k] = v
|
2016-08-07 15:17:33 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2016-08-08 01:10:47 +02:00
|
|
|
local init_commands
|
|
|
|
init_commands = function()
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
minetest.register_privilege("faction_user",
|
|
|
|
{
|
|
|
|
description = "this user is allowed to interact with faction mod",
|
|
|
|
give_to_singleplayer = true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
minetest.register_privilege("faction_admin",
|
|
|
|
{
|
2016-08-07 19:31:11 +02:00
|
|
|
description = "this user is allowed to create or delete factions",
|
2016-07-30 05:02:22 +02:00
|
|
|
give_to_singleplayer = true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
minetest.register_chatcommand("factions",
|
2016-07-30 05:02:22 +02:00
|
|
|
{
|
|
|
|
params = "<cmd> <parameter 1> .. <parameter n>",
|
|
|
|
description = "faction administration functions",
|
|
|
|
privs = { interact=true },
|
2016-08-07 19:31:11 +02:00
|
|
|
func = factions_chat.cmdhandler,
|
2016-07-30 05:02:22 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_chatcommand("f",
|
|
|
|
{
|
2016-08-08 23:25:31 +02:00
|
|
|
params = "<command> parameters",
|
|
|
|
description = "Factions commands. Type /f help for available commands.",
|
|
|
|
privs = { interact=true},
|
2016-08-08 01:10:47 +02:00
|
|
|
func = factions_chat.cmdhandler,
|
2016-07-30 05:02:22 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
|
2016-07-30 05:02:22 +02:00
|
|
|
|
2016-08-07 15:17:33 +02:00
|
|
|
-------------------------------------------
|
|
|
|
-- R E G I S T E R E D C O M M A N D S |
|
|
|
|
-------------------------------------------
|
2016-07-30 05:02:22 +02:00
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command ("claim", {
|
2016-08-07 15:17:33 +02:00
|
|
|
faction_permissions = {"claim"},
|
|
|
|
description = "Claim the plot of land you're on.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
local can_claim = faction:can_claim_parcel(parcelpos)
|
2016-08-09 04:39:40 +02:00
|
|
|
if can_claim then
|
2016-08-14 15:53:40 +02:00
|
|
|
minetest.chat_send_player(player, "Claming parcel "..parcelpos)
|
|
|
|
faction:claim_parcel(parcelpos)
|
2016-08-07 15:17:33 +02:00
|
|
|
return true
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-20 00:47:35 +02:00
|
|
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
|
|
|
if not parcel_faction then
|
2016-08-14 15:53:40 +02:00
|
|
|
send_error(player, "You faction cannot claim any (more) parcel(s).")
|
2016-08-09 04:39:40 +02:00
|
|
|
return false
|
2016-08-20 00:47:35 +02:00
|
|
|
elseif parcel_faction.name == faction.name then
|
2016-08-14 15:53:40 +02:00
|
|
|
send_error(player, "This parcel already belongs to your faction.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-14 15:53:40 +02:00
|
|
|
send_error(player, "This parcel belongs to another faction.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
end
|
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("unclaim", {
|
2016-08-07 15:17:33 +02:00
|
|
|
faction_permissions = {"claim"},
|
|
|
|
description = "Unclaim the plot of land you're on.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-20 00:47:35 +02:00
|
|
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
|
|
|
if parcel_faction.name ~= faction.name then
|
2016-08-14 15:53:40 +02:00
|
|
|
send_error(player, "This parcel does not belong to you.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-14 15:53:40 +02:00
|
|
|
faction:unclaim_parcel(parcelpos)
|
2016-08-07 15:17:33 +02:00
|
|
|
return true
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
end
|
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 15:17:33 +02:00
|
|
|
--list all known factions
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("list", {
|
2016-08-07 15:17:33 +02:00
|
|
|
description = "List all registered factions.",
|
2016-08-08 01:10:47 +02:00
|
|
|
infaction = false,
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:31:11 +02:00
|
|
|
local list = factions.get_faction_list()
|
2016-08-08 01:10:47 +02:00
|
|
|
local tosend = "Existing factions:"
|
2016-08-07 15:17:33 +02:00
|
|
|
|
|
|
|
for i,v in ipairs(list) do
|
|
|
|
if i ~= #list then
|
|
|
|
tosend = tosend .. " " .. v .. ","
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-07 15:17:33 +02:00
|
|
|
tosend = tosend .. " " .. v
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
end
|
|
|
|
minetest.chat_send_player(player, tosend, false)
|
|
|
|
return true
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
--show factions mod version
|
|
|
|
factions.register_command("version", {
|
2016-08-07 15:17:33 +02:00
|
|
|
description = "Displays mod version.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-08 01:10:47 +02:00
|
|
|
minetest.chat_send_player(player, "factions: version " .. factions_version , false)
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
})
|
2016-07-30 06:22:28 +02:00
|
|
|
|
2016-08-07 15:17:33 +02:00
|
|
|
--show description of faction
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("info", {
|
2016-08-07 15:17:33 +02:00
|
|
|
format = {"faction"},
|
|
|
|
description = "Shows a faction's description.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
minetest.chat_send_player(player,
|
2016-08-07 19:31:11 +02:00
|
|
|
"factions: " .. args.factions[1].name .. ": " ..
|
2016-08-07 15:17:33 +02:00
|
|
|
args.factions[1].description, false)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("leave", {
|
2016-08-07 19:36:56 +02:00
|
|
|
description = "Leave your faction.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:22:31 +02:00
|
|
|
faction:remove_player(player)
|
|
|
|
return true
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("kick", {
|
2016-08-08 13:46:42 +02:00
|
|
|
faction_permissions = {"playerslist"},
|
2016-08-07 15:17:33 +02:00
|
|
|
format = {"player"},
|
|
|
|
description = "Kick a player from your faction.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
local victim = args.players[1]
|
2016-08-20 00:47:35 +02:00
|
|
|
local victim_faction = factions.get_player_faction(victim:get_player_name())
|
|
|
|
if victim_faction and victim:get_player_name() ~= faction.leader then -- can't kick da king
|
2016-08-07 15:17:33 +02:00
|
|
|
faction:remove_player(player)
|
|
|
|
return true
|
2016-08-20 00:47:35 +02:00
|
|
|
elseif not victim_faction then
|
|
|
|
send_error(player, victim:get_player_name().." is not in your faction.")
|
|
|
|
return false
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-20 00:47:35 +02:00
|
|
|
send_error(player, victim:get_player_name().." cannot be kicked from your faction.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 15:17:33 +02:00
|
|
|
--create new faction
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("create", {
|
2016-08-07 15:17:33 +02:00
|
|
|
format = {"string"},
|
2016-08-07 19:22:31 +02:00
|
|
|
infaction = false,
|
2016-08-07 15:17:33 +02:00
|
|
|
description = "Create a new faction.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
if faction then
|
2016-08-08 01:10:47 +02:00
|
|
|
send_error(player, "You are already in a faction.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
|
|
|
end
|
2016-08-08 01:10:47 +02:00
|
|
|
local factionname = args.strings[1]
|
2016-08-07 19:31:11 +02:00
|
|
|
if factions.can_create_faction(factionname) then
|
2016-08-08 03:30:29 +02:00
|
|
|
new_faction = factions.new_faction(factionname, nil)
|
2016-08-08 01:10:47 +02:00
|
|
|
new_faction:add_player(player, new_faction.default_leader_rank)
|
2016-08-07 15:17:33 +02:00
|
|
|
return true
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-08 01:10:47 +02:00
|
|
|
send_error(player, "Faction cannot be created.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 19:36:56 +02:00
|
|
|
factions.register_command("join", {
|
2016-08-07 15:17:33 +02:00
|
|
|
format = {"faction"},
|
|
|
|
description = "Join a faction.",
|
2016-08-07 19:22:31 +02:00
|
|
|
infaction = false,
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
local new_faction = args.factions[1]
|
|
|
|
if new_faction:can_join(player) then
|
2016-08-14 15:43:53 +02:00
|
|
|
if faction then -- leave old faction
|
|
|
|
faction:remove_player(player)
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
new_faction:add_player(player)
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-08 01:10:47 +02:00
|
|
|
send_error(player, "You cannot join this faction.")
|
2016-08-07 15:17:33 +02:00
|
|
|
return false
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
return true
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("disband", {
|
2016-08-07 15:17:33 +02:00
|
|
|
faction_permissions = {"disband"},
|
|
|
|
description = "Disband your faction.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
faction:disband()
|
|
|
|
return true
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
})
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("close", {
|
2016-08-07 15:17:33 +02:00
|
|
|
faction_permissions = {"playerslist"},
|
|
|
|
description = "Make your faction invite-only.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
faction:toggle_join_free(false)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("open", {
|
2016-08-07 15:17:33 +02:00
|
|
|
faction_permissions = {"playerslist"},
|
|
|
|
description = "Allow any player to join your faction.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
faction:toggle_join_free(true)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("description", {
|
2016-08-07 15:17:33 +02:00
|
|
|
faction_permissions = {"description"},
|
|
|
|
description = "Set your faction's description",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-08 13:46:42 +02:00
|
|
|
faction:set_description(table.concat(args.other," "))
|
2016-08-07 15:17:33 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("invite", {
|
2016-08-07 15:17:33 +02:00
|
|
|
format = {"player"},
|
|
|
|
faction_permissions = {"playerslist"},
|
|
|
|
description = "Invite a player to your faction.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:36:56 +02:00
|
|
|
faction:invite_player(args.players[1]:get_player_name())
|
2016-08-07 15:17:33 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("uninvite", {
|
2016-08-07 15:17:33 +02:00
|
|
|
format = {"player"},
|
|
|
|
faction_permissions = {"playerslist"},
|
|
|
|
description = "Revoke a player's invite.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:36:56 +02:00
|
|
|
faction:revoke_invite(args.players[1]:get_player_name())
|
2016-08-07 15:17:33 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("delete", {
|
2016-08-07 15:17:33 +02:00
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction"},
|
2016-08-08 01:10:47 +02:00
|
|
|
infaction = false,
|
2016-08-07 15:17:33 +02:00
|
|
|
description = "Delete a faction.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 15:17:33 +02:00
|
|
|
args.factions[1]:disband()
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("ranks", {
|
2016-08-07 19:22:31 +02:00
|
|
|
description = "List ranks within your faction",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:22:31 +02:00
|
|
|
for rank, permissions in pairs(faction.ranks) do
|
2016-08-08 01:10:47 +02:00
|
|
|
minetest.chat_send_player(player, rank..": "..table.concat(permissions, " "))
|
2016-08-07 19:22:31 +02:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("who", {
|
2016-08-07 19:22:31 +02:00
|
|
|
description = "List players in your faction, and their ranks.",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-08 01:10:47 +02:00
|
|
|
if not faction.players then
|
|
|
|
minetest.chat_send_player(player, "There is nobody in this faction ("..faction.name..")")
|
|
|
|
return true
|
2016-08-07 19:22:31 +02:00
|
|
|
end
|
2016-08-12 17:09:43 +02:00
|
|
|
minetest.chat_send_player(player, "Players in faction "..faction.name..": ")
|
2016-08-14 23:55:42 +02:00
|
|
|
for p, rank in pairs(faction.players) do
|
|
|
|
minetest.chat_send_player(player, p.." ("..rank..")")
|
2016-08-07 19:22:31 +02:00
|
|
|
end
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("newrank", {
|
2016-08-07 19:22:31 +02:00
|
|
|
description = "Add a new rank.",
|
|
|
|
format = {"string"},
|
|
|
|
faction_permissions = {"ranks"},
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:22:31 +02:00
|
|
|
local rank = args.strings[1]
|
2016-08-18 15:29:43 +02:00
|
|
|
if #rank > factions.rank then
|
|
|
|
send_error(player, "Go away Todd")
|
|
|
|
return false
|
|
|
|
end
|
2016-08-07 19:22:31 +02:00
|
|
|
if faction.ranks[rank] then
|
2016-08-18 15:29:43 +02:00
|
|
|
send_error(player, "Rank already exists")
|
2016-08-07 19:22:31 +02:00
|
|
|
return false
|
|
|
|
end
|
2016-08-08 16:31:11 +02:00
|
|
|
faction:add_rank(rank, args.other)
|
2016-08-07 19:22:31 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("delrank", {
|
2016-08-07 19:22:31 +02:00
|
|
|
description = "Replace and delete a rank.",
|
|
|
|
format = {"string", "string"},
|
|
|
|
faction_permissions = {"ranks"},
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:22:31 +02:00
|
|
|
local rank = args.strings[1]
|
2016-08-08 16:31:11 +02:00
|
|
|
local newrank = args.strings[2]
|
2016-08-16 21:05:41 +02:00
|
|
|
if not faction.ranks[rank] or not faction.ranks[newrank] then
|
2016-08-16 21:08:44 +02:00
|
|
|
send_error(player, "One of the specified ranks do not exist.")
|
2016-08-07 19:22:31 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
faction:delete_rank(rank, newrank)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
factions.register_command("setspawn", {
|
2016-08-07 19:22:31 +02:00
|
|
|
description = "Set the faction's spawn",
|
|
|
|
faction_permissions = {"spawn"},
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-07 19:22:31 +02:00
|
|
|
faction:set_spawn(pos)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-08 01:10:47 +02:00
|
|
|
factions.register_command("where", {
|
2016-08-14 15:53:40 +02:00
|
|
|
description = "See whose parcel you stand on.",
|
2016-08-08 01:10:47 +02:00
|
|
|
infaction = false,
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-20 00:47:35 +02:00
|
|
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
|
|
|
local place_name = (parcel_faction and parcel_faction.name) or "Wilderness"
|
|
|
|
minetest.chat_send_player(player, "You are standing on parcel "..parcelpos..", part of "..place_name)
|
2016-08-08 01:10:47 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-08 03:30:29 +02:00
|
|
|
factions.register_command("help", {
|
|
|
|
description = "Shows help for commands.",
|
|
|
|
infaction = false,
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-08 03:30:29 +02:00
|
|
|
factions_chat.show_help(player)
|
2016-08-08 21:09:10 +02:00
|
|
|
return true
|
2016-08-08 03:30:29 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-08 16:31:11 +02:00
|
|
|
factions.register_command("spawn", {
|
|
|
|
description = "Shows your faction's spawn",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-28 12:07:44 +02:00
|
|
|
local spawn = faction.spawn
|
|
|
|
if spawn then
|
|
|
|
local spawn = {spawn.x, spawn.y, spawn.z}
|
|
|
|
minetest.chat_send_player(player, "Spawn is at ("..table.concat(spawn, ", ")..")")
|
2016-08-08 16:31:11 +02:00
|
|
|
return true
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(player, "Your faction has no spawn set.")
|
2016-08-08 21:09:10 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-08 23:25:31 +02:00
|
|
|
factions.register_command("promote", {
|
|
|
|
description = "Promotes a player to a rank",
|
|
|
|
format = {"player", "string"},
|
|
|
|
faction_permissions = {"promote"},
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-08 23:25:31 +02:00
|
|
|
local rank = args.strings[1]
|
|
|
|
if faction.ranks[rank] then
|
2016-08-15 16:39:19 +02:00
|
|
|
faction:promote(args.players[1]:get_player_name(), rank)
|
2016-08-08 23:25:31 +02:00
|
|
|
return true
|
|
|
|
else
|
|
|
|
send_error(player, "The specified rank does not exist.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-08 21:09:10 +02:00
|
|
|
factions.register_command("power", {
|
|
|
|
description = "Display your faction's power",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-16 15:44:19 +02:00
|
|
|
minetest.chat_send_player(player, "Power: "..faction.power.."/"..faction.maxpower - faction.usedpower.."/"..faction.maxpower)
|
2016-08-08 21:09:10 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
factions.register_command("setbanner", {
|
|
|
|
description = "Sets the banner you're on as the faction's banner.",
|
|
|
|
faction_permissions = {"banner"},
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-08 21:09:10 +02:00
|
|
|
local meta = minetest.get_meta({x = pos.x, y = pos.y - 1, z = pos.z})
|
|
|
|
local banner = meta:get_string("banner")
|
|
|
|
if not banner then
|
|
|
|
minetest.chat_send_player(player, "No banner found.")
|
|
|
|
return false
|
2016-08-08 16:31:11 +02:00
|
|
|
end
|
2016-08-08 21:09:10 +02:00
|
|
|
faction:set_banner(banner)
|
2016-08-08 16:31:11 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-08 18:51:17 +02:00
|
|
|
factions.register_command("convert", {
|
|
|
|
description = "Load factions in the old format",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"string"},
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-08 18:51:17 +02:00
|
|
|
if factions.convert(args.strings[1]) then
|
|
|
|
minetest.chat_send_player(player, "Factions successfully converted.")
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(player, "Error.")
|
|
|
|
end
|
2016-08-08 23:42:20 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
factions.register_command("free", {
|
2016-08-14 15:53:40 +02:00
|
|
|
description = "Forcefully frees a parcel",
|
2016-08-08 23:42:20 +02:00
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-20 00:47:35 +02:00
|
|
|
local parcel_faction = factions.get_parcel_faction(parcelpos)
|
|
|
|
if not parcel_faction then
|
2016-08-08 23:42:20 +02:00
|
|
|
send_error(player, "No claim at this position")
|
|
|
|
return false
|
2016-08-20 00:47:35 +02:00
|
|
|
else
|
|
|
|
parcel_faction:unclaim_parcel(parcelpos)
|
|
|
|
return true
|
2016-08-08 23:42:20 +02:00
|
|
|
end
|
2016-08-08 18:51:17 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-12 17:18:09 +02:00
|
|
|
factions.register_command("chat", {
|
|
|
|
description = "Send a message to your faction's members",
|
2016-08-14 15:53:40 +02:00
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-12 11:34:39 +02:00
|
|
|
local msg = table.concat(args.other, " ")
|
|
|
|
faction:broadcast(msg, player)
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-15 09:54:28 +02:00
|
|
|
factions.register_command("forceupdate", {
|
|
|
|
description = "Forces an update tick.",
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
factions.faction_tick()
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-27 22:10:25 +02:00
|
|
|
factions.register_command("which", {
|
|
|
|
description = "Gets a player's faction",
|
|
|
|
infaction = false,
|
|
|
|
format = {"string"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
local playername = args.strings[1]
|
|
|
|
local faction = factions.get_player_faction(playername)
|
|
|
|
if not faction then
|
|
|
|
send_error(player, "Player "..playername.." does not belong to any faction")
|
|
|
|
return false
|
|
|
|
else
|
|
|
|
minetest.chat_send_player(player, "player "..playername.." belongs to faction "..faction.name)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-27 22:34:09 +02:00
|
|
|
factions.register_command("setleader", {
|
|
|
|
description = "Set a player as a faction's leader",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction", "player"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
local playername = args.players[1]:get_player_name()
|
|
|
|
local playerfaction = factions.get_player_faction(playername)
|
|
|
|
local targetfaction = args.factions[1]
|
|
|
|
if playerfaction.name ~= targetfaction.name then
|
|
|
|
send_error(player, "Player "..playername.." is not in faction "..targetfaction.name..".")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
targetfaction:set_leader(playername)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-27 23:16:11 +02:00
|
|
|
factions.register_command("setadmin", {
|
|
|
|
description = "Make a faction an admin faction",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
args.factions[1].is_admin = false
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-28 11:55:16 +02:00
|
|
|
factions.register_command("resetpower", {
|
2016-08-28 11:37:14 +02:00
|
|
|
description = "Reset a faction's power",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
2016-08-28 11:55:16 +02:00
|
|
|
args.factions[1].power = 0
|
2016-08-28 11:37:14 +02:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-28 11:55:16 +02:00
|
|
|
|
|
|
|
factions.register_command("obliterate", {
|
|
|
|
description = "Remove all factions",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
for _, f in pairs(factions.factions) do
|
|
|
|
f:disband("obliterated")
|
|
|
|
end
|
2016-08-28 11:59:51 +02:00
|
|
|
return true
|
2016-08-28 11:55:16 +02:00
|
|
|
end
|
|
|
|
})
|
|
|
|
|
|
|
|
factions.register_command("getspawn", {
|
|
|
|
description = "Get a faction's spawn",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
local spawn = args.factions[1].spawn
|
|
|
|
if spawn then
|
|
|
|
minetest.chat_send_player(player, spawn.x..","..spawn.y..","..spawn.z)
|
|
|
|
return true
|
|
|
|
else
|
|
|
|
send_error(player, "Faction has no spawn set.")
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-28 11:59:51 +02:00
|
|
|
factions.register_command("whoin", {
|
|
|
|
description = "Get all members of a faction.",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
local msg = {}
|
|
|
|
for player, _ in pairs(args.factions[1].players) do
|
|
|
|
table.insert(msg, player)
|
|
|
|
end
|
|
|
|
minetest.chat_send_player(player, table.concat(msg, ", "))
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-28 12:03:12 +02:00
|
|
|
factions.register_command("stats", {
|
|
|
|
description = "Get stats of a faction.",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
local f = args.factions[1]
|
|
|
|
minetest.chat_send_player(player, "Power: "..f.power.."/"..f.maxpower - f.usedpower.."/"..f.maxpower)
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-28 12:19:58 +02:00
|
|
|
factions.register_command("seen", {
|
|
|
|
description = "Check the last time a faction had a member logged in",
|
|
|
|
infaction = false,
|
|
|
|
global_privileges = {"faction_admin"},
|
|
|
|
format = {"faction"},
|
|
|
|
on_success = function(player, faction, pos, parcelpos, args)
|
|
|
|
local lastseen = args.factions[1].last_logon
|
|
|
|
local now = os.time()
|
|
|
|
local time = now - lastseen
|
|
|
|
local minutes = math.floor(time / 60)
|
|
|
|
local hours = math.floor(minutes / 60)
|
|
|
|
local days = math.floor(hours / 24)
|
|
|
|
minetest.chat_send_player(player, "Last seen "..days.." day(s), "..
|
|
|
|
hours % 24 .." hour(s), "..minutes % 60 .." minutes, "..time % 60 .." second(s) ago.")
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
})
|
|
|
|
|
2016-08-07 15:17:33 +02:00
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: cmdhandler(playername,parameter)
|
|
|
|
--
|
|
|
|
--! @brief chat command handler
|
2016-08-07 19:31:11 +02:00
|
|
|
--! @memberof factions_chat
|
2016-08-07 15:17:33 +02:00
|
|
|
--! @private
|
|
|
|
--
|
|
|
|
--! @param playername name
|
|
|
|
--! @param parameter data supplied to command
|
|
|
|
-------------------------------------------------------------------------------
|
2016-08-08 01:10:47 +02:00
|
|
|
factions_chat.cmdhandler = function (playername,parameter)
|
2016-08-07 15:17:33 +02:00
|
|
|
|
|
|
|
local player = minetest.env:get_player_by_name(playername)
|
|
|
|
local params = parameter:split(" ")
|
2016-08-20 00:47:35 +02:00
|
|
|
local player_faction = factions.get_player_faction(playername)
|
2016-08-07 15:17:33 +02:00
|
|
|
|
|
|
|
if parameter == nil or
|
|
|
|
parameter == "" then
|
|
|
|
if player_faction then
|
2016-08-20 00:47:35 +02:00
|
|
|
minetest.chat_send_player(playername, "You are in faction "..player_faction.name..". Type /f help for a list of commands.")
|
2016-08-07 02:11:17 +02:00
|
|
|
else
|
2016-08-08 01:10:47 +02:00
|
|
|
minetest.chat_send_player(playername, "You are part of no faction")
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-08-07 15:17:33 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
local cmd = factions.commands[params[1]]
|
2016-08-07 15:17:33 +02:00
|
|
|
if not cmd then
|
2016-08-08 03:30:29 +02:00
|
|
|
send_error(playername, "Unknown command.")
|
2016-08-08 01:10:47 +02:00
|
|
|
return false
|
2016-08-07 15:17:33 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
local argv = {}
|
|
|
|
for i=2, #params, 1 do
|
|
|
|
table.insert(argv, params[i])
|
2016-08-07 02:11:17 +02:00
|
|
|
end
|
2016-07-30 05:02:22 +02:00
|
|
|
|
2016-08-08 01:10:47 +02:00
|
|
|
cmd:run(playername, argv)
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: show_help(playername,parameter)
|
|
|
|
--
|
|
|
|
--! @brief send help message to player
|
2016-08-07 19:31:11 +02:00
|
|
|
--! @memberof factions_chat
|
2016-07-30 05:02:22 +02:00
|
|
|
--! @private
|
|
|
|
--
|
|
|
|
--! @param playername name
|
|
|
|
-------------------------------------------------------------------------------
|
2016-08-07 19:31:11 +02:00
|
|
|
function factions_chat.show_help(playername)
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
local MSG = function(text)
|
|
|
|
minetest.chat_send_player(playername,text,false)
|
|
|
|
end
|
|
|
|
|
2016-08-07 19:31:11 +02:00
|
|
|
MSG("factions mod")
|
2016-07-30 05:02:22 +02:00
|
|
|
MSG("Usage:")
|
2016-08-07 19:31:11 +02:00
|
|
|
for k, v in pairs(factions.commands) do
|
2016-08-07 15:17:33 +02:00
|
|
|
local args = {}
|
|
|
|
for i in ipairs(v.format) do
|
|
|
|
table.insert(args, v.format[i])
|
|
|
|
end
|
2016-08-08 03:30:29 +02:00
|
|
|
MSG("\t/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description)
|
2016-08-07 15:17:33 +02:00
|
|
|
end
|
2016-07-30 22:33:10 +02:00
|
|
|
end
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-08-08 01:10:47 +02:00
|
|
|
init_commands()
|
|
|
|
|