(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,
}
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)
et.trap_SendConsoleCommand(et.EXEC_APPEND, "forceteam "..clientId.." "..util.getTeamCode(teamId)..";")
end
@ -77,22 +45,6 @@ function admin.unlockTeam(teamId)
teamLocks[teamId] = false
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)
local playerid = 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/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local util = require "luascripts.wolfadmin.util.util"
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 util = require "luascripts.wolfadmin.util.util"
function commandPlayerLock(clientId, cmdArguments)
if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dplock usage: "..commands.getadmin("plock")["syntax"].."\";")
@ -42,7 +45,7 @@ function commandPlayerLock(clientId, cmdArguments)
return true
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.\";")
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\";")
admin.lockPlayer(cmdClient)
players.setPlayerTeamLocked(cmdClient, true)
return true
end

View file

@ -16,11 +16,14 @@
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local util = require "luascripts.wolfadmin.util.util"
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 util = require "luascripts.wolfadmin.util.util"
function commandPlayerUnlock(clientId, cmdArguments)
if cmdArguments[1] == nil then
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay "..clientId.." \"^dpunlock usage: "..commands.getadmin("punlock")["syntax"].."\";")
@ -42,7 +45,7 @@ function commandPlayerUnlock(clientId, cmdArguments)
return true
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\";")
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\";")
admin.unlockPlayer(cmdClient)
players.setPlayerTeamLocked(cmdClient, false)
return true
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/>.
local auth = require "luascripts.wolfadmin.auth.auth"
local util = require "luascripts.wolfadmin.util.util"
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)
if cmdArguments[1] == nil then
@ -56,7 +59,7 @@ function commandVoiceMute(clientId, cmdArguments)
return true
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.\";")
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\";")
admin.muteVoice(cmdClient, os.time() + vmuteTime)
players.setPlayerMuted(cmdClient, true, players.MUTE_VOICE, os.time(), vmuteTime)
return true
end

View file

@ -16,8 +16,10 @@
-- 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 admin = require "luascripts.wolfadmin.admin.admin"
local players = require "luascripts.wolfadmin.players.players"
function commandVoiceUnmute(clientId, cmdArguments)
if cmdArguments[1] == nil then
@ -40,7 +42,7 @@ function commandVoiceUnmute(clientId, cmdArguments)
return true
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\";")
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\";")
admin.unmuteVoice(cmdClient)
players.setPlayerMuted(cmdClient, false)
return true
end

View file

@ -210,7 +210,7 @@ function commands.onclientcommand(clientId, cmdText)
-- all Wolfenstein-related commands defined separately for now
if wolfCmd == "team" then
if admin.isPlayerLocked(clientId) then
if players.isPlayerTeamLocked(clientId) then
local clientTeam = tonumber(et.gentity_get(clientId, "sess.sessionTeam"))
local teamName = util.getTeamName(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)
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\"")
return 1
end
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\"")
return 1

View file

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