]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonotice.cpp
In the grand tradition of huge fucking commits:
[user/henk/code/inspircd.git] / src / modules / m_nonotice.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2007 InspIRCd Development Team
6  * See: http://www.inspircd.org/wiki/index.php/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 ModeHandler
19 {
20  public:
21         NoNotice(InspIRCd* Instance) : ModeHandler(Instance, 'T', 0, 0, false, MODETYPE_CHANNEL, false) { }
22
23         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
24         {
25                 if (adding)
26                 {
27                         if (!channel->IsModeSet('T'))
28                         {
29                                 channel->SetMode('T',true);
30                                 return MODEACTION_ALLOW;
31                         }
32                 }
33                 else
34                 {
35                         if (channel->IsModeSet('T'))
36                         {
37                                 channel->SetMode('T',false);
38                                 return MODEACTION_ALLOW;
39                         }
40                 }
41
42                 return MODEACTION_DENY;
43         }
44 };
45
46 class ModuleNoNotice : public Module
47 {
48         
49         NoNotice* nt;
50  public:
51  
52         ModuleNoNotice(InspIRCd* Me)
53                 : Module(Me)
54         {
55                 
56                 nt = new NoNotice(ServerInstance);
57                 if (!ServerInstance->AddMode(nt, 'T'))
58                         throw ModuleException("Could not add new modes!");
59         }
60
61         void Implements(char* List)
62         {
63                 List[I_OnUserPreNotice] = 1;
64         }
65         
66         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
67         {
68                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
69                 {
70                         Channel* c = (Channel*)dest;
71                         if (c->IsModeSet('T'))
72                         {
73                                 if ((ServerInstance->ULine(user->server)) || (c->GetStatus(user) == STATUS_OP) || (c->GetStatus(user) == STATUS_HOP))
74                                 {
75                                         // ops and halfops can still /NOTICE the channel
76                                         return 0;
77                                 }
78                                 else
79                                 {
80                                         user->WriteServ("404 %s %s :Can't send NOTICE to channel (+T set)",user->nick, c->name);
81                                         return 1;
82                                 }
83                         }
84                 }
85                 return 0;
86         }
87
88         virtual ~ModuleNoNotice()
89         {
90                 ServerInstance->Modes->DelMode(nt);
91                 delete nt;
92         }
93         
94         virtual Version GetVersion()
95         {
96                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
97         }
98 };
99
100 MODULE_INIT(ModuleNoNotice)