From 13ac2a332fd08e1a21957cf7e58ef34fad4436dd Mon Sep 17 00:00:00 2001 From: Michiel Broek Date: Sat, 27 May 2006 20:45:55 +0000 Subject: [PATCH] Delete users from channel when a server disconnects --- mbtask/taskibc.c | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/mbtask/taskibc.c b/mbtask/taskibc.c index 8973c21c..a393914a 100644 --- a/mbtask/taskibc.c +++ b/mbtask/taskibc.c @@ -283,6 +283,27 @@ int add_user(char *server, char *name, char *realname) } +/* + * Delete user from channel + */ +void del_userchannel(char *channel) +{ + int i; + + for (i = 0; i < MAXIBC_CHN; i++) { + if (strcmp(chn_list[i].name, channel) == 0) { + chnchg = TRUE; + chn_list[i].users--; + if (chn_list[i].users == 0) { + Syslog('+', "IBC: deleted empty channel %s", channel); + del_channel(channel); + } + break; + } + } +} + + /* * Delete one user. If name == NULL then delete all users of a server. @@ -293,11 +314,15 @@ void del_user(char *server, char *name) for (i = 0; i < MAXIBC_USR; i++) { if (name && (strcmp(usr_list[i].server, server) == 0) && (strcmp(usr_list[i].name, name) == 0)) { + if (strlen(usr_list[i].channel)) + del_userchannel(usr_list[i].channel); Syslog('r', "IBC: del_user(%s, %s) from slot %d", server, printable(name, 0), i); memset(&usr_list[i], 0, sizeof(_usr_list)); usrchg = TRUE; count++; } else if ((name == NULL) && (strcmp(usr_list[i].server, server) == 0)) { + if (strlen(usr_list[i].channel)) + del_userchannel(usr_list[i].channel); Syslog('r', "IBC: del_user(%s, %s) user %s from slot %d", server, printable(name, 0), usr_list[i].name, i); memset(&usr_list[i], 0, sizeof(_usr_list)); usrchg = TRUE; @@ -1442,17 +1467,7 @@ int command_part(int slot, char *hostname, char *parameters) return 0; } - for (i = 0; i < MAXIBC_CHN; i++) { - if (strcmp(chn_list[i].name, channel) == 0) { - chnchg = TRUE; - chn_list[i].users--; - if (chn_list[i].users == 0) { - Syslog('+', "IBC: deleted empty channel %s", channel); - del_channel(channel); - } - break; - } - } + del_userchannel(channel); for (i = 0; i < MAXIBC_USR; i++) { if ((strcmp(usr_list[i].server, server) == 0) &&