diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-10-28 18:12:45 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-10-28 18:12:45 +0000 |
commit | 034f74a23b3d6aff177682c916e18382621f495a (patch) | |
tree | 99840e8e12ee0da70c8e2acbb205a31d6e4cf3d9 /src | |
parent | 73d36e20ed9f7ccdb6ce4e745a5eeed065f73bef (diff) |
Add support for OnWhoisLine, which allows modules to change or drop any line of whois before its sent to a user
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@5570 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src')
-rw-r--r-- | src/cmd_modules.cpp | 2 | ||||
-rw-r--r-- | src/cmd_whois.cpp | 24 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 22 | ||||
-rw-r--r-- | src/modules.cpp | 2 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_gnutls.cpp | 2 | ||||
-rw-r--r-- | src/modules/extra/m_ssl_openssl.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_botmode.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_helpop.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_services.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_services_account.cpp | 2 | ||||
-rw-r--r-- | src/modules/m_ssl_dummy.cpp | 3 | ||||
-rw-r--r-- | src/modules/m_swhois.cpp | 2 | ||||
-rw-r--r-- | src/users.cpp | 7 |
13 files changed, 49 insertions, 25 deletions
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()); } } |