]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
7dcfebdf627c0dadea88ecc34bf8c81d6ab56ce9
[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                 if (!ServerInstance->AddMode(sw, 'W'))
67                         throw ModuleException("Could not add new modes!");
68         }
69
70         ~ModuleShowwhois()
71         {
72                 ServerInstance->Modes->DelMode(sw);
73                 DELETE(sw);
74         }
75
76         void Implements(char* List)
77         {
78                 List[I_OnWhois] = 1;
79         }
80
81         virtual Version GetVersion()
82         {
83                 return Version(1,1,0,3,VF_COMMON|VF_VENDOR,API_VERSION);
84         }
85
86         virtual void OnWhois(userrec* source, userrec* dest)
87         {
88                 if ((dest->IsModeSet('W')) && (source != dest))
89                 {
90                         dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you.",dest->nick,source->nick,source->ident,source->host);
91                 }
92         }
93
94 };
95
96 class ModuleShowwhoisFactory : public ModuleFactory
97 {
98         public:
99                 ModuleShowwhoisFactory()
100                 {
101                 }
102
103                 ~ModuleShowwhoisFactory()
104                 {
105                 }
106
107                 virtual Module* CreateModule(InspIRCd* Me)
108                 {
109                         return new ModuleShowwhois(Me);
110                 }
111
112 };
113
114 extern "C" void* init_module()
115 {
116         return new ModuleShowwhoisFactory;
117 }