]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Convert all to new Attach() system. The Implements() method needs removing from all...
[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 "inspircd.h"
15
16 /* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */
17
18 /** Handle user mode +W
19  */
20 class SeeWhois : public ModeHandler
21 {
22  public:
23         SeeWhois(InspIRCd* Instance) : ModeHandler(Instance, 'W', 0, 0, false, MODETYPE_USER, true) { }
24
25         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
26         {
27                 /* Only opers can change other users modes */
28                 if (source != dest)
29                         return MODEACTION_DENY;
30
31                 if (adding)
32                 {
33                         if (!dest->IsModeSet('W'))
34                         {
35                                 dest->SetMode('W',true);
36                                 return MODEACTION_ALLOW;
37                         }
38                 }
39                 else
40                 {
41                         if (dest->IsModeSet('W'))
42                         {
43                                 dest->SetMode('W',false);
44                                 return MODEACTION_ALLOW;
45                         }
46                 }
47
48                 return MODEACTION_DENY;
49         }
50 };
51
52 class ModuleShowwhois : public Module
53 {
54         
55         SeeWhois* sw;
56
57  public:
58
59         ModuleShowwhois(InspIRCd* Me) : Module(Me)
60         {
61                 
62                 sw = new SeeWhois(ServerInstance);
63                 if (!ServerInstance->AddMode(sw))
64                         throw ModuleException("Could not add new modes!");
65                 Implementation eventlist[] = { I_OnWhois };
66                 ServerInstance->Modules->Attach(eventlist, this, 1);
67         }
68
69         ~ModuleShowwhois()
70         {
71                 ServerInstance->Modes->DelMode(sw);
72                 DELETE(sw);
73         }
74
75         void Implements(char* List)
76         {
77                 List[I_OnWhois] = 1;
78         }
79
80         virtual Version GetVersion()
81         {
82                 return Version(1,1,0,3,VF_COMMON|VF_VENDOR,API_VERSION);
83         }
84
85         virtual void OnWhois(User* source, User* dest)
86         {
87                 if ((dest->IsModeSet('W')) && (source != dest))
88                 {
89                         if (IS_LOCAL(dest))
90                         {
91                                 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you.",dest->nick,source->nick,source->ident,source->host);
92                         }
93                         else
94                         {
95                                 std::deque<std::string> params;
96                                 params.push_back(dest->nick);
97                                 std::string msg = ":";
98                                 msg = msg + dest->server + " NOTICE " + dest->nick + " :*** " + source->nick + " (" + source->ident + "@" + source->host + ") did a /whois on you.";
99                                 params.push_back(msg);
100                                 Event ev((char *) &params, NULL, "send_push");
101                                 ev.Send(ServerInstance);
102                         }
103                 }
104         }
105
106 };
107
108 MODULE_INIT(ModuleShowwhois)