From c597156adc60a45b5f827793cd420945f47bc03b Mon Sep 17 00:00:00 2001 From: Max Teufel Date: Sun, 6 Mar 2016 10:27:40 +0100 Subject: [PATCH] chanserv/flags: make Anope FLAGS compatibility an option Previously, ChanServ FLAGS behavior could be modified by registering or dropping the keyword nicks "LIST", "CLEAR", and "MODIFY". Now, a configuration option is available that when turned on (default), disables registration of these keyword nicks and enables this compatibility feature. When turned off, registration of these keyword nicks is possible, and compatibility to Anope's FLAGS command is disabled. Fixes atheme/atheme#397 --- modules/chanserv/flags.c | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/modules/chanserv/flags.c b/modules/chanserv/flags.c index 289345d..72d8fcf 100644 --- a/modules/chanserv/flags.c +++ b/modules/chanserv/flags.c @@ -17,18 +17,35 @@ DECLARE_MODULE_V1 ); static void cs_cmd_flags(sourceinfo_t *si, int parc, char *parv[]); +static void check_registration_keywords(hook_user_register_check_t *hdata); command_t cs_flags = { "FLAGS", N_("Manipulates specific permissions on a channel."), AC_NONE, 3, cs_cmd_flags, { .path = "cservice/flags" } }; +static bool anope_flags_compat = true; + void _modinit(module_t *m) { service_named_bind_command("chanserv", &cs_flags); + + add_bool_conf_item("ANOPE_FLAGS_COMPAT", &chansvs.me->conf_table, 0, &anope_flags_compat, true); + + hook_add_event("nick_can_register"); + hook_add_nick_can_register(check_registration_keywords); + + hook_add_event("user_can_register"); + hook_add_user_can_register(check_registration_keywords); } void _moddeinit(module_unload_intent_t intent) { service_named_unbind_command("chanserv", &cs_flags); + + hook_del_nick_can_register(check_registration_keywords); + + hook_del_user_can_register(check_registration_keywords); + + del_conf_item("ANOPE_FLAGS_COMPAT", &chansvs.me->conf_table); } typedef struct { @@ -150,6 +167,20 @@ static void do_list(sourceinfo_t *si, mychan_t *mc, unsigned int flags) logcommand(si, CMDLOG_GET, "FLAGS: \2%s\2", mc->name); } +static void check_registration_keywords(hook_user_register_check_t *hdata) +{ + if (hdata->approved || !anope_flags_compat) + { + return; + } + + if (!strcasecmp(hdata->account, "LIST") || !strcasecmp(hdata->account, "CLEAR") || !strcasecmp(hdata->account, "MODIFY")) + { + command_fail(hdata->si, fault_badparams, "The nick \2%s\2 is reserved and cannot be registered.", hdata->account); + hdata->approved = 1; + } +} + /* FLAGS [user] [flags] */ static void cs_cmd_flags(sourceinfo_t *si, int parc, char *parv[]) { @@ -218,14 +249,14 @@ static void cs_cmd_flags(sourceinfo_t *si, int parc, char *parv[]) * * --nenolod */ - else if (!strcasecmp(target, "LIST") && myentity_find_ext(target) == NULL) + else if (anope_flags_compat && !strcasecmp(target, "LIST") && myentity_find_ext(target) == NULL) { do_list(si, mc, 0); free(target); return; } - else if (!strcasecmp(target, "CLEAR") && myentity_find_ext(target) == NULL) + else if (anope_flags_compat && !strcasecmp(target, "CLEAR") && myentity_find_ext(target) == NULL) { free(target); @@ -251,7 +282,7 @@ static void cs_cmd_flags(sourceinfo_t *si, int parc, char *parv[]) command_success_nodata(si, _("Cleared flags in \2%s\2."), mc->name); return; } - else if (!strcasecmp(target, "MODIFY") && myentity_find_ext(target) == NULL) + else if (anope_flags_compat && !strcasecmp(target, "MODIFY") && myentity_find_ext(target) == NULL) { free(target); -- 2.6.6