From 4332765b27b8b10e4f450bbdf8ddb50dc6cfca43 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Thu, 3 Jul 2014 12:16:07 +0200 Subject: core_user Deduplicate code that calls the OnUserRegister hook --- src/coremods/core_user/cmd_nick.cpp | 12 +----------- src/coremods/core_user/cmd_user.cpp | 10 +++++++--- src/coremods/core_user/core_user.h | 9 +++++++++ 3 files changed, 17 insertions(+), 14 deletions(-) (limited to 'src/coremods/core_user') diff --git a/src/coremods/core_user/cmd_nick.cpp b/src/coremods/core_user/cmd_nick.cpp index 49e5efacc..1b25616dd 100644 --- a/src/coremods/core_user/cmd_nick.cpp +++ b/src/coremods/core_user/cmd_nick.cpp @@ -67,17 +67,7 @@ CmdResult CommandNick::HandleLocal(const std::vector& parameters, L if (user->registered < REG_NICKUSER) { user->registered = (user->registered | REG_NICK); - if (user->registered == REG_NICKUSER) - { - /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */ - ModResult MOD_RESULT; - FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (user)); - if (MOD_RESULT == MOD_RES_DENY) - return CMD_FAILURE; - - // return early to not penalize new users - return CMD_SUCCESS; - } + return CommandUser::CheckRegister(user); } return CMD_SUCCESS; diff --git a/src/coremods/core_user/cmd_user.cpp b/src/coremods/core_user/cmd_user.cpp index 6de762e44..d593d7f4b 100644 --- a/src/coremods/core_user/cmd_user.cpp +++ b/src/coremods/core_user/cmd_user.cpp @@ -62,15 +62,19 @@ CmdResult CommandUser::HandleLocal(const std::vector& parameters, L } /* parameters 2 and 3 are local and remote hosts, and are ignored */ + return CheckRegister(user); +} + +CmdResult CommandUser::CheckRegister(LocalUser* user) +{ + // If the user is registered, return CMD_SUCCESS/CMD_FAILURE depending on what modules say, otherwise just + // return CMD_SUCCESS without doing anything, knowing the other handler will call us again if (user->registered == REG_NICKUSER) { ModResult MOD_RESULT; - - /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */ FIRST_MOD_RESULT(OnUserRegister, MOD_RESULT, (user)); if (MOD_RESULT == MOD_RES_DENY) return CMD_FAILURE; - } return CMD_SUCCESS; diff --git a/src/coremods/core_user/core_user.h b/src/coremods/core_user/core_user.h index 4c91a39ab..a529e0ccf 100644 --- a/src/coremods/core_user/core_user.h +++ b/src/coremods/core_user/core_user.h @@ -135,4 +135,13 @@ class CommandUser : public SplitCommand * @return A value from CmdResult to indicate command success or failure. */ CmdResult HandleLocal(const std::vector& parameters, LocalUser *user); + + /** Run the OnUserRegister hook if the user has sent both NICK and USER. Called after an unregistered user + * successfully executes the USER or the NICK command. + * @param user User to inspect and possibly pass to the OnUserRegister hook + * @return CMD_FAILURE if OnUserRegister was called and it returned MOD_RES_DENY, CMD_SUCCESS in every other case + * (i.e. if the hook wasn't fired because the user still needs to send NICK/USER or if it was fired and finished with + * a non-MOD_RES_DENY result). + */ + static CmdResult CheckRegister(LocalUser* user); }; -- cgit v1.2.3