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