]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_operchans.cpp
e1d7d6f9a95df38d473e1de6754da39d08bf8e97
[user/henk/code/inspircd.git] / src / modules / m_operchans.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
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(Module* Creator) : ModeHandler(Creator, "operonly", 'O', PARAM_NONE, MODETYPE_CHANNEL) { oper = true; }
23
24         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
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         OperChans oc;
50  public:
51         ModuleOperChans() : oc(this)
52         {
53                 if (!ServerInstance->Modes->AddMode(&oc))
54                         throw ModuleException("Could not add new modes!");
55                 Implementation eventlist[] = { I_OnCheckBan, I_On005Numeric, I_OnUserPreJoin };
56                 ServerInstance->Modules->Attach(eventlist, this, 3);
57         }
58
59         ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven)
60         {
61                 if (chan && chan->IsModeSet('O') && !IS_OPER(user))
62                 {
63                         user->WriteNumeric(ERR_CANTJOINOPERSONLY, "%s %s :Only IRC operators may join %s (+O is set)",
64                                 user->nick.c_str(), chan->name.c_str(), chan->name.c_str());
65                         return MOD_RES_DENY;
66                 }
67                 return MOD_RES_PASSTHRU;
68         }
69
70         ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
71         {
72                 if (mask[0] == 'O' && mask[1] == ':')
73                 {
74                         if (IS_OPER(user) && InspIRCd::Match(user->oper, mask.substr(2)))
75                                 return MOD_RES_DENY;
76                 }
77                 return MOD_RES_PASSTHRU;
78         }
79
80         void On005Numeric(std::string &output)
81         {
82                 ServerInstance->AddExtBanChar('O');
83         }
84
85         ~ModuleOperChans()
86         {
87         }
88
89         Version GetVersion()
90         {
91                 return Version("Provides support for oper-only chans via the +O channel mode and 'O' extban", VF_VENDOR | VF_COMMON, API_VERSION);
92         }
93 };
94
95 MODULE_INIT(ModuleOperChans)