From ea2d2700961d1a8fdd94942720bd11b7145758f0 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Thu, 14 Jan 2016 06:57:04 -0600 Subject: [PATCH] STATS: allow modules to override normal stats requests --- include/hook.h | 1 + modules/m_stats.c | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/hook.h b/include/hook.h index 5d768c8d..167122d7 100644 --- a/include/hook.h +++ b/include/hook.h @@ -53,6 +53,7 @@ typedef struct struct Client *client; const void *arg1; int arg2; + int result; } hook_data_int; typedef struct diff --git a/modules/m_stats.c b/modules/m_stats.c index cdb64195..b1d55967 100644 --- a/modules/m_stats.c +++ b/modules/m_stats.c @@ -76,7 +76,7 @@ static void stats_l_list(struct Client *s, const char *, int, int, rb_dlink_list static void stats_l_client(struct Client *source_p, struct Client *target_p, char statchar); -static void stats_spy(struct Client *, char, const char *); +static int stats_spy(struct Client *, char, const char *); static void stats_p_spy(struct Client *); /* Heres our struct for the stats table */ @@ -192,6 +192,7 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char * static time_t last_used = 0; int i; char statchar; + int did_stats = 0; statchar = parv[1][0]; @@ -215,7 +216,11 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char * return 0; if((statchar != 'L') && (statchar != 'l')) - stats_spy(source_p, statchar, NULL); + did_stats = stats_spy(source_p, statchar, NULL); + + /* if did_stats is true, a module grabbed this STATS request */ + if (did_stats) + goto stats_out; for (i = 0; stats_cmd_table[i].letter; i++) { @@ -246,6 +251,7 @@ m_stats(struct Client *client_p, struct Client *source_p, int parc, const char * } } +stats_out: /* Send the end of stats notice, and the stats_spy */ sendto_one_numeric(source_p, RPL_ENDOFSTATS, form_str(RPL_ENDOFSTATS), statchar); @@ -1711,7 +1717,7 @@ stats_comm(struct Client *source_p) * any damage with stats requests now anyway. So, why show them? * -Dianora */ -static void +static int stats_spy(struct Client *source_p, char statchar, const char *name) { hook_data_int data; @@ -1719,8 +1725,11 @@ stats_spy(struct Client *source_p, char statchar, const char *name) data.client = source_p; data.arg1 = name; data.arg2 = (int) statchar; + data.result = 0; call_hook(doing_stats_hook, &data); + + return data.result; } /* stats_p_spy()