]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/cull_list.cpp
Hash rehashing change
[user/henk/code/inspircd.git] / src / cull_list.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/Credits
7  *
8  * This program is free but copyrighted software; see
9  *            the file COPYING for details.
10  *
11  * ---------------------------------------------------
12  */
13
14 #include "inspircd.h"
15 #include "users.h"
16 #include "cull_list.h"
17
18 /*
19  * In current implementation of CullList, this isn't used. It did odd things with a lot of sockets.
20  */
21 bool CullList::IsValid(userrec* user)
22 {
23         time_t esignon = 0;
24         std::map<userrec*,time_t>::iterator es = exempt.find(user);
25         if (es != exempt.end())
26                 esignon = es->second;
27
28         for (user_hash::iterator u = ServerInstance->clientlist->begin(); u != ServerInstance->clientlist->end(); u++)
29         {
30                 if (user == u->second)
31                         return (u->second->signon == esignon);
32         }
33         return false;
34 }
35
36 CullItem::CullItem(userrec* u, std::string &r)
37 {
38         this->user = u;
39         this->reason = r;
40 }
41
42 CullItem::CullItem(userrec* u, const char* r)
43 {
44         this->user = u;
45         this->reason = r;
46 }
47
48 CullItem::~CullItem()
49 {
50 }
51
52 userrec* CullItem::GetUser()
53 {
54         return this->user;
55 }
56
57 std::string& CullItem::GetReason()
58 {
59         return this->reason;
60 }
61
62 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
63 {
64         list.clear();
65         exempt.clear();
66 }
67
68 void CullList::AddItem(userrec* user, std::string &reason)
69 {
70         if (exempt.find(user) == exempt.end())
71         {
72                 CullItem item(user,reason);
73                 list.push_back(item);
74                 exempt[user] = user->signon;
75         }
76 }
77
78 void CullList::AddItem(userrec* user, const char* reason)
79 {
80         if (exempt.find(user) == exempt.end())
81         {
82                 CullItem item(user,reason);
83                 list.push_back(item);
84                 exempt[user] = user->signon;
85         }
86 }
87
88 int CullList::Apply()
89 {
90         int n = list.size();
91         while (list.size())
92         {
93                 std::vector<CullItem>::iterator a = list.begin();
94
95                 userrec::QuitUser(ServerInstance, a->GetUser(), a->GetReason().c_str());
96                 list.erase(list.begin());
97         }
98         return n;
99 }