]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/timer.cpp
Remove references to inspircd_io from these, stop configure making all the modules...
[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 using namespace std;
18
19 #include "inspircd_config.h"
20 #include <time.h>
21 #include <vector>
22 #include <map>
23 #include "users.h"
24 #include "ctables.h"
25 #include "typedefs.h"
26 #include "commands.h"
27 #include "globals.h"
28 #include "hashcomp.h"
29 #include "inspircd.h"
30 #include "inspstring.h"
31 #include "helperfuncs.h"
32
33 extern InspIRCd* ServerInstance;
34 extern ServerConfig* Config;
35 extern time_t TIME;
36
37 typedef std::vector<InspTimer*> timergroup;
38 typedef std::map<time_t, timergroup*> timerlist;
39 timerlist Timers;
40
41 void TickTimers(time_t TIME)
42 {
43         timerlist::iterator found = Timers.find(TIME);
44
45         if (found != Timers.end())
46         {
47                 timergroup* x = found->second;
48                 /*
49                  * There are pending timers to trigger
50                  */
51                 for (timergroup::iterator y = x->begin(); y != x->end(); y++)
52                 {
53                         InspTimer* n = *y;
54                         n->Tick(TIME);
55                         delete n;
56                 }
57
58                 Timers.erase(found);
59                 delete x;
60         }
61 }
62
63 /*
64  * Because some muppets may do odd things, and their ircd may lock up due
65  * to crappy 3rd party modules, or they may change their system time a bit,
66  * this accounts for shifts of up to 120 secs by looking behind for missed
67  * timers and executing them. This is only executed once every 5 secs.
68  * If you move your clock BACK, and your timers move further ahead as a result,
69  * then tough titty you'll just have to wait.
70  */
71 void TickMissedTimers(time_t TIME)
72 {
73         for (time_t n = TIME-1; n > TIME-120; n--)
74         {
75                 timerlist::iterator found = Timers.find(n);
76                 if (found != Timers.end())
77                 {
78                         timergroup* x = found->second;
79                         for (timergroup::iterator y = x->begin(); y != x->end(); y++)
80                         {
81                                 InspTimer* z = *y;
82                                 z->Tick(TIME);
83                                 delete z;
84                         }
85
86                         Timers.erase(found);
87                         delete x;
88                 }
89         }
90 }
91
92 void AddTimer(InspTimer* T)
93 {
94         timergroup* x = NULL;
95
96         timerlist::iterator found = Timers.find(T->GetTimer());
97         
98         if (found != Timers.end())
99         {
100                 x = found->second;
101         }
102         else
103         {
104                 x = new timergroup;
105                 Timers[T->GetTimer()] = x;
106         }
107
108         x->push_back(T);
109 }