Add ctf_team_mgr priv, clean ctf_chat

This commit is contained in:
rubenwardy 2015-12-08 00:15:24 +00:00
parent f024f83e85
commit b70fb29a11
4 changed files with 64 additions and 49 deletions

View File

@ -13,7 +13,7 @@ function minetest.chat_send_all(msg)
end end
-- Privs -- Privs
minetest.register_privilege("team", { minetest.register_privilege("ctf_team_mgr", {
description = "Team manager", description = "Team manager",
}) })

View File

@ -216,7 +216,7 @@ function ctf.can_mod(player,team)
local privs = minetest.get_player_privs(player) local privs = minetest.get_player_privs(player)
if privs then if privs then
if privs.team == true then if privs.ctf_admin == true then
return true return true
end end
end end

View File

@ -1 +1,2 @@
ctf ctf
chatplus?

View File

@ -16,57 +16,59 @@ local function team_console_help(name)
minetest.chat_send_player(name, "/team player <name> - get which team 'player' is in") minetest.chat_send_player(name, "/team player <name> - get which team 'player' is in")
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.team == true then if privs and privs.ctf_admin == true then
minetest.chat_send_player(name, "/team add <team> - add a team called name (admin only)") minetest.chat_send_player(name, "/team add <team> - add a team called name (ctf_admin only)")
minetest.chat_send_player(name, "/team remove <team> - add a team called name (admin only)") minetest.chat_send_player(name, "/team remove <team> - add a team called name (ctf_admin only)")
minetest.chat_send_player(name, "/team join <name> <team> - add 'player' to team 'team' (admin only)") end
minetest.chat_send_player(name, "/team removeply <name> - add 'player' to team 'team' (admin only)") if privs and privs.ctf_team_mgr == true then
minetest.chat_send_player(name, "/team join <name> <team> - add 'player' to team 'team' (ctf_team_mgr only)")
minetest.chat_send_player(name, "/team removeply <name> - add 'player' to team 'team' (ctf_team_mgr only)")
end end
end end
minetest.register_chatcommand("team", { minetest.register_chatcommand("team", {
description = "Open the team console, or run team command (see /team help)", description = "Open the team console, or run team command (see /team help)",
func = function(name, param) func = function(name, param)
local test = string.match(param,"^player ([%a%d_]+)") local test = string.match(param,"^player ([%a%d_-]+)")
local create = string.match(param,"^add ([%a%d_]+)") local create = string.match(param,"^add ([%a%d_-]+)")
local remove = string.match(param,"^remove ([%a%d_]+)") local remove = string.match(param,"^remove ([%a%d_-]+)")
local j_name, j_tname = string.match(param,"^join ([%a%d_]+) ([%a%d_]+)") local j_name, j_tname = string.match(param,"^join ([%a%d_-]+) ([%a%d_]+)")
local l_name = string.match(param,"^removeplr ([%a%d_]+)") local l_name = string.match(param,"^removeplr ([%a%d_-]+)")
if create then if create then
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.team == true then if privs and privs.ctf_admin == true then
if ( if (
string.match(create, "([%a%b_]-)") string.match(create, "([%a%b_]-)")
and ctf.team({name=create, add_team=true})
and create ~= "" and create ~= ""
and create ~= nil and create ~= nil
and ctf.team({name=create, add_team=true})
) then ) then
minetest.chat_send_player(name, "Added team '"..create.."'") return true, "Added team '"..create.."'"
else else
minetest.chat_send_player(name, "Error adding team '"..create.."'") return false, "Error adding team '"..create.."'"
end end
else else
minetest.chat_send_player(name, "You are not a ctf_admin!") return false, "You are not a ctf_admin!"
end end
elseif remove then elseif remove then
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.team == true then if privs and privs.ctf_admin == true then
if ctf.remove_team(remove) then if ctf.remove_team(remove) then
minetest.chat_send_player(name, "Removed team '" .. remove .. "'") return true, "Removed team '" .. remove .. "'"
else else
minetest.chat_send_player(name, "Error removing team '" .. remove .. "'") return false, "Error removing team '" .. remove .. "'"
end end
else else
minetest.chat_send_player(name, "You are not a ctf_admin!") return false, "You are not a ctf_admin!"
end end
elseif param == "all" then elseif param == "all" then
ctf.list_teams(name) ctf.list_teams(name)
elseif ctf.team(param) then elseif ctf.team(param) then
minetest.chat_send_player(name,"Team "..param..":") minetest.chat_send_player(name, "Team "..param..":")
local count = 0 local count = 0
for _,value in pairs(ctf.team(param).players) do for _,value in pairs(ctf.team(param).players) do
count = count + 1 count = count + 1
if value.aut == true then if value.auth == true then
minetest.chat_send_player(name, count .. ">> " .. value.name minetest.chat_send_player(name, count .. ">> " .. value.name
.. " (team owner)") .. " (team owner)")
else else
@ -79,40 +81,42 @@ minetest.register_chatcommand("team", {
end end
if ctf.player(test).team then if ctf.player(test).team then
if ctf.player(test).auth then if ctf.player(test).auth then
minetest.chat_send_player(name, test .. return true, test ..
" is in team " .. ctf.player(test).team.." (team owner)") " is in team " .. ctf.player(test).team.." (team owner)"
else else
minetest.chat_send_player(name, test .. return true, test ..
" is in team " .. ctf.player(test).team) " is in team " .. ctf.player(test).team
end end
else else
minetest.chat_send_player(name, test.." is not in a team") return true, test.." is not in a team"
end end
elseif j_name and j_tname then elseif j_name and j_tname then
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.ctf_admin == true then if privs and privs.ctf_team_mgr == true then
if not ctf.join(j_name, j_tname, true, name) then if ctf.join(j_name, j_tname, true, name) then
minetest.chat_send_player(name, "Failed to add player to team.") return true, "Successfully added " .. j_name .. " to " .. j_tname
else
return false, "Failed to add " .. j_name .. " to " .. j_tname
end end
else else
minetest.chat_send_player(name, "You are not a ctf_admin!") return true, "You are not a ctf_team_mgr!"
end end
elseif l_name then elseif l_name then
local privs = minetest.get_player_privs(name) local privs = minetest.get_player_privs(name)
if privs and privs.ctf_admin == true then if privs and privs.ctf_team_mgr == true then
if ctf.remove_player(l_name) then if ctf.remove_player(l_name) then
minetest.chat_send_player(name, "Removed player " .. l_name) return true, "Removed player " .. l_name
else else
minetest.chat_send_player(name, "Failed to remove player.") return false, "Failed to remove player."
end end
else else
minetest.chat_send_player(name, "You are not a ctf_admin!") return false, "You are not a ctf_team_mgr!"
end end
elseif param=="help" then elseif param=="help" then
team_console_help(name) team_console_help(name)
else else
if param~="" and param~= nil then if param~="" and param~= nil then
minetest.chat_send_player(name,"'"..param.."' is an invalid parameter to /team") minetest.chat_send_player(name, "'"..param.."' is an invalid parameter to /team")
team_console_help(name) team_console_help(name)
end end
if ( if (
@ -132,8 +136,12 @@ minetest.register_chatcommand("join", {
params = "team name", params = "team name",
description = "Add to team", description = "Add to team",
func = function(name, param) func = function(name, param)
ctf.join(name, param, false, name) if ctf.join(name, param, false, name) then
end, return true, "Joined team " .. param .. "!"
else
return false, "Failed to join team!"
end
end
}) })
minetest.register_chatcommand("ctf_clean", { minetest.register_chatcommand("ctf_clean", {
@ -145,17 +153,18 @@ minetest.register_chatcommand("ctf_clean", {
if ctf_flag and ctf_flag.assert_flags then if ctf_flag and ctf_flag.assert_flags then
ctf_flag.assert_flags() ctf_flag.assert_flags()
end end
minetest.chat_send_player(name, "CTF cleaned!") return true, "CTF cleaned!"
end, end
}) })
minetest.register_chatcommand("ctf_reset", { minetest.register_chatcommand("ctf_reset", {
description = "Delete all CTF saved states and start again.", description = "Delete all CTF saved states and start again.",
privs = {ctf_admin=true}, privs = {ctf_admin=true},
func = function(name, param) func = function(name, param)
minetest.chat_send_all("The CTF core was reset. All team memberships," .. minetest.chat_send_all("The CTF core was reset by the admin. All team memberships," ..
"flags, land ownerships etc have been deleted.") "flags, land ownerships etc have been deleted.")
ctf.reset() ctf.reset()
return true, "Reset CTF core."
end, end,
}) })
@ -165,7 +174,7 @@ minetest.register_chatcommand("ctf_reload", {
func = function(name, param) func = function(name, param)
ctf.needs_save = true ctf.needs_save = true
ctf.init() ctf.init()
minetest.chat_send_player(name, "CTF core reloaded!") return true, "CTF core reloaded!"
end end
}) })
@ -178,6 +187,7 @@ minetest.register_chatcommand("ctf_ls", {
minetest.chat_send_player(name, " - " .. set .. ": " .. dump(ctf.setting(set))) minetest.chat_send_player(name, " - " .. set .. ": " .. dump(ctf.setting(set)))
print("\"" .. set .. "\" " .. dump(ctf.setting(set))) print("\"" .. set .. "\" " .. dump(ctf.setting(set)))
end end
return true
end end
}) })
@ -189,16 +199,16 @@ minetest.register_chatcommand("team_owner", {
if ctf and ctf.players and ctf.player(param) and ctf.player(param).team and ctf.team(ctf.player(param).team) then if ctf and ctf.players and ctf.player(param) and ctf.player(param).team and ctf.team(ctf.player(param).team) then
if ctf.player(param).auth == true then if ctf.player(param).auth == true then
ctf.player(param).auth = false ctf.player(param).auth = false
minetest.chat_send_player(name, param.." was downgraded from team admin status") return true, param.." was downgraded from team admin status"
else else
ctf.player(param).auth = true ctf.player(param).auth = true
minetest.chat_send_player(name, param.." was upgraded to an admin of "..ctf.player(name).team) return true, param.." was upgraded to an admin of "..ctf.player(name).team
end end
ctf.needs_save = true ctf.needs_save = true
else else
minetest.chat_send_player(name, "Unable to do that :/ "..param.." does not exist, or is not part of a valid team.") return false, "Unable to do that :/ "..param.." does not exist, or is not part of a valid team."
end
end end
end,
}) })
minetest.register_chatcommand("post", { minetest.register_chatcommand("post", {
@ -234,8 +244,12 @@ minetest.register_chatcommand("all", {
end end
if ctf.player(name).team then if ctf.player(name).team then
minetest.chat_send_all(ctf.player(name).team .. " <" .. local tosend = ctf.player(name).team ..
name .. "> " .. param) " <" .. name .. "> " .. param
minetest.chat_send_all(tosend)
if minetest.global_exists("chatplus") then
chatplus.log(tosend)
end
else else
minetest.chat_send_all("<"..name.."> "..param) minetest.chat_send_all("<"..name.."> "..param)
end end