From f12b590a6db310c5111b68c6e79ecfb11971b3f7 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 2 May 2026 14:34:17 +0100 Subject: [PATCH] Change Timer::Tick to return bool, get rid of the repeating field. --- include/modules/dns.h | 3 ++- include/timers.h | 17 +++-------------- modules/botserv/bs_kick.cpp | 5 +++-- modules/botserv/bs_set.cpp | 3 ++- modules/chanserv/chanserv.cpp | 6 ++++-- modules/chanserv/cs_ban.cpp | 4 +++- modules/dns.cpp | 8 +++++--- modules/httpd.cpp | 5 +++-- modules/nickserv/nickserv.cpp | 13 ++++++++----- modules/nickserv/ns_sasl.cpp | 5 +++-- modules/operserv/os_defcon.cpp | 3 ++- modules/proxyscan.cpp | 5 +++-- src/main.cpp | 10 ++++++---- src/timers.cpp | 15 +++------------ src/uplink.cpp | 3 ++- 15 files changed, 52 insertions(+), 53 deletions(-) diff --git a/include/modules/dns.h b/include/modules/dns.h index 5f050a9a5..f470c2437 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -194,12 +194,13 @@ namespace DNS /** Used to time out the query, xalls OnError and lets the TimerManager * delete this request. */ - void Tick() override + bool Tick() override { Log(LOG_DEBUG_2) << "Resolver: timeout for query " << this->name; Query rr(*this); rr.error = ERROR_TIMEDOUT; this->OnError(&rr); + return false; } }; diff --git a/include/timers.h b/include/timers.h index f389447fc..3a7c5fadf 100644 --- a/include/timers.h +++ b/include/timers.h @@ -31,23 +31,17 @@ private: */ time_t secs; - /** True if this is a repeating timer - */ - bool repeat; - public: /** Constructor, initializes the triggering time * @param time_from_now The number of seconds from now to trigger the timer - * @param repeating Repeat this timer every time_from_now if this is true */ - Timer(time_t time_from_now, bool repeating = false); + Timer(time_t time_from_now); /** Constructor, initializes the triggering time * @param creator The creator of the timer * @param time_from_now The number of seconds from now to trigger the timer - * @param repeating Repeat this timer every time_from_now if this is true */ - Timer(Module *creator, time_t time_from_now, bool repeating = false); + Timer(Module *creator, time_t time_from_now); /** Destructor, removes the timer from the list */ @@ -63,11 +57,6 @@ public: */ time_t GetTimer() const; - /** Returns true if the timer is set to repeat - * @return Returns true if the timer is set to repeat - */ - bool GetRepeat() const; - /** Set the interval between ticks * @paramt t The new interval */ @@ -86,7 +75,7 @@ public: /** Called when the timer ticks * This should be overridden with something useful */ - virtual void Tick() = 0; + virtual bool Tick() = 0; }; /** This class manages sets of Timers, and triggers them at their defined times. diff --git a/modules/botserv/bs_kick.cpp b/modules/botserv/bs_kick.cpp index 5e52d25ae..ced42c8a2 100644 --- a/modules/botserv/bs_kick.cpp +++ b/modules/botserv/bs_kick.cpp @@ -1030,11 +1030,11 @@ class BanDataPurger final { public: BanDataPurger(Module *o) - : Timer(o, 300, true) + : Timer(o, 300) { } - void Tick() override + bool Tick() override { Log(LOG_DEBUG) << "bs_main: Running bandata purger"; @@ -1048,6 +1048,7 @@ public: c->Shrink("bandata"); } } + return true; } }; diff --git a/modules/botserv/bs_set.cpp b/modules/botserv/bs_set.cpp index 7ccde9352..57ef224b5 100644 --- a/modules/botserv/bs_set.cpp +++ b/modules/botserv/bs_set.cpp @@ -92,11 +92,12 @@ public: { } - void Tick() override + bool Tick() override { Channel *c = Channel::Find(chname); if (c) c->RemoveMode(NULL, "BAN", mask); + return false; } }; diff --git a/modules/chanserv/chanserv.cpp b/modules/chanserv/chanserv.cpp index 9b4a490a5..3f95cd4db 100644 --- a/modules/chanserv/chanserv.cpp +++ b/modules/chanserv/chanserv.cpp @@ -82,10 +82,10 @@ public: /** Called when the delay is up * @param The current time */ - void Tick() override + bool Tick() override { if (!c) - return; + return false; // Dead channel. /* In the event we don't part */ c->RemoveMode(NULL, "SECRET"); @@ -101,6 +101,8 @@ public: /* If someone has rejoined this channel in the meantime, don't part the bot */ else if (c->users.size() <= 1) c->ci->bi->Part(c); + + return false; } }; diff --git a/modules/chanserv/cs_ban.cpp b/modules/chanserv/cs_ban.cpp index e8544bcf9..7c138a87e 100644 --- a/modules/chanserv/cs_ban.cpp +++ b/modules/chanserv/cs_ban.cpp @@ -53,7 +53,7 @@ public: && bmask == this->mask; } - void Tick() override + bool Tick() override { // We need to do this to prevent the remove-on-unban logic from double // deleting the timer. @@ -62,6 +62,8 @@ public: Channel *c = Channel::Find(this->channel); if (c) c->RemoveMode(NULL, mode, this->mask); + + return false; } }; diff --git a/modules/dns.cpp b/modules/dns.cpp index 5149a5940..ced55de54 100644 --- a/modules/dns.cpp +++ b/modules/dns.cpp @@ -534,8 +534,9 @@ public: } /* Times out after a few seconds */ - void Tick() override + bool Tick() override { + return false; } void Reply(Packet *p) override @@ -718,7 +719,7 @@ public: MyManager(Module *creator) : Manager(creator) - , Timer(300, true) + , Timer(300) , serial(Anope::CurTime) , cur_id(Anope::RandomNumber()) { @@ -1011,7 +1012,7 @@ public: return serial; } - void Tick() override + bool Tick() override { Log(LOG_DEBUG_2) << "Resolver: Purging DNS cache"; @@ -1025,6 +1026,7 @@ public: if (req.created + static_cast(req.ttl) < Anope::CurTime) this->cache.erase(it); } + return true; } private: diff --git a/modules/httpd.cpp b/modules/httpd.cpp index 098613db2..e4490a0c3 100644 --- a/modules/httpd.cpp +++ b/modules/httpd.cpp @@ -298,12 +298,12 @@ public: MyHTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, const int t, bool s) : Socket(-1, i.find(':') == Anope::string::npos ? AF_INET : AF_INET6) , HTTP::Provider(c, n, i, p, s) - , Timer(c, 10, true) + , Timer(c, 10) , timeout(t) { } - void Tick() override + bool Tick() override { while (!this->clients.empty()) { @@ -314,6 +314,7 @@ public: delete c; this->clients.pop_front(); } + return true; } ClientSocket *OnAccept(int fd, const sockaddrs &addr) override diff --git a/modules/nickserv/nickserv.cpp b/modules/nickserv/nickserv.cpp index e87d058f4..af1d5f8a4 100644 --- a/modules/nickserv/nickserv.cpp +++ b/modules/nickserv/nickserv.cpp @@ -61,16 +61,17 @@ public: return na; } - void Tick() override + bool Tick() override { if (!u || !na || !NickServ::service) - return; + return false; /* If they identified or don't exist anymore, don't kill them. */ if (u->Account() == na->nc || u->timestamp > ts) - return; + return false; NickServ::service->Collide(u, na); + return false; } }; @@ -90,10 +91,11 @@ public: n->Extend("HELD"); } - void Tick() override + bool Tick() override { if (na) na->Shrink("HELD"); + return false; } }; @@ -133,8 +135,9 @@ public: NickServReleases.erase(this->nick); } - void Tick() override + bool Tick() override { + return false; } }; diff --git a/modules/nickserv/ns_sasl.cpp b/modules/nickserv/ns_sasl.cpp index 00dc41ec0..8190b09d0 100644 --- a/modules/nickserv/ns_sasl.cpp +++ b/modules/nickserv/ns_sasl.cpp @@ -29,7 +29,7 @@ public: SASLService(Module *o) : SASL::Service(o) - , Timer(o, 60, true) + , Timer(o, 60) { } @@ -221,7 +221,7 @@ public: this->SendMessage(session, "M", buf.empty() ? "" : buf.substr(1)); } - void Tick() override + bool Tick() override { for (auto it = badpasswords.begin(); it != badpasswords.end(); ) { @@ -240,6 +240,7 @@ public: sessions.erase(uid); } } + return true; } }; diff --git a/modules/operserv/os_defcon.cpp b/modules/operserv/os_defcon.cpp index dd15ecaaf..1afeb23b2 100644 --- a/modules/operserv/os_defcon.cpp +++ b/modules/operserv/os_defcon.cpp @@ -125,7 +125,7 @@ public: timeout = NULL; } - void Tick() override + bool Tick() override { if (DConfig.defaultlevel != level) { @@ -146,6 +146,7 @@ public: runDefCon(); } + return false; } }; diff --git a/modules/proxyscan.cpp b/modules/proxyscan.cpp index 23bf62adf..38fa2298a 100644 --- a/modules/proxyscan.cpp +++ b/modules/proxyscan.cpp @@ -218,11 +218,11 @@ class ModuleProxyScan final { public: ConnectionTimeout(Module *c, time_t timeout) - : Timer(c, timeout, true) + : Timer(c, timeout) { } - void Tick() override + bool Tick() override { for (auto it = ProxyConnect::proxies.begin(), it_end = ProxyConnect::proxies.end(); it != it_end;) { @@ -232,6 +232,7 @@ class ModuleProxyScan final if (p->created + this->GetSecs() < Anope::CurTime) delete p; } + return true; } } connectionTimeout; diff --git a/src/main.cpp b/src/main.cpp index 92e5dd9bd..5af253433 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -50,13 +50,14 @@ class UpdateTimer final { public: UpdateTimer(time_t timeout) - : Timer(timeout, true) + : Timer(timeout) { } - void Tick() override + bool Tick() override { Anope::SaveDatabases(); + return true; } }; @@ -65,13 +66,14 @@ class ExpireTimer final { public: ExpireTimer(time_t timeout) - : Timer(timeout, true) + : Timer(timeout) { } - void Tick() override + bool Tick() override { FOREACH_MOD(OnExpireTick, ()); + return true; } }; diff --git a/src/timers.cpp b/src/timers.cpp index 7c2430f5b..3b27f2418 100644 --- a/src/timers.cpp +++ b/src/timers.cpp @@ -17,20 +17,18 @@ std::multimap TimerManager::Timers; -Timer::Timer(time_t time_from_now, bool repeating) +Timer::Timer(time_t time_from_now) : trigger(Anope::CurTime + std::abs(time_from_now)) , secs(time_from_now) - , repeat(repeating) { if (time_from_now) TimerManager::AddTimer(this); } -Timer::Timer(Module *creator, time_t time_from_now, bool repeating) +Timer::Timer(Module *creator, time_t time_from_now) : owner(creator) , trigger(Anope::CurTime + std::abs(time_from_now)) , secs(time_from_now) - , repeat(repeating) { if (time_from_now) TimerManager::AddTimer(this); @@ -53,11 +51,6 @@ time_t Timer::GetTimer() const return trigger; } -bool Timer::GetRepeat() const -{ - return repeat; -} - void Timer::SetSecs(time_t t) { TimerManager::DelTimer(this); @@ -104,9 +97,7 @@ void TimerManager::TickTimers() if (t->GetTimer() > Anope::CurTime) break; - t->Tick(); - - if (t->GetRepeat()) + if (t->Tick()) t->SetTimer(Anope::CurTime + t->GetSecs()); else delete t; diff --git a/src/uplink.cpp b/src/uplink.cpp index d6281924a..80511fe38 100644 --- a/src/uplink.cpp +++ b/src/uplink.cpp @@ -29,7 +29,7 @@ public: { } - void Tick() override + bool Tick() override { try { @@ -39,6 +39,7 @@ public: { Log(LOG_TERMINAL) << "Unable to connect to uplink #" << (Anope::CurrentUplink + 1) << " (" << Config->Uplinks[Anope::CurrentUplink].str() << "): " << ex.GetReason(); } + return false; } };