From 9470338742a22b299e94029bd4b1d5c043fa86e2 Mon Sep 17 00:00:00 2001 From: Michael Poole Date: Sat, 3 Jan 2009 15:12:04 -0500 Subject: [PATCH] Automatically stop most user-oriented hooks if the user becomes dead. src/hash.c (NickChange): Stop iterating if the user is killed by any hook. (AddChannelUser): Likewise. src/nickserv.c (set_user_handle_info): Likewise. src/proto-common.c (of_list, of_size, of_used, reg_oper_func, call_oper_funcs): Move from the proto-*.c files. Make call_oper_funcs stop iterating if the user is killed by any hook. src/proto-bahahmut.c (AddUser): Likewise. (of_list, of_size, of_used, reg_oper_func, call_oper_funcs): Move to proto-common.c src/proto-p10.c: Likewise to proto-bahamut.c. --- src/hash.c | 8 +++++--- src/nickserv.c | 2 +- src/proto-bahamut.c | 33 ++------------------------------- src/proto-common.c | 30 ++++++++++++++++++++++++++++++ src/proto-p10.c | 30 +----------------------------- 5 files changed, 39 insertions(+), 64 deletions(-) diff --git a/src/hash.c b/src/hash.c index a7aa6a0..5cb7b0c 100644 --- a/src/hash.c +++ b/src/hash.c @@ -191,9 +191,11 @@ NickChange(struct userNode* user, const char *new_nick, int no_announce) #endif /* Make callbacks for nick changes. Do this with new nick in - * place because that is slightly more useful. + * place because that is slightly more useful. Stop if the user + * gets killed by any of the hooks, so that later hooks do not get + * confused by the user having disappeared. */ - for (nn=0; nndead; nn++) ncf2_list[nn](user, old_nick); user->timestamp = now; if (IsLocal(user) && !no_announce) @@ -502,7 +504,7 @@ AddChannelUser(struct userNode *user, struct chanNode* channel) irc_join(user, channel); } - for (n=0; ndead; n++) { /* Callbacks return true if they kick or kill the user, * and we can continue without removing mNode. */ if (jf_list[n](mNode)) diff --git a/src/nickserv.c b/src/nickserv.c index 424150f..7df54b1 100644 --- a/src/nickserv.c +++ b/src/nickserv.c @@ -935,7 +935,7 @@ set_user_handle_info(struct userNode *user, struct handle_info *hi, int stamp) user->handle_info = hi; if (hi && !hi->users && !hi->opserv_level) HANDLE_CLEAR_FLAG(hi, HELPING); - for (n=0; ndead; n++) auth_func_list[n](user, old_info); if (hi) { struct nick_info *ni; diff --git a/src/proto-bahamut.c b/src/proto-bahamut.c index 790010e..e7f0b2b 100644 --- a/src/proto-bahamut.c +++ b/src/proto-bahamut.c @@ -168,7 +168,7 @@ AddUser(struct server* uplink, const char *nick, const char *ident, const char * if (dummy) uNode->modes |= FLAGS_DUMMY; if (stamp) call_account_func(uNode, NULL, 0, stamp); if (IsLocal(uNode)) irc_user(uNode); - for (nn=0; nndead; nn++) { if (nuf_list[nn](uNode)) break; } return uNode; @@ -1043,12 +1043,9 @@ static CMD_FUNC(cmd_svsnick) return 1; } -static oper_func_t *of_list; -static unsigned int of_size = 0, of_used = 0; - void parse_cleanup(void) { unsigned int nn; - if (of_list) free(of_list); + free(of_list); dict_delete(irc_func_dict); dict_delete(service_msginfo_dict); free(mcf_list); @@ -1206,32 +1203,6 @@ unreg_notice_func(struct userNode *user) { } } -void -reg_oper_func(oper_func_t handler) -{ - if (of_used == of_size) { - if (of_size) { - of_size <<= 1; - of_list = realloc(of_list, of_size*sizeof(oper_func_t)); - } else { - of_size = 8; - of_list = malloc(of_size*sizeof(oper_func_t)); - } - } - of_list[of_used++] = handler; -} - -static void -call_oper_funcs(struct userNode *user) -{ - unsigned int n; - if (IsLocal(user)) return; - for (n=0; ndead; n++) + { + of_list[n](user); + } +} + struct mod_chanmode * mod_chanmode_alloc(unsigned int argc) { diff --git a/src/proto-p10.c b/src/proto-p10.c index e9ab2f4..d288524 100644 --- a/src/proto-p10.c +++ b/src/proto-p10.c @@ -1591,9 +1591,6 @@ static CMD_FUNC(cmd_svsnick) return 1; } -static oper_func_t *of_list; -static unsigned int of_size = 0, of_used = 0; - void free_user(struct userNode *user) { @@ -2141,7 +2138,7 @@ AddUser(struct server* uplink, const char *nick, const char *ident, const char * } if (IsLocal(uNode)) irc_user(uNode); - for (n=0; ndead; n++) if (nuf_list[n](uNode)) break; return uNode; @@ -2821,31 +2818,6 @@ unreg_notice_func(struct userNode *user) notice_funcs[user->num_local] = NULL; } -void -reg_oper_func(oper_func_t handler) -{ - if (of_used == of_size) { - if (of_size) { - of_size <<= 1; - of_list = realloc(of_list, of_size*sizeof(oper_func_t)); - } else { - of_size = 8; - of_list = malloc(of_size*sizeof(oper_func_t)); - } - } - of_list[of_used++] = handler; -} - -static void -call_oper_funcs(struct userNode *user) -{ - unsigned int n; - if (IsLocal(user)) - return; - for (n=0; n