From 7907a1f1cc78ca532547c824cd221060b57f4fff Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 23 Feb 2006 19:39:38 +0000 Subject: [PATCH 1/1] Incorporating InspTimer into safelist as a test git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@3301 e03df62e-2008-0410-955e-edbf42e46eb7 --- include/modules.h | 4 ++++ include/timer.h | 2 ++ src/inspircd.cpp | 6 ++++++ src/modules.cpp | 6 ++++++ src/modules/m_safelist.cpp | 21 +++++++++++++++++++++ 5 files changed, 39 insertions(+) diff --git a/include/modules.h b/include/modules.h index 8c37a8cc2..56bf2d18f 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1390,6 +1390,10 @@ class Server : public classbase */ virtual int CountUsers(chanrec* c); + /** Adds an InspTimer which will trigger at a future time + */ + virtual void AddTimer(InspTimer* T); + /** Attempts to look up a nick and return a pointer to it. * This function will return NULL if the nick does not exist. */ diff --git a/include/timer.h b/include/timer.h index 894a0d0e1..143ff4d97 100644 --- a/include/timer.h +++ b/include/timer.h @@ -12,4 +12,6 @@ class InspTimer virtual void Tick(time_t TIME) {} }; +void TickTimers(time_t TIME); +void AddTimer(InspTimer* T); diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 2b57a2292..6e8040d87 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -57,6 +57,7 @@ using namespace std; #include "socket.h" #include "typedefs.h" #include "command_parse.h" +#include "timer.h" InspIRCd* ServerInstance; @@ -655,6 +656,11 @@ int InspIRCd::Run() if (TIME < OLDTIME) WriteOpers("*** \002EH?!\002 -- Time is flowing BACKWARDS in this dimension! Clock drifted backwards %d secs.",abs(OLDTIME-TIME)); DoBackgroundUserStuff(TIME); + + /* + * Trigger all InspTimers that are pending + */ + TickTimers(TIME); } /* Process timeouts on module sockets each time around diff --git a/src/modules.cpp b/src/modules.cpp index 6f1236f60..7640f0edc 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -50,6 +50,7 @@ using namespace std; #include "typedefs.h" #include "modules.h" #include "command_parse.h" +#include "timer.h" extern ServerConfig *Config; extern InspIRCd* ServerInstance; @@ -414,6 +415,11 @@ chanrec* Server::GetChannelIndex(long index) return NULL; } +void Server::AddTimer(InspTimer* T) +{ + AddTimer(T); +} + void Server::SendOpers(std::string s) { WriteOpers("%s",s.c_str()); diff --git a/src/modules/m_safelist.cpp b/src/modules/m_safelist.cpp index 641fd7559..52e5e36a0 100644 --- a/src/modules/m_safelist.cpp +++ b/src/modules/m_safelist.cpp @@ -40,15 +40,36 @@ class ListData typedef std::vector UserList; +class ListTimer : public InspTimer +{ + private: + Server* Srv; + public: + ListTimer(long interval, Server* Me) : InspTimer(interval), Server(Me) + { + } + + Tick(time_t TIME) + { + log(DEBUG,"*** Timer tick!"); + MyTimer = new ListTimer(1); + Srv->AddTimer(MyTimer); + } +}; + class ModuleSafeList : public Module { private: Server *Srv; + ListTimer* MyTimer; UserList listusers; /* vector of people doing a /list */ public: ModuleSafeList(Server* Me) : Module::Module(Me) { Srv = Me; + + MyTimer = new ListTimer(1); + Srv->AddTimer(MyTimer,Me); } virtual ~ModuleSafeList() -- 2.39.2