]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
Add extban +b O: for opertype banning.. mostly useful for +be to create a channel...
[user/henk/code/inspircd.git] / src / modules / m_operchans.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
16 /* $ModDesc: Provides support for oper-only chans via the +O channel mode */
17
18 class OperChans : public ModeHandler
19 {
20  public:
21         /* This is an oper-only mode */
22         OperChans(InspIRCd* Instance) : ModeHandler(Instance, 'O', 0, 0, false, MODETYPE_CHANNEL, true) { }
23
24         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
25         {
26                 if (adding)
27                 {
28                         if (!channel->IsModeSet('O'))
29                         {
30                                 channel->SetMode('O',true);
31                                 return MODEACTION_ALLOW;
32                         }
33                 }
34                 else
35                 {
36                         if (channel->IsModeSet('O'))
37                         {
38                                 channel->SetMode('O',false);
39                                 return MODEACTION_ALLOW;
40                         }
41                 }
42
43                 return MODEACTION_DENY;
44         }
45 };
46
47 class ModuleOperChans : public Module
48 {
49
50         OperChans* oc;
51  public:
52         ModuleOperChans(InspIRCd* Me)
53                 : Module(Me)
54         {
55
56                 oc = new OperChans(ServerInstance);
57                 if (!ServerInstance->Modes->AddMode(oc))
58                         throw ModuleException("Could not add new modes!");
59                 Implementation eventlist[] = { I_OnUserPreJoin };
60                 ServerInstance->Modules->Attach(eventlist, this, 1);
61         }
62
63
64         virtual int OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
65         {
66                 bool banned = false;
67
68                 if (!IS_OPER(user))
69                 {
70                         if (chan)
71                         {
72                                 if (chan->IsModeSet('O'))
73                                 {
74                                         banned = true;
75                                 }
76                         }
77                 }
78                 else
79                 {
80                         if (chan && chan->IsExtBanned(user->oper, 'O'))
81                         {
82                                 banned = true;
83                         }
84                 }
85
86                 if (banned)
87                 {
88                         user->WriteNumeric(ERR_CANTJOINOPERSONLY, "%s %s :Only IRC operators may join the channel %s (+O is set)",user->nick.c_str(), chan->name.c_str(), chan->name.c_str());
89                         return 1;
90                 }
91
92                 return 0;
93         }
94
95         virtual ~ModuleOperChans()
96         {
97                 ServerInstance->Modes->DelMode(oc);
98                 delete oc;
99         }
100
101         virtual Version GetVersion()
102         {
103                 return Version(1,2,0,0,VF_VENDOR|VF_COMMON,API_VERSION);
104         }
105 };
106
107 MODULE_INIT(ModuleOperChans)