summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSir Pogsalot <sir.pogsalot@gmail.com>2012-06-12 23:03:56 -0700
committerSir Pogsalot <sir.pogsalot@gmail.com>2012-06-12 23:03:56 -0700
commit32e724e58f8ad9a6202124f3de887655e5be2055 (patch)
treebda2e9cd12cbe3619a810c2114e5127217ebe7e1
parentcc3daff2126623e04824892a65c853be5a3ee0ff (diff)
parentd4cde190df1562dee3f3c0c2fa53e51315b98ade (diff)
Merge pull request #213 from attilamolnar/insp20+namesx
[2.0] Add support to m_namesx for altering /WHO replies
-rw-r--r--src/modules/m_namesx.cpp39
1 files changed, 37 insertions, 2 deletions
diff --git a/src/modules/m_namesx.cpp b/src/modules/m_namesx.cpp
index 1ab824388..2603b0ce5 100644
--- a/src/modules/m_namesx.cpp
+++ b/src/modules/m_namesx.cpp
@@ -31,8 +31,8 @@ class ModuleNamesX : public Module
GenericCap cap;
ModuleNamesX() : cap(this, "multi-prefix")
{
- Implementation eventlist[] = { I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
- ServerInstance->Modules->Attach(eventlist, this, 4);
+ Implementation eventlist[] = { I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent, I_OnSendWhoLine };
+ ServerInstance->Modules->Attach(eventlist, this, 5);
}
@@ -81,6 +81,41 @@ class ModuleNamesX : public Module
prefixes = memb->chan->GetAllPrefixChars(memb->user);
}
+ void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
+ {
+ if (!cap.ext.get(source) || line.empty())
+ return;
+
+ std::string::size_type pos = line.find(':');
+ if (pos == std::string::npos || pos < 2)
+ return;
+ pos -= 2;
+ // Don't do anything if the user has no prefixes
+ if ((line[pos] == 'H') || (line[pos] == 'G') || (line[pos] == '*'))
+ return;
+
+ // 352 21DAAAAAB #chan ident localhost insp21.test 21DAAAAAB H@ :0 a
+ // a b pos
+ std::string::size_type a = 4 + source->nick.length() + 1;
+ std::string::size_type b = line.find(' ', a);
+ if (b == std::string::npos)
+ return;
+
+ // Try to find this channel
+ std::string channame = line.substr(a, b-a);
+ Channel* chan = ServerInstance->FindChan(channame.c_str());
+ if (!chan)
+ return;
+
+ // Don't do anything if the user has only one prefix
+ std::string prefixes = chan->GetAllPrefixChars(user);
+ if (prefixes.length() <= 1)
+ return;
+
+ line.erase(pos, 1);
+ line.insert(pos, prefixes);
+ }
+
void OnEvent(Event& ev)
{
cap.HandleEvent(ev);