Elimate buggy old ctf.add_user() and use ctf.join()
This commit is contained in:
parent
4f1763265f
commit
1aa85c35b8
@ -75,6 +75,10 @@ function ctf.count_players_in_team(team)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function ctf.new_player(name)
|
function ctf.new_player(name)
|
||||||
|
if not name then
|
||||||
|
ctf.error("team", "Can't create a blank player")
|
||||||
|
ctf.log("team", debug.traceback())
|
||||||
|
end
|
||||||
ctf.log("team", "Creating player " .. name)
|
ctf.log("team", "Creating player " .. name)
|
||||||
ctf.players[name] = {
|
ctf.players[name] = {
|
||||||
name = name
|
name = name
|
||||||
@ -94,8 +98,7 @@ function ctf.player_or_nil(name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Player joins team
|
-- Player joins team
|
||||||
-- Called by /join or auto allocate.
|
-- Called by /join, /team join or auto allocate.
|
||||||
-- /team join uses ctf.add_user()
|
|
||||||
function ctf.join(name, team, force)
|
function ctf.join(name, team, force)
|
||||||
if not name or name == "" or not team or team == "" then
|
if not name or name == "" or not team or team == "" then
|
||||||
ctf.log("team", "Missing parameters to ctf.join")
|
ctf.log("team", "Missing parameters to ctf.join")
|
||||||
@ -111,46 +114,26 @@ function ctf.join(name, team, force)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if not ctf.team(team) then
|
|
||||||
|
local team_data = ctf.team(team)
|
||||||
|
if team_data then
|
||||||
minetest.log("action", name .. " attempted to join " .. team .. ", which doesn't exist")
|
minetest.log("action", name .. " attempted to join " .. team .. ", which doesn't exist")
|
||||||
minetest.chat_send_player(name, "No such team.")
|
minetest.chat_send_player(name, "No such team.")
|
||||||
ctf.list_teams(name)
|
ctf.list_teams(name)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
if ctf.add_user(team, player) == true then
|
player.team = team
|
||||||
minetest.log("action", name .. " joined team " .. team)
|
team_data.players[player.name] = player
|
||||||
minetest.chat_send_all(name.." has joined team "..team)
|
|
||||||
|
|
||||||
if ctf.setting("hud") then
|
minetest.log("action", name .. " joined team " .. team)
|
||||||
ctf.hud.update(minetest.get_player_by_name(name))
|
minetest.chat_send_all(name.." has joined team "..team)
|
||||||
end
|
|
||||||
|
|
||||||
return true
|
if ctf.setting("hud") then
|
||||||
|
ctf.hud.update(minetest.get_player_by_name(name))
|
||||||
end
|
end
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
-- TODO: refactor ctf.add_user etc
|
return true
|
||||||
-- Add a player to a team in data structures
|
|
||||||
function ctf.add_user(team, user)
|
|
||||||
local _team = ctf.team(team)
|
|
||||||
local _user = ctf.player(user.name)
|
|
||||||
if _team and user and user.name then
|
|
||||||
if _user.team and ctf.team(_user.team) then
|
|
||||||
ctf.teams[_user.team].players[user.name] = nil
|
|
||||||
end
|
|
||||||
|
|
||||||
user.team = team
|
|
||||||
user.auth = false
|
|
||||||
_team.players[user.name] = user
|
|
||||||
ctf.players[user.name] = user
|
|
||||||
ctf.needs_save = true
|
|
||||||
|
|
||||||
return true
|
|
||||||
else
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Cleans up the player lists
|
-- Cleans up the player lists
|
||||||
|
@ -71,20 +71,17 @@ minetest.register_chatcommand("team", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif tplayer and tteam then
|
elseif tplayer and tteam then
|
||||||
minetest.chat_send_player(name,"joining '"..tplayer.."' to team '"..tteam.."'",false)
|
minetest.chat_send_player(name, "joining '" .. tplayer ..
|
||||||
|
"' to team '" .. tteam .. "'",false)
|
||||||
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
|
||||||
local player = ctf.player(tplayer)
|
if ctf.join(tplayer, tteam, true) then
|
||||||
|
|
||||||
if not player then
|
|
||||||
player = {name=tplayer}
|
|
||||||
end
|
|
||||||
|
|
||||||
if ctf.add_user(tteam,tplayer) == true then
|
|
||||||
minetest.chat_send_all(tplayer.." has joined team "..tteam)
|
minetest.chat_send_all(tplayer.." has joined team "..tteam)
|
||||||
|
else
|
||||||
|
minetest.char_send_player(name, "Failed to add player to team.")
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
minetest.chat_send_player(name, "You can not do this!")
|
minetest.chat_send_player(name, "You do not have the required privileges!")
|
||||||
end
|
end
|
||||||
elseif param=="help" then
|
elseif param=="help" then
|
||||||
team_console_help(name)
|
team_console_help(name)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user