]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Header update: 2007 -> 2008
[user/henk/code/inspircd.git] / src / modules / m_showwhois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2008 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
76         virtual Version GetVersion()
77         {
78                 return Version(1,1,0,3,VF_COMMON|VF_VENDOR,API_VERSION);
79         }
80
81         virtual void OnWhois(User* source, User* dest)
82         {
83                 if ((dest->IsModeSet('W')) && (source != dest))
84                 {
85                         if (IS_LOCAL(dest))
86                         {
87                                 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you.",dest->nick,source->nick,source->ident,source->host);
88                         }
89                         else
90                         {
91                                 std::deque<std::string> params;
92                                 params.push_back(dest->nick);
93                                 std::string msg = ":";
94                                 msg = msg + dest->server + " NOTICE " + dest->nick + " :*** " + source->nick + " (" + source->ident + "@" + source->host + ") did a /whois on you.";
95                                 params.push_back(msg);
96                                 Event ev((char *) &params, NULL, "send_push");
97                                 ev.Send(ServerInstance);
98                         }
99                 }
100         }
101
102 };
103
104 MODULE_INIT(ModuleShowwhois)