]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
Optimized helperfuncs
[user/henk/code/inspircd.git] / src / cull_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2005 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 "inspircd.h"
21 #include "inspircd_io.h"
22 #include "inspircd_util.h"
23 #include <unistd.h>
24 #include <fcntl.h>
25 #include <sys/errno.h>
26 #include <time.h>
27 #include <string>
28 #ifdef GCC3
29 #include <ext/hash_map>
30 #else
31 #include <hash_map>
32 #endif
33 #include <map>
34 #include <sstream>
35 #include <vector>
36 #include <deque>
37 #include "users.h"
38 #include "ctables.h"
39 #include "globals.h"
40 #include "modules.h"
41 #include "dynamic.h"
42 #include "wildcard.h"
43 #include "message.h"
44 #include "commands.h"
45 #include "xline.h"
46 #include "inspstring.h"
47 #include "helperfuncs.h"
48 #include "hashcomp.h"
49 #include "typedefs.h"
50 #include "cull_list.h"
51
52 CullItem::CullItem(userrec* u, std::string r)
53 {
54         this->user = u;
55         this->reason = r;
56 }
57
58 userrec* CullItem::GetUser()
59 {
60         return this->user;
61 }
62
63 std::string CullItem::GetReason()
64 {
65         return this->reason;
66 }
67
68 CullList::CullList()
69 {
70         list.clear();
71         exempt.clear();
72 }
73
74 void CullList::AddItem(userrec* user, std::string reason)
75 {
76         if (exempt.find(user) == exempt.end())
77         {
78                 CullItem item(user,reason);
79                 list.push_back(item);
80                 exempt[user] = 1;
81         }
82 }
83
84 int CullList::Apply()
85 {
86         int n = 0;
87         while (list.size())
88         {
89                std::vector<CullItem>::iterator a = list.begin();
90                userrec* u = a->GetUser();
91                std::string reason = a->GetReason();
92                kill_link(u,reason.c_str());
93                list.erase(list.begin());
94                n++;
95         }
96         return n;
97 }