diff options
author | Wilmer van der Gaast <wilmer@gaast.net> | 2010-04-04 20:39:04 -0400 |
---|---|---|
committer | Wilmer van der Gaast <wilmer@gaast.net> | 2010-04-04 20:39:04 -0400 |
commit | 0b5cc72bc7b4192ff5b474b81038c299d03721f1 (patch) | |
tree | e727779c8d5a02dae6f9baad5a834706059a6307 | |
parent | 1d3915951bfbcdfa1a7829a4082e90e154d4a486 (diff) |
Send nickname change notifications when necessary.
-rw-r--r-- | irc.h | 4 | ||||
-rw-r--r-- | irc_channel.c | 10 | ||||
-rw-r--r-- | irc_send.c | 6 | ||||
-rw-r--r-- | irc_user.c | 18 |
4 files changed, 34 insertions, 4 deletions
@@ -178,6 +178,7 @@ irc_channel_t *irc_channel_by_name( irc_t *irc, const char *name ); int irc_channel_free( irc_channel_t *ic ); int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu ); int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu ); +gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu ); int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who ); gboolean irc_channel_name_ok( const char *name ); @@ -197,12 +198,13 @@ void irc_send_whois( irc_user_t *iu ); void irc_send_who( irc_t *irc, GSList *l, const char *channel ); void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix ); void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg ); +void irc_send_nick( irc_user_t *iu, const char *new ); /* irc_user.c */ irc_user_t *irc_user_new( irc_t *irc, const char *nick ); int irc_user_free( irc_t *irc, const char *nick ); irc_user_t *irc_user_by_name( irc_t *irc, const char *nick ); -int irc_user_rename( irc_t *irc, const char *old, const char *new ); +int irc_user_set_nick( irc_t *irc, const char *old, const char *new ); gint irc_user_cmp( gconstpointer a_, gconstpointer b_ ); #endif diff --git a/irc_channel.c b/irc_channel.c index db3ecd34..27216f3c 100644 --- a/irc_channel.c +++ b/irc_channel.c @@ -81,7 +81,7 @@ int irc_channel_free( irc_channel_t *ic ) int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu ) { - if( g_slist_find( ic->users, iu ) != NULL ) + if( !irc_channel_has_user( ic, iu ) ) return 0; ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp ); @@ -97,7 +97,7 @@ int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu ) int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu ) { - if( g_slist_find( ic->users, iu ) == NULL ) + if( !irc_channel_has_user( ic, iu ) ) return 0; ic->users = g_slist_remove( ic->users, iu ); @@ -111,6 +111,12 @@ int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu ) return 1; } +/* Currently a fairly stupid one-liner but I fear it's going to get worse. :-) */ +gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu ) +{ + return g_slist_find( ic->users, iu ) != NULL; +} + int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *iu ) { g_free( ic->topic ); @@ -310,3 +310,9 @@ void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const irc_write( iu->irc, ":%s!%s@%s %s %s :%s", iu->nick, iu->user, iu->host, type, dst, msg ); } + +void irc_send_nick( irc_user_t *iu, const char *new ) +{ + irc_write( iu->irc, ":%s!%s@%s NICK %s", + iu->nick, iu->user, iu->host, new ); +} @@ -82,15 +82,31 @@ irc_user_t *irc_user_by_name( irc_t *irc, const char *nick ) return NULL; } -int irc_user_rename( irc_t *irc, const char *old, const char *new ) +int irc_user_set_nick( irc_t *irc, const char *old, const char *new ) { irc_user_t *iu = irc_user_by_name( irc, old ); char key[strlen(new)+1]; + GSList *cl; strcpy( key, new ); if( iu == NULL || !nick_lc( key ) || irc_user_by_name( irc, new ) ) return 0; + for( cl = irc->channels; cl; cl = cl->next ) + { + irc_channel_t *ic = cl->data; + + /* Send a NICK update if we're renaming our user, or someone + who's in the same channel like our user. */ + if( iu == irc->user || + ( irc_channel_has_user( ic, irc->user ) && + irc_channel_has_user( ic, iu ) ) ) + { + irc_send_nick( iu, new ); + break; + } + } + irc->users = g_slist_remove( irc->users, iu ); g_hash_table_remove( irc->nick_user_hash, iu->key ); |