From bcb667c59e17f7227ac31decef3e47a0ebe6bc2b Mon Sep 17 00:00:00 2001 From: Bram Matthys Date: Mon, 21 Jan 2019 10:12:46 +0100 Subject: [PATCH] New hook HOOKTYPE_WELCOME (aClient *acptr, int after_numeric): allows you to send a message at very specific places during the initial welcome https://www.unrealircd.org/docs/Dev:Hook_API#HOOKTYPE_WELCOME --- doc/RELEASE-NOTES | 3 +++ include/modules.h | 5 ++++- src/modules/m_nick.c | 21 ++++++++++++++++++--- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/doc/RELEASE-NOTES b/doc/RELEASE-NOTES index 2430fa25f..6b01cfcbd 100644 --- a/doc/RELEASE-NOTES +++ b/doc/RELEASE-NOTES @@ -25,6 +25,9 @@ Minor issues fixed: Deprecated: Module coders: +* New hook HOOKTYPE_WELCOME (aClient *acptr, int after_numeric): allows you + to send a message at very specific places during the initial welcome + https://www.unrealircd.org/docs/Dev:Hook_API#HOOKTYPE_WELCOME Future versions: * We intend to change the default plaintext oper policy from 'warn' to 'deny' diff --git a/include/modules.h b/include/modules.h index 3bf8471c0..086191f06 100644 --- a/include/modules.h +++ b/include/modules.h @@ -820,6 +820,7 @@ extern char *moddata_client_get(aClient *acptr, char *varname); #define HOOKTYPE_SASL_RESULT 94 #define HOOKTYPE_PLACE_HOST_BAN 95 #define HOOKTYPE_FIND_TKLINE_MATCH 96 +#define HOOKTYPE_WELCOME 97 /* Adding a new hook here? * 1) Add the #define HOOKTYPE_.... with a new number @@ -923,6 +924,7 @@ int hooktype_sasl_continuation(aClient *sptr, char *buf); int hooktype_sasl_result(aClient *sptr, int success); int hooktype_place_host_ban(aClient *sptr, int action, char *reason, long duration); int hooktype_find_tkline_match(aClient *sptr, aTKline *tk); +int hooktype_welcome(aClient *sptr, int after_numeric); #ifdef GCC_TYPECHECKING #define ValidateHook(validatefunc, func) __builtin_types_compatible_p(__typeof__(func), __typeof__(validatefunc)) @@ -1023,7 +1025,8 @@ _UNREAL_ERROR(_hook_error_incompatible, "Incompatible hook function. Check argum ((hooktype == HOOKTYPE_SASL_CONTINUATION) && !ValidateHook(hooktype_sasl_continuation, func)) || \ ((hooktype == HOOKTYPE_SASL_RESULT) && !ValidateHook(hooktype_sasl_result, func)) || \ ((hooktype == HOOKTYPE_PLACE_HOST_BAN) && !ValidateHook(hooktype_place_host_ban, func)) || \ - ((hooktype == HOOKTYPE_FIND_TKLINE_MATCH) && !ValidateHook(hooktype_find_tkline_match, func)) ) \ + ((hooktype == HOOKTYPE_FIND_TKLINE_MATCH) && !ValidateHook(hooktype_find_tkline_match, func)) || \ + ((hooktype == HOOKTYPE_WELCOME) && !ValidateHook(hooktype_welcome, func)) ) \ _hook_error_incompatible(); #endif /* GCC_TYPECHECKING */ diff --git a/src/modules/m_nick.c b/src/modules/m_nick.c index 5716410ea..7f17af59d 100644 --- a/src/modules/m_nick.c +++ b/src/modules/m_nick.c @@ -1413,20 +1413,29 @@ int _register_user(aClient *cptr, aClient *sptr, char *nick, char *username, cha else ircd_log(LOG_CLIENT, "Connect - %s!%s@%s", nick, user->username, user->realhost); + RunHook2(HOOKTYPE_WELCOME, sptr, 0); sendto_one(sptr, rpl_str(RPL_WELCOME), me.name, nick, ircnetwork, nick, user->username, user->realhost); - /* This is a duplicate of the NOTICE but see below... */ - sendto_one(sptr, rpl_str(RPL_YOURHOST), me.name, nick, - me.name, version); + RunHook2(HOOKTYPE_WELCOME, sptr, 1); + sendto_one(sptr, rpl_str(RPL_YOURHOST), me.name, nick, + me.name, version); + RunHook2(HOOKTYPE_WELCOME, sptr, 2); sendto_one(sptr, rpl_str(RPL_CREATED), me.name, nick, creation); + RunHook2(HOOKTYPE_WELCOME, sptr, 3); sendto_one(sptr, rpl_str(RPL_MYINFO), me.name, sptr->name, me.name, version, umodestring, cmodestring); + RunHook2(HOOKTYPE_WELCOME, sptr, 4); for (i = 0; IsupportStrings[i]; i++) sendto_one(sptr, rpl_str(RPL_ISUPPORT), me.name, nick, IsupportStrings[i]); + RunHook2(HOOKTYPE_WELCOME, sptr, 5); + if (IsHidden(sptr)) + { sendto_one(sptr, err_str(RPL_HOSTHIDDEN), me.name, sptr->name, user->virthost); + RunHook2(HOOKTYPE_WELCOME, sptr, 396); + } if (IsSecureConnect(sptr)) { @@ -1445,9 +1454,13 @@ int _register_user(aClient *cptr, aClient *sptr, char *nick, char *username, cha parv[1] = NULL; do_cmd(sptr, sptr, "LUSERS", 1, parv); } + + RunHook2(HOOKTYPE_WELCOME, sptr, 266); short_motd(sptr); + RunHook2(HOOKTYPE_WELCOME, sptr, 376); + #ifdef EXPERIMENTAL sendto_one(sptr, ":%s NOTICE %s :*** \2NOTE:\2 This server is running experimental IRC server software (UnrealIRCd %s). If you find any bugs or problems, please report them at https://bugs.unrealircd.org/", @@ -1593,6 +1606,8 @@ int _register_user(aClient *cptr, aClient *sptr, char *nick, char *username, cha */ sptr->local->since = TStime(); + RunHook2(HOOKTYPE_WELCOME, sptr, 999); + /* NOTE: Code after this 'if (savetkl)' will not be executed for quarantined- * virus-users. So be carefull with the order. -- Syzop */