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