]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Windows support. Tested and working to compile on freebsd and linux. Next step is...
[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)
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(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                         if (IS_LOCAL(dest))
91                         {
92                                 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you.",dest->nick,source->nick,source->ident,source->host);
93                         }
94                         else
95                         {
96                                 std::deque<std::string> params;
97                                 params.push_back(dest->nick);
98                                 std::string msg = ":";
99                                 msg = msg + dest->server + " NOTICE " + dest->nick + " :*** " + source->nick + " (" + source->ident + "@" + source->host + ") did a /whois on you.";
100                                 params.push_back(msg);
101                                 Event ev((char *) &params, NULL, "send_push");
102                                 ev.Send(ServerInstance);
103                         }
104                 }
105         }
106
107 };
108
109 class ModuleShowwhoisFactory : public ModuleFactory
110 {
111         public:
112                 ModuleShowwhoisFactory()
113                 {
114                 }
115
116                 ~ModuleShowwhoisFactory()
117                 {
118                 }
119
120                 virtual Module* CreateModule(InspIRCd* Me)
121                 {
122                         return new ModuleShowwhois(Me);
123                 }
124
125 };
126
127 extern "C" DllExport void* init_module()
128 {
129         return new ModuleShowwhoisFactory;
130 }