Added timers to remove expired mutes and bans from database

This commit is contained in:
Timo Smit 2019-02-04 13:00:46 +01:00
parent d00d30b2ba
commit d8ef69a6da
4 changed files with 39 additions and 3 deletions

View file

@ -19,8 +19,13 @@ local db = wolfa_requireModule("db.db")
local players = wolfa_requireModule("players.players") local players = wolfa_requireModule("players.players")
local events = wolfa_requireModule("util.events")
local timers = wolfa_requireModule("util.timers")
local bans = {} local bans = {}
local storedBanTimer
function bans.get(banId) function bans.get(banId)
return db.getBan(banId) return db.getBan(banId)
end end
@ -48,4 +53,13 @@ function bans.remove(banId)
db.removeBan(banId) db.removeBan(banId)
end 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 return bans

View file

@ -24,7 +24,8 @@ local timers = wolfa_requireModule("util.timers")
local mutes = {} local mutes = {}
local muteTimer local storedMuteTimer
local liveMuteTimer
function mutes.get(muteId) function mutes.get(muteId)
return db.getMute(muteId) return db.getMute(muteId)
@ -64,7 +65,11 @@ function mutes.removeByClient(clientId)
end end
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 for clientId = 0, et.trap_Cvar_Get("sv_maxclients") - 1 do
if players.isMuted(clientId) and players.getMuteExpiresAt(clientId) < os.time() then if players.isMuted(clientId) and players.getMuteExpiresAt(clientId) < os.time() then
mutes.removeByClient(clientId) mutes.removeByClient(clientId)
@ -75,7 +80,8 @@ function mutes.checkUnmutes()
end end
function mutes.onInit() 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 end
events.handle("onGameInit", mutes.onInit) events.handle("onGameInit", mutes.onInit)

View file

@ -336,6 +336,10 @@ function mysql.removeMute(muteId)
cur = assert(con:execute("DELETE FROM `mute` WHERE `id`="..tonumber(muteId).."")) cur = assert(con:execute("DELETE FROM `mute` WHERE `id`="..tonumber(muteId)..""))
end end
function mysql.removeExpiredMutes()
cur = assert(con:execute("DELETE FROM `mute` WHERE `expires`<="..os.time()))
end
function mysql.getMutesCount() function mysql.getMutesCount()
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `mute`")) 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).."")) cur = assert(con:execute("DELETE FROM `ban` WHERE `id`="..tonumber(banId)..""))
end end
function mysql.removeExpiredBans()
cur = assert(con:execute("DELETE FROM `ban` WHERE `expires`<="..os.time()))
end
function mysql.getBansCount() function mysql.getBansCount()
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `ban`")) cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `ban`"))

View file

@ -336,6 +336,10 @@ function sqlite3.removeMute(muteId)
cur = assert(con:execute("DELETE FROM `mute` WHERE `id`="..tonumber(muteId).."")) cur = assert(con:execute("DELETE FROM `mute` WHERE `id`="..tonumber(muteId)..""))
end end
function sqlite3.removeExpiredMutes()
cur = assert(con:execute("DELETE FROM `mute` WHERE `expires`<="..os.time()))
end
function sqlite3.getMutesCount() function sqlite3.getMutesCount()
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `mute`")) 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).."")) cur = assert(con:execute("DELETE FROM `ban` WHERE `id`="..tonumber(banId)..""))
end end
function sqlite3.removeExpiredBans()
cur = assert(con:execute("DELETE FROM `ban` WHERE `expires`<="..os.time()))
end
function sqlite3.getBansCount() function sqlite3.getBansCount()
cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `ban`")) cur = assert(con:execute("SELECT COUNT(`id`) AS `count` FROM `ban`"))