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(InspIRCd* Instance, bool IsOpersOnly) : ModeHandler(Instance, 'W', 0, 0, false, MODETYPE_USER, IsOpersOnly) { }
25 ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding, bool)
29 if (!dest->IsModeSet('W'))
31 dest->SetMode('W',true);
32 return MODEACTION_ALLOW;
37 if (dest->IsModeSet('W'))
39 dest->SetMode('W',false);
40 return MODEACTION_ALLOW;
44 return MODEACTION_DENY;
48 class WhoisNoticeCmd : public Command
51 WhoisNoticeCmd(InspIRCd* Instance) : Command(Instance,"WHOISNOTICE", 0, 1)
53 this->source = "m_showwhois.cpp";
56 void HandleFast(User* dest, User* src)
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());
63 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
65 User* dest = ServerInstance->FindNick(parameters[0]);
68 HandleFast(dest, user);
74 class ModuleShowwhois : public Module
76 bool ShowWhoisFromOpers;
82 ModuleShowwhois(InspIRCd* Me) : Module(Me), cmd(Me)
84 ConfigReader conf(ServerInstance);
85 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
86 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
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);
98 ServerInstance->Modes->DelMode(sw);
102 virtual Version GetVersion()
104 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
107 virtual void OnWhois(User* source, User* dest)
109 if (!dest->IsModeSet('W') || source == dest)
112 if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest)))
117 cmd.HandleFast(dest, source);
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);
131 MODULE_INIT(ModuleShowwhois)