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