]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/timer.cpp
I'll give you ##TOAST, :p
[user/henk/code/inspircd.git] / src / timer.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include "inspircd.h"
18 #include "timer.h"
19
20 void TimerManager::TickTimers(time_t TIME)
21 {
22         timerlist::iterator found = Timers.find(TIME);
23
24         if (found != Timers.end())
25         {
26                 timergroup* x = found->second;
27                 /*
28                  * There are pending timers to trigger
29                  */
30                 for (timergroup::iterator y = x->begin(); y != x->end(); y++)
31                 {
32                         InspTimer* n = *y;
33                         n->Tick(TIME);
34                         DELETE(n);
35                 }
36
37                 Timers.erase(found);
38                 DELETE(x);
39         }
40 }
41
42 /*
43  * Because some muppets may do odd things, and their ircd may lock up due
44  * to crappy 3rd party modules, or they may change their system time a bit,
45  * this accounts for shifts of up to 120 secs by looking behind for missed
46  * timers and executing them. This is only executed once every 5 secs.
47  * If you move your clock BACK, and your timers move further ahead as a result,
48  * then tough titty you'll just have to wait.
49  */
50 void TimerManager::TickMissedTimers(time_t TIME)
51 {
52         for (time_t n = TIME-1; n > TIME-120; n--)
53         {
54                 timerlist::iterator found = Timers.find(n);
55                 if (found != Timers.end())
56                 {
57                         timergroup* x = found->second;
58                         for (timergroup::iterator y = x->begin(); y != x->end(); y++)
59                         {
60                                 InspTimer* z = *y;
61                                 z->Tick(TIME);
62                                 DELETE(z);
63                         }
64
65                         Timers.erase(found);
66                         DELETE(x);
67                 }
68         }
69 }
70
71 void TimerManager::AddTimer(InspTimer* T)
72 {
73         timergroup* x = NULL;
74
75         timerlist::iterator found = Timers.find(T->GetTimer());
76         
77         if (found != Timers.end())
78         {
79                 x = found->second;
80         }
81         else
82         {
83                 x = new timergroup;
84                 Timers[T->GetTimer()] = x;
85         }
86
87         x->push_back(T);
88 }
89