commit
2ac24e091c
676
chatcommands.lua
676
chatcommands.lua
|
@ -1,10 +1,10 @@
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- factionsmod Mod by Sapier
|
-- factions Mod by Sapier
|
||||||
--
|
--
|
||||||
-- License WTFPL
|
-- License WTFPL
|
||||||
--
|
--
|
||||||
--! @file chatcommnd.lua
|
--! @file chatcommnd.lua
|
||||||
--! @brief factionsmod chat interface
|
--! @brief factions chat interface
|
||||||
--! @copyright Sapier
|
--! @copyright Sapier
|
||||||
--! @author Sapier
|
--! @author Sapier
|
||||||
--! @date 2013-05-08
|
--! @date 2013-05-08
|
||||||
|
@ -12,18 +12,108 @@
|
||||||
-- Contact sapier a t gmx net
|
-- Contact sapier a t gmx net
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
--! @class factionsmod_chat
|
local send_error = function(player, message)
|
||||||
--! @brief chat interface class
|
minetest.chat_send_player(player, message)
|
||||||
factionsmod_chat = {}
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
factions_chat = {}
|
||||||
-- name: init()
|
|
||||||
--
|
factions.commands = {}
|
||||||
--! @brief initialize chat interface
|
|
||||||
--! @memberof factionsmod_chat
|
factions.register_command = function(cmd_name, cmd)
|
||||||
--! @public
|
factions.commands[cmd_name] = { -- default command
|
||||||
-------------------------------------------------------------------------------
|
name = cmd_name,
|
||||||
function factionsmod_chat.init()
|
faction_permissions = {},
|
||||||
|
global_privileges = {},
|
||||||
|
format = {},
|
||||||
|
infaction = true,
|
||||||
|
description = "This command has no description.",
|
||||||
|
run = function(self, player, argv)
|
||||||
|
--[[ check global privileges
|
||||||
|
if self.global_privileges then
|
||||||
|
local bool, missing_privs = minetest.check_player_privs(player, self.global_privileges)
|
||||||
|
if not bool then
|
||||||
|
send_error(player, "Missing global privileges: "..table.concat(missing_privs, ", "))
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end]]
|
||||||
|
-- checks argument formats
|
||||||
|
local args = {
|
||||||
|
factions = {},
|
||||||
|
players = {},
|
||||||
|
strings = {},
|
||||||
|
other = {}
|
||||||
|
}
|
||||||
|
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]
|
||||||
|
local arg = argv[i]
|
||||||
|
if argtype == "faction" then
|
||||||
|
local fac = factions.factions[arg]
|
||||||
|
if not fac then
|
||||||
|
send_error(player, "Specified faction "..arg.." does not exist")
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
table.insert(args.factions, fac)
|
||||||
|
end
|
||||||
|
elseif argtype == "player" then
|
||||||
|
local pl = minetest.get_player_by_name(arg)
|
||||||
|
if not pl then
|
||||||
|
send_error(player, "Player is not invited.")
|
||||||
|
--TODO: track existing players for offsync invites and the like
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
table.insert(args.players, pl)
|
||||||
|
end
|
||||||
|
elseif argtype == "string" then
|
||||||
|
table.insert(args.strings, arg)
|
||||||
|
else
|
||||||
|
minetest.log("error", "Bad format definition for function "..self.name)
|
||||||
|
send_error(player, "Internal server error")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=#self.format, #argv, 1 do
|
||||||
|
table.insert(args.other, argv[i])
|
||||||
|
end
|
||||||
|
|
||||||
|
-- checks permissions
|
||||||
|
local player_faction = factions.players[player]
|
||||||
|
if self.infaction and not player_faction then
|
||||||
|
minetest.chat_send_player(player, "This command is only available within a faction.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
player_faction = factions.factions[player_faction]
|
||||||
|
if faction_permissions then
|
||||||
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
-- get some more data
|
||||||
|
local pos = minetest.get_player_by_name(player):getpos()
|
||||||
|
local chunkpos = factions.get_chunk_pos(pos)
|
||||||
|
return self.on_success(player, player_faction, pos, chunkpos, args)
|
||||||
|
end,
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
minetest.chat_send_player(player, "Not implemented yet!")
|
||||||
|
end
|
||||||
|
}
|
||||||
|
-- override defaults
|
||||||
|
for k, v in pairs(cmd) do
|
||||||
|
factions.commands[cmd_name][k] = v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
local init_commands
|
||||||
|
init_commands = function()
|
||||||
|
|
||||||
minetest.register_privilege("faction_user",
|
minetest.register_privilege("faction_user",
|
||||||
{
|
{
|
||||||
|
@ -34,17 +124,17 @@ function factionsmod_chat.init()
|
||||||
|
|
||||||
minetest.register_privilege("faction_admin",
|
minetest.register_privilege("faction_admin",
|
||||||
{
|
{
|
||||||
description = "this user is allowed to create or delete factionsmod",
|
description = "this user is allowed to create or delete factions",
|
||||||
give_to_singleplayer = true,
|
give_to_singleplayer = true,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
minetest.register_chatcommand("factionsmod",
|
minetest.register_chatcommand("factions",
|
||||||
{
|
{
|
||||||
params = "<cmd> <parameter 1> .. <parameter n>",
|
params = "<cmd> <parameter 1> .. <parameter n>",
|
||||||
description = "faction administration functions",
|
description = "faction administration functions",
|
||||||
privs = { interact=true },
|
privs = { interact=true },
|
||||||
func = factionsmod_chat.cmdhandler,
|
func = factions_chat.cmdhandler,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -54,271 +144,383 @@ function factionsmod_chat.init()
|
||||||
params = "<factionname> text",
|
params = "<factionname> text",
|
||||||
description = "send message to a specific faction",
|
description = "send message to a specific faction",
|
||||||
privs = { faction_user=true },
|
privs = { faction_user=true },
|
||||||
func = factionsmod_chat.chathandler,
|
func = factions_chat.cmdhandler,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
-------------------------------------------
|
||||||
|
-- R E G I S T E R E D C O M M A N D S |
|
||||||
|
-------------------------------------------
|
||||||
|
|
||||||
|
factions.register_command ("claim", {
|
||||||
|
faction_permissions = {"claim"},
|
||||||
|
description = "Claim the plot of land you're on.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local chunk = factions.chunks[chunkpos]
|
||||||
|
if not chunk then
|
||||||
|
minetest.chat_send_player(player, "Claming chunk "..chunkpos)
|
||||||
|
faction:claim_chunk(chunkpos)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
if chunk == faction.name then
|
||||||
|
send_error(player, "This chunk already belongs to your faction.")
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
send_error(player, "This chunk belongs to another faction.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("unclaim", {
|
||||||
|
faction_permissions = {"claim"},
|
||||||
|
description = "Unclaim the plot of land you're on.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local chunk = factions.chunk[chunkpos]
|
||||||
|
if chunk ~= player_faction.name then
|
||||||
|
--TODO: error (not your faction's chunk)
|
||||||
|
return false
|
||||||
|
else
|
||||||
|
player_faction:unclaim_chunk(chunkpos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
--list all known factions
|
||||||
|
factions.register_command("list", {
|
||||||
|
description = "List all registered factions.",
|
||||||
|
infaction = false,
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local list = factions.get_faction_list()
|
||||||
|
local tosend = "Existing factions:"
|
||||||
|
|
||||||
|
for i,v in ipairs(list) do
|
||||||
|
if i ~= #list then
|
||||||
|
tosend = tosend .. " " .. v .. ","
|
||||||
|
else
|
||||||
|
tosend = tosend .. " " .. v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
minetest.chat_send_player(player, tosend, false)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
--show factions mod version
|
||||||
|
factions.register_command("version", {
|
||||||
|
description = "Displays mod version.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
minetest.chat_send_player(player, "factions: version " .. factions_version , false)
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
--show description of faction
|
||||||
|
factions.register_command("info", {
|
||||||
|
format = {"faction"},
|
||||||
|
description = "Shows a faction's description.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
minetest.chat_send_player(player,
|
||||||
|
"factions: " .. args.factions[1].name .. ": " ..
|
||||||
|
args.factions[1].description, false)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("leave", {
|
||||||
|
description = "Leave your faction.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:remove_player(player)
|
||||||
|
--TODO: message?
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("kick", {
|
||||||
|
faction_permissions = {"playerlist"},
|
||||||
|
format = {"player"},
|
||||||
|
description = "Kick a player from your faction.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local victim = args.players[1]
|
||||||
|
if factions.players[victim.name] == faction.name
|
||||||
|
and victim.name ~= faction.leader then -- can't kick da king
|
||||||
|
faction:remove_player(player)
|
||||||
|
--TODO: message?
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
--TODO: error (player is leader or in faction)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
--create new faction
|
||||||
|
factions.register_command("create", {
|
||||||
|
format = {"string"},
|
||||||
|
infaction = false,
|
||||||
|
description = "Create a new faction.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
if faction then
|
||||||
|
send_error(player, "You are already in a faction.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
local factionname = args.strings[1]
|
||||||
|
if factions.can_create_faction(factionname) then
|
||||||
|
new_faction = factions.new_faction(factionname)
|
||||||
|
new_faction:add_player(player, new_faction.default_leader_rank)
|
||||||
|
return true
|
||||||
|
else
|
||||||
|
send_error(player, "Faction cannot be created.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("join", {
|
||||||
|
format = {"faction"},
|
||||||
|
description = "Join a faction.",
|
||||||
|
infaction = false,
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local new_faction = args.factions[1]
|
||||||
|
if new_faction:can_join(player) then
|
||||||
|
if player_faction then -- leave old faction
|
||||||
|
player_faction:remove_player(player)
|
||||||
|
--TODO: message
|
||||||
|
end
|
||||||
|
new_faction:add_player(player)
|
||||||
|
else
|
||||||
|
send_error(player, "You cannot join this faction.")
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("disband", {
|
||||||
|
faction_permissions = {"disband"},
|
||||||
|
description = "Disband your faction.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:disband()
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("close", {
|
||||||
|
faction_permissions = {"playerslist"},
|
||||||
|
description = "Make your faction invite-only.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:toggle_join_free(false)
|
||||||
|
--TODO: message
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("open", {
|
||||||
|
faction_permissions = {"playerslist"},
|
||||||
|
description = "Allow any player to join your faction.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:toggle_join_free(true)
|
||||||
|
--TODO: message
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("description", {
|
||||||
|
faction_permissions = {"description"},
|
||||||
|
description = "Set your faction's description",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:set_description(args.other.concat(" "))
|
||||||
|
--TODO: message
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("invite", {
|
||||||
|
format = {"player"},
|
||||||
|
faction_permissions = {"playerslist"},
|
||||||
|
description = "Invite a player to your faction.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:invite_player(args.players[1]:get_player_name())
|
||||||
|
--TODO: message
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("uninvite", {
|
||||||
|
format = {"player"},
|
||||||
|
faction_permissions = {"playerslist"},
|
||||||
|
description = "Revoke a player's invite.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:revoke_invite(args.players[1]:get_player_name())
|
||||||
|
--TODO: message
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("delete", {
|
||||||
|
global_privileges = {"faction_admin"},
|
||||||
|
format = {"faction"},
|
||||||
|
infaction = false,
|
||||||
|
description = "Delete a faction.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
args.factions[1]:disband()
|
||||||
|
--TODO: message
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("ranks", {
|
||||||
|
description = "List ranks within your faction",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
if not faction then
|
||||||
|
--TODO: error message
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
for rank, permissions in pairs(faction.ranks) do
|
||||||
|
minetest.chat_send_player(player, rank..": "..table.concat(permissions, " "))
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("who", {
|
||||||
|
description = "List players in your faction, and their ranks.",
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
if not faction.players then
|
||||||
|
minetest.chat_send_player(player, "There is nobody in this faction ("..faction.name..")")
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
for player, rank in pairs(faction.players) do
|
||||||
|
minetest.chat_send_player(player, player.." ("..rank..")")
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("newrank", {
|
||||||
|
description = "Add a new rank.",
|
||||||
|
format = {"string"},
|
||||||
|
faction_permissions = {"ranks"},
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local rank = args.strings[1]
|
||||||
|
if faction.ranks[rank] then
|
||||||
|
--TODO: rank already exists
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
faction:new_rank(rank, args.other)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("delrank", {
|
||||||
|
description = "Replace and delete a rank.",
|
||||||
|
format = {"string", "string"},
|
||||||
|
faction_permissions = {"ranks"},
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local rank = args.strings[1]
|
||||||
|
local newrank = args.string[2]
|
||||||
|
if not faction.ranks[rank] or not faction.ranks[rank] then
|
||||||
|
--TODO: error (one of either ranks do not exist)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
faction:delete_rank(rank, newrank)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("setspawn", {
|
||||||
|
description = "Set the faction's spawn",
|
||||||
|
faction_permissions = {"spawn"},
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
faction:set_spawn(pos)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
|
factions.register_command("where", {
|
||||||
|
description = "See whose chunk you stand on",
|
||||||
|
infaction = false,
|
||||||
|
on_success = function(player, faction, pos, chunkpos, args)
|
||||||
|
local chunk = factions.chunks[chunkpos]
|
||||||
|
minetest.chat_send_player(player, "You are standing on chunk "..chunkpos)
|
||||||
|
if not chunk then
|
||||||
|
minetest.chat_send_player(player, "This chunk is free.")
|
||||||
|
else
|
||||||
|
minetest.chat_send_player(player, "This chunk belongs to "..chunk)
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
})
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: cmdhandler(playername,parameter)
|
-- name: cmdhandler(playername,parameter)
|
||||||
--
|
--
|
||||||
--! @brief chat command handler
|
--! @brief chat command handler
|
||||||
--! @memberof factionsmod_chat
|
--! @memberof factions_chat
|
||||||
--! @private
|
--! @private
|
||||||
--
|
--
|
||||||
--! @param playername name
|
--! @param playername name
|
||||||
--! @param parameter data supplied to command
|
--! @param parameter data supplied to command
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod_chat.cmdhandler(playername,parameter)
|
factions_chat.cmdhandler = function (playername,parameter)
|
||||||
|
|
||||||
--let's not duplicate code
|
|
||||||
local player = minetest.env:get_player_by_name(playername)
|
local player = minetest.env:get_player_by_name(playername)
|
||||||
local params = parameter:split(" ")
|
local params = parameter:split(" ")
|
||||||
local cmd = params[1]
|
local player_faction = factions.players[playersname]
|
||||||
local player_faction = factionsmod[playername]
|
|
||||||
local player_position = player:getpos()
|
|
||||||
local chunk = factionsmod.get_chunk(player_position)
|
|
||||||
local chunkpos = factionsmod.get_chunkpos(player_position)
|
|
||||||
|
|
||||||
--handle common commands
|
|
||||||
if parameter == nil or
|
if parameter == nil or
|
||||||
parameter == "" then
|
parameter == "" then
|
||||||
if player_faction then
|
if player_faction then
|
||||||
minetest.chat_send_player(playername, player_faction.description)
|
minetest.chat_send_player(playername, player_faction.description)
|
||||||
else
|
else
|
||||||
--TODO: message, no faction
|
minetest.chat_send_player(playername, "You are part of no faction")
|
||||||
end
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "claim" then
|
|
||||||
if player_faction:has_permission(playername, "claim") then
|
|
||||||
if not chunk then
|
|
||||||
player_faction:claim_chunk(chunkpos)
|
|
||||||
else
|
|
||||||
if chunk == player_faction.name then
|
|
||||||
--TODO: error (chunk already claimed by faction)
|
|
||||||
else
|
|
||||||
--TODO: error (chunk claimed by another faction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
--TODO: error message (no permission to claim)
|
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if cmd == "unclaim" then
|
local cmd = factions.commands[params[1]]
|
||||||
if player_faction:has_permission(playername, "claim") then
|
if not cmd then
|
||||||
if chunk ~= player_faction.name then
|
send_error(player, "Unknown command.")
|
||||||
--TODO: error (not your faction's chunk)
|
return false
|
||||||
else
|
end
|
||||||
player_faction:unclaim_chunk(chunkpos)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
--TODO: error (no permission to claim)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--list all known factionsmod
|
local argv = {}
|
||||||
if cmd == "list" then
|
for i=2, #params, 1 do
|
||||||
local list = factionsmod.get_faction_list()
|
table.insert(argv, params[i])
|
||||||
local tosend = "factionsmod: current available factionsmod:"
|
|
||||||
|
|
||||||
for i,v in ipairs(list) do
|
|
||||||
if i ~= #list then
|
|
||||||
tosend = tosend .. " " .. v .. ","
|
|
||||||
else
|
|
||||||
tosend = tosend .. " " .. v
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.chat_send_player(playername, tosend, false)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
--show factionsmod mod version
|
|
||||||
if cmd == "version" then
|
|
||||||
minetest.chat_send_player(playername, "factionsmod: version " .. factionsmod_version , false)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
--show description of faction
|
|
||||||
if cmd == "info" then
|
|
||||||
if params[2] ~= nil then
|
|
||||||
minetest.chat_send_player(playername,
|
|
||||||
"factionsmod: " .. params[2] .. ": " ..
|
|
||||||
factionsmod.factions[params[2]].description, false)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "leave" then
|
|
||||||
player_faction:remove_player(playername)
|
|
||||||
--TODO: message?
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "kick" then
|
|
||||||
if param[2] then
|
|
||||||
if player_faction:has_permission(playername, "playerlist") then
|
|
||||||
player_faction:remove_player(playername)
|
|
||||||
--TODO: message?
|
|
||||||
else
|
|
||||||
--TODO: error (no permissions)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
--TODO: error (no player specified)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--create new faction
|
cmd:run(playername, argv)
|
||||||
if cmd == "create" then
|
|
||||||
if params[2] ~= nil then
|
|
||||||
local factioname = params[2]
|
|
||||||
if factionsmod.can_create_faction(factionname) then
|
|
||||||
player_faction = factionsmod.create_faction(faction)
|
|
||||||
player_faction:add_player(playername)
|
|
||||||
player_faction:set_leader(playername)
|
|
||||||
else
|
|
||||||
--TODO: error (cannot create faction)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
--TODO: error (help message?)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "join" then
|
|
||||||
if params[2] then
|
|
||||||
local factionname = params[2]
|
|
||||||
local faction = factionsmod.factons[factionname]
|
|
||||||
if not faction then
|
|
||||||
--TODO: error (faction doesn't exist)
|
|
||||||
else
|
|
||||||
if faction:can_join(playername) then
|
|
||||||
if player_faction then -- leave old faction
|
|
||||||
player_faction:remove_player(playername)
|
|
||||||
--TODO: message
|
|
||||||
end
|
|
||||||
faction:add_player(playername)
|
|
||||||
else
|
|
||||||
--TODO: error (could not join faction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "disband" then
|
|
||||||
if player_faction:has_permission(playername, "disband") then
|
|
||||||
player_faction:disband()
|
|
||||||
else
|
|
||||||
--TODO: error (no permission)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "close" then
|
|
||||||
if player_faction:has_permission(playername, "playerlist") then
|
|
||||||
player_faction:toggle_join_free(false)
|
|
||||||
else
|
|
||||||
--TODO: error (no permission)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "open" then
|
|
||||||
if player_faction:has_permission(playername, "playerlist") then
|
|
||||||
player_faction:toggle_join_free(true)
|
|
||||||
else
|
|
||||||
--TODO: error (no permission)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "description" then
|
|
||||||
if player_faction:has_permission(playername, "description") then
|
|
||||||
local description = {}
|
|
||||||
for i=2, #params, 1 do
|
|
||||||
table.insert(description, params[i])
|
|
||||||
end
|
|
||||||
player_faction:set_description(description.concat(" "))
|
|
||||||
else
|
|
||||||
--TODO: error (no permission)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "invite" then
|
|
||||||
if params[2] then
|
|
||||||
if player_faction:has_permission(playername, "playerlist") then
|
|
||||||
player_faction:invite_player(params[2])
|
|
||||||
else
|
|
||||||
--TODO: error (no permission)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
--TODO: error (player unspecified)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if cmd == "uninvite" then
|
|
||||||
if params[2] then
|
|
||||||
if player_faction:has_permission(playername, "playerlist") then
|
|
||||||
player_faction:revoke_invite(params[2])
|
|
||||||
else
|
|
||||||
--TODO: error (no permission)
|
|
||||||
end
|
|
||||||
else
|
|
||||||
--TODO: error (player unspecified)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--all following commands require at least two parameters
|
|
||||||
if params[2] then
|
|
||||||
if minetest.check_player_privs(playername,{ faction_admin=true }) then
|
|
||||||
|
|
||||||
--delete faction
|
|
||||||
if cmd == "delete" then
|
|
||||||
faction = factionsmod.factions[params[2]]
|
|
||||||
if faction then
|
|
||||||
faction:disband()
|
|
||||||
--TODO: message
|
|
||||||
else
|
|
||||||
--TODO: error (no such faction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
factionsmod_chat.show_help(playername)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: show_help(playername,parameter)
|
-- name: show_help(playername,parameter)
|
||||||
--
|
--
|
||||||
--! @brief send help message to player
|
--! @brief send help message to player
|
||||||
--! @memberof factionsmod_chat
|
--! @memberof factions_chat
|
||||||
--! @private
|
--! @private
|
||||||
--
|
--
|
||||||
--! @param playername name
|
--! @param playername name
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod_chat.show_help(playername)
|
function factions_chat.show_help(playername)
|
||||||
|
|
||||||
local MSG = function(text)
|
local MSG = function(text)
|
||||||
minetest.chat_send_player(playername,text,false)
|
minetest.chat_send_player(playername,text,false)
|
||||||
end
|
end
|
||||||
|
|
||||||
MSG("factionsmod mod")
|
MSG("factions mod")
|
||||||
MSG("Usage:")
|
MSG("Usage:")
|
||||||
MSG("\tUser commands:")
|
for k, v in pairs(factions.commands) do
|
||||||
MSG("\t\t/factionsmod -> info on your current faction")
|
local args = {}
|
||||||
MSG("\t\t/factionsmod info <factionname> -> show description of faction")
|
for i in ipairs(v.format) do
|
||||||
MSG("\t\t/factionsmod list -> show list of factions")
|
table.insert(args, v.format[i])
|
||||||
MSG("\t\t/factionsmod leave -> leave current faction")
|
end
|
||||||
MSG("\t\t/factionsmod join <factionname> -> join specified faction")
|
MSG{"\t/factions "..k.." <"..table.concat(args, "> <").."> : "..v.description}
|
||||||
MSG("\t\t/factionsmod version -> show version number of mod")
|
end
|
||||||
|
|
||||||
MSG("\tAdmin commands:")
|
|
||||||
MSG("\t\t/factionsmod create <factionname> -> create a new faction")
|
|
||||||
MSG("\t\t/factionsmod delete <factionname> -> delete a faction faction")
|
|
||||||
MSG("\t\t/factionsmod leave <factionname> <playername> -> remove player from faction")
|
|
||||||
MSG("\t\t/factionsmod invite <factionname> <playername> -> invite player to faction")
|
|
||||||
MSG("\t\t/factionsmod set_free <factionname> <value> -> set faction free to join")
|
|
||||||
MSG("\t\t/factionsmod admin <factionname> <playername> <value> -> make player admin of faction")
|
|
||||||
MSG("\t\t/factionsmod description <factionname> <text> -> set description for faction")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
init_commands()
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- factionsmod Mod by Sapier
|
-- factions Mod by Sapier
|
||||||
--
|
--
|
||||||
-- License WTFPL
|
-- License WTFPL
|
||||||
--
|
--
|
||||||
--! @file factionsmod.lua
|
--! @file factions.lua
|
||||||
--! @brief factionsmod core file containing datastorage
|
--! @brief factions core file containing datastorage
|
||||||
--! @copyright Sapier
|
--! @copyright Sapier
|
||||||
--! @author Sapier
|
--! @author Sapier
|
||||||
--! @date 2013-05-08
|
--! @date 2013-05-08
|
||||||
|
@ -13,47 +13,47 @@
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
--read some basic information
|
--read some basic information
|
||||||
local factionsmod_worldid = minetest.get_worldpath()
|
local factions_worldid = minetest.get_worldpath()
|
||||||
|
|
||||||
--! @class factionsmod
|
--! @class factions
|
||||||
--! @brief main class for factionsmod
|
--! @brief main class for factions
|
||||||
factionsmod = {}
|
factions = {}
|
||||||
|
|
||||||
--! @brief runtime data
|
--! @brief runtime data
|
||||||
factionsmod.factions = {}
|
factions.factions = {}
|
||||||
factionsmod.chunks = {}
|
factions.chunks = {}
|
||||||
factionsmod.players = {}
|
factions.players = {}
|
||||||
|
|
||||||
factionsmod.print = function(text)
|
factions.print = function(text)
|
||||||
print("factionsmod: " .. dump(text))
|
print("factions: " .. dump(text))
|
||||||
end
|
end
|
||||||
|
|
||||||
factionsmod.dbg_lvl1 = function() end --factionsmod.print -- errors
|
factions.dbg_lvl1 = function() end --factions.print -- errors
|
||||||
factionsmod.dbg_lvl2 = function() end --factionsmod.print -- non cyclic trace
|
factions.dbg_lvl2 = function() end --factions.print -- non cyclic trace
|
||||||
factionsmod.dbg_lvl3 = function() end --factionsmod.print -- cyclic trace
|
factions.dbg_lvl3 = function() end --factions.print -- cyclic trace
|
||||||
|
|
||||||
factionsmod.factions = {}
|
factions.factions = {}
|
||||||
--- settings
|
--- settings
|
||||||
factionsmod.lower_claimable_height = -512
|
factions.lower_laimable_height = -512
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
--! @brief returns whether a faction can be created or not (allows for implementation of blacklists and the like)
|
||||||
factionsmod.can_create_faction = function(name)
|
factions.can_create_faction = function(name)
|
||||||
if factionsmod.factions[name] then
|
if factions.factions[name] then
|
||||||
return false
|
return false
|
||||||
else
|
else
|
||||||
return true
|
return true
|
||||||
end,
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
---------------------
|
---------------------
|
||||||
--! @brief create a faction object
|
--! @brief create a faction object
|
||||||
factionsmod.new_faction = function(name)
|
factions.new_faction = function(name)
|
||||||
local faction = {
|
local faction = {
|
||||||
name = name,
|
name = name,
|
||||||
power = 0.,
|
power = 0.,
|
||||||
players = {},
|
players = {},
|
||||||
ranks = {["leader"] = {"disband", "claim", "playerlist", "build", "edit"},
|
ranks = {["leader"] = {"disband", "claim", "playerlist", "build", "edit", "ranks"},
|
||||||
["member"] = {"build"}
|
["member"] = {"build"}
|
||||||
},
|
},
|
||||||
leader = nil,
|
leader = nil,
|
||||||
|
@ -64,68 +64,88 @@ factionsmod.new_faction = function(name)
|
||||||
land = {},
|
land = {},
|
||||||
allies = {},
|
allies = {},
|
||||||
enemies = {},
|
enemies = {},
|
||||||
join_free = false
|
join_free = false,
|
||||||
|
spawn = nil,
|
||||||
|
|
||||||
----------------------
|
----------------------
|
||||||
-- methods
|
-- methods
|
||||||
increase_power = function(self, power)
|
increase_power = function(self, power)
|
||||||
self.power = self.power + power
|
self.power = self.power + power
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
decrease_power = function(self, power)
|
decrease_power = function(self, power)
|
||||||
self.power = self.power - power
|
self.power = self.power - power
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
add_player = function(self, player, rank)
|
add_player = function(self, player, rank)
|
||||||
self.players[player] = rank or self.default_rank
|
self.players[player] = rank or self.default_rank
|
||||||
|
factions.players[player] = self.name
|
||||||
self:on_player_join(player)
|
self:on_player_join(player)
|
||||||
self.invited_players[player] = nil
|
self.invited_players[player] = nil
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
remove_player = function(self, player)
|
remove_player = function(self, player)
|
||||||
self.players[player] = nil
|
self.players[player] = nil
|
||||||
|
factions.players[player] = nil
|
||||||
self:on_player_leave(player)
|
self:on_player_leave(player)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
claim_chunk = function(self, chunkpos)
|
claim_chunk = function(self, chunkpos)
|
||||||
factionsmod.chunks[chunkpos] = self.name
|
factions.chunks[chunkpos] = self.name
|
||||||
self.land[chunkpos] = true
|
self.land[chunkpos] = true
|
||||||
self:on_claim_chunk(chunkpos)
|
self:on_claim_chunk(chunkpos)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
unclaim_chunk = function(self, chunkpos)
|
unclaim_chunk = function(self, chunkpos)
|
||||||
factionsmod.chunks[chunkpos] = nil
|
factions.chunks[chunkpos] = nil
|
||||||
self.land[chunkpos] = nil
|
self.land[chunkpos] = nil
|
||||||
self:on_unclaim_chunks(chunkpos)
|
self:on_unclaim_chunks(chunkpos)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
disband = function(self)
|
disband = function(self)
|
||||||
factionsmod.factions[self.name] = nil
|
|
||||||
for i in ipairs(self.players) do -- remove players affiliation
|
for i in ipairs(self.players) do -- remove players affiliation
|
||||||
factionsmod.players[self.players[i]] = nil
|
factions.players[self.players[i]] = nil
|
||||||
end
|
end
|
||||||
for k, v in self.land do -- remove chunk claims
|
for k, v in pairs(self.land) do -- remove chunk claims
|
||||||
factionsmod.chunks[v] = nil
|
factions.chunks[v] = nil
|
||||||
end
|
end
|
||||||
self:on_disband()
|
self:on_disband()
|
||||||
|
factions.factions[self.name] = nil
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
set_leader = function(self, player)
|
set_leader = function(self, player)
|
||||||
self.leader = player
|
self.leader = player
|
||||||
self.players[player] = self.default_leader_rank
|
self.players[player] = self.default_leader_rank
|
||||||
self:on_new_leader()
|
self:on_new_leader()
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
has_permission = function(self, player, permission)
|
has_permission = function(self, player, permission)
|
||||||
local p = self.players[player]
|
local p = self.players[player]
|
||||||
if not p then
|
if not p then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
return table.contains(self.groups[p], permission)
|
local perms = self.ranks[p]
|
||||||
|
for i in ipairs(perms) do
|
||||||
|
if perms[i] == permission then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
end,
|
end,
|
||||||
set_description = function(self, new)
|
set_description = function(self, new)
|
||||||
self.description = new
|
self.description = new
|
||||||
self:on_change_description()
|
self:on_change_description()
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
invite_player = function(self, player)
|
invite_player = function(self, player)
|
||||||
self.invited_players[player] = true
|
self.invited_players[player] = true
|
||||||
self:on_player_invited(player)
|
self:on_player_invited(player)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
revoke_invite = function(self, player)
|
revoke_invite = function(self, player)
|
||||||
self.invited_player[player = nil
|
self.invited_players[player] = nil
|
||||||
self:on_revoke_invite(player)
|
self:on_revoke_invite(player)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
is_invited = function(self, player)
|
is_invited = function(self, player)
|
||||||
return table.contains(self.invited_players, player)
|
return table.contains(self.invited_players, player)
|
||||||
|
@ -133,9 +153,10 @@ factionsmod.new_faction = function(name)
|
||||||
toggle_join_free = function(self, bool)
|
toggle_join_free = function(self, bool)
|
||||||
self.join_free = bool
|
self.join_free = bool
|
||||||
self:on_toggle_join_free()
|
self:on_toggle_join_free()
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
can_join = function(self, player)
|
can_join = function(self, player)
|
||||||
return self.join_free or invited_players[player]
|
return self.join_free or self.invited_players[player]
|
||||||
end,
|
end,
|
||||||
new_alliance = function(self, faction)
|
new_alliance = function(self, faction)
|
||||||
self.allies[faction] = true
|
self.allies[faction] = true
|
||||||
|
@ -143,25 +164,49 @@ factionsmod.new_faction = function(name)
|
||||||
if self.enemies[faction] then
|
if self.enemies[faction] then
|
||||||
self:end_enemy(faction)
|
self:end_enemy(faction)
|
||||||
end
|
end
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
end_alliance = function(self, faction)
|
end_alliance = function(self, faction)
|
||||||
self.allies[faction] = nil
|
self.allies[faction] = nil
|
||||||
self:on_end_alliance(faction)
|
self:on_end_alliance(faction)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
new_enemy = function(self, faction)
|
new_enemy = function(self, faction)
|
||||||
self.enemies[faction] = true
|
self.enemies[faction] = true
|
||||||
self:on_new_enemy[faction]
|
self:on_new_enemy(faction)
|
||||||
if self.allies[faction] then
|
if self.allies[faction] then
|
||||||
self:end_alliance(faction)
|
self:end_alliance(faction)
|
||||||
end
|
end
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
end_enemy = function(self, faction)
|
end_enemy = function(self, faction)
|
||||||
self.enemies[faction] = nil
|
self.enemies[faction] = nil
|
||||||
self:on_end_enemy[faction]
|
self:on_end_enemy(faction)
|
||||||
|
factions.save()
|
||||||
|
end,
|
||||||
|
set_spawn = function(self, pos)
|
||||||
|
self.spawn = pos
|
||||||
|
self:on_set_spawn()
|
||||||
|
factions.save()
|
||||||
|
end,
|
||||||
|
add_rank = function(self, rank, perms)
|
||||||
|
self.ranks[rank] = perms
|
||||||
|
self:on_new_rank(rank)
|
||||||
|
factions.save()
|
||||||
|
end,
|
||||||
|
delete_rank = function(self, rank, newrank)
|
||||||
|
for player, r in pairs(self.players) do
|
||||||
|
if r == rank then
|
||||||
|
self.players[player] = newrank
|
||||||
|
end
|
||||||
|
end
|
||||||
|
self.ranks[rank] = nil
|
||||||
|
self:on_delete_rank(rank, newrank)
|
||||||
|
factions.save()
|
||||||
end,
|
end,
|
||||||
|
|
||||||
-----------------------
|
--------------------------
|
||||||
-- callbacks for events
|
-- callbacks for events --
|
||||||
on_create = function(self) --! @brief called when the faction is added to the global faction list
|
on_create = function(self) --! @brief called when the faction is added to the global faction list
|
||||||
--TODO: implement
|
--TODO: implement
|
||||||
end,
|
end,
|
||||||
|
@ -198,60 +243,71 @@ factionsmod.new_faction = function(name)
|
||||||
on_end_alliance = function(self, faction)
|
on_end_alliance = function(self, faction)
|
||||||
--TODO: implement
|
--TODO: implement
|
||||||
end,
|
end,
|
||||||
|
on_set_spawn = function(self)
|
||||||
|
--TODO: implement
|
||||||
|
end,
|
||||||
|
on_add_rank = function(self, rank)
|
||||||
|
--TODO: implement
|
||||||
|
end,
|
||||||
|
on_delete_rank = function(self, rank, newrank)
|
||||||
|
--TODO: implement
|
||||||
|
end,
|
||||||
}
|
}
|
||||||
factionsmod[name] = faction
|
factions.factions[name] = faction
|
||||||
|
factions.save()
|
||||||
return faction
|
return faction
|
||||||
end
|
end
|
||||||
|
|
||||||
--??????????????
|
--??????????????
|
||||||
function factionsmod.fix_powercap(name)
|
function factions.fix_powercap(name)
|
||||||
factionsmod.data.factionsmod[name].powercap = #factionsmod.dynamic_data.membertable[name] + 10
|
factions.data.factions[name].powercap = #factions.dynamic_data.membertable[name] + 10
|
||||||
end
|
end
|
||||||
--??????????????
|
--??????????????
|
||||||
|
|
||||||
function factionsmod.get_chunk(pos)
|
function factions.get_chunk(pos)
|
||||||
return factionsmod.chunks[factionsmod.get_chunkpos(pos)]
|
return factions.chunks[factions.get_chunkpos(pos)]
|
||||||
end
|
end
|
||||||
|
|
||||||
function factionsmod.get_chunkpos(pos)
|
function factions.get_chunk_pos(pos)
|
||||||
return {math.floor(pos.x / 16.), math.floor(pos.z / 16.)}
|
return math.floor(pos.x / 16.)..","..math.floor(pos.z / 16.)
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: add_faction(name)
|
-- name: add_faction(name)
|
||||||
--
|
--
|
||||||
--! @brief add a faction
|
--! @brief add a faction
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @public
|
--! @public
|
||||||
--
|
--
|
||||||
--! @param name of faction to add
|
--! @param name of faction to add
|
||||||
--!
|
--!
|
||||||
--! @return faction object/false (succesfully added faction or not)
|
--! @return faction object/false (succesfully added faction or not)
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.add_faction(name)
|
function factions.add_faction(name)
|
||||||
if factionsmod.can_create_faction(name) then
|
if factions.can_create_faction(name) then
|
||||||
local fac = factionsmod.new_faction(name)
|
local fac = factions.new_faction(name)
|
||||||
fac:on_create()
|
fac:on_create()
|
||||||
return fac
|
return fac
|
||||||
else
|
else
|
||||||
return nil
|
return nil
|
||||||
end,
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- name: get_faction_list()
|
-- name: get_faction_list()
|
||||||
--
|
--
|
||||||
--! @brief get list of factionsmod
|
--! @brief get list of factions
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @public
|
--! @public
|
||||||
--!
|
--!
|
||||||
--! @return list of factionsmod
|
--! @return list of factions
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.get_faction_list()
|
function factions.get_faction_list()
|
||||||
|
|
||||||
local retval = {}
|
local retval = {}
|
||||||
|
|
||||||
for key,value in pairs(factionsmod.factions) do
|
for key,value in pairs(factions.factions) do
|
||||||
table.insert(retval,key)
|
table.insert(retval,key)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -262,23 +318,23 @@ end
|
||||||
-- name: save()
|
-- name: save()
|
||||||
--
|
--
|
||||||
--! @brief save data to file
|
--! @brief save data to file
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @private
|
--! @private
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.save()
|
function factions.save()
|
||||||
|
|
||||||
--saving is done much more often than reading data to avoid delay
|
--saving is done much more often than reading data to avoid delay
|
||||||
--due to figuring out which data to save and which is temporary only
|
--due to figuring out which data to save and which is temporary only
|
||||||
--all data is saved here
|
--all data is saved here
|
||||||
--this implies data needs to be cleant up on load
|
--this implies data needs to be cleant up on load
|
||||||
|
|
||||||
local file,error = io.open(factionsmod_worldid .. "/" .. "factionsmod.conf","w")
|
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","w")
|
||||||
|
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
file:write(minetest.serialize(factionsmod.factions))
|
file:write(minetest.serialize(factions.factions))
|
||||||
file:close()
|
file:close()
|
||||||
else
|
else
|
||||||
minetest.log("error","MOD factionsmod: unable to save factionsmod world specific data!: " .. error)
|
minetest.log("error","MOD factions: unable to save factions world specific data!: " .. error)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -287,30 +343,31 @@ end
|
||||||
-- name: load()
|
-- name: load()
|
||||||
--
|
--
|
||||||
--! @brief load data from file
|
--! @brief load data from file
|
||||||
--! @memberof factionsmod
|
--! @memberof factions
|
||||||
--! @private
|
--! @private
|
||||||
--
|
--
|
||||||
--! @return true/false
|
--! @return true/false
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
function factionsmod.load()
|
function factions.load()
|
||||||
local file,error = io.open(factionsmod_worldid .. "/" .. "factionsmod.conf","r")
|
local file,error = io.open(factions_worldid .. "/" .. "factions.conf","r")
|
||||||
|
|
||||||
if file ~= nil then
|
if file ~= nil then
|
||||||
local raw_data = file:read("*a")
|
local raw_data = file:read("*a")
|
||||||
factionsmod.factions = minetest.deserialize(raw_data)
|
factions.factions = minetest.deserialize(raw_data)
|
||||||
for facname, faction in pairs(factionsmod.factions) do
|
for facname, faction in pairs(factions.factions) do
|
||||||
for i in ipairs(faction.players) do
|
minetest.log("action", facname..","..faction.name)
|
||||||
factionsmod.players[faction.players[i]] = facname
|
for player, rank in pairs(faction.players) do
|
||||||
|
minetest.log("action", player..","..rank)
|
||||||
|
factions.players[player] = facname
|
||||||
end
|
end
|
||||||
for chunkpos, val in pairs(faction.land) do
|
for chunkpos, val in pairs(faction.land) do
|
||||||
factionsmod.chunks[chunkpos] = val
|
factions.chunks[chunkpos] = facname
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
file:close()
|
file:close()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
--autojoin players to faction players
|
|
||||||
minetest.register_on_dieplayer(
|
minetest.register_on_dieplayer(
|
||||||
function(player)
|
function(player)
|
||||||
end
|
end
|
||||||
|
@ -325,3 +382,16 @@ minetest.register_on_joinplayer(
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
local default_is_protected = minetest.is_protected
|
||||||
|
minetest.is_protected = function(pos, player)
|
||||||
|
local chunkpos = factions.get_chunk_pos(pos)
|
||||||
|
local faction = factions.chunks[chunkpos]
|
||||||
|
if not faction then
|
||||||
|
return default_is_protected(pos, player)
|
||||||
|
else
|
||||||
|
faction = factions.factions[faction]
|
||||||
|
return not faction:has_permission(player, "build")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
19
init.lua
19
init.lua
|
@ -1,10 +1,10 @@
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
-- factionsmod Mod by Sapier
|
-- factions Mod by Sapier
|
||||||
--
|
--
|
||||||
-- License WTFPL
|
-- License WTFPL
|
||||||
--
|
--
|
||||||
--! @file init.lua
|
--! @file init.lua
|
||||||
--! @brief factionsmod mod to be used by other mods
|
--! @brief factions mod to be used by other mods
|
||||||
--! @copyright Sapier
|
--! @copyright Sapier
|
||||||
--! @author Sapier
|
--! @author Sapier
|
||||||
--! @date 2013-05-08
|
--! @date 2013-05-08
|
||||||
|
@ -12,18 +12,17 @@
|
||||||
-- Contact sapier a t gmx net
|
-- Contact sapier a t gmx net
|
||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
local factionsmod_version = "0.1.6"
|
local factions_version = "0.1.6"
|
||||||
|
|
||||||
core.log("action", "MOD: factionsmod (by sapier) loading ...")
|
core.log("action", "MOD: factions (by sapier) loading ...")
|
||||||
|
|
||||||
--!path of mod
|
--!path of mod
|
||||||
factionsmod_modpath = minetest.get_modpath("factionsmod")
|
factions_modpath = minetest.get_modpath("factions")
|
||||||
|
|
||||||
|
|
||||||
dofile (factionsmod_modpath .. "/factionsmod.lua")
|
dofile (factions_modpath .. "/factions.lua")
|
||||||
dofile (factionsmod_modpath .. "/chatcommands.lua")
|
dofile (factions_modpath .. "/chatcommands.lua")
|
||||||
|
|
||||||
factionsmod.load()
|
factions.load()
|
||||||
factionsmod_chat.init()
|
|
||||||
|
|
||||||
core.log("action","MOD: factionsmod (by sapier) " .. factionsmod_version .. " loaded.")
|
core.log("action","MOD: factions (by sapier) " .. factions_version .. " loaded.")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user