]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_inviteexception.cpp
9d0e0f54ecf1bde906450ecf16f7a09c98a629ba
[user/henk/code/inspircd.git] / src / modules / m_inviteexception.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 /** Handles channel mode +I
31  */
32 class InviteException : public ListModeBase
33 {
34  public:
35         InviteException(Module* Creator) : ListModeBase(Creator, "invex", 'I', "End of Channel Invite Exception List", 346, 347, true) { }
36 };
37
38 class ModuleInviteException : public Module
39 {
40         InviteException ie;
41 public:
42         ModuleInviteException() : ie(this)
43         {
44                 if (!ServerInstance->Modes->AddMode(&ie))
45                         throw ModuleException("Could not add new modes!");
46
47                 ie.DoImplements(this);
48                 Implementation eventlist[] = { I_On005Numeric, I_OnCheckInvite };
49                 ServerInstance->Modules->Attach(eventlist, this, 2);
50         }
51
52         void On005Numeric(std::string &output)
53         {
54                 output.append(" INVEX=I");
55         }
56
57         ModResult OnCheckInvite(User* user, Channel* chan)
58         {
59                 if(chan != NULL)
60                 {
61                         modelist* list = ie.extItem.get(chan);
62                         if (list)
63                         {
64                                 for (modelist::iterator it = list->begin(); it != list->end(); it++)
65                                 {
66                                         if (chan->CheckBan(user, it->mask))
67                                         {
68                                                 return MOD_RES_ALLOW;
69                                         }
70                                 }
71                         }
72                 }
73
74                 return MOD_RES_PASSTHRU;
75         }
76
77         void OnCleanup(int target_type, void* item)
78         {
79                 ie.DoCleanup(target_type, item);
80         }
81
82         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
83         {
84                 ie.DoSyncChannel(chan, proto, opaque);
85         }
86
87         void OnRehash(User* user)
88         {
89                 ie.DoRehash();
90         }
91
92         Version GetVersion()
93         {
94                 return Version("Provides support for the +I channel mode", VF_VENDOR | VF_COMMON);
95         }
96 };
97
98 MODULE_INIT(ModuleInviteException)