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, Module* Creator, bool IsOpersOnly) : ModeHandler(Instance, Creator, '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, Module* Creator) : Command(Instance, Creator,"WHOISNOTICE", 0, 1)
55 void HandleFast(User* dest, User* src)
57 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
58 dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
59 dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
62 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
64 User* dest = ServerInstance->FindNick(parameters[0]);
67 HandleFast(dest, user);
73 class ModuleShowwhois : public Module
75 bool ShowWhoisFromOpers;
81 ModuleShowwhois(InspIRCd* Me) : Module(Me), cmd(Me, this)
83 ConfigReader conf(ServerInstance);
84 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
85 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
87 sw = new SeeWhois(ServerInstance, this, OpersOnly);
88 if (!ServerInstance->Modes->AddMode(sw))
89 throw ModuleException("Could not add new modes!");
90 ServerInstance->AddCommand(&cmd);
91 Implementation eventlist[] = { I_OnWhois };
92 ServerInstance->Modules->Attach(eventlist, this, 1);
97 ServerInstance->Modes->DelMode(sw);
101 virtual Version GetVersion()
103 return Version("$Id$",VF_COMMON|VF_VENDOR,API_VERSION);
106 virtual void OnWhois(User* source, User* dest)
108 if (!dest->IsModeSet('W') || source == dest)
111 if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest)))
116 cmd.HandleFast(dest, source);
120 std::vector<std::string> params;
121 params.push_back(dest->server);
122 params.push_back("WHOISNOTICE");
123 params.push_back(dest->uuid);
124 ServerInstance->PI->SendEncapsulatedData(params);
130 MODULE_INIT(ModuleShowwhois)