]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_banexception.cpp
Convert all to new Attach() system. The Implements() method needs removing from all...
[user/henk/code/inspircd.git] / src / modules / m_banexception.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 "u_listmode.h"
16 #include "wildcard.h"
17
18 /* $ModDesc: Provides support for the +e channel mode */
19 /* $ModDep: ../../include/u_listmode.h */
20
21 /* Written by Om<om@inspircd.org>, April 2005. */
22 /* Rewritten to use the listmode utility by Om, December 2005 */
23 /* Adapted from m_exception, which was originally based on m_chanprotect and m_silence */
24
25 // The +e channel mode takes a nick!ident@host, glob patterns allowed,
26 // and if a user matches an entry on the +e list then they can join the channel, overriding any (+b) bans set on them
27 // Now supports CIDR and IP addresses -- Brain
28
29
30 /** Handles +e channel mode
31  */
32 class BanException : public ListModeBase
33 {
34  public:
35         BanException(InspIRCd* Instance) : ListModeBase(Instance, 'e', "End of Channel Exception List", "348", "349", true) { }
36 };
37
38
39 class ModuleBanException : public Module
40 {
41         BanException* be;
42         
43
44 public:
45         ModuleBanException(InspIRCd* Me)
46         : Module(Me)
47         {
48                 be = new BanException(ServerInstance);
49                 if (!ServerInstance->AddMode(be))
50                         throw ModuleException("Could not add new modes!");
51                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
52
53                 //be->DoImplements(List);
54                 Implementation list[] = { I_OnRehash, I_OnRequest, I_On005Numeric, I_OnCheckBan };
55                 Me->Modules->Attach(list, this, 4);
56
57         }
58         
59         virtual void On005Numeric(std::string &output)
60         {
61                 output.append(" EXCEPTS=e");
62         }
63
64         virtual int OnCheckBan(User* user, Channel* chan)
65         {
66                 if (chan != NULL)
67                 {
68                         modelist* list;
69                         chan->GetExt(be->GetInfoKey(), list);
70                         
71                         if (list)
72                         {
73                                 char mask[MAXBUF];
74                                 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
75                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
76                                 {
77                                         if (match(user->GetFullRealHost(), it->mask.c_str()) || match(user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
78                                         {
79                                                 // They match an entry on the list, so let them in.
80                                                 return 1;
81                                         }
82                                 }
83                                 return 0;
84                         }
85                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
86                 }
87                 return 0;       
88         }
89
90         virtual void OnCleanup(int target_type, void* item)
91         {
92                 be->DoCleanup(target_type, item);
93         }
94
95         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
96         {
97                 be->DoSyncChannel(chan, proto, opaque);
98         }
99
100         virtual void OnChannelDelete(Channel* chan)
101         {
102                 be->DoChannelDelete(chan);
103         }
104
105         virtual void OnRehash(User* user, const std::string &param)
106         {
107                 be->DoRehash();
108         }
109
110         virtual char* OnRequest(Request* request)
111         {
112                 ListModeRequest* LM = (ListModeRequest*)request;
113                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
114                 {
115                         modelist* list;
116                         LM->chan->GetExt(be->GetInfoKey(), list);
117                         if (list)
118                         {
119                                 char mask[MAXBUF];
120                                 snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
121                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
122                                 {
123                                         if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
124                                         {
125                                                 // They match an entry
126                                                 return (char*)it->mask.c_str();
127                                         }
128                                 }
129                                 return NULL;
130                         }
131                 }
132                 return NULL;
133         }
134
135         virtual Version GetVersion()
136         {
137                 return Version(1, 1, 0, 3, VF_COMMON | VF_VENDOR, API_VERSION);
138         }
139         
140         virtual ~ModuleBanException()
141         {
142                 ServerInstance->Modes->DelMode(be);
143                 delete be;
144                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
145         }
146 };
147
148 MODULE_INIT(ModuleBanException)