1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2009 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
16 /* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */
18 /** Handle user mode +W
20 class SeeWhois : public ModeHandler
23 SeeWhois(Module* Creator, bool IsOpersOnly) : ModeHandler(Creator, 'W', PARAM_NONE, MODETYPE_USER)
28 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
32 if (!dest->IsModeSet('W'))
34 dest->SetMode('W',true);
35 return MODEACTION_ALLOW;
40 if (dest->IsModeSet('W'))
42 dest->SetMode('W',false);
43 return MODEACTION_ALLOW;
47 return MODEACTION_DENY;
51 class WhoisNoticeCmd : public Command
54 WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 1)
58 void HandleFast(User* dest, User* src)
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());
65 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
67 User* dest = ServerInstance->FindNick(parameters[0]);
70 HandleFast(dest, user);
76 class ModuleShowwhois : public Module
78 bool ShowWhoisFromOpers;
84 ModuleShowwhois(InspIRCd* Me) : cmd(this)
86 ConfigReader conf(ServerInstance);
87 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
88 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
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);
100 ServerInstance->Modes->DelMode(sw);
104 virtual Version GetVersion()
106 return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_COMMON|VF_VENDOR,API_VERSION);
109 virtual void OnWhois(User* source, User* dest)
111 if (!dest->IsModeSet('W') || source == dest)
114 if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest)))
119 cmd.HandleFast(dest, source);
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);
133 MODULE_INIT(ModuleShowwhois)