]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_channelban.cpp
Fix crash on matching j:@#chan ban when the user is not in the channel
[user/henk/code/inspircd.git] / src / modules / m_channelban.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
16 /* $ModDesc: Implements extban +b j: - matching channel bans */
17
18 class ModuleBadChannelExtban : public Module
19 {
20  private:
21  public:
22         ModuleBadChannelExtban()        {
23                 Implementation eventlist[] = { I_OnCheckBan, I_On005Numeric };
24                 ServerInstance->Modules->Attach(eventlist, this, 2);
25         }
26
27         ~ModuleBadChannelExtban()
28         {
29         }
30
31         Version GetVersion()
32         {
33                 return Version("Extban 'j' - channel status/join ban", VF_OPTCOMMON|VF_VENDOR);
34         }
35
36         ModResult OnCheckBan(User *user, Channel *c, const std::string& mask)
37         {
38                 if (mask[0] == 'j' && mask[1] == ':')
39                 {
40                         std::string rm = mask.substr(2);
41                         char status = 0;
42                         ModeHandler* mh = ServerInstance->Modes->FindPrefix(rm[0]);
43                         if (mh)
44                         {
45                                 rm = mask.substr(3);
46                                 status = mh->GetModeChar();
47                         }
48                         for (UCListIter i = user->chans.begin(); i != user->chans.end(); i++)
49                         {
50                                 if (InspIRCd::Match((**i).name, rm))
51                                 {
52                                         if (status)
53                                         {
54                                                 Membership* memb = c->GetUser(user);
55                                                 if (memb && memb->hasMode(status))
56                                                         return MOD_RES_DENY;
57                                         }
58                                         else
59                                                 return MOD_RES_DENY;
60                                 }
61                         }
62                 }
63                 return MOD_RES_PASSTHRU;
64         }
65
66         void On005Numeric(std::string &output)
67         {
68                 ServerInstance->AddExtBanChar('j');
69         }
70 };
71
72
73 MODULE_INIT(ModuleBadChannelExtban)
74