]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
a38f7ed8aa240a62f3e0c598a7e9c56f085d5766
[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                 Implementation eventlist[] = { I_OnRequest, I_On005Numeric, I_OnCheckInvite };
51                 ServerInstance->Modules->Attach(eventlist, this, 3);
52         }
53
54         virtual void Implements(char* List)
55         {
56                 ie->DoImplements(List);
57                 List[I_OnRequest] = List[I_On005Numeric] = List[I_OnCheckInvite] = 1;
58         }
59         
60         virtual void On005Numeric(std::string &output)
61         {
62                 output.append(" INVEX=I");
63         }
64          
65         virtual int OnCheckInvite(User* user, Channel* chan)
66         {
67                 if(chan != NULL)
68                 {
69                         modelist* list;
70                         chan->GetExt(ie->GetInfoKey(), list);
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                         }
84                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
85                 }
86
87                 return 0;               
88         }
89
90         virtual char* OnRequest(Request* request)
91         {
92                 ListModeRequest* LM = (ListModeRequest*)request;
93                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
94                 {
95                         modelist* list;
96                         LM->chan->GetExt(ie->GetInfoKey(), list);
97                         if (list)
98                         {
99                                 char mask[MAXBUF];
100                                 snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
101                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
102                                 {
103                                         if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
104                                         {
105                                                 // They match an entry
106                                                 return (char*)it->mask.c_str();
107                                         }
108                                 }
109                                 return NULL;
110                         }
111                 }
112                 return NULL;
113         }
114
115         virtual void OnCleanup(int target_type, void* item)
116         {
117                 ie->DoCleanup(target_type, item);
118         }
119
120         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
121         {
122                 ie->DoSyncChannel(chan, proto, opaque);
123         }
124
125         virtual void OnChannelDelete(Channel* chan)
126         {
127                 ie->DoChannelDelete(chan);
128         }
129
130         virtual void OnRehash(User* user, const std::string &param)
131         {
132                 ie->DoRehash();
133         }
134                 
135         virtual Version GetVersion()
136         {
137                 return Version(1, 1, 0, 3, VF_VENDOR | VF_COMMON, API_VERSION);
138         }
139
140         ~ModuleInviteException()
141         {
142                 ServerInstance->Modes->DelMode(ie);
143                 delete ie;
144                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
145         }
146 };
147
148 MODULE_INIT(ModuleInviteException)