]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Fix iteration of oper blocks by SSLINFO
[user/henk/code/inspircd.git] / src / modules / m_showwhois.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd: (C) 2002-2010 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, "showwhois", '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                 User* source = ServerInstance->FindNick(parameters[1]);
69
70                 if (IS_LOCAL(dest) && source)
71                         HandleFast(dest, source);
72
73                 return CMD_SUCCESS;
74         }
75 };
76
77 class ModuleShowwhois : public Module
78 {
79         bool ShowWhoisFromOpers;
80         SeeWhois* sw;
81         WhoisNoticeCmd cmd;
82
83  public:
84
85         ModuleShowwhois() : cmd(this)
86         {
87                 ConfigReader conf;
88                 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
89                 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
90
91                 sw = new SeeWhois(this, OpersOnly);
92                 if (!ServerInstance->Modes->AddMode(sw))
93                         throw ModuleException("Could not add new modes!");
94                 ServerInstance->AddCommand(&cmd);
95                 Implementation eventlist[] = { I_OnWhois };
96                 ServerInstance->Modules->Attach(eventlist, this, 1);
97         }
98
99         ~ModuleShowwhois()
100         {
101                 delete sw;
102         }
103
104         Version GetVersion()
105         {
106                 return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
107         }
108
109         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(source->uuid);
127                         params.push_back(dest->uuid);
128                         ServerInstance->PI->SendEncapsulatedData(params);
129                 }
130         }
131
132 };
133
134 MODULE_INIT(ModuleShowwhois)