]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
Make u_listmode more sensible and make it properly use WriteNumeric, and a few other...
[user/henk/code/inspircd.git] / src / modules / m_inviteexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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->Modes->AddMode(ie))
48                         throw ModuleException("Could not add new modes!");
49                 ServerInstance->Modules->PublishInterface("ChannelBanList", this);
50
51                 ie->DoImplements(this);
52                 Implementation eventlist[] = { I_OnRequest, I_On005Numeric, I_OnCheckInvite };
53                 ServerInstance->Modules->Attach(eventlist, this, 3);
54         }
55         
56         virtual void On005Numeric(std::string &output)
57         {
58                 output.append(" INVEX=I");
59         }
60          
61         virtual int OnCheckInvite(User* user, Channel* chan)
62         {
63                 if(chan != NULL)
64                 {
65                         modelist* list;
66                         chan->GetExt(ie->GetInfoKey(), list);
67                         if (list)
68                         {
69                                 char mask[MAXBUF];
70                                 snprintf(mask, MAXBUF, "%s!%s@%s", user->nick, user->ident, user->GetIPString());
71                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
72                                 {
73                                         if(match(user->GetFullRealHost(), it->mask.c_str()) || match(user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
74                                         {
75                                                 // They match an entry on the list, so let them in.
76                                                 return 1;
77                                         }
78                                 }
79                         }
80                         // or if there wasn't a list, there can't be anyone on it, so we don't need to do anything.
81                 }
82
83                 return 0;               
84         }
85
86         virtual const char* OnRequest(Request* request)
87         {
88                 ListModeRequest* LM = (ListModeRequest*)request;
89                 if (strcmp("LM_CHECKLIST", request->GetId()) == 0)
90                 {
91                         modelist* list;
92                         LM->chan->GetExt(ie->GetInfoKey(), list);
93                         if (list)
94                         {
95                                 char mask[MAXBUF];
96                                 snprintf(mask, MAXBUF, "%s!%s@%s", LM->user->nick, LM->user->ident, LM->user->GetIPString());
97                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
98                                 {
99                                         if (match(LM->user->GetFullRealHost(), it->mask.c_str()) || match(LM->user->GetFullHost(), it->mask.c_str()) || (match(mask, it->mask.c_str(), true)))
100                                         {
101                                                 // They match an entry
102                                                 return (char*)it->mask.c_str();
103                                         }
104                                 }
105                                 return NULL;
106                         }
107                 }
108                 return NULL;
109         }
110
111         virtual void OnCleanup(int target_type, void* item)
112         {
113                 ie->DoCleanup(target_type, item);
114         }
115
116         virtual void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
117         {
118                 ie->DoSyncChannel(chan, proto, opaque);
119         }
120
121         virtual void OnChannelDelete(Channel* chan)
122         {
123                 ie->DoChannelDelete(chan);
124         }
125
126         virtual void OnRehash(User* user, const std::string &param)
127         {
128                 ie->DoRehash();
129         }
130                 
131         virtual Version GetVersion()
132         {
133                 return Version(1, 2, 0, 3, VF_VENDOR | VF_COMMON, API_VERSION);
134         }
135
136         ~ModuleInviteException()
137         {
138                 ServerInstance->Modes->DelMode(ie);
139                 delete ie;
140                 ServerInstance->Modules->UnpublishInterface("ChannelBanList", this);
141         }
142 };
143
144 MODULE_INIT(ModuleInviteException)