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