From a3df29ba4902da2dd0e2dea1c8a9469ced629804 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Wed, 19 Feb 2020 08:24:40 +0000 Subject: Extract time skip warning code to a static function. --- src/inspircd.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/inspircd.cpp b/src/inspircd.cpp index e2d3f8dff..4d4c9a6ea 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -135,6 +135,21 @@ namespace #endif } + // Checks whether the server clock has skipped too much and warn about it if it has. + void CheckTimeSkip(time_t oldtime, time_t newtime) + { + if (!ServerInstance->Config->TimeSkipWarn) + return; + + time_t timediff = oldtime - newtime; + + if (timediff > ServerInstance->Config->TimeSkipWarn) + ServerInstance->SNO->WriteToSnoMask('a', "\002Performance warning!\002 Server clock jumped forwards by %lu seconds!", timediff); + + else if (timediff < -ServerInstance->Config->TimeSkipWarn) + ServerInstance->SNO->WriteToSnoMask('a', "\002Performance warning!\002 Server clock jumped backwards by %lu seconds!", labs(timediff)); + } + // Drops to the unprivileged user/group specified in . void DropRoot() { @@ -667,17 +682,7 @@ void InspIRCd::Run() if (TIME.tv_sec != OLDTIME) { CollectStats(); - - if (Config->TimeSkipWarn) - { - time_t timediff = TIME.tv_sec - OLDTIME; - - if (timediff > Config->TimeSkipWarn) - SNO->WriteToSnoMask('a', "\002Performance warning!\002 Server clock jumped forwards by %lu seconds!", timediff); - - else if (timediff < -Config->TimeSkipWarn) - SNO->WriteToSnoMask('a', "\002Performance warning!\002 Server clock jumped backwards by %lu seconds!", labs(timediff)); - } + CheckTimeSkip(OLDTIME, TIME.tv_sec); OLDTIME = TIME.tv_sec; -- cgit v1.2.3