]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonotice.cpp
925b8b7fe37f2bd52ac1dc0ce5e54d0313c3c8f5
[user/henk/code/inspircd.git] / src / modules / m_nonotice.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 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: Provides support for unreal-style channel mode +T */
17
18 class NoNotice : public SimpleChannelModeHandler
19 {
20  public:
21         NoNotice(Module* Creator) : SimpleChannelModeHandler(Creator, "nonotice", 'T') { }
22 };
23
24 class ModuleNoNotice : public Module
25 {
26         NoNotice nt;
27  public:
28
29         ModuleNoNotice()
30                 : nt(this)
31         {
32                 if (!ServerInstance->Modes->AddMode(&nt))
33                         throw ModuleException("Could not add new modes!");
34                 Implementation eventlist[] = { I_OnUserPreNotice, I_On005Numeric };
35                 ServerInstance->Modules->Attach(eventlist, this, 2);
36         }
37
38         virtual void On005Numeric(std::string &output)
39         {
40                 ServerInstance->AddExtBanChar('T');
41         }
42
43         virtual ModResult OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
44         {
45                 ModResult res;
46                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
47                 {
48                         Channel* c = (Channel*)dest;
49                         if (!c->GetExtBanStatus(user, 'T').check(!c->IsModeSet('T')))
50                         {
51                                 if (ServerInstance->ULine(user->server))
52                                 {
53                                         // ulines are exempt.
54                                         return MOD_RES_PASSTHRU;
55                                 }
56                                 FIRST_MOD_RESULT(OnChannelRestrictionApply, res, (user,c,"nonotice"));
57                                 if (res == MOD_RES_ALLOW)
58                                         return MOD_RES_PASSTHRU;
59                                 else
60                                 {
61                                         user->WriteNumeric(ERR_CANNOTSENDTOCHAN, "%s %s :Can't send NOTICE to channel (+T set)",user->nick.c_str(), c->name.c_str());
62                                         return MOD_RES_DENY;
63                                 }
64                         }
65                 }
66                 return MOD_RES_PASSTHRU;
67         }
68
69         virtual ~ModuleNoNotice()
70         {
71         }
72
73         virtual Version GetVersion()
74         {
75                 return Version("Provides support for unreal-style channel mode +T", VF_COMMON | VF_VENDOR);
76         }
77 };
78
79 MODULE_INIT(ModuleNoNotice)