]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
e4e666a1d5e0b825568981923e9ed02ba0162835
[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, bool IsOpersOnly) : ModeHandler(Instance, 'W', 0, 0, false, MODETYPE_USER, IsOpersOnly) { }
24
25         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding, bool)
26         {
27                 if (adding)
28                 {
29                         if (!dest->IsModeSet('W'))
30                         {
31                                 dest->SetMode('W',true);
32                                 return MODEACTION_ALLOW;
33                         }
34                 }
35                 else
36                 {
37                         if (dest->IsModeSet('W'))
38                         {
39                                 dest->SetMode('W',false);
40                                 return MODEACTION_ALLOW;
41                         }
42                 }
43
44                 return MODEACTION_DENY;
45         }
46 };
47
48 class ModuleShowwhois : public Module
49 {
50         bool ShowWhoisFromOpers;
51         SeeWhois* sw;
52
53  public:
54
55         ModuleShowwhois(InspIRCd* Me) : Module(Me)
56         {
57                 ConfigReader conf(ServerInstance);
58                 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
59                 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
60
61                 sw = new SeeWhois(ServerInstance, OpersOnly);
62                 if (!ServerInstance->Modes->AddMode(sw))
63                         throw ModuleException("Could not add new modes!");
64                 Implementation eventlist[] = { I_OnWhois };
65                 ServerInstance->Modules->Attach(eventlist, this, 1);
66         }
67
68         ~ModuleShowwhois()
69         {
70                 ServerInstance->Modes->DelMode(sw);
71                 delete sw;
72         }
73
74         virtual Version GetVersion()
75         {
76                 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
77         }
78
79         virtual void OnWhois(User* source, User* dest)
80         {
81                 if ((dest->IsModeSet('W')) && (source != dest))
82                 {
83                         if (!ShowWhoisFromOpers && IS_OPER(source))
84                                 return;
85
86                         std::string wmsg = "*** ";
87                         wmsg += source->nick + "(" + source->ident + "@";
88
89                         if (dest->HasPrivPermission("users/auspex"))
90                         {
91                                 wmsg += source->host;
92                         }
93                         else
94                         {
95                                 wmsg += source->dhost;
96                         }
97
98                         wmsg += ") did a /whois on you";
99
100                         if (IS_LOCAL(dest))
101                         {
102                                 dest->WriteServ("NOTICE %s :%s", dest->nick.c_str(), wmsg.c_str());
103                         }
104                         else
105                         {
106                                 std::string msg = std::string(":") + dest->server + " NOTICE " + dest->nick + " :" + wmsg;
107                                 ServerInstance->PI->PushToClient(dest, msg);
108                         }
109                 }
110         }
111
112 };
113
114 MODULE_INIT(ModuleShowwhois)