(Re-)implemented muting and player locking

This commit is contained in:
Timo Smit 2016-09-07 18:52:48 +02:00
parent 5ea4fc90e4
commit 03b18f9c0a
9 changed files with 197 additions and 76 deletions

View file

@ -33,38 +33,6 @@ local teamLocks = {
[constants.TEAM_SPECTATORS] = false, [constants.TEAM_SPECTATORS] = false,
} }
function admin.isPlayerMuted(clientId)
-- return players.isPlayerMuted(clientId)
end
function admin.mutePlayer(clientId, length)
--
end
function admin.unmutePlayer(clientId)
--
end
function admin.isVoiceMuted(clientId)
if stats.get(clientId, "voiceMute") then
if stats.get(clientId, "voiceMute") - os.time() > 0 then
return true
else
admin.unmuteVoice(clientId)
end
end
return false
end
function admin.muteVoice(clientId, length)
stats.set(clientId, "voiceMute", length)
end
function admin.unmuteVoice(clientId)
stats.set(clientId, "voiceMute", false)
end
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
@ -77,22 +45,6 @@ function admin.unlockTeam(teamId)
teamLocks[teamId] = false teamLocks[teamId] = false
end end
function admin.isPlayerLocked(clientId)
if stats.get(clientId, "teamLock") then
return true
end
return false
end
function admin.lockPlayer(clientId)
stats.set(clientId, "teamLock", true)
end
function admin.unlockPlayer(clientId)
stats.set(clientId, "teamLock", 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"]

View file

@ -0,0 +1,82 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2016 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local commands = require "luascripts.wolfadmin.commands.commands"
local players = require "luascripts.wolfadmin.players.players"
local util = require "luascripts.wolfadmin.util.util"
function commandMute(clientId, cmdArguments)
if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute usage: "..commands.getadmin("mute")["syntax"].."\";")
return true
elseif tonumber(cmdArguments[1]) == nil then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
else
cmdClient = tonumber(cmdArguments[1])
end
if cmdClient == -1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^9no connected player by that name or slot #\";")
return true
end
local muteTime, muteReason = 600, "muted by admin"
if cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) and cmdArguments[3] then
muteTime = util.getTimeFromString(cmdArguments[2])
muteReason = table.concat(cmdArguments, " ", 3)
elseif cmdArguments[2] and util.getTimeFromString(cmdArguments[2]) then
muteTime = util.getTimeFromString(cmdArguments[2])
elseif cmdArguments[2] then
muteReason = table.concat(cmdArguments, " ", 2)
elseif auth.isallowed(clientId, "8") ~= 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute usage: "..commands.getadmin("mute")["syntax"].."\";")
return true
end
if players.isPlayerMuted(cmdClient) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
return true
elseif auth.isallowed(cmdClient, "!") == 1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is immune to this command.\";")
return true
elseif auth.getlevel(cmdClient) > auth.getlevel(clientId) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dmute: ^9sorry, but your intended victim has a higher admin level than you do.\";")
return true
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been muted for "..muteTime.." seconds\";")
players.setPlayerMuted(cmdClient, true, players.MUTE_CHAT + players.MUTE_VOICE, os.time(), muteTime)
return true
end
commands.addadmin("mute", commandMute, auth.PERM_MUTE, "voicemutes a player", "^9[^3name|slot#^9]")

View file

@ -16,11 +16,14 @@
-- 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 util = require "luascripts.wolfadmin.util.util"
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local admin = require "luascripts.wolfadmin.admin.admin"
local players = require "luascripts.wolfadmin.players.players"
local stats = require "luascripts.wolfadmin.players.stats" local stats = require "luascripts.wolfadmin.players.stats"
local util = require "luascripts.wolfadmin.util.util"
function commandPlayerLock(clientId, cmdArguments) function commandPlayerLock(clientId, cmdArguments)
if cmdArguments[1] == nil then if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock usage: "..commands.getadmin("plock")["syntax"].."\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock usage: "..commands.getadmin("plock")["syntax"].."\";")
@ -42,7 +45,7 @@ function commandPlayerLock(clientId, cmdArguments)
return true return true
end end
if admin.isPlayerLocked(cmdClient) then if players.isPlayerTeamLocked(cmdClient) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already locked to a team.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already locked to a team.\";")
return true return true
@ -58,7 +61,7 @@ function commandPlayerLock(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been locked to his team\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dplock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been locked to his team\";")
admin.lockPlayer(cmdClient) players.setPlayerTeamLocked(cmdClient, true)
return true return true
end end

View file

@ -16,11 +16,14 @@
-- 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 util = require "luascripts.wolfadmin.util.util"
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local admin = require "luascripts.wolfadmin.admin.admin"
local players = require "luascripts.wolfadmin.players.players"
local stats = require "luascripts.wolfadmin.players.stats" local stats = require "luascripts.wolfadmin.players.stats"
local util = require "luascripts.wolfadmin.util.util"
function commandPlayerUnlock(clientId, cmdArguments) function commandPlayerUnlock(clientId, cmdArguments)
if cmdArguments[1] == nil then if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock usage: "..commands.getadmin("punlock")["syntax"].."\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock usage: "..commands.getadmin("punlock")["syntax"].."\";")
@ -42,7 +45,7 @@ function commandPlayerUnlock(clientId, cmdArguments)
return true return true
end end
if not admin.isPlayerLocked(cmdClient) then if not players.isPlayerTeamLocked(cmdClient) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock: ^9no player by that name or slot # is locked to a team\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock: ^9no player by that name or slot # is locked to a team\";")
return true return true
@ -50,7 +53,7 @@ function commandPlayerUnlock(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dpunlock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unlocked from his team\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dpunlock: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unlocked from his team\";")
admin.unlockPlayer(cmdClient) players.setPlayerTeamLocked(cmdClient, false)
return true return true
end end

View file

@ -0,0 +1,57 @@
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2016 Timo 'Timothy' Smit
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local commands = require "luascripts.wolfadmin.commands.commands"
local players = require "luascripts.wolfadmin.players.players"
function commandUnmute(clientId, cmdArguments)
if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunmute usage: "..commands.getadmin("unmute")["syntax"].."\";")
return true
elseif tonumber(cmdArguments[1]) == nil then
cmdClient = et.ClientNumberFromString(cmdArguments[1])
else
cmdClient = tonumber(cmdArguments[1])
end
if cmdClient == -1 then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunmute: ^9no or multiple matches for '^7"..cmdArguments[1].."^9'.\";")
return true
elseif not et.gentity_get(cmdClient, "pers.netname") then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunmute: ^9no connected player by that name or slot #\";")
return true
end
if not players.isPlayerMuted(cmdClient) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dunmute: ^9no player by that name or slot # is muted\";")
return true
end
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unmuted\";")
players.setPlayerMuted(cmdClient, false)
return true
end
commands.addadmin("unmute", commandUnmute, auth.PERM_MUTE, "unvoicemutes a player", "^9[^3name|slot#^9]")

View file

@ -16,9 +16,12 @@
-- 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 util = require "luascripts.wolfadmin.util.util"
local commands = require "luascripts.wolfadmin.commands.commands" local commands = require "luascripts.wolfadmin.commands.commands"
local admin = require "luascripts.wolfadmin.admin.admin"
local players = require "luascripts.wolfadmin.players.players"
local util = require "luascripts.wolfadmin.util.util"
function commandVoiceMute(clientId, cmdArguments) function commandVoiceMute(clientId, cmdArguments)
if cmdArguments[1] == nil then if cmdArguments[1] == nil then
@ -56,7 +59,7 @@ function commandVoiceMute(clientId, cmdArguments)
return true return true
end end
if admin.isVoiceMuted(cmdClient) then if players.isPlayerMuted(cmdClient) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9is already muted.\";")
return true return true
@ -72,7 +75,7 @@ function commandVoiceMute(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been voicemuted for "..vmuteTime.." seconds\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been voicemuted for "..vmuteTime.." seconds\";")
admin.muteVoice(cmdClient, os.time() + vmuteTime) players.setPlayerMuted(cmdClient, true, players.MUTE_VOICE, os.time(), vmuteTime)
return true return true
end end

View file

@ -16,8 +16,10 @@
-- 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 commands = require "luascripts.wolfadmin.commands.commands"
local admin = require "luascripts.wolfadmin.admin.admin"
local players = require "luascripts.wolfadmin.players.players"
function commandVoiceUnmute(clientId, cmdArguments) function commandVoiceUnmute(clientId, cmdArguments)
if cmdArguments[1] == nil then if cmdArguments[1] == nil then
@ -40,7 +42,7 @@ function commandVoiceUnmute(clientId, cmdArguments)
return true return true
end end
if not admin.isVoiceMuted(cmdClient) then if not players.isPlayerMuted(cmdClient) then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvunmute: ^9no player by that name or slot # is voicemuted\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dvunmute: ^9no player by that name or slot # is voicemuted\";")
return true return true
@ -48,7 +50,7 @@ function commandVoiceUnmute(clientId, cmdArguments)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unvoicemuted\";") et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dvunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unvoicemuted\";")
admin.unmuteVoice(cmdClient) players.setPlayerMuted(cmdClient, false)
return true return true
end end

View file

@ -210,7 +210,7 @@ function commands.onclientcommand(clientId, cmdText)
-- all Wolfenstein-related commands defined separately for now -- all Wolfenstein-related commands defined separately for now
if wolfCmd == "team" then if wolfCmd == "team" then
if admin.isPlayerLocked(clientId) then if players.isPlayerTeamLocked(clientId) then
local clientTeam = tonumber(et.gentity_get(clientId, "sess.sessionTeam")) local clientTeam = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
local teamName = util.getTeamName(clientTeam) local teamName = util.getTeamName(clientTeam)
local teamColor = util.getTeamColor(clientTeam) local teamColor = util.getTeamColor(clientTeam)
@ -231,13 +231,13 @@ function commands.onclientcommand(clientId, cmdText)
return events.trigger("onCallvote", clientId, et.trap_Argv(1), voteArguments) return events.trigger("onCallvote", clientId, et.trap_Argv(1), voteArguments)
elseif wolfCmd == "say" or wolfCmd == "say_team" or wolfCmd == "say_teamnl" or wolfCmd == "say_buddy" then elseif wolfCmd == "say" or wolfCmd == "say_team" or wolfCmd == "say_teamnl" or wolfCmd == "say_buddy" then
if et.gentity_get(clientId, "sess.muted") == 1 then if players.isPlayerMuted(clientId, players.MUTE_CHAT) then
et.trap_SendServerCommand(clientId, "cp \"^1You are muted\"") et.trap_SendServerCommand(clientId, "cp \"^1You are muted\"")
return 1 return 1
end end
elseif wolfCmd == "vsay" or wolfCmd == "vsay_team" then elseif wolfCmd == "vsay" or wolfCmd == "vsay_team" then
if admin.isVoiceMuted(clientId) then if players.isPlayerMuted(clientId, players.MUTE_VOICE) then
et.trap_SendServerCommand(clientId, "cp \"^1You are voicemuted\"") et.trap_SendServerCommand(clientId, "cp \"^1You are voicemuted\"")
return 1 return 1

View file

@ -17,10 +17,14 @@
local db = require "luascripts.wolfadmin.db.db" local db = require "luascripts.wolfadmin.db.db"
local bits = require "luascripts.wolfadmin.util.bits"
local events = require "luascripts.wolfadmin.util.events" local events = require "luascripts.wolfadmin.util.events"
local players = {} local players = {}
players.MUTE_CHAT = 1
players.MUTE_VOICE = 2
local data = {} local data = {}
function players.isConnected(clientId) function players.isConnected(clientId)
@ -47,25 +51,40 @@ function players.isBot(clientId)
return data[clientId]["bot"] return data[clientId]["bot"]
end end
function players.setPlayerMuted(clientId, state, type, duration) function players.setPlayerMuted(clientId, state, type, issued, expires)
data[clientId]["mute"] = state data[clientId]["mute"] = nil
if state == true then if state == true then
data[clientId]["mutetype"] = type data[clientId]["mute"] = {
data[clientId]["muteduration"] = duration ["type"] = type,
["issued"] = issued,
["expires"] = expires
}
end end
end end
function players.isPlayerMuted(clientId) function players.isPlayerMuted(clientId, type)
return data[clientId]["mute"] if type == nil then
return data[clientId]["mute"] ~= nil
elseif type == players.MUTE_CHAT then
return data[clientId]["mute"] ~= nil and bits.hasbit(data[clientId]["mute"]["type"], players.MUTE_CHAT)
elseif type == players.MUTE_VOICE then
return data[clientId]["mute"] ~= nil and bits.hasbit(data[clientId]["mute"]["type"], players.MUTE_VOICE)
end
return false
end end
function players.getPlayerMuteType(clientId, state, type, duration) function players.getPlayerMuteType(clientId)
return data[clientId]["mutetype"] return data[clientId]["mute"]["type"]
end end
function players.getPlayerMuteDuration(clientId, state, type, duration) function players.getPlayerMuteIssuedAt(clientId)
return data[clientId]["muteduration"] return data[clientId]["mute"]["issued"]
end
function players.getPlayerMuteExpiresAt(clientId)
return data[clientId]["mute"]["expires"]
end end
function players.setPlayerTeamLocked(clientId, state) function players.setPlayerTeamLocked(clientId, state)