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