]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_nonotice.cpp
6d8e8a4019ffa26bc7f037e6c1e0de98e339222f
[user/henk/code/inspircd.git] / src / modules / m_nonotice.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
6  *                       E-mail:
7  *                <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *            the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 #include <stdio.h>
18 #include "users.h"
19 #include "channels.h"
20 #include "modules.h"
21
22 /* $ModDesc: Provides support for unreal-style channel mode +T */
23
24 class ModuleNoNotice : public Module
25 {
26         Server *Srv;
27  public:
28  
29         ModuleNoNotice()
30         {
31                 Srv = new Server;
32                 Srv->AddExtendedMode('T',MT_CHANNEL,false,0,0);
33         }
34         
35         virtual int OnUserPreNotice(userrec* user,void* dest,int target_type, std::string &text)
36         {
37                 if (target_type == TYPE_CHANNEL)
38                 {
39                         chanrec* c = (chanrec*)dest;
40                         if (c->IsCustomModeSet('T'))
41                         {
42                                 if ((Srv->ChanMode(user,c) == "@") || (Srv->ChanMode(user,c) == "%"))
43                                 {
44                                         // ops and halfops can still /NOTICE the channel
45                                         return 0;
46                                 }
47                                 else
48                                 {
49                                         WriteServ(user->fd,"404 %s %s :Can't send NOTICE to channel (+T set)",user->nick, c->name);
50                                         return 1;
51                                 }
52                         }
53                 }
54                 return 0;
55         }
56
57         virtual void On005Numeric(std::string &output)
58         {
59                 std::stringstream line(output);
60                 std::string temp1, temp2;
61                 while (!line.eof())
62                 {
63                         line >> temp1;
64                         if (temp1.substr(0,10) == "CHANMODES=")
65                         {
66                                 // append the chanmode to the end
67                                 temp1 = temp1.substr(10,temp1.length());
68                                 temp1 = "CHANMODES=" + temp1 + "T";
69                         }
70                         temp2 = temp2 + temp1 + " ";
71                 }
72                 output = temp2.substr(0,temp2.length()-1);
73         }
74
75         virtual int OnExtendedMode(userrec* user, void* target, char modechar, int type, bool mode_on, string_list &params)
76         {
77                 // check if this is our mode character...
78                 if ((modechar == 'T') && (type == MT_CHANNEL))
79                 {
80                         return 1;
81                 }
82                 else
83                 {
84                         return 0;
85                 }
86         }
87         
88         virtual ~ModuleNoNotice()
89         {
90                 delete Srv;
91         }
92         
93         virtual Version GetVersion()
94         {
95                 return Version(1,0,0,0);
96         }
97 };
98
99
100 class ModuleNoNoticeFactory : public ModuleFactory
101 {
102  public:
103         ModuleNoNoticeFactory()
104         {
105         }
106         
107         ~ModuleNoNoticeFactory()
108         {
109         }
110         
111         virtual Module * CreateModule()
112         {
113                 return new ModuleNoNotice;
114         }
115         
116 };
117
118
119 extern "C" void * init_module( void )
120 {
121         return new ModuleNoNoticeFactory;
122 }
123