]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
63e02c76d39fcdea6ecd91b04ad8da56d5a1da28
[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(Module* Creator, bool IsOpersOnly) : ModeHandler(Creator, 'W', PARAM_NONE, MODETYPE_USER)
24         {
25                 oper = IsOpersOnly;
26         }
27
28         ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string &parameter, bool adding)
29         {
30                 if (adding)
31                 {
32                         if (!dest->IsModeSet('W'))
33                         {
34                                 dest->SetMode('W',true);
35                                 return MODEACTION_ALLOW;
36                         }
37                 }
38                 else
39                 {
40                         if (dest->IsModeSet('W'))
41                         {
42                                 dest->SetMode('W',false);
43                                 return MODEACTION_ALLOW;
44                         }
45                 }
46
47                 return MODEACTION_DENY;
48         }
49 };
50
51 class WhoisNoticeCmd : public Command
52 {
53  public:
54         WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 1)
55         {
56         }
57
58         void HandleFast(User* dest, User* src)
59         {
60                 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
61                         dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
62                         dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
63         }
64
65         CmdResult Handle(const std::vector<std::string> &parameters, User *user)
66         {
67                 User* dest = ServerInstance->FindNick(parameters[0]);
68
69                 if (IS_LOCAL(dest))
70                         HandleFast(dest, user);
71
72                 return CMD_SUCCESS;
73         }
74 };
75
76 class ModuleShowwhois : public Module
77 {
78         bool ShowWhoisFromOpers;
79         SeeWhois* sw;
80         WhoisNoticeCmd cmd;
81
82  public:
83
84         ModuleShowwhois(InspIRCd* Me) : cmd(this)
85         {
86                 ConfigReader conf(ServerInstance);
87                 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
88                 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
89
90                 sw = new SeeWhois(this, OpersOnly);
91                 if (!ServerInstance->Modes->AddMode(sw))
92                         throw ModuleException("Could not add new modes!");
93                 ServerInstance->AddCommand(&cmd);
94                 Implementation eventlist[] = { I_OnWhois };
95                 ServerInstance->Modules->Attach(eventlist, this, 1);
96         }
97
98         ~ModuleShowwhois()
99         {
100                 ServerInstance->Modes->DelMode(sw);
101                 delete sw;
102         }
103
104         virtual Version GetVersion()
105         {
106                 return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_COMMON|VF_VENDOR,API_VERSION);
107         }
108
109         virtual void OnWhois(User* source, User* dest)
110         {
111                 if (!dest->IsModeSet('W') || source == dest)
112                         return;
113
114                 if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest)))
115                         return;
116
117                 if (IS_LOCAL(dest))
118                 {
119                         cmd.HandleFast(dest, source);
120                 }
121                 else
122                 {
123                         std::vector<std::string> params;
124                         params.push_back(dest->server);
125                         params.push_back("WHOISNOTICE");
126                         params.push_back(dest->uuid);
127                         ServerInstance->PI->SendEncapsulatedData(params);
128                 }
129         }
130
131 };
132
133 MODULE_INIT(ModuleShowwhois)