mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-10 06:41:53 +00:00
Load mutes from database and apply to online players (issue #55)
This commit is contained in:
parent
f8ec599932
commit
c9889d4598
8 changed files with 112 additions and 18 deletions
|
@ -32,14 +32,6 @@ function admin.putPlayer(clientId, teamId)
|
|||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "forceteam "..clientId.." "..util.getTeamCode(teamId)..";")
|
||||
end
|
||||
|
||||
function admin.mutePlayer(victimId, invokerId, type, duration, reason)
|
||||
players.setMuted(victimId, true, type, os.time(), duration)
|
||||
db.addMute(victimId, invokerId, type, os.time(), duration, reason)
|
||||
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "ccp "..victimId.." \"^7You have been muted by "..players.getName(invokerId)..": ^7"..reason..".\";")
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "csay -1 \"^dmute: ^7"..players.getName(victimId).." ^9has been muted.\";")
|
||||
end
|
||||
|
||||
function admin.kickPlayer(victimId, invokerId, reason)
|
||||
et.trap_DropClient(victimId, "You have been kicked, Reason: "..(reason and reason or "kicked by admin"), 0)
|
||||
end
|
||||
|
@ -76,6 +68,14 @@ function admin.onconnect(clientId, firstTime, isBot)
|
|||
-- clientbegin which is also triggered on warmup/maprestart/etc)
|
||||
--[[ stats.set(clientId, "namechangeStart", os.time())
|
||||
stats.set(clientId, "namechangePts", 0) ]]
|
||||
|
||||
local guid = et.Info_ValueForKey(et.trap_GetUserinfo(clientId), "cl_guid")
|
||||
local playerId = db.getplayer(guid)["id"]
|
||||
local mute = db.getMuteByPlayer(playerId)
|
||||
|
||||
if mute then
|
||||
players.setMuted(clientId, true, mute["type"], mute["issued"], mute["expires"])
|
||||
end
|
||||
end
|
||||
events.handle("onClientConnect", admin.onconnect)
|
||||
|
||||
|
|
82
luascripts/admin/mutes.lua
Normal file
82
luascripts/admin/mutes.lua
Normal file
|
@ -0,0 +1,82 @@
|
|||
|
||||
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
|
||||
-- Copyright (C) 2015-2017 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 db = require "luascripts.wolfadmin.db.db"
|
||||
|
||||
local players = require "luascripts.wolfadmin.players.players"
|
||||
|
||||
local events = require "luascripts.wolfadmin.util.events"
|
||||
local timers = require "luascripts.wolfadmin.util.timers"
|
||||
|
||||
local mutes = {}
|
||||
|
||||
local muteTimer
|
||||
|
||||
function mutes.get(muteId)
|
||||
return db.getMute(muteId)
|
||||
end
|
||||
|
||||
function mutes.getCount()
|
||||
return db.getMutesCount()
|
||||
end
|
||||
|
||||
function mutes.getList(start, limit)
|
||||
return db.getMutes(start, limit)
|
||||
end
|
||||
|
||||
function mutes.add(victimId, invokerId, type, duration, reason)
|
||||
local victimPlayerId = db.getplayer(players.getGUID(victimId))["id"]
|
||||
local invokerPlayerId = db.getplayer(players.getGUID(invokerId))["id"]
|
||||
|
||||
local reason = reason and reason or "muted by admin"
|
||||
|
||||
players.setMuted(victimId, true, type, os.time(), os.time() + duration)
|
||||
db.addMute(victimPlayerId, invokerPlayerId, type, os.time(), duration, reason)
|
||||
end
|
||||
|
||||
function mutes.remove(muteId)
|
||||
db.removeMute(muteId)
|
||||
end
|
||||
|
||||
function mutes.removeByClient(clientId)
|
||||
players.setMuted(clientId, false)
|
||||
|
||||
local guid = et.Info_ValueForKey(et.trap_GetUserinfo(clientId), "cl_guid")
|
||||
local playerId = db.getplayer(guid)["id"]
|
||||
local mute = db.getMuteByPlayer(playerId)
|
||||
|
||||
if mute then
|
||||
return mutes.remove(mute["id"])
|
||||
end
|
||||
end
|
||||
|
||||
function mutes.checkUnmutes()
|
||||
for clientId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
|
||||
if players.isMuted(clientId) and players.getMuteExpiresAt(clientId) < os.time() then
|
||||
mutes.removeByClient(clientId)
|
||||
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been automatically unmuted\";")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function mutes.onInit()
|
||||
muteTimer = timers.add(mutes.checkUnmutes, 1000, 0, false, false)
|
||||
end
|
||||
events.handle("onGameInit", mutes.onInit)
|
||||
|
||||
return mutes
|
|
@ -19,6 +19,7 @@ local auth = require "luascripts.wolfadmin.auth.auth"
|
|||
|
||||
local admin = require "luascripts.wolfadmin.admin.admin"
|
||||
local history = require "luascripts.wolfadmin.admin.history"
|
||||
local mutes = require "luascripts.wolfadmin.admin.mutes"
|
||||
|
||||
local commands = require "luascripts.wolfadmin.commands.commands"
|
||||
|
||||
|
@ -77,7 +78,7 @@ function commandMute(clientId, cmdArguments)
|
|||
return true
|
||||
end
|
||||
|
||||
admin.mutePlayer(cmdClient, clientId, players.MUTE_CHAT + players.MUTE_VOICE, duration, reason)
|
||||
mutes.add(cmdClient, clientId, players.MUTE_CHAT + players.MUTE_VOICE, duration, reason)
|
||||
history.add(cmdClient, clientId, "mute", reason)
|
||||
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been muted for "..duration.." seconds\";")
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
|
||||
local auth = require "luascripts.wolfadmin.auth.auth"
|
||||
|
||||
local mutes = require "luascripts.wolfadmin.admin.mutes"
|
||||
|
||||
local commands = require "luascripts.wolfadmin.commands.commands"
|
||||
|
||||
local players = require "luascripts.wolfadmin.players.players"
|
||||
|
@ -52,7 +54,7 @@ function commandUnmute(clientId, cmdArguments)
|
|||
|
||||
et.trap_SendConsoleCommand(et.EXEC_APPEND, "chat \"^dunmute: ^7"..et.gentity_get(cmdClient, "pers.netname").." ^9has been unmuted\";")
|
||||
|
||||
players.setMuted(cmdClient, false)
|
||||
mutes.removeByClient(cmdClient)
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
|
||||
local auth = require "luascripts.wolfadmin.auth.auth"
|
||||
|
||||
local admin = require "luascripts.wolfadmin.admin.admin"
|
||||
local history = require "luascripts.wolfadmin.admin.history"
|
||||
local mutes = require "luascripts.wolfadmin.admin.mutes"
|
||||
|
||||
local commands = require "luascripts.wolfadmin.commands.commands"
|
||||
|
||||
|
@ -76,10 +76,10 @@ function commandVoiceMute(clientId, cmdArguments)
|
|||
return true
|
||||
end
|
||||
|
||||
admin.mutePlayer(cmdClient, clientId, players.MUTE_VOICE, duration, reason)
|
||||
history.add(cmdClient, clientId, "mute", reason)
|
||||
mutes.add(cmdClient, clientId, players.MUTE_VOICE, duration, reason)
|
||||
history.add(cmdClient, clientId, "vmute", reason)
|
||||
|
||||
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 "..duration.." seconds\";")
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -50,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\";")
|
||||
|
||||
players.setMuted(cmdClient, false)
|
||||
mutes.removeByClient(cmdClient)
|
||||
|
||||
return true
|
||||
end
|
||||
|
|
|
@ -296,6 +296,15 @@ function sqlite3.getMute(muteId)
|
|||
return mute
|
||||
end
|
||||
|
||||
function sqlite3.getMuteByPlayer(playerId)
|
||||
cur = assert(con:execute("SELECT * FROM `mute` WHERE `victim_id`="..tonumber(playerId).." AND `expires`>"..os.time()))
|
||||
|
||||
local mute = cur:fetch({}, "a")
|
||||
cur:close()
|
||||
|
||||
return mute
|
||||
end
|
||||
|
||||
-- bans
|
||||
function sqlite3.addBan(victimId, invokerId, issued, duration, reason)
|
||||
cur = assert(con:execute("INSERT INTO `ban` (`victim_id`, `invoker_id`, `issued`, `expires`, `duration`, `reason`) VALUES ("..tonumber(victimId)..", "..tonumber(invokerId)..", "..tonumber(issued)..", "..(tonumber(issued) + tonumber(duration))..", "..tonumber(duration)..", '"..util.escape(reason).."')"))
|
||||
|
|
|
@ -85,11 +85,11 @@ end
|
|||
|
||||
function players.isMuted(clientId, type)
|
||||
if type == nil then
|
||||
return data[clientId]["mute"] ~= nil
|
||||
return data[clientId] ~= nil and 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)
|
||||
return data[clientId] ~= nil and 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)
|
||||
return data[clientId] ~= nil and data[clientId]["mute"] ~= nil and bits.hasbit(data[clientId]["mute"]["type"], players.MUTE_VOICE)
|
||||
end
|
||||
|
||||
return false
|
||||
|
|
Loading…
Reference in a new issue