]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
7464a0d21b02f68b411133d255fd8f5b4a39ddba
[user/henk/code/inspircd.git] / src / modules / m_showwhois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2009 InspIRCd Development Team
6  * See: http://wiki.inspircd.org/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 WhoisNoticeCmd : public Command
49 {
50  public:
51         WhoisNoticeCmd(InspIRCd* Instance) : Command(Instance,"WHOISNOTICE", 0, 1)
52         {
53                 this->source = "m_showwhois.cpp";
54         }
55
56         void HandleFast(User* dest, User* src)
57         {
58                 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
59                         dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
60                         dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
61         }
62
63         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
64         {
65                 User* dest = ServerInstance->FindNick(parameters[0]);
66
67                 if (IS_LOCAL(dest))
68                         HandleFast(dest, user);
69
70                 return CMD_SUCCESS;
71         }
72 };
73
74 class ModuleShowwhois : public Module
75 {
76         bool ShowWhoisFromOpers;
77         SeeWhois* sw;
78         WhoisNoticeCmd cmd;
79
80  public:
81
82         ModuleShowwhois(InspIRCd* Me) : Module(Me), cmd(Me)
83         {
84                 ConfigReader conf(ServerInstance);
85                 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
86                 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
87
88                 sw = new SeeWhois(ServerInstance, OpersOnly);
89                 if (!ServerInstance->Modes->AddMode(sw))
90                         throw ModuleException("Could not add new modes!");
91                 ServerInstance->AddCommand(&cmd);
92                 Implementation eventlist[] = { I_OnWhois };
93                 ServerInstance->Modules->Attach(eventlist, this, 1);
94         }
95
96         ~ModuleShowwhois()
97         {
98                 ServerInstance->Modes->DelMode(sw);
99                 delete sw;
100         }
101
102         virtual Version GetVersion()
103         {
104                 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
105         }
106
107         virtual void OnWhois(User* source, User* dest)
108         {
109                 if (!dest->IsModeSet('W') || source == dest)
110                         return;
111
112                 if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest)))
113                         return;
114
115                 if (IS_LOCAL(dest))
116                 {
117                         cmd.HandleFast(dest, source);
118                 }
119                 else
120                 {
121                         std::vector<std::string> params;
122                         params.push_back(dest->server);
123                         params.push_back("WHOISNOTICE");
124                         params.push_back(dest->uuid);
125                         ServerInstance->PI->SendEncapsulatedData(params);
126                 }
127         }
128
129 };
130
131 MODULE_INIT(ModuleShowwhois)