]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonotice.cpp
Remove a redundant method here, call the mode manager directly
[user/henk/code/inspircd.git] / src / modules / m_nonotice.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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->Modes->AddMode(nt))
58                         throw ModuleException("Could not add new modes!");
59                 Implementation eventlist[] = { I_OnUserPreNotice };
60                 ServerInstance->Modules->Attach(eventlist, this, 1);
61         }
62
63         
64         virtual int OnUserPreNotice(User* user,void* dest,int target_type, std::string &text, char status, CUList &exempt_list)
65         {
66                 if ((target_type == TYPE_CHANNEL) && (IS_LOCAL(user)))
67                 {
68                         Channel* c = (Channel*)dest;
69                         if (c->IsModeSet('T'))
70                         {
71                                 if ((ServerInstance->ULine(user->server)) || (c->GetStatus(user) == STATUS_OP) || (c->GetStatus(user) == STATUS_HOP))
72                                 {
73                                         // ops and halfops can still /NOTICE the channel
74                                         return 0;
75                                 }
76                                 else
77                                 {
78                                         user->WriteServ("404 %s %s :Can't send NOTICE to channel (+T set)",user->nick, c->name);
79                                         return 1;
80                                 }
81                         }
82                 }
83                 return 0;
84         }
85
86         virtual ~ModuleNoNotice()
87         {
88                 ServerInstance->Modes->DelMode(nt);
89                 delete nt;
90         }
91         
92         virtual Version GetVersion()
93         {
94                 return Version(1,1,0,0,VF_COMMON|VF_VENDOR,API_VERSION);
95         }
96 };
97
98 MODULE_INIT(ModuleNoNotice)