Skip to content
This repository
Browse code

m_namesx Add support for altering /WHO replies to be compliant with t…

…he specification
  • Loading branch information...
commit d4cde190df1562dee3f3c0c2fa53e51315b98ade 1 parent cc3daff
Attila Molnar authored June 12, 2012

Showing 1 changed file with 37 additions and 2 deletions. Show diff stats Hide diff stats

  1. 39  src/modules/m_namesx.cpp
39  src/modules/m_namesx.cpp
@@ -31,8 +31,8 @@ class ModuleNamesX : public Module
31 31
 	GenericCap cap;
32 32
 	ModuleNamesX() : cap(this, "multi-prefix")
33 33
 	{
34  
-		Implementation eventlist[] = { I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent };
35  
-		ServerInstance->Modules->Attach(eventlist, this, 4);
  34
+		Implementation eventlist[] = { I_OnPreCommand, I_OnNamesListItem, I_On005Numeric, I_OnEvent, I_OnSendWhoLine };
  35
+		ServerInstance->Modules->Attach(eventlist, this, 5);
36 36
 	}
37 37
 
38 38
 
@@ -81,6 +81,41 @@ class ModuleNamesX : public Module
81 81
 		prefixes = memb->chan->GetAllPrefixChars(memb->user);
82 82
 	}
83 83
 
  84
+	void OnSendWhoLine(User* source, const std::vector<std::string>& params, User* user, std::string& line)
  85
+	{
  86
+		if (!cap.ext.get(source) || line.empty())
  87
+			return;
  88
+
  89
+		std::string::size_type pos = line.find(':');
  90
+		if (pos == std::string::npos || pos < 2)
  91
+			return;
  92
+		pos -= 2;
  93
+		// Don't do anything if the user has no prefixes
  94
+		if ((line[pos] == 'H') || (line[pos] == 'G') || (line[pos] == '*'))
  95
+			return;
  96
+
  97
+		// 352 21DAAAAAB #chan ident localhost insp21.test 21DAAAAAB H@ :0 a
  98
+		//              a     b                                       pos
  99
+		std::string::size_type a = 4 + source->nick.length() + 1;
  100
+		std::string::size_type b = line.find(' ', a);
  101
+		if (b == std::string::npos)
  102
+			return;
  103
+
  104
+		// Try to find this channel
  105
+		std::string channame = line.substr(a, b-a);
  106
+		Channel* chan = ServerInstance->FindChan(channame.c_str());
  107
+		if (!chan)
  108
+			return;
  109
+
  110
+		// Don't do anything if the user has only one prefix
  111
+		std::string prefixes = chan->GetAllPrefixChars(user);
  112
+		if (prefixes.length() <= 1)
  113
+			return;
  114
+
  115
+		line.erase(pos, 1);
  116
+		line.insert(pos, prefixes);
  117
+	}
  118
+
84 119
 	void OnEvent(Event& ev)
85 120
 	{
86 121
 		cap.HandleEvent(ev);

0 notes on commit d4cde19

Please sign in to comment.
Something went wrong with that request. Please try again.