diff options
author | Attila Molnar <attilamolnar@hush.com> | 2014-07-03 12:16:07 +0200 |
---|---|---|
committer | Attila Molnar <attilamolnar@hush.com> | 2014-07-03 12:16:07 +0200 |
commit | 4332765b27b8b10e4f450bbdf8ddb50dc6cfca43 (patch) | |
tree | f13f9c85df0c915b7fee15bfd7335633652242b0 | |
parent | 4ab1eb3d1e54d205317dafad538138bb40feace9 (diff) |
core_user Deduplicate code that calls the OnUserRegister hook
-rw-r--r-- | src/coremods/core_user/cmd_nick.cpp | 12 | ||||
-rw-r--r-- | src/coremods/core_user/cmd_user.cpp | 10 | ||||
-rw-r--r-- | src/coremods/core_user/core_user.h | 9 |
3 files changed, 17 insertions, 14 deletions
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<std::string>& 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<std::string>& 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<std::string>& 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); }; |