]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Add sanity checks to the ssl modules so that theres no possibility of an out of range...
[user/henk/code/inspircd.git] / src / modules / m_showwhois.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: Allows opers to set +W to see when a user uses WHOIS on them */
17
18 /** Handle user mode +W
19  */
20 class SeeWhois : public ModeHandler
21 {
22  public:
23         SeeWhois(InspIRCd* Instance) : ModeHandler(Instance, 'W', 0, 0, false, MODETYPE_USER, true) { }
24
25         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
26         {
27                 /* Only opers can change other users modes */
28                 if (source != dest)
29                         return MODEACTION_DENY;
30
31                 if (adding)
32                 {
33                         if (!dest->IsModeSet('W'))
34                         {
35                                 dest->SetMode('W',true);
36                                 return MODEACTION_ALLOW;
37                         }
38                 }
39                 else
40                 {
41                         if (dest->IsModeSet('W'))
42                         {
43                                 dest->SetMode('W',false);
44                                 return MODEACTION_ALLOW;
45                         }
46                 }
47
48                 return MODEACTION_DENY;
49         }
50 };
51
52 class ModuleShowwhois : public Module
53 {
54         
55         SeeWhois* sw;
56
57  public:
58
59         ModuleShowwhois(InspIRCd* Me) : Module(Me)
60         {
61                 
62                 sw = new SeeWhois(ServerInstance);
63                 if (!ServerInstance->AddMode(sw, 'W'))
64                         throw ModuleException("Could not add new modes!");
65         }
66
67         ~ModuleShowwhois()
68         {
69                 ServerInstance->Modes->DelMode(sw);
70                 DELETE(sw);
71         }
72
73         void Implements(char* List)
74         {
75                 List[I_OnWhois] = 1;
76         }
77
78         virtual Version GetVersion()
79         {
80                 return Version(1,1,0,3,VF_COMMON|VF_VENDOR,API_VERSION);
81         }
82
83         virtual void OnWhois(userrec* source, userrec* dest)
84         {
85                 if ((dest->IsModeSet('W')) && (source != dest))
86                 {
87                         if (IS_LOCAL(dest))
88                         {
89                                 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you.",dest->nick,source->nick,source->ident,source->host);
90                         }
91                         else
92                         {
93                                 std::deque<std::string> params;
94                                 params.push_back(dest->nick);
95                                 std::string msg = ":";
96                                 msg = msg + dest->server + " NOTICE " + dest->nick + " :*** " + source->nick + " (" + source->ident + "@" + source->host + ") did a /whois on you.";
97                                 params.push_back(msg);
98                                 Event ev((char *) &params, NULL, "send_push");
99                                 ev.Send(ServerInstance);
100                         }
101                 }
102         }
103
104 };
105
106 MODULE_INIT(ModuleShowwhois)