summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/inspircd.h4
-rw-r--r--include/modules.h15
-rw-r--r--src/cmd_modules.cpp2
-rw-r--r--src/cmd_whois.cpp24
-rw-r--r--src/helperfuncs.cpp22
-rw-r--r--src/modules.cpp2
-rw-r--r--src/modules/extra/m_ssl_gnutls.cpp2
-rw-r--r--src/modules/extra/m_ssl_openssl.cpp2
-rw-r--r--src/modules/m_botmode.cpp2
-rw-r--r--src/modules/m_helpop.cpp2
-rw-r--r--src/modules/m_services.cpp2
-rw-r--r--src/modules/m_services_account.cpp2
-rw-r--r--src/modules/m_ssl_dummy.cpp3
-rw-r--r--src/modules/m_swhois.cpp2
-rw-r--r--src/users.cpp7
15 files changed, 67 insertions, 26 deletions
diff --git a/include/inspircd.h b/include/inspircd.h
index 16b42e50b..1aead5d5e 100644
--- a/include/inspircd.h
+++ b/include/inspircd.h
@@ -998,6 +998,10 @@ class InspIRCd : public classbase
*/
void Log(int level, const std::string &text);
+ void SendWhoisLine(userrec* user, int numeric, const std::string &text);
+
+ void SendWhoisLine(userrec* user, int numeric, const char* format, ...);
+
/** Begin execution of the server.
* NOTE: this function NEVER returns. Internally,
* after performing some initialisation routines,
diff --git a/include/modules.h b/include/modules.h
index 18269e144..2d7e9f4ab 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -356,7 +356,8 @@ enum Implementation { I_OnUserConnect, I_OnUserQuit, I_OnUserDisconnect, I_OnUse
I_OnCheckKey, I_OnCheckLimit, I_OnCheckBan, I_OnStats, I_OnChangeLocalUserHost, I_OnChangeLocalUserGecos, I_OnLocalTopicChange,
I_OnPostLocalTopicChange, I_OnEvent, I_OnRequest, I_OnOperCompre, I_OnGlobalOper, I_OnPostConnect, I_OnAddBan, I_OnDelBan,
I_OnRawSocketAccept, I_OnRawSocketClose, I_OnRawSocketWrite, I_OnRawSocketRead, I_OnChangeLocalUserGECOS, I_OnUserRegister,
- I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList, I_OnPostCommand, I_OnPostJoin };
+ I_OnOperCompare, I_OnChannelDelete, I_OnPostOper, I_OnSyncOtherMetaData, I_OnSetAway, I_OnCancelAway, I_OnUserList,
+ I_OnPostCommand, I_OnPostJoin, I_OnWhoisLine };
/** Base class for all InspIRCd modules
* This class is the base class for InspIRCd modules. All modules must inherit from this class,
@@ -1286,6 +1287,18 @@ class Module : public Extensible
* return 0.
*/
virtual int OnUserList(userrec* user, chanrec* Ptr);
+
+ /** Called whenever a line of WHOIS output is sent to a user.
+ * You may change the numeric and the text of the output by changing
+ * the values numeric and text, but you cannot change the user the
+ * numeric is sent to. You may however change the user's userrec values.
+ * @param user The user the numeric is being sent to
+ * @param numeric The numeric of the line being sent
+ * @param text The text of the numeric, including any parameters
+ * @return nonzero to drop the line completely so that the user does not
+ * receive it, or zero to allow the line to be sent.
+ */
+ virtual int OnWhoisLine(userrec* user, int &numeric, std::string &text);
};
diff --git a/src/cmd_modules.cpp b/src/cmd_modules.cpp
index c2fe71f70..9c714e439 100644
--- a/src/cmd_modules.cpp
+++ b/src/cmd_modules.cpp
@@ -34,7 +34,7 @@ char* itab[] = {
"OnPostLocalTopicChange", "OnEvent", "OnRequest", "OnOperCompre", "OnGlobalOper", "OnPostConnect", "OnAddBan", "OnDelBan",
"OnRawSocketAccept", "OnRawSocketClose", "OnRawSocketWrite", "OnRawSocketRead", "OnChangeLocalUserGECOS", "OnUserRegister",
"OnOperCompare", "OnChannelDelete", "OnPostOper", "OnSyncOtherMetaData", "OnSetAway", "OnCancelAway", "OnNamesList",
- "OnPostCommand", "OnPostJoin", NULL
+ "OnPostCommand", "OnPostJoin", "OnWhoisLine", NULL
};
extern "C" command_t* init_command(InspIRCd* Instance)
diff --git a/src/cmd_whois.cpp b/src/cmd_whois.cpp
index c0c5b97a3..42c272c97 100644
--- a/src/cmd_whois.cpp
+++ b/src/cmd_whois.cpp
@@ -26,10 +26,10 @@ void do_whois(InspIRCd* ServerInstance, userrec* user, userrec* dest,unsigned lo
// bug found by phidjit - were able to whois an incomplete connection if it had sent a NICK or USER
if (dest->registered == REG_ALL)
{
- user->WriteServ("311 %s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
+ ServerInstance->SendWhoisLine(user, 311, "%s %s %s %s * :%s",user->nick, dest->nick, dest->ident, dest->dhost, dest->fullname);
if ((user == dest) || (*user->oper))
{
- user->WriteServ("378 %s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, dest->GetIPString());
+ ServerInstance->SendWhoisLine(user, 378, "%s %s :is connecting from *@%s %s",user->nick, dest->nick, dest->host, dest->GetIPString());
}
std::string cl = dest->ChannelList(user);
if (cl.length())
@@ -40,24 +40,24 @@ void do_whois(InspIRCd* ServerInstance, userrec* user, userrec* dest,unsigned lo
}
else
{
- user->WriteServ("319 %s %s :%s",user->nick, dest->nick, cl.c_str());
+ ServerInstance->SendWhoisLine(user, 319, "%s %s :%s",user->nick, dest->nick, cl.c_str());
}
}
if (*ServerInstance->Config->HideWhoisServer && !(*user->oper))
{
- user->WriteServ("312 %s %s %s :%s",user->nick, dest->nick, ServerInstance->Config->HideWhoisServer, ServerInstance->Config->Network);
+ ServerInstance->SendWhoisLine(user, 312, "%s %s %s :%s",user->nick, dest->nick, ServerInstance->Config->HideWhoisServer, ServerInstance->Config->Network);
}
else
{
- user->WriteServ("312 %s %s %s :%s",user->nick, dest->nick, dest->server, ServerInstance->GetServerDescription(dest->server).c_str());
+ ServerInstance->SendWhoisLine(user, 312, "%s %s %s :%s",user->nick, dest->nick, dest->server, ServerInstance->GetServerDescription(dest->server).c_str());
}
if (*dest->awaymsg)
{
- user->WriteServ("301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
+ ServerInstance->SendWhoisLine(user, 301, "%s %s :%s",user->nick, dest->nick, dest->awaymsg);
}
if (*dest->oper)
{
- user->WriteServ("313 %s %s :is %s %s on %s",user->nick, dest->nick, (strchr("AEIOUaeiou",*dest->oper) ? "an" : "a"),irc::Spacify(dest->oper), ServerInstance->Config->Network);
+ ServerInstance->SendWhoisLine(user, 313, "%s %s :is %s %s on %s",user->nick, dest->nick, (strchr("AEIOUaeiou",*dest->oper) ? "an" : "a"),irc::Spacify(dest->oper), ServerInstance->Config->Network);
}
if ((!signon) && (!idle))
{
@@ -66,19 +66,19 @@ void do_whois(InspIRCd* ServerInstance, userrec* user, userrec* dest,unsigned lo
if (!strcasecmp(user->server,dest->server))
{
// idle time and signon line can only be sent if youre on the same server (according to RFC)
- user->WriteServ("317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-ServerInstance->Time()), dest->signon);
+ ServerInstance->SendWhoisLine(user, 317, "%s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-ServerInstance->Time()), dest->signon);
}
else
{
if ((idle) || (signon))
- user->WriteServ("317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
+ ServerInstance->SendWhoisLine(user, 317, "%s %s %d %d :seconds idle, signon time",user->nick, dest->nick, idle, signon);
}
- user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
+ ServerInstance->SendWhoisLine(user, 318, "%s %s :End of /WHOIS list.",user->nick, dest->nick);
}
else
{
- user->WriteServ("401 %s %s :No such nick/channel",user->nick, *nick ? nick : "*");
- user->WriteServ("318 %s %s :End of /WHOIS list.",user->nick, *nick ? nick : "*");
+ ServerInstance->SendWhoisLine(user, 401, "%s %s :No such nick/channel",user->nick, *nick ? nick : "*");
+ ServerInstance->SendWhoisLine(user, 318, "%s %s :End of /WHOIS list.",user->nick, *nick ? nick : "*");
}
}
diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp
index c09b714f1..7eb4544fb 100644
--- a/src/helperfuncs.cpp
+++ b/src/helperfuncs.cpp
@@ -506,3 +506,25 @@ void InspIRCd::LoadAllModules()
this->Log(DEFAULT,"Total loaded modules: %d", this->ModCount+1);
}
+void InspIRCd::SendWhoisLine(userrec* user, int numeric, const std::string &text)
+{
+ std::string copy_text = text;
+
+ int MOD_RESULT = 0;
+ FOREACH_RESULT_I(this, I_OnWhoisLine, OnWhoisLine(user, numeric, copy_text));
+
+ if (!MOD_RESULT)
+ user->WriteServ("%d %s", numeric, copy_text.c_str());
+}
+
+void InspIRCd::SendWhoisLine(userrec* user, int numeric, const char* format, ...)
+{
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+ va_start (argsPtr, format);
+ vsnprintf(textbuffer, MAXBUF, format, argsPtr);
+ va_end(argsPtr);
+
+ this->SendWhoisLine(user, numeric, std::string(textbuffer));
+}
+
diff --git a/src/modules.cpp b/src/modules.cpp
index 6d6b39d87..5822e0975 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -192,7 +192,7 @@ Priority Module::Prioritize() { return PRIORITY_DONTCARE; }
void Module::OnSetAway(userrec* user) { };
void Module::OnCancelAway(userrec* user) { };
int Module::OnUserList(userrec* user, chanrec* Ptr) { return 0; };
-
+int Module::OnWhoisLine(userrec* user, int &numeric, std::string &text) { return 0; };
long InspIRCd::PriorityAfter(const std::string &modulename)
{
diff --git a/src/modules/extra/m_ssl_gnutls.cpp b/src/modules/extra/m_ssl_gnutls.cpp
index 049d3bfea..1d2e8561b 100644
--- a/src/modules/extra/m_ssl_gnutls.cpp
+++ b/src/modules/extra/m_ssl_gnutls.cpp
@@ -477,7 +477,7 @@ class ModuleSSLGnuTLS : public Module
// Bugfix, only send this numeric for *our* SSL users
if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->GetPort(), listenports)))
{
- source->WriteServ("320 %s %s :is using a secure connection", source->nick, dest->nick);
+ ServerInstance->SendWhoisLine(source, 320, "%s %s :is using a secure connection", source->nick, dest->nick);
}
}
diff --git a/src/modules/extra/m_ssl_openssl.cpp b/src/modules/extra/m_ssl_openssl.cpp
index 7f62bbfcb..905a9bf42 100644
--- a/src/modules/extra/m_ssl_openssl.cpp
+++ b/src/modules/extra/m_ssl_openssl.cpp
@@ -563,7 +563,7 @@ class ModuleSSLOpenSSL : public Module
// Bugfix, only send this numeric for *our* SSL users
if(dest->GetExt("ssl", dummy) || (IS_LOCAL(dest) && isin(dest->GetPort(), listenports)))
{
- source->WriteServ("320 %s %s :is using a secure connection", source->nick, dest->nick);
+ ServerInstance->SendWhoisLine(source, 320, "%s %s :is using a secure connection", source->nick, dest->nick);
}
}
diff --git a/src/modules/m_botmode.cpp b/src/modules/m_botmode.cpp
index 707a4e10c..4860ca55b 100644
--- a/src/modules/m_botmode.cpp
+++ b/src/modules/m_botmode.cpp
@@ -93,7 +93,7 @@ class ModuleBotMode : public Module
{
if (dst->IsModeSet('B'))
{
- src->WriteServ("335 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is a \2bot\2 on "+ServerInstance->Config->Network);
+ ServerInstance->SendWhoisLine(src, 335, std::string(src->nick)+" "+std::string(dst->nick)+" :is a \2bot\2 on "+ServerInstance->Config->Network);
}
}
diff --git a/src/modules/m_helpop.cpp b/src/modules/m_helpop.cpp
index 3b1406368..8a69c422e 100644
--- a/src/modules/m_helpop.cpp
+++ b/src/modules/m_helpop.cpp
@@ -253,7 +253,7 @@ class ModuleHelpop : public Module
{
if (dst->IsModeSet('h'))
{
- src->WriteServ("310 "+std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
+ ServerInstance->SendWhoisLine(src, 310, std::string(src->nick)+" "+std::string(dst->nick)+" :is available for help.");
}
}
diff --git a/src/modules/m_services.cpp b/src/modules/m_services.cpp
index 1ae3c0992..b2797d72b 100644
--- a/src/modules/m_services.cpp
+++ b/src/modules/m_services.cpp
@@ -204,7 +204,7 @@ class ModuleServices : public Module
if (dest->IsModeSet('r'))
{
/* user is registered */
- source->WriteServ("307 %s %s :is a registered nick", source->nick, dest->nick);
+ ServerInstance->SendWhoisLine(source, 307, "%s %s :is a registered nick", source->nick, dest->nick);
}
}
diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp
index 651735e44..2e26d8fd5 100644
--- a/src/modules/m_services_account.cpp
+++ b/src/modules/m_services_account.cpp
@@ -140,7 +140,7 @@ class ModuleServicesAccount : public Module
if (account)
{
- source->WriteServ("330 %s %s %s :is logged in as", source->nick, dest->nick, account->c_str());
+ ServerInstance->SendWhoisLine(source, 330, "%s %s %s :is logged in as", source->nick, dest->nick, account->c_str());
}
}
diff --git a/src/modules/m_ssl_dummy.cpp b/src/modules/m_ssl_dummy.cpp
index fadccae1e..c509e68cd 100644
--- a/src/modules/m_ssl_dummy.cpp
+++ b/src/modules/m_ssl_dummy.cpp
@@ -17,6 +17,7 @@
#include "users.h"
#include "modules.h"
+#include "inspircd.h"
/* $ModDesc: Makes remote /whoises to SSL servers work on a non-ssl server */
@@ -51,7 +52,7 @@ class ModuleSSLDummy : public Module
{
if(dest->GetExt("ssl", dummy))
{
- source->WriteServ("320 %s %s :is using a secure connection", source->nick, dest->nick);
+ ServerInstance->SendWhoisLine(source, 320, "%s %s :is using a secure connection", source->nick, dest->nick);
}
}
diff --git a/src/modules/m_swhois.cpp b/src/modules/m_swhois.cpp
index 849028dce..9d0cb70dc 100644
--- a/src/modules/m_swhois.cpp
+++ b/src/modules/m_swhois.cpp
@@ -110,7 +110,7 @@ class ModuleSWhois : public Module
dest->GetExt("swhois", swhois);
if (swhois)
{
- source->WriteServ("320 %s %s :%s",source->nick,dest->nick,swhois->c_str());
+ ServerInstance->SendWhoisLine(source, 320, "%s %s :%s",source->nick,dest->nick,swhois->c_str());
}
}
diff --git a/src/users.cpp b/src/users.cpp
index 4100e3452..90b6ee859 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -1887,14 +1887,15 @@ void userrec::SplitChanList(userrec* dest, const std::string &cl)
try
{
- prefix << ":" << ServerInstance->Config->ServerName << " 319 " << this->nick << " " << dest->nick << " :";
+ prefix << this->nick << " " << dest->nick << " :";
line = prefix.str();
+ int namelen = strlen(ServerInstance->Config->ServerName) + 6;
for (start = 0; (pos = cl.find(' ', start)) != std::string::npos; start = pos+1)
{
length = (pos == std::string::npos) ? cl.length() : pos;
- if (line.length() + length - start > 510)
+ if (line.length() + namelen + length - start > 510)
{
this->Write(line);
line = prefix.str();
@@ -1913,7 +1914,7 @@ void userrec::SplitChanList(userrec* dest, const std::string &cl)
if (line.length())
{
- this->Write(line);
+ ServerInstance->SendWhoisLine(this, 319, "%s", line.c_str());
}
}