]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Added <oper:swhois> to m_swhois, which will override <type:swhois> if specified
[user/henk/code/inspircd.git] / src / modules / m_showwhois.cpp
1 using namespace std;
2
3 // showwhois module by typobox43
4 // Modified by Craig
5
6 #include "users.h"
7 #include "channels.h"
8 #include "modules.h"
9 #include "inspircd.h"
10
11 /* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */
12
13 /** Handle user mode +W
14  */
15 class SeeWhois : public ModeHandler
16 {
17  public:
18         SeeWhois(InspIRCd* Instance) : ModeHandler(Instance, 'W', 0, 0, false, MODETYPE_USER, true) { }
19
20         ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
21         {
22                 /* Only opers can change other users modes */
23                 if ((source != dest) && (!*source->oper))
24                         return MODEACTION_DENY;
25
26                 if (adding)
27                 {
28                         if (!dest->IsModeSet('W'))
29                         {
30                                 dest->SetMode('W',true);
31                                 return MODEACTION_ALLOW;
32                         }
33                 }
34                 else
35                 {
36                         if (dest->IsModeSet('W'))
37                         {
38                                 dest->SetMode('W',false);
39                                 return MODEACTION_ALLOW;
40                         }
41                 }
42
43                 return MODEACTION_DENY;
44         }
45 };
46
47 class ModuleShowwhois : public Module
48 {
49         
50         SeeWhois* sw;
51
52  public:
53
54         ModuleShowwhois(InspIRCd* Me) : Module::Module(Me)
55         {
56                 
57                 sw = new SeeWhois(ServerInstance);
58                 ServerInstance->AddMode(sw, 'W');
59         }
60
61         ~ModuleShowwhois()
62         {
63                 ServerInstance->Modes->DelMode(sw);
64                 DELETE(sw);
65         }
66
67         void Implements(char* List)
68         {
69                 List[I_OnWhois] = 1;
70         }
71
72         virtual Version GetVersion()
73         {
74                 return Version(1,1,0,3,VF_COMMON|VF_VENDOR,API_VERSION);
75         }
76
77         virtual void OnWhois(userrec* source, userrec* dest)
78         {
79                 if ((dest->IsModeSet('W')) && (source != dest))
80                 {
81                         dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you.",dest->nick,source->nick,source->ident,source->host);
82                 }
83         }
84
85 };
86
87 class ModuleShowwhoisFactory : public ModuleFactory
88 {
89         public:
90                 ModuleShowwhoisFactory()
91                 {
92                 }
93
94                 ~ModuleShowwhoisFactory()
95                 {
96                 }
97
98                 virtual Module* CreateModule(InspIRCd* Me)
99                 {
100                         return new ModuleShowwhois(Me);
101                 }
102
103 };
104
105 extern "C" void* init_module()
106 {
107         return new ModuleShowwhoisFactory;
108 }