mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-29 07:21:54 +00:00
Implemented team locking (issue #62)
This commit is contained in:
parent
039855b4d0
commit
3252c6a563
7 changed files with 124 additions and 43 deletions
|
@ -28,12 +28,6 @@ local util = require "luascripts.wolfadmin.util.util"
|
||||||
|
|
||||||
local admin = {}
|
local admin = {}
|
||||||
|
|
||||||
local teamLocks = {
|
|
||||||
[constants.TEAM_AXIS] = false,
|
|
||||||
[constants.TEAM_ALLIES] = false,
|
|
||||||
[constants.TEAM_SPECTATORS] = false,
|
|
||||||
}
|
|
||||||
|
|
||||||
function admin.putPlayer(clientId, teamId)
|
function admin.putPlayer(clientId, teamId)
|
||||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "forceteam "..clientId.." "..util.getTeamCode(teamId)..";")
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "forceteam "..clientId.." "..util.getTeamCode(teamId)..";")
|
||||||
end
|
end
|
||||||
|
@ -50,14 +44,6 @@ function admin.kickPlayer(victimId, invokerId, reason)
|
||||||
et.trap_DropClient(victimId, "You have been kicked, Reason: "..(reason and reason or "kicked by admin"), 0)
|
et.trap_DropClient(victimId, "You have been kicked, Reason: "..(reason and reason or "kicked by admin"), 0)
|
||||||
end
|
end
|
||||||
|
|
||||||
function admin.lockTeam(teamId)
|
|
||||||
teamLocks[teamId] = false
|
|
||||||
end
|
|
||||||
|
|
||||||
function admin.unlockTeam(teamId)
|
|
||||||
teamLocks[teamId] = false
|
|
||||||
end
|
|
||||||
|
|
||||||
function admin.setPlayerLevel(clientId, level, adminId)
|
function admin.setPlayerLevel(clientId, level, adminId)
|
||||||
local playerid = db.getplayer(players.getGUID(clientId))["id"]
|
local playerid = db.getplayer(players.getGUID(clientId))["id"]
|
||||||
local adminid = db.getplayer(players.getGUID(clientId))["id"]
|
local adminid = db.getplayer(players.getGUID(clientId))["id"]
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local auth = require "luascripts.wolfadmin.auth.auth"
|
local auth = require "luascripts.wolfadmin.auth.auth"
|
||||||
|
|
||||||
|
local commands = require "luascripts.wolfadmin.commands.commands"
|
||||||
|
|
||||||
|
local teams = require "luascripts.wolfadmin.game.teams"
|
||||||
|
|
||||||
local util = require "luascripts.wolfadmin.util.util"
|
local util = require "luascripts.wolfadmin.util.util"
|
||||||
local constants = require "luascripts.wolfadmin.util.constants"
|
local constants = require "luascripts.wolfadmin.util.constants"
|
||||||
local commands = require "luascripts.wolfadmin.commands.commands"
|
|
||||||
local admin = require "luascripts.wolfadmin.admin.admin"
|
|
||||||
|
|
||||||
function commandLock(clientId, cmdArguments)
|
function commandLock(clientId, cmdArguments)
|
||||||
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
|
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
|
||||||
|
@ -27,15 +30,41 @@ function commandLock(clientId, cmdArguments)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cmdArguments[1] == "all" then
|
if cmdArguments[1] == "all" then
|
||||||
admin.lockTeam(constants.TEAM_AXIS)
|
teams.lock(constants.TEAM_AXIS)
|
||||||
admin.lockTeam(constants.TEAM_ALLIES)
|
teams.lock(constants.TEAM_ALLIES)
|
||||||
admin.lockTeam(constants.TEAM_SPECTATORS)
|
teams.lock(constants.TEAM_SPECTATORS)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
admin.lockTeam(util.getTeamFromCode(cmdArguments[1]))
|
teams.lock(util.getTeamFromCode(cmdArguments[1]))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
commands.addadmin("lock", commandLock, auth.PERM_LOCKTEAM, "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", true)
|
commands.addadmin("lock", commandLock, auth.PERM_LOCKTEAM, "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", true)
|
||||||
|
|
||||||
|
function commandLock(clientId, cmdArguments)
|
||||||
|
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dlock usage: "..commands.getadmin("lock")["syntax"].."\";")
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if cmdArguments[1] == "all" then
|
||||||
|
teams.lock(constants.TEAM_AXIS)
|
||||||
|
teams.lock(constants.TEAM_ALLIES)
|
||||||
|
teams.lock(constants.TEAM_SPECTATORS)
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: ^9all teams have been locked.\";")
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local team = util.getTeamFromCode(cmdArguments[1])
|
||||||
|
teams.lock(team)
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: "..util.getTeamColor(team).util.getTeamName(team).." ^9team has been locked.\";")
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
commands.addadmin("lock", commandLock, auth.PERM_LOCKTEAM, "lock one or all of the teams from players joining", "^9[^3r|b|s|all#^9]", (settings.get("g_standalone") == 0))
|
||||||
|
|
|
@ -16,10 +16,13 @@
|
||||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
local auth = require "luascripts.wolfadmin.auth.auth"
|
local auth = require "luascripts.wolfadmin.auth.auth"
|
||||||
|
|
||||||
|
local commands = require "luascripts.wolfadmin.commands.commands"
|
||||||
|
|
||||||
|
local teams = require "luascripts.wolfadmin.game.teams"
|
||||||
|
|
||||||
local util = require "luascripts.wolfadmin.util.util"
|
local util = require "luascripts.wolfadmin.util.util"
|
||||||
local constants = require "luascripts.wolfadmin.util.constants"
|
local constants = require "luascripts.wolfadmin.util.constants"
|
||||||
local commands = require "luascripts.wolfadmin.commands.commands"
|
|
||||||
local admin = require "luascripts.wolfadmin.admin.admin"
|
|
||||||
|
|
||||||
function commandUnlock(clientId, cmdArguments)
|
function commandUnlock(clientId, cmdArguments)
|
||||||
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
|
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
|
||||||
|
@ -27,15 +30,41 @@ function commandUnlock(clientId, cmdArguments)
|
||||||
end
|
end
|
||||||
|
|
||||||
if cmdArguments[1] == "all" then
|
if cmdArguments[1] == "all" then
|
||||||
admin.unlockTeam(constants.TEAM_AXIS)
|
teams.unlock(constants.TEAM_AXIS)
|
||||||
admin.unlockTeam(constants.TEAM_ALLIES)
|
teams.unlock(constants.TEAM_ALLIES)
|
||||||
admin.unlockTeam(constants.TEAM_SPECTATORS)
|
teams.unlock(constants.TEAM_SPECTATORS)
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
admin.unlockTeam(util.getTeamFromCode(cmdArguments[1]))
|
teams.unlock(util.getTeamFromCode(cmdArguments[1]))
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
commands.addadmin("unlock", commandUnlock, auth.PERM_LOCKTEAM, "unlock one or all locked teams", "^9[^3r|b|s|all#^9]", true)
|
commands.addadmin("unlock", commandUnlock, auth.PERM_LOCKTEAM, "unlock one or all locked teams", "^9[^3r|b|s|all#^9]", true)
|
||||||
|
|
||||||
|
function commandUnlock(clientId, cmdArguments)
|
||||||
|
if cmdArguments[1] == nil or (cmdArguments[1] ~= constants.TEAM_AXIS_SC and cmdArguments[1] ~= constants.TEAM_ALLIES_SC and cmdArguments[1] ~= constants.TEAM_SPECTATORS_SC and cmdArguments[1] ~= "all") then
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunlock usage: "..commands.getadmin("unlock")["syntax"].."\";")
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
if cmdArguments[1] == "all" then
|
||||||
|
teams.unlock(constants.TEAM_AXIS)
|
||||||
|
teams.unlock(constants.TEAM_ALLIES)
|
||||||
|
teams.unlock(constants.TEAM_SPECTATORS)
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: ^9all teams have been unlocked.\";")
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
local team = util.getTeamFromCode(cmdArguments[1])
|
||||||
|
teams.unlock(team)
|
||||||
|
|
||||||
|
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dlock: "..util.getTeamColor(team).util.getTeamName(team).." ^9team has been unlocked.\";")
|
||||||
|
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
commands.addadmin("unlock", commandUnlock, auth.PERM_LOCKTEAM, "unlock one or all locked teams", "^9[^3r|b|s|all#^9]", (settings.get("g_standalone") == 0))
|
||||||
|
|
|
@ -21,6 +21,8 @@ local admin = require "luascripts.wolfadmin.admin.admin"
|
||||||
|
|
||||||
local auth = require "luascripts.wolfadmin.auth.auth"
|
local auth = require "luascripts.wolfadmin.auth.auth"
|
||||||
|
|
||||||
|
local teams = require "luascripts.wolfadmin.game.teams"
|
||||||
|
|
||||||
local players = require "luascripts.wolfadmin.players.players"
|
local players = require "luascripts.wolfadmin.players.players"
|
||||||
|
|
||||||
local util = require "luascripts.wolfadmin.util.util"
|
local util = require "luascripts.wolfadmin.util.util"
|
||||||
|
@ -218,6 +220,16 @@ function commands.onclientcommand(clientId, cmdText)
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local team = util.getTeamFromCode(et.trap_Argv(1))
|
||||||
|
if teams.isLocked(team) then
|
||||||
|
local teamName = util.getTeamName(team)
|
||||||
|
local teamColor = util.getTeamColor(team)
|
||||||
|
|
||||||
|
et.trap_SendServerCommand(clientId, "cp \""..teamColor..teamName.." ^7team is locked")
|
||||||
|
|
||||||
|
return 1
|
||||||
|
end
|
||||||
elseif wolfCmd == "callvote" then
|
elseif wolfCmd == "callvote" then
|
||||||
local voteArguments = {}
|
local voteArguments = {}
|
||||||
for i = 2, et.trap_Argc() - 1 do
|
for i = 2, et.trap_Argc() - 1 do
|
||||||
|
|
|
@ -21,51 +21,69 @@ local events = require "luascripts.wolfadmin.util.events"
|
||||||
|
|
||||||
local teams = {}
|
local teams = {}
|
||||||
|
|
||||||
local data = {
|
local players = {
|
||||||
[constants.TEAM_AXIS] = {},
|
[constants.TEAM_AXIS] = {},
|
||||||
[constants.TEAM_ALLIES] = {},
|
[constants.TEAM_ALLIES] = {},
|
||||||
[constants.TEAM_SPECTATORS] = {}
|
[constants.TEAM_SPECTATORS] = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local locks = {
|
||||||
|
[constants.TEAM_AXIS] = false,
|
||||||
|
[constants.TEAM_ALLIES] = false,
|
||||||
|
[constants.TEAM_SPECTATORS] = false
|
||||||
|
}
|
||||||
|
|
||||||
function teams.get()
|
function teams.get()
|
||||||
return data
|
return players
|
||||||
end
|
end
|
||||||
|
|
||||||
function teams.count(team)
|
function teams.count(team)
|
||||||
return #data[team]
|
return #players[team]
|
||||||
end
|
end
|
||||||
|
|
||||||
function teams.difference()
|
function teams.difference()
|
||||||
return math.abs(teams.count(constants.TEAM_AXIS) - teams.count(constants.TEAM_ALLIES))
|
return math.abs(teams.count(constants.TEAM_AXIS) - teams.count(constants.TEAM_ALLIES))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function teams.lock(teamId)
|
||||||
|
locks[teamId] = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function teams.unlock(teamId)
|
||||||
|
locks[teamId] = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function teams.isLocked(teamId)
|
||||||
|
return locks[teamId]
|
||||||
|
end
|
||||||
|
|
||||||
function teams.onconnect(clientId, firstTime, isBot)
|
function teams.onconnect(clientId, firstTime, isBot)
|
||||||
local team = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
|
local team = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
|
||||||
|
|
||||||
if not tables.contains(data[team], clientId) then
|
if not tables.contains(players[team], clientId) then
|
||||||
table.insert(data[team], clientId)
|
table.insert(players[team], clientId)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
events.handle("onClientConnect", teams.onconnect)
|
events.handle("onClientConnect", teams.onconnect)
|
||||||
|
|
||||||
function teams.ondisconnect(clientId)
|
function teams.ondisconnect(clientId)
|
||||||
local team = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
|
local team = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
|
||||||
local idx = tables.find(data[team], clientId)
|
local idx = tables.find(players[team], clientId)
|
||||||
|
|
||||||
if idx then
|
if idx then
|
||||||
table.remove(data[team], idx)
|
table.remove(players[team], idx)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
events.handle("onClientDisconnect", teams.ondisconnect)
|
events.handle("onClientDisconnect", teams.ondisconnect)
|
||||||
|
|
||||||
function teams.onclientteamchange(clientId, old, new)
|
function teams.onclientteamchange(clientId, old, new)
|
||||||
local idx = tables.find(data[old], clientId)
|
local idx = tables.find(players[old], clientId)
|
||||||
|
|
||||||
if idx then
|
if idx then
|
||||||
table.remove(data[old], idx)
|
table.remove(players[old], idx)
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert(data[new], clientId)
|
table.insert(players[new], clientId)
|
||||||
end
|
end
|
||||||
events.handle("onClientTeamChange", teams.onclientteamchange)
|
events.handle("onClientTeamChange", teams.onclientteamchange)
|
||||||
|
|
||||||
|
|
|
@ -35,10 +35,17 @@ constants.TEAM_AXIS_SC = "r"
|
||||||
constants.TEAM_ALLIES_SC = "b"
|
constants.TEAM_ALLIES_SC = "b"
|
||||||
constants.TEAM_SPECTATORS_SC = "s"
|
constants.TEAM_SPECTATORS_SC = "s"
|
||||||
|
|
||||||
|
constants.TEAM_AXIS_NAME = "axis"
|
||||||
|
constants.TEAM_ALLIES_NAME = "allies"
|
||||||
|
constants.TEAM_SPECTATORS_NAME = "spectator"
|
||||||
|
|
||||||
constants.TEAM_AXIS_COLOR = "^1"
|
constants.TEAM_AXIS_COLOR = "^1"
|
||||||
constants.TEAM_ALLIES_COLOR = "^4"
|
constants.TEAM_ALLIES_COLOR = "^4"
|
||||||
constants.TEAM_SPECTATORS_COLOR = "^2"
|
constants.TEAM_SPECTATORS_COLOR = "^2"
|
||||||
|
|
||||||
|
constants.TEAM_AXIS_COLOR_NAME = "red"
|
||||||
|
constants.TEAM_ALLIES_COLOR_NAME = "blue"
|
||||||
|
|
||||||
constants.CLASS_SOLDIER = 0
|
constants.CLASS_SOLDIER = 0
|
||||||
constants.CLASS_MEDIC = 1
|
constants.CLASS_MEDIC = 1
|
||||||
constants.CLASS_ENGINEER = 2
|
constants.CLASS_ENGINEER = 2
|
||||||
|
|
|
@ -61,11 +61,11 @@ function util.getTeamName(teamId)
|
||||||
end
|
end
|
||||||
|
|
||||||
function util.getTeamFromCode(teamCode)
|
function util.getTeamFromCode(teamCode)
|
||||||
if teamCode == constants.TEAM_AXIS_SC then
|
if teamCode == constants.TEAM_AXIS_SC or teamCode == constants.TEAM_AXIS_NAME or teamCode == constants.TEAM_AXIS_COLOR_NAME then
|
||||||
return constants.TEAM_AXIS
|
return constants.TEAM_AXIS
|
||||||
elseif teamCode == constants.TEAM_ALLIES_SC then
|
elseif teamCode == constants.TEAM_ALLIES_SC or teamCode == constants.TEAM_ALLIES_NAME or teamCode == constants.TEAM_ALLIES_COLOR_NAME then
|
||||||
return constants.TEAM_ALLIES
|
return constants.TEAM_ALLIES
|
||||||
elseif teamCode == constants.TEAM_SPECTATORS_SC then
|
elseif teamCode == constants.TEAM_SPECTATORS_SC or teamCode == constants.TEAM_SPECTATORS_NAME then
|
||||||
return constants.TEAM_SPECTATORS
|
return constants.TEAM_SPECTATORS
|
||||||
else
|
else
|
||||||
return 0
|
return 0
|
||||||
|
|
Loading…
Reference in a new issue