]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_autoop.cpp
Add RAWIO log level which is more verbose than DEBUG
[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         ModeHandler* FindMode(const std::string& mid)
30         {
31                 if (mid.length() == 1)
32                         return ServerInstance->Modes->FindMode(mid[0], MODETYPE_CHANNEL);
33                 for(char c='A'; c < 'z'; c++)
34                 {
35                         ModeHandler* mh = ServerInstance->Modes->FindMode(c, MODETYPE_CHANNEL);
36                         if (mh && mh->name == mid)
37                                 return mh;
38                 }
39                 return NULL;
40         }
41
42         ModResult AccessCheck(User* source, Channel* channel, std::string &parameter, bool adding)
43         {
44                 std::string::size_type pos = parameter.find(':');
45                 if (pos == 0 || pos == std::string::npos)
46                         return adding ? MOD_RES_DENY : MOD_RES_PASSTHRU;
47                 unsigned int mylevel = channel->GetPrefixValue(source);
48                 std::string mid = parameter.substr(0, pos);
49                 ModeHandler* mh = FindMode(mid);
50
51                 if (adding && (!mh || !mh->GetPrefixRank()))
52                 {
53                         source->WriteNumeric(415, "%s %s :Cannot find prefix mode '%s' for autoop",
54                                 source->nick.c_str(), mid.c_str(), mid.c_str());
55                         return MOD_RES_DENY;
56                 }
57                 else if (!mh)
58                         return MOD_RES_PASSTHRU;
59
60                 std::string dummy;
61                 if (mh->AccessCheck(source, channel, dummy, true) == MOD_RES_DENY)
62                         return MOD_RES_DENY;
63                 if (mh->GetLevelRequired() > mylevel)
64                 {
65                         source->WriteNumeric(482, "%s %s :You must be able to set mode '%s' to include it in an autoop",
66                                 source->nick.c_str(), channel->name.c_str(), mid.c_str());
67                         return MOD_RES_DENY;
68                 }
69                 return MOD_RES_PASSTHRU;
70         }
71 };
72
73 class ModuleAutoOp : public Module
74 {
75         AutoOpList mh;
76
77 public:
78         ModuleAutoOp() : mh(this)
79         {
80                 ServerInstance->Modules->AddService(mh);
81                 mh.DoImplements(this);
82
83                 Implementation list[] = { I_OnUserPreJoin, };
84                 ServerInstance->Modules->Attach(list, this, 1);
85         }
86
87         ModResult OnUserPreJoin(User *user, Channel *chan, const char *cname, std::string &privs, const std::string &keygiven)
88         {
89                 if (!chan)
90                         return MOD_RES_PASSTHRU;
91
92                 modelist* list = mh.extItem.get(chan);
93                 if (list)
94                 {
95                         for (modelist::iterator it = list->begin(); it != list->end(); it++)
96                         {
97                                 std::string::size_type colon = it->mask.find(':');
98                                 if (colon == std::string::npos)
99                                         continue;
100                                 if (chan->CheckBan(user, it->mask.substr(colon+1)))
101                                 {
102                                         ModeHandler* given = mh.FindMode(it->mask.substr(0, colon));
103                                         if (given)
104                                                 privs += given->GetModeChar();
105                                 }
106                         }
107                 }
108
109                 return MOD_RES_PASSTHRU;
110         }
111
112         void OnCleanup(int target_type, void* item)
113         {
114                 mh.DoCleanup(target_type, item);
115         }
116
117         void OnSyncChannel(Channel* chan, Module* proto, void* opaque)
118         {
119                 mh.DoSyncChannel(chan, proto, opaque);
120         }
121
122         void OnRehash(User* user)
123         {
124                 mh.DoRehash();
125         }
126
127         Version GetVersion()
128         {
129                 return Version("Provides support for the +w channel mode", VF_VENDOR);
130         }
131 };
132
133 MODULE_INIT(ModuleAutoOp)