/
mutes.lua
88 lines (64 loc) · 2.69 KB
/
mutes.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
-- Copyright (C) 2015-2019 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 = wolfa_requireModule("db.db")
local players = wolfa_requireModule("players.players")
local events = wolfa_requireModule("util.events")
local timers = wolfa_requireModule("util.timers")
local mutes = {}
local storedMuteTimer
local liveMuteTimer
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.checkStoredMutes()
db.removeExpiredMutes()
end
function mutes.checkLiveMutes()
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, "cchat -1 \"^dunmute: ^7"..et.gentity_get(clientId, "pers.netname").." ^9has been automatically unmuted\";")
end
end
end
function mutes.onInit()
storedMuteTimer = timers.add(mutes.checkStoredMutes, 60000, 0, false, false)
liveMuteTimer = timers.add(mutes.checkLiveMutes, 1000, 0, false, false)
end
events.handle("onGameInit", mutes.onInit)
return mutes