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