summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2016-02-25 17:02:03 +0100
committerAttila Molnar <attilamolnar@hush.com>2016-02-25 17:02:03 +0100
commit304b6dbbf56710b1310fce8c5cf71b73334c060a (patch)
tree002d219057b5b4fda5c49595eada3eb7e1e8d525 /src/modules
parentdbe5a1fc6f9e18765863f332a3e79d7c918d3e65 (diff)
Introduce Stats::Context, pass it to the OnStats hook and switch all code to it
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/extra/m_geoip.cpp9
-rw-r--r--src/modules/m_cban.cpp6
-rw-r--r--src/modules/m_dnsbl.cpp10
-rw-r--r--src/modules/m_filter.cpp12
-rw-r--r--src/modules/m_hideoper.cpp10
-rw-r--r--src/modules/m_rline.cpp6
-rw-r--r--src/modules/m_shun.cpp6
-rw-r--r--src/modules/m_spanningtree/main.h2
-rw-r--r--src/modules/m_spanningtree/override_stats.cpp21
-rw-r--r--src/modules/m_svshold.cpp6
10 files changed, 47 insertions, 41 deletions
diff --git a/src/modules/extra/m_geoip.cpp b/src/modules/extra/m_geoip.cpp
index d21a82149..967c6a761 100644
--- a/src/modules/extra/m_geoip.cpp
+++ b/src/modules/extra/m_geoip.cpp
@@ -97,9 +97,9 @@ class ModuleGeoIP : public Module
return MOD_RES_DENY;
}
- ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
{
- if (symbol != 'G')
+ if (stats.GetSymbol() != 'G')
return MOD_RES_PASSTHRU;
unsigned int unknown = 0;
@@ -115,14 +115,13 @@ class ModuleGeoIP : public Module
unknown++;
}
- std::string p = "801 " + user->nick + " :GeoIPSTATS ";
for (std::map<std::string, unsigned int>::const_iterator i = results.begin(); i != results.end(); ++i)
{
- out.push_back(p + i->first + " " + ConvToStr(i->second));
+ stats.AddRow(801, "GeoIPSTATS " + i->first + " " + ConvToStr(i->second));
}
if (unknown)
- out.push_back(p + "Unknown " + ConvToStr(unknown));
+ stats.AddRow(801, "GeoIPSTATS Unknown " + ConvToStr(unknown));
return MOD_RES_DENY;
}
diff --git a/src/modules/m_cban.cpp b/src/modules/m_cban.cpp
index 1ddc625db..2a969bec7 100644
--- a/src/modules/m_cban.cpp
+++ b/src/modules/m_cban.cpp
@@ -165,12 +165,12 @@ class ModuleCBan : public Module
ServerInstance->XLines->UnregisterFactory(&f);
}
- ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
{
- if (symbol != 'C')
+ if (stats.GetSymbol() != 'C')
return MOD_RES_PASSTHRU;
- ServerInstance->XLines->InvokeStats("CBAN", 210, user, out);
+ ServerInstance->XLines->InvokeStats("CBAN", 210, stats);
return MOD_RES_DENY;
}
diff --git a/src/modules/m_dnsbl.cpp b/src/modules/m_dnsbl.cpp
index 726ee1351..44328480e 100644
--- a/src/modules/m_dnsbl.cpp
+++ b/src/modules/m_dnsbl.cpp
@@ -406,9 +406,9 @@ class ModuleDNSBL : public Module
return MOD_RES_PASSTHRU;
}
- ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
{
- if (symbol != 'd')
+ if (stats.GetSymbol() != 'd')
return MOD_RES_PASSTHRU;
unsigned long total_hits = 0, total_misses = 0;
@@ -418,12 +418,12 @@ class ModuleDNSBL : public Module
total_hits += (*i)->stats_hits;
total_misses += (*i)->stats_misses;
- results.push_back("304 " + user->nick + " :DNSBLSTATS DNSbl \"" + (*i)->name + "\" had " +
+ stats.AddRow(304, "DNSBLSTATS DNSbl \"" + (*i)->name + "\" had " +
ConvToStr((*i)->stats_hits) + " hits and " + ConvToStr((*i)->stats_misses) + " misses");
}
- results.push_back("304 " + user->nick + " :DNSBLSTATS Total hits: " + ConvToStr(total_hits));
- results.push_back("304 " + user->nick + " :DNSBLSTATS Total misses: " + ConvToStr(total_misses));
+ stats.AddRow(304, "DNSBLSTATS Total hits: " + ConvToStr(total_hits));
+ stats.AddRow(304, "DNSBLSTATS Total misses: " + ConvToStr(total_misses));
return MOD_RES_PASSTHRU;
}
diff --git a/src/modules/m_filter.cpp b/src/modules/m_filter.cpp
index bd1022a08..a3e30ecb4 100644
--- a/src/modules/m_filter.cpp
+++ b/src/modules/m_filter.cpp
@@ -187,7 +187,7 @@ class ModuleFilter : public Module
FilterResult DecodeFilter(const std::string &data);
void OnSyncNetwork(ProtocolInterface::Server& server) CXX11_OVERRIDE;
void OnDecodeMetaData(Extensible* target, const std::string &extname, const std::string &extdata) CXX11_OVERRIDE;
- ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE;
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE;
ModResult OnPreCommand(std::string &command, std::vector<std::string> &parameters, LocalUser *user, bool validated, const std::string &original_line) CXX11_OVERRIDE;
void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
bool AppliesToMe(User* user, FilterResult* filter, int flags);
@@ -693,21 +693,21 @@ void ModuleFilter::ReadFilters()
}
}
-ModResult ModuleFilter::OnStats(char symbol, User* user, string_list &results)
+ModResult ModuleFilter::OnStats(Stats::Context& stats)
{
- if (symbol == 's')
+ if (stats.GetSymbol() == 's')
{
for (std::vector<FilterResult>::iterator i = filters.begin(); i != filters.end(); i++)
{
- results.push_back("223 "+user->nick+" :"+RegexEngine.GetProvider()+":"+i->freeform+" "+i->GetFlags()+" "+FilterActionToString(i->action)+" "+ConvToStr(i->gline_time)+" :"+i->reason);
+ stats.AddRow(223, RegexEngine.GetProvider()+":"+i->freeform+" "+i->GetFlags()+" "+FilterActionToString(i->action)+" "+ConvToStr(i->gline_time)+" :"+i->reason);
}
for (ExemptTargetSet::const_iterator i = exemptedchans.begin(); i != exemptedchans.end(); ++i)
{
- results.push_back("223 "+user->nick+" :EXEMPT "+(*i));
+ stats.AddRow(223, "EXEMPT "+(*i));
}
for (ExemptTargetSet::const_iterator i = exemptednicks.begin(); i != exemptednicks.end(); ++i)
{
- results.push_back("223 "+user->nick+" :EXEMPT "+(*i));
+ stats.AddRow(223, "EXEMPT "+(*i));
}
}
return MOD_RES_PASSTHRU;
diff --git a/src/modules/m_hideoper.cpp b/src/modules/m_hideoper.cpp
index 92af045d5..0fa5206ea 100644
--- a/src/modules/m_hideoper.cpp
+++ b/src/modules/m_hideoper.cpp
@@ -122,9 +122,9 @@ class ModuleHideOper : public Module, public Whois::LineEventListener
}
}
- ModResult OnStats(char symbol, User* user, string_list& results) CXX11_OVERRIDE
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
{
- if (symbol != 'P')
+ if (stats.GetSymbol() != 'P')
return MOD_RES_PASSTHRU;
unsigned int count = 0;
@@ -132,15 +132,15 @@ class ModuleHideOper : public Module, public Whois::LineEventListener
for (UserManager::OperList::const_iterator i = opers.begin(); i != opers.end(); ++i)
{
User* oper = *i;
- if (!oper->server->IsULine() && (user->IsOper() || !oper->IsModeSet(hm)))
+ if (!oper->server->IsULine() && (stats.GetSource()->IsOper() || !oper->IsModeSet(hm)))
{
LocalUser* lu = IS_LOCAL(oper);
- results.push_back("249 " + user->nick + " :" + oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " +
+ stats.AddRow(249, oper->nick + " (" + oper->ident + "@" + oper->dhost + ") Idle: " +
(lu ? ConvToStr(ServerInstance->Time() - lu->idle_lastmsg) + " secs" : "unavailable"));
count++;
}
}
- results.push_back("249 "+user->nick+" :"+ConvToStr(count)+" OPER(s)");
+ stats.AddRow(249, ConvToStr(count)+" OPER(s)");
return MOD_RES_DENY;
}
diff --git a/src/modules/m_rline.cpp b/src/modules/m_rline.cpp
index 2aee89ad2..97fbf169a 100644
--- a/src/modules/m_rline.cpp
+++ b/src/modules/m_rline.cpp
@@ -284,12 +284,12 @@ class ModuleRLine : public Module
initing = false;
}
- ModResult OnStats(char symbol, User* user, string_list &results) CXX11_OVERRIDE
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
{
- if (symbol != 'R')
+ if (stats.GetSymbol() != 'R')
return MOD_RES_PASSTHRU;
- ServerInstance->XLines->InvokeStats("R", 223, user, results);
+ ServerInstance->XLines->InvokeStats("R", 223, stats);
return MOD_RES_DENY;
}
diff --git a/src/modules/m_shun.cpp b/src/modules/m_shun.cpp
index a3a2909a0..5388bb485 100644
--- a/src/modules/m_shun.cpp
+++ b/src/modules/m_shun.cpp
@@ -194,12 +194,12 @@ class ModuleShun : public Module
ServerInstance->Modules->SetPriority(this, I_OnPreCommand, PRIORITY_BEFORE, alias);
}
- ModResult OnStats(char symbol, User* user, string_list& out) CXX11_OVERRIDE
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
{
- if (symbol != 'H')
+ if (stats.GetSymbol() != 'H')
return MOD_RES_PASSTHRU;
- ServerInstance->XLines->InvokeStats("SHUN", 223, user, out);
+ ServerInstance->XLines->InvokeStats("SHUN", 223, stats);
return MOD_RES_DENY;
}
diff --git a/src/modules/m_spanningtree/main.h b/src/modules/m_spanningtree/main.h
index 3e02ce93f..2490c83ef 100644
--- a/src/modules/m_spanningtree/main.h
+++ b/src/modules/m_spanningtree/main.h
@@ -165,7 +165,7 @@ class ModuleSpanningTree : public Module
void OnOper(User* user, const std::string &opertype) CXX11_OVERRIDE;
void OnAddLine(User *u, XLine *x) CXX11_OVERRIDE;
void OnDelLine(User *u, XLine *x) CXX11_OVERRIDE;
- ModResult OnStats(char statschar, User* user, string_list &results) CXX11_OVERRIDE;
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE;
ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE;
void OnLoadModule(Module* mod) CXX11_OVERRIDE;
void OnUnloadModule(Module* mod) CXX11_OVERRIDE;
diff --git a/src/modules/m_spanningtree/override_stats.cpp b/src/modules/m_spanningtree/override_stats.cpp
index 14b3f5ef7..b28c2d984 100644
--- a/src/modules/m_spanningtree/override_stats.cpp
+++ b/src/modules/m_spanningtree/override_stats.cpp
@@ -24,27 +24,34 @@
#include "utils.h"
#include "link.h"
-ModResult ModuleSpanningTree::OnStats(char statschar, User* user, string_list &results)
+ModResult ModuleSpanningTree::OnStats(Stats::Context& stats)
{
- if ((statschar == 'c') || (statschar == 'n'))
+ if ((stats.GetSymbol() == 'c') || (stats.GetSymbol() == 'n'))
{
for (std::vector<reference<Link> >::iterator i = Utils->LinkBlocks.begin(); i != Utils->LinkBlocks.end(); ++i)
{
Link* L = *i;
- results.push_back("213 "+user->nick+" "+statschar+" *@"+(L->HiddenFromStats ? "<hidden>" : L->IPAddr)+" * "+(*i)->Name.c_str()+" "+ConvToStr(L->Port)+" "+(L->Hook.empty() ? "plaintext" : L->Hook));
- if (statschar == 'c')
- results.push_back("244 "+user->nick+" H * * "+L->Name.c_str());
+ std::string ipaddr = "*@";
+ if (L->HiddenFromStats)
+ ipaddr.append("<hidden>");
+ else
+ ipaddr.append(L->IPAddr);
+
+ const std::string hook = (L->Hook.empty() ? "plaintext" : L->Hook);
+ stats.AddRow(213, stats.GetSymbol(), ipaddr, '*', L->Name.c_str(), L->Port, hook);
+ if (stats.GetSymbol() == 'c')
+ stats.AddRow(244, 'H', '*', '*', L->Name.c_str());
}
return MOD_RES_DENY;
}
- else if (statschar == 'U')
+ else if (stats.GetSymbol() == 'U')
{
ConfigTagList tags = ServerInstance->Config->ConfTags("uline");
for (ConfigIter i = tags.first; i != tags.second; ++i)
{
std::string name = i->second->getString("server");
if (!name.empty())
- results.push_back("248 "+user->nick+" U "+name);
+ stats.AddRow(248, 'U', name);
}
return MOD_RES_DENY;
}
diff --git a/src/modules/m_svshold.cpp b/src/modules/m_svshold.cpp
index b95a847a5..ad6a4d1aa 100644
--- a/src/modules/m_svshold.cpp
+++ b/src/modules/m_svshold.cpp
@@ -183,12 +183,12 @@ class ModuleSVSHold : public Module
silent = tag->getBool("silent", true);
}
- ModResult OnStats(char symbol, User* user, string_list &out) CXX11_OVERRIDE
+ ModResult OnStats(Stats::Context& stats) CXX11_OVERRIDE
{
- if(symbol != 'S')
+ if (stats.GetSymbol() != 'S')
return MOD_RES_PASSTHRU;
- ServerInstance->XLines->InvokeStats("SVSHOLD", 210, user, out);
+ ServerInstance->XLines->InvokeStats("SVSHOLD", 210, stats);
return MOD_RES_DENY;
}