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