]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/modules/m_showwhois.cpp
Add <showwhois:opersonly>, allows server admins to unlock umode +W use for regular...
[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
51         SeeWhois* sw;
52
53  public:
54
55         ModuleShowwhois(InspIRCd* Me) : Module(Me)
56         {
57                 sw = NULL;
58                 OnRehash(NULL, "");
59                 Implementation eventlist[] = { I_OnWhois, I_OnRehash };
60                 ServerInstance->Modules->Attach(eventlist, this, 2);
61         }
62
63         ~ModuleShowwhois()
64         {
65                 ServerInstance->Modes->DelMode(sw);
66                 delete sw;
67         }
68
69         virtual Version GetVersion()
70         {
71                 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
72         }
73
74         virtual void OnRehash(User *user, const std::string &parameter)
75         {
76                 ConfigReader conf(ServerInstance);
77                 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", 0, true);
78
79                 if (sw)
80                 {
81                         ServerInstance->Modes->DelMode(sw);
82                         delete sw;                      
83                 }
84
85                 sw = new SeeWhois(ServerInstance, OpersOnly);
86                 if (!ServerInstance->Modes->AddMode(sw))
87                         throw ModuleException("Could not add new modes!");
88         }
89
90         virtual void OnWhois(User* source, User* dest)
91         {
92                 if ((dest->IsModeSet('W')) && (source != dest))
93                 {
94                         std::string wmsg = "*** ";
95                         wmsg += source->nick + "(" + source->ident + "@";
96
97                         if (dest->HasPrivPermission("users/auspex"))
98                         {
99                                 wmsg += source->host;
100                         }
101                         else
102                         {
103                                 wmsg += source->dhost;
104                         }
105
106                         wmsg += ") did a /whois on you";
107
108                         if (IS_LOCAL(dest))
109                         {
110                                 dest->WriteServ("NOTICE %s :%s", dest->nick.c_str(), wmsg.c_str());
111                         }
112                         else
113                         {
114                                 std::string msg = std::string(":") + dest->server + " NOTICE " + dest->nick + " :" + wmsg;
115                                 ServerInstance->PI->PushToClient(dest, msg);
116                         }
117                 }
118         }
119
120 };
121
122 MODULE_INIT(ModuleShowwhois)