diff options
-rw-r--r-- | irc.h | 1 | ||||
-rw-r--r-- | irc_send.c | 5 | ||||
-rw-r--r-- | irc_user.c | 42 |
3 files changed, 47 insertions, 1 deletions
@@ -238,6 +238,7 @@ void irc_send_motd( irc_t *irc ); void irc_usermsg( irc_t *irc, char *format, ... ); void irc_send_join( irc_channel_t *ic, irc_user_t *iu ); void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason ); +void irc_send_quit( irc_user_t *iu, const char *reason ); void irc_send_names( irc_channel_t *ic ); void irc_send_topic( irc_channel_t *ic, gboolean topic_change ); void irc_send_whois( irc_user_t *iu ); @@ -152,6 +152,11 @@ void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason ) irc_write( ic->irc, ":%s!%s@%s PART %s :%s", iu->nick, iu->user, iu->host, ic->name, reason ? : "" ); } +void irc_send_quit( irc_user_t *iu, const char *reason ) +{ + irc_write( iu->irc, ":%s!%s@%s QUIT :%s", iu->nick, iu->user, iu->host, reason ? : "" ); +} + void irc_send_names( irc_channel_t *ic ) { GSList *l; @@ -49,6 +49,7 @@ irc_user_t *irc_user_new( irc_t *irc, const char *nick ) int irc_user_free( irc_t *irc, irc_user_t *iu ) { GSList *l; + gboolean send_quit = FALSE; if( !iu ) return 0; @@ -57,7 +58,46 @@ int irc_user_free( irc_t *irc, irc_user_t *iu ) g_hash_table_remove( irc->nick_user_hash, iu->key ); for( l = irc->channels; l; l = l->next ) - irc_channel_del_user( (irc_channel_t*) l->data, iu, FALSE, NULL ); + send_quit |= irc_channel_del_user( (irc_channel_t*) l->data, iu, TRUE, NULL ); + + if( send_quit ) + { + static struct im_connection *last_ic; + static char *msg; + + if( iu->bu && + ( iu->bu->ic->flags & OPT_LOGGING_OUT ) && + iu->bu->ic != last_ic ) + { + char host_prefix[] = "bitlbee."; + char *s; + + /* Irssi recognises netsplits by quitmsgs with two + hostnames, where a hostname is a "word" with one + of more dots. Mangle no-dot hostnames a bit. */ + if( strchr( irc->root->host, '.' ) ) + *host_prefix = '\0'; + + last_ic = iu->bu->ic; + g_free( msg ); + if( !set_getbool( &irc->b->set, "simulate_netsplit" ) ) + msg = g_strdup( "Account off-line" ); + else if( ( s = strchr( iu->bu->ic->acc->user, '@' ) ) ) + msg = g_strdup_printf( "%s%s %s", host_prefix, + irc->root->host, s + 1 ); + else + msg = g_strdup_printf( "%s%s %s.%s", + host_prefix, irc->root->host, + iu->bu->ic->acc->prpl->name, irc->root->host ); + } + else if( !iu->bu || !( iu->bu->ic->flags & OPT_LOGGING_OUT ) ) + { + g_free( msg ); + msg = g_strdup( "Removed" ); + last_ic = NULL; + } + irc_send_quit( iu, msg ); + } g_free( iu->nick ); if( iu->nick != iu->user ) g_free( iu->user ); |