mirror of
https://github.com/etlegacy/wolfadmin.git
synced 2024-11-10 06:41:53 +00:00
Added timers to remove expired mutes and bans from database
This commit is contained in:
parent
d00d30b2ba
commit
d8ef69a6da
4 changed files with 39 additions and 3 deletions
|
@ -19,8 +19,13 @@ 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 bans = {}
|
||||
|
||||
local storedBanTimer
|
||||
|
||||
function bans.get(banId)
|
||||
return db.getBan(banId)
|
||||
end
|
||||
|
@ -48,4 +53,13 @@ function bans.remove(banId)
|
|||
db.removeBan(banId)
|
||||
end
|
||||
|
||||
function bans.checkStoredBans()
|
||||
db.removeExpiredBans()
|
||||
end
|
||||
|
||||
function bans.onInit()
|
||||
storedBanTimer = timers.add(bans.checkStoredBans, 60000, 0, false, false)
|
||||
end
|
||||
events.handle("onGameInit", bans.onInit)
|
||||
|
||||
return bans
|
||||
|
|
|
@ -24,7 +24,8 @@ local timers = wolfa_requireModule("util.timers")
|
|||
|
||||
local mutes = {}
|
||||
|
||||
local muteTimer
|
||||
local storedMuteTimer
|
||||
local liveMuteTimer
|
||||
|
||||
function mutes.get(muteId)
|
||||
return db.getMute(muteId)
|
||||
|
@ -64,7 +65,11 @@ function mutes.removeByClient(clientId)
|
|||
end
|
||||
end
|
||||
|
||||
function mutes.checkUnmutes()
|
||||
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)
|
||||
|
@ -75,7 +80,8 @@ function mutes.checkUnmutes()
|
|||
end
|
||||
|
||||
function mutes.onInit()
|
||||
muteTimer = timers.add(mutes.checkUnmutes, 1000, 0, false, false)
|
||||
storedMuteTimer = timers.add(mutes.checkStoredMutes, 60000, 0, false, false)
|
||||
liveMuteTimer = timers.add(mutes.checkLiveMutes, 1000, 0, false, false)
|
||||
end
|
||||
events.handle("onGameInit", mutes.onInit)
|
||||
|
||||
|
|
|
@ -336,6 +336,10 @@ function mysql.removeMute(muteId)
|
|||
cur = assert(con:execute("DELETE FROM `mute` WHERE `id`="..tonumber(muteId)..""))
|
||||
end
|
||||
|
||||
function mysql.removeExpiredMutes()
|
||||
cur = assert(con:execute("DELETE FROM `mute` WHERE `expires`<="..os.time()))
|
||||
end
|
||||
|
||||
function mysql.getMutesCount()
|
||||
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `mute`"))
|
||||
|
||||
|
@ -391,6 +395,10 @@ function mysql.removeBan(banId)
|
|||
cur = assert(con:execute("DELETE FROM `ban` WHERE `id`="..tonumber(banId)..""))
|
||||
end
|
||||
|
||||
function mysql.removeExpiredBans()
|
||||
cur = assert(con:execute("DELETE FROM `ban` WHERE `expires`<="..os.time()))
|
||||
end
|
||||
|
||||
function mysql.getBansCount()
|
||||
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `ban`"))
|
||||
|
||||
|
|
|
@ -336,6 +336,10 @@ function sqlite3.removeMute(muteId)
|
|||
cur = assert(con:execute("DELETE FROM `mute` WHERE `id`="..tonumber(muteId)..""))
|
||||
end
|
||||
|
||||
function sqlite3.removeExpiredMutes()
|
||||
cur = assert(con:execute("DELETE FROM `mute` WHERE `expires`<="..os.time()))
|
||||
end
|
||||
|
||||
function sqlite3.getMutesCount()
|
||||
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `mute`"))
|
||||
|
||||
|
@ -391,6 +395,10 @@ function sqlite3.removeBan(banId)
|
|||
cur = assert(con:execute("DELETE FROM `ban` WHERE `id`="..tonumber(banId)..""))
|
||||
end
|
||||
|
||||
function sqlite3.removeExpiredBans()
|
||||
cur = assert(con:execute("DELETE FROM `ban` WHERE `expires`<="..os.time()))
|
||||
end
|
||||
|
||||
function sqlite3.getBansCount()
|
||||
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `ban`"))
|
||||
|
||||
|
|
Loading…
Reference in a new issue