]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_autoop.cpp
Add access checking for m_autoop
[user/henk/code/inspircd.git] / src / modules / m_autoop.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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 +w channel mode, autoop list */
18
19 /** Handles +w channel mode
20  */
21 class AutoOpList : public ListModeBase
22 {
23  public:
24         AutoOpList(Module* Creator) : ListModeBase(Creator, "autoop", 'w', "End of Channel Access List", 910, 911, true)
25         {
26                 levelrequired = OP_VALUE;
27         }
28
29         ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding)
30         {
31                 std::string::size_type pos = parameter.find(':');
32                 if (pos == 0 || pos == std::string::npos)
33                         return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
34                 unsigned int mylevel = channel->GetPrefixValue(source);
35                 while (pos > 0)
36                 {
37                         pos--;
38                         ModeHandler* mh = ServerInstance->Modes->FindMode(parameter[pos], MODETYPE_CHANNEL);
39                         if (adding && !mh)
40                                 return MOD_RES_DENY;
41                         else if (!mh)
42                                 continue;
43
44                         std::string dummy;
45                         if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
46                                 return MOD_RES_DENY;
47                         if (mh->GetLevelRequired() > mylevel)
48                                 return MOD_RES_DENY;
49                 }
50                 return MOD_RES_PASSTHRU;
51         }
52 };
53
54
55 class ModuleAutoOp : public Module
56 {
57         AutoOpList mh;
58
59 public:
60         ModuleAutoOp() : mh(this)
61         {
62                 ServerInstance->Modules->AddService(mh);
63                 mh.DoImplements(this);
64
65                 Implementation list[] = { I_OnUserPreJoin, };
66                 ServerInstance->Modules->Attach(list, this, 1);
67         }
68
69         ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
70         {
71                 if (!chan)
72                         return MOD_RES_PASSTHRU;
73
74                 modelist* list = mh.extItem.get(chan);
75                 if (list)
76                 {
77                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
78                         {
79                                 std::string::size_type colon = it->mask.find(':');
80                                 if (colon == std::string::npos)
81                                         continue;
82                                 if (chan->CheckBan(user, it->mask.substr(colon+1)))
83                                         privs += it->mask.substr(0, colon);
84                         }
85                 }
86
87                 return MOD_RES_PASSTHRU;
88         }
89
90         void OnCleanup(int target_type, void* item)
91         {
92                 mh.DoCleanup(target_type, item);
93         }
94
95         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
96         {
97                 mh.DoSyncChannel(chan, proto, opaque);
98         }
99
100         void OnRehash(User* user)
101         {
102                 mh.DoRehash();
103         }
104
105         Version GetVersion()
106         {
107                 return Version("Provides support for the +w channel mode", VF_VENDOR);
108         }
109 };
110
111 MODULE_INIT(ModuleAutoOp)