1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 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, "showwhois", '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)
56 flags_needed = FLAG_SERVERONLY;
59 void HandleFast(User* dest, User* src)
61 dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
62 dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
63 dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
66 CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
68 User* dest = ServerInstance->FindNick(parameters[0]);
69 User* source = ServerInstance->FindNick(parameters[1]);
71 if (IS_LOCAL(dest) && source)
72 HandleFast(dest, source);
78 class ModuleShowwhois : public Module
80 bool ShowWhoisFromOpers;
86 ModuleShowwhois() : cmd(this)
89 bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
90 ShowWhoisFromOpers = conf.ReadFlag("showwhois", "showfromopers", "yes", 0);
92 sw = new SeeWhois(this, OpersOnly);
93 if (!ServerInstance->Modes->AddMode(sw))
94 throw ModuleException("Could not add new modes!");
95 ServerInstance->AddCommand(&cmd);
96 Implementation eventlist[] = { I_OnWhois };
97 ServerInstance->Modules->Attach(eventlist, this, 1);
107 return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
110 void OnWhois(User* source, User* dest)
112 if (!dest->IsModeSet('W') || source == dest)
115 if (!ShowWhoisFromOpers && (!IS_OPER(source) != !IS_OPER(dest)))
120 cmd.HandleFast(dest, source);
124 std::vector<std::string> params;
125 params.push_back(dest->server);
126 params.push_back("WHOISNOTICE");
127 params.push_back(dest->uuid);
128 params.push_back(source->uuid);
129 ServerInstance->PI->SendEncapsulatedData(params);
135 MODULE_INIT(ModuleShowwhois)