-/* +------------------------------------+\r * | Inspire Internet Relay Chat Daemon |\r * +------------------------------------+\r *\r * InspIRCd: (C) 2002-2007 InspIRCd Development Team\r * See: http://www.inspircd.org/wiki/index.php/Credits\r *\r * This program is free but copyrighted software; see\r * the file COPYING for details.\r *\r * ---------------------------------------------------\r */\r\r#include "inspircd.h"\r#include "users.h"\r#include "channels.h"\r#include "modules.h"\r\r/* $ModDesc: Allows opers to set +W to see when a user uses WHOIS on them */\r\r/** Handle user mode +W\r */\rclass SeeWhois : public ModeHandler\r{\r public:\r SeeWhois(InspIRCd* Instance) : ModeHandler(Instance, 'W', 0, 0, false, MODETYPE_USER, true) { }\r\r ModeAction OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string ¶meter, bool adding)\r {\r /* Only opers can change other users modes */\r if (source != dest)\r return MODEACTION_DENY;\r\r if (adding)\r {\r if (!dest->IsModeSet('W'))\r {\r dest->SetMode('W',true);\r return MODEACTION_ALLOW;\r }\r }\r else\r {\r if (dest->IsModeSet('W'))\r {\r dest->SetMode('W',false);\r return MODEACTION_ALLOW;\r }\r }\r\r return MODEACTION_DENY;\r }\r};\r\rclass ModuleShowwhois : public Module\r{\r \r SeeWhois* sw;\r\r public:\r\r ModuleShowwhois(InspIRCd* Me) : Module(Me)\r {\r \r sw = new SeeWhois(ServerInstance);\r if (!ServerInstance->AddMode(sw, 'W'))\r throw ModuleException("Could not add new modes!");\r }\r\r ~ModuleShowwhois()\r {\r ServerInstance->Modes->DelMode(sw);\r DELETE(sw);\r }\r\r void Implements(char* List)\r {\r List[I_OnWhois] = 1;\r }\r\r virtual Version GetVersion()\r {\r return Version(1,1,0,3,VF_COMMON|VF_VENDOR,API_VERSION);\r }\r\r virtual void OnWhois(userrec* source, userrec* dest)\r {\r if ((dest->IsModeSet('W')) && (source != dest))\r {\r if (IS_LOCAL(dest))\r {\r dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you.",dest->nick,source->nick,source->ident,source->host);\r }\r else\r {\r std::deque<std::string> params;\r params.push_back(dest->nick);\r std::string msg = ":";\r msg = msg + dest->server + " NOTICE " + dest->nick + " :*** " + source->nick + " (" + source->ident + "@" + source->host + ") did a /whois on you.";\r params.push_back(msg);\r Event ev((char *) ¶ms, NULL, "send_push");\r ev.Send(ServerInstance);\r }\r }\r }\r\r};\r\rMODULE_INIT(ModuleShowwhois)\r
\ No newline at end of file
+/*
+ * InspIRCd -- Internet Relay Chat Daemon
+ *
+ * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
+ * Copyright (C) 2005, 2008 Robin Burchell <robin+git@viroteck.net>
+ * Copyright (C) 2007 Dennis Friis <peavey@inspircd.org>
+ * Copyright (C) 2006 Craig Edwards <craigedwards@brainbox.cc>
+ * Copyright (C) 2004 Christopher Hall <typobox43@gmail.com>
+ *
+ * This file is part of InspIRCd. InspIRCd is free software: you can
+ * redistribute it and/or modify it under the terms of the GNU General Public
+ * License as published by the Free Software Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+ * details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include "inspircd.h"
+
+/** Handle user mode +W
+ */
+class SeeWhois : public SimpleUserModeHandler
+{
+ public:
+ SeeWhois(Module* Creator)
+ : SimpleUserModeHandler(Creator, "showwhois", 'W')
+ {
+ }
+
+ void SetOperOnly(bool operonly)
+ {
+ oper = operonly;
+ }
+};
+
+class WhoisNoticeCmd : public Command
+{
+ public:
+ WhoisNoticeCmd(Module* Creator) : Command(Creator,"WHOISNOTICE", 2)
+ {
+ flags_needed = FLAG_SERVERONLY;
+ }
+
+ void HandleFast(User* dest, User* src)
+ {
+ dest->WriteNotice("*** " + src->nick + " (" + src->ident + "@" +
+ (dest->HasPrivPermission("users/auspex") ? src->host : src->dhost) +
+ ") did a /whois on you");
+ }
+
+ CmdResult Handle(const std::vector<std::string> ¶meters, User *user)
+ {
+ User* dest = ServerInstance->FindNick(parameters[0]);
+ if (!dest)
+ return CMD_FAILURE;
+
+ User* source = ServerInstance->FindNick(parameters[1]);
+
+ if (IS_LOCAL(dest) && source)
+ HandleFast(dest, source);
+
+ return CMD_SUCCESS;
+ }
+};
+
+class ModuleShowwhois : public Module
+{
+ bool ShowWhoisFromOpers;
+ SeeWhois sw;
+ WhoisNoticeCmd cmd;
+
+ public:
+
+ ModuleShowwhois()
+ : sw(this), cmd(this)
+ {
+ }
+
+ void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE
+ {
+ ConfigTag* tag = ServerInstance->Config->ConfValue("showwhois");
+
+ sw.SetOperOnly(tag->getBool("opersonly", true));
+ ShowWhoisFromOpers = tag->getBool("showfromopers", true);
+ }
+
+ Version GetVersion() CXX11_OVERRIDE
+ {
+ return Version("Allows opers to set +W to see when a user uses WHOIS on them",VF_OPTCOMMON|VF_VENDOR);
+ }
+
+ void OnWhois(User* source, User* dest) CXX11_OVERRIDE
+ {
+ if (!dest->IsModeSet(sw) || source == dest)
+ return;
+
+ if (!ShowWhoisFromOpers && source->IsOper())
+ return;
+
+ if (IS_LOCAL(dest))
+ {
+ cmd.HandleFast(dest, source);
+ }
+ else
+ {
+ std::vector<std::string> params;
+ params.push_back(dest->uuid);
+ params.push_back(source->uuid);
+ ServerInstance->PI->SendEncapsulatedData(dest->server->GetName(), cmd.name, params);
+ }
+ }
+};
+
+MODULE_INIT(ModuleShowwhois)