summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/usermanager.h8
-rw-r--r--src/modules/m_showwhois.cpp72
2 files changed, 48 insertions, 32 deletions
diff --git a/include/usermanager.h b/include/usermanager.h
index 8b396eab0..56a545353 100644
--- a/include/usermanager.h
+++ b/include/usermanager.h
@@ -83,10 +83,10 @@ class CoreExport UserManager : public Extensible
void AddUser(InspIRCd* Instance, int socket, bool iscached, irc::sockets::sockaddrs* client, irc::sockets::sockaddrs* server);
/** Disconnect a user gracefully
- * @param user The user to remove
- * @param r The quit reason to show to normal users
- * @param oreason The quit reason to show to opers
- * @return Although this function has no return type, on exit the user provided will no longer exist.
+ * @param user The user to remove
+ * @param r The quit reason to show to normal users
+ * @param oreason The quit reason to show to opers
+ * @return Although this function has no return type, on exit the user provided will no longer exist.
*/
void QuitUser(User *user, const std::string &quitreason, const char* operreason = "");
diff --git a/src/modules/m_showwhois.cpp b/src/modules/m_showwhois.cpp
index 473fd6adc..7464a0d21 100644
--- a/src/modules/m_showwhois.cpp
+++ b/src/modules/m_showwhois.cpp
@@ -45,14 +45,41 @@ class SeeWhois : public ModeHandler
}
};
+class WhoisNoticeCmd : public Command
+{
+ public:
+ WhoisNoticeCmd(InspIRCd* Instance) : Command(Instance,"WHOISNOTICE", 0, 1)
+ {
+ this->source = "m_showwhois.cpp";
+ }
+
+ void HandleFast(User* dest, User* src)
+ {
+ dest->WriteServ("NOTICE %s :*** %s (%s@%s) did a /whois on you",
+ dest->nick.c_str(), src->nick.c_str(), src->ident.c_str(),
+ dest->HasPrivPermission("users/auspex") ? src->host.c_str() : src->dhost.c_str());
+ }
+
+ CmdResult Handle(const std::vector<std::string> &parameters, User *user)
+ {
+ User* dest = ServerInstance->FindNick(parameters[0]);
+
+ if (IS_LOCAL(dest))
+ HandleFast(dest, user);
+
+ return CMD_SUCCESS;
+ }
+};
+
class ModuleShowwhois : public Module
{
bool ShowWhoisFromOpers;
SeeWhois* sw;
+ WhoisNoticeCmd cmd;
public:
- ModuleShowwhois(InspIRCd* Me) : Module(Me)
+ ModuleShowwhois(InspIRCd* Me) : Module(Me), cmd(Me)
{
ConfigReader conf(ServerInstance);
bool OpersOnly = conf.ReadFlag("showwhois", "opersonly", "yes", 0);
@@ -61,6 +88,7 @@ class ModuleShowwhois : public Module
sw = new SeeWhois(ServerInstance, OpersOnly);
if (!ServerInstance->Modes->AddMode(sw))
throw ModuleException("Could not add new modes!");
+ ServerInstance->AddCommand(&cmd);
Implementation eventlist[] = { I_OnWhois };
ServerInstance->Modules->Attach(eventlist, this, 1);
}
@@ -78,35 +106,23 @@ class ModuleShowwhois : public Module
virtual void OnWhois(User* source, User* dest)
{
- if ((dest->IsModeSet('W')) && (source != dest))
- {
- if (!ShowWhoisFromOpers && IS_OPER(source))
- return;
+ if (!dest->IsModeSet('W') || source == dest)
+ return;
- std::string wmsg = "*** ";
- wmsg += source->nick + " (" + source->ident + "@";
+ if (!ShowWhoisFromOpers && (IS_OPER(source) != IS_OPER(dest)))
+ return;
- /* XXX HasPrivPermission doesn't work correctly for remote users */
- if (IS_LOCAL(dest) && dest->HasPrivPermission("users/auspex"))
- {
- wmsg += source->host;
- }
- else
- {
- wmsg += source->dhost;
- }
-
- wmsg += ") did a /whois on you";
-
- if (IS_LOCAL(dest))
- {
- dest->WriteServ("NOTICE %s :%s", dest->nick.c_str(), wmsg.c_str());
- }
- else
- {
- std::string msg = std::string("::") + dest->server + " NOTICE " + dest->nick + " :" + wmsg;
- ServerInstance->PI->PushToClient(dest, msg);
- }
+ if (IS_LOCAL(dest))
+ {
+ cmd.HandleFast(dest, source);
+ }
+ else
+ {
+ std::vector<std::string> params;
+ params.push_back(dest->server);
+ params.push_back("WHOISNOTICE");
+ params.push_back(dest->uuid);
+ ServerInstance->PI->SendEncapsulatedData(params);
}
}