2016-07-30 05:02:22 +02:00
|
|
|
-------------------------------------------------------------------------------
|
2016-07-30 07:38:52 +02:00
|
|
|
-- factionsmod Mod by Sapier
|
2016-07-30 05:02:22 +02:00
|
|
|
--
|
|
|
|
-- License WTFPL
|
|
|
|
--
|
|
|
|
--! @file chatcommnd.lua
|
2016-07-30 07:38:52 +02:00
|
|
|
--! @brief factionsmod chat interface
|
2016-07-30 05:02:22 +02:00
|
|
|
--! @copyright Sapier
|
|
|
|
--! @author Sapier
|
|
|
|
--! @date 2013-05-08
|
|
|
|
--
|
|
|
|
-- Contact sapier a t gmx net
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
|
2016-07-30 07:38:52 +02:00
|
|
|
--! @class factionsmod_chat
|
2016-07-30 05:02:22 +02:00
|
|
|
--! @brief chat interface class
|
2016-07-30 07:38:52 +02:00
|
|
|
factionsmod_chat = {}
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: init()
|
|
|
|
--
|
|
|
|
--! @brief initialize chat interface
|
2016-07-30 07:38:52 +02:00
|
|
|
--! @memberof factionsmod_chat
|
2016-07-30 05:02:22 +02:00
|
|
|
--! @public
|
|
|
|
-------------------------------------------------------------------------------
|
2016-07-30 07:38:52 +02:00
|
|
|
function factionsmod_chat.init()
|
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-07-30 07:38:52 +02:00
|
|
|
description = "this user is allowed to create or delete factionsmod",
|
2016-07-30 05:02:22 +02:00
|
|
|
give_to_singleplayer = true,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2016-07-30 07:38:52 +02:00
|
|
|
minetest.register_chatcommand("factionsmod",
|
2016-07-30 05:02:22 +02:00
|
|
|
{
|
|
|
|
params = "<cmd> <parameter 1> .. <parameter n>",
|
|
|
|
description = "faction administration functions",
|
|
|
|
privs = { interact=true },
|
2016-07-30 07:38:52 +02:00
|
|
|
func = factionsmod_chat.cmdhandler,
|
2016-07-30 05:02:22 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
minetest.register_chatcommand("f",
|
|
|
|
{
|
|
|
|
params = "<factionname> text",
|
|
|
|
description = "send message to a specific faction",
|
|
|
|
privs = { faction_user=true },
|
2016-07-30 07:38:52 +02:00
|
|
|
func = factionsmod_chat.chathandler,
|
2016-07-30 05:02:22 +02:00
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: cmdhandler(playername,parameter)
|
|
|
|
--
|
|
|
|
--! @brief chat command handler
|
2016-07-30 07:38:52 +02:00
|
|
|
--! @memberof factionsmod_chat
|
2016-07-30 05:02:22 +02:00
|
|
|
--! @private
|
|
|
|
--
|
|
|
|
--! @param playername name
|
|
|
|
--! @param parameter data supplied to command
|
|
|
|
-------------------------------------------------------------------------------
|
2016-07-30 07:38:52 +02:00
|
|
|
function factionsmod_chat.cmdhandler(playername,parameter)
|
2016-07-30 05:02:22 +02:00
|
|
|
|
2016-08-07 02:11:17 +02:00
|
|
|
--let's not duplicate code
|
2016-07-30 05:02:22 +02:00
|
|
|
local player = minetest.env:get_player_by_name(playername)
|
|
|
|
local params = parameter:split(" ")
|
|
|
|
local cmd = params[1]
|
2016-08-07 02:11:17 +02:00
|
|
|
local player_faction = factionsmod[playername]
|
|
|
|
local player_position = player:getpos()
|
|
|
|
local chunk = factionsmod.get_chunk(player_position)
|
|
|
|
local chunkpos = factionsmod.get_chunkpos(player_position)
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
--handle common commands
|
|
|
|
if parameter == nil or
|
|
|
|
parameter == "" then
|
2016-08-07 02:11:17 +02:00
|
|
|
if player_faction then
|
|
|
|
minetest.chat_send_player(playername, player_faction.description)
|
|
|
|
else
|
|
|
|
--TODO: message, no faction
|
|
|
|
end
|
2016-07-30 05:02:22 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
if cmd == "claim" then
|
2016-08-07 02:11:17 +02:00
|
|
|
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
|
2016-07-30 05:02:22 +02:00
|
|
|
return
|
|
|
|
end
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-07-30 05:02:22 +02:00
|
|
|
if cmd == "unclaim" then
|
2016-08-07 02:11:17 +02:00
|
|
|
if player_faction:has_permission(playername, "claim") then
|
|
|
|
if chunk ~= player_faction.name then
|
|
|
|
--TODO: error (not your faction's chunk)
|
|
|
|
else
|
|
|
|
player_faction:unclaim_chunk(chunkpos)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
--TODO: error (no permission to claim)
|
|
|
|
end
|
2016-07-30 05:02:22 +02:00
|
|
|
end
|
2016-08-07 02:11:17 +02:00
|
|
|
|
2016-07-30 07:38:52 +02:00
|
|
|
--list all known factionsmod
|
2016-07-30 05:02:22 +02:00
|
|
|
if cmd == "list" then
|
2016-07-30 07:38:52 +02:00
|
|
|
local list = factionsmod.get_faction_list()
|
|
|
|
local tosend = "factionsmod: current available factionsmod:"
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2016-07-30 07:38:52 +02:00
|
|
|
--show factionsmod mod version
|
2016-07-30 05:02:22 +02:00
|
|
|
if cmd == "version" then
|
2016-07-30 07:38:52 +02:00
|
|
|
minetest.chat_send_player(playername, "factionsmod: version " .. factionsmod_version , false)
|
2016-07-30 05:02:22 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
--show description of faction
|
|
|
|
if cmd == "info" then
|
|
|
|
if params[2] ~= nil then
|
|
|
|
minetest.chat_send_player(playername,
|
2016-07-30 07:38:52 +02:00
|
|
|
"factionsmod: " .. params[2] .. ": " ..
|
2016-08-07 02:11:17 +02:00
|
|
|
factionsmod.factions[params[2]].description, false)
|
2016-07-30 05:02:22 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if cmd == "leave" then
|
2016-08-07 02:11:17 +02:00
|
|
|
player_faction:remove_player(playername)
|
|
|
|
--TODO: message?
|
2016-07-30 05:02:22 +02:00
|
|
|
end
|
2016-08-07 02:11:17 +02:00
|
|
|
|
|
|
|
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
|
2016-07-30 05:02:22 +02:00
|
|
|
|
2016-08-07 02:11:17 +02:00
|
|
|
--create new faction
|
|
|
|
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
|
2016-07-30 06:22:28 +02:00
|
|
|
|
2016-07-30 05:02:22 +02:00
|
|
|
if cmd == "join" then
|
2016-08-07 02:11:17 +02:00
|
|
|
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
|
2016-07-30 05:02:22 +02:00
|
|
|
end
|
|
|
|
end
|
2016-08-07 02:11:17 +02:00
|
|
|
|
|
|
|
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
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
--all following commands require at least two parameters
|
2016-08-07 02:11:17 +02:00
|
|
|
if params[2] then
|
|
|
|
if minetest.check_player_privs(playername,{ faction_admin=true }) then
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
--delete faction
|
|
|
|
if cmd == "delete" then
|
2016-08-07 02:11:17 +02:00
|
|
|
faction = factionsmod.factions[params[2]]
|
|
|
|
if faction then
|
|
|
|
faction:disband()
|
|
|
|
--TODO: message
|
|
|
|
else
|
|
|
|
--TODO: error (no such faction)
|
|
|
|
end
|
2016-07-30 05:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-30 07:38:52 +02:00
|
|
|
factionsmod_chat.show_help(playername)
|
2016-07-30 05:02:22 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
-------------------------------------------------------------------------------
|
|
|
|
-- name: show_help(playername,parameter)
|
|
|
|
--
|
|
|
|
--! @brief send help message to player
|
2016-07-30 07:38:52 +02:00
|
|
|
--! @memberof factionsmod_chat
|
2016-07-30 05:02:22 +02:00
|
|
|
--! @private
|
|
|
|
--
|
|
|
|
--! @param playername name
|
|
|
|
-------------------------------------------------------------------------------
|
2016-07-30 07:38:52 +02:00
|
|
|
function factionsmod_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-07-30 07:38:52 +02:00
|
|
|
MSG("factionsmod mod")
|
2016-07-30 05:02:22 +02:00
|
|
|
MSG("Usage:")
|
|
|
|
MSG("\tUser commands:")
|
2016-08-07 02:11:17 +02:00
|
|
|
MSG("\t\t/factionsmod -> info on your current faction")
|
2016-07-30 07:38:52 +02:00
|
|
|
MSG("\t\t/factionsmod info <factionname> -> show description of faction")
|
2016-08-07 02:11:17 +02:00
|
|
|
MSG("\t\t/factionsmod list -> show list of factions")
|
|
|
|
MSG("\t\t/factionsmod leave -> leave current faction")
|
2016-07-30 07:38:52 +02:00
|
|
|
MSG("\t\t/factionsmod join <factionname> -> join specified faction")
|
|
|
|
MSG("\t\t/factionsmod version -> show version number of mod")
|
2016-07-30 05:02:22 +02:00
|
|
|
|
|
|
|
MSG("\tAdmin commands:")
|
2016-07-30 07:38:52 +02:00
|
|
|
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")
|
2016-07-30 22:33:10 +02:00
|
|
|
end
|
2016-08-07 02:11:17 +02:00
|
|
|
|