]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Change to use std::string::iterator rather than making a copy of the pointer and...
[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 "users.h"
15 #include "channels.h"
16 #include "modules.h"
17 #include "inspircd.h"
18
19 /* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */
20
21 /** Handle user mode +W
22  */
23 class SeeWhois : public ModeHandler
24 {
25  public:
26         SeeWhois(InspIRCd* Instance) : ModeHandler(Instance, 'W', 0, 0, false, MODETYPE_USER, true) { }
27
28         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
29         {
30                 /* Only opers can change other users modes */
31                 if ((source != dest) && (!*source->oper))
32                         return MODEACTION_DENY;
33
34                 if (adding)
35                 {
36                         if (!dest->IsModeSet('W'))
37                         {
38                                 dest->SetMode('W',true);
39                                 return MODEACTION_ALLOW;
40                         }
41                 }
42                 else
43                 {
44                         if (dest->IsModeSet('W'))
45                         {
46                                 dest->SetMode('W',false);
47                                 return MODEACTION_ALLOW;
48                         }
49                 }
50
51                 return MODEACTION_DENY;
52         }
53 };
54
55 class ModuleShowwhois : public Module
56 {
57         
58         SeeWhois* sw;
59
60  public:
61
62         ModuleShowwhois(InspIRCd* Me) : Module::Module(Me)
63         {
64                 
65                 sw = new SeeWhois(ServerInstance);
66                 ServerInstance->AddMode(sw, 'W');
67         }
68
69         ~ModuleShowwhois()
70         {
71                 ServerInstance->Modes->DelMode(sw);
72                 DELETE(sw);
73         }
74
75         void Implements(char* List)
76         {
77                 List[I_OnWhois] = 1;
78         }
79
80         virtual Version GetVersion()
81         {
82                 return Version(1,1,0,3,VF_COMMON|VF_VENDOR,API_VERSION);
83         }
84
85         virtual void OnWhois(userrec* source, userrec* dest)
86         {
87                 if ((dest->IsModeSet('W')) && (source != 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         }
92
93 };
94
95 class ModuleShowwhoisFactory : public ModuleFactory
96 {
97         public:
98                 ModuleShowwhoisFactory()
99                 {
100                 }
101
102                 ~ModuleShowwhoisFactory()
103                 {
104                 }
105
106                 virtual Module* CreateModule(InspIRCd* Me)
107                 {
108                         return new ModuleShowwhois(Me);
109                 }
110
111 };
112
113 extern "C" void* init_module()
114 {
115         return new ModuleShowwhoisFactory;
116 }