Changeset 0b5cc72


Ignore:
Timestamp:
2010-04-05T00:39:04Z (9 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
57c96f7
Parents:
1d39159
Message:

Send nickname change notifications when necessary.

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • irc.h

    r1d39159 r0b5cc72  
    179179int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu );
    180180int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu );
     181gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu );
    181182int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who );
    182183gboolean irc_channel_name_ok( const char *name );
     
    198199void irc_send_msg( irc_user_t *iu, const char *type, const char *dst, const char *msg, const char *prefix );
    199200void irc_send_msg_raw( irc_user_t *iu, const char *type, const char *dst, const char *msg );
     201void irc_send_nick( irc_user_t *iu, const char *new );
    200202
    201203/* irc_user.c */
     
    203205int irc_user_free( irc_t *irc, const char *nick );
    204206irc_user_t *irc_user_by_name( irc_t *irc, const char *nick );
    205 int irc_user_rename( irc_t *irc, const char *old, const char *new );
     207int irc_user_set_nick( irc_t *irc, const char *old, const char *new );
    206208gint irc_user_cmp( gconstpointer a_, gconstpointer b_ );
    207209
  • irc_channel.c

    r1d39159 r0b5cc72  
    8282int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
    8383{
    84         if( g_slist_find( ic->users, iu ) != NULL )
     84        if( !irc_channel_has_user( ic, iu ) )
    8585                return 0;
    8686       
     
    9898int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu )
    9999{
    100         if( g_slist_find( ic->users, iu ) == NULL )
     100        if( !irc_channel_has_user( ic, iu ) )
    101101                return 0;
    102102       
     
    110110       
    111111        return 1;
     112}
     113
     114/* Currently a fairly stupid one-liner but I fear it's going to get worse. :-) */
     115gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu )
     116{
     117        return g_slist_find( ic->users, iu ) != NULL;
    112118}
    113119
  • irc_send.c

    r1d39159 r0b5cc72  
    311311                   iu->nick, iu->user, iu->host, type, dst, msg );
    312312}
     313
     314void irc_send_nick( irc_user_t *iu, const char *new )
     315{
     316        irc_write( iu->irc, ":%s!%s@%s NICK %s",
     317                   iu->nick, iu->user, iu->host, new );
     318}
  • irc_user.c

    r1d39159 r0b5cc72  
    8383}
    8484
    85 int irc_user_rename( irc_t *irc, const char *old, const char *new )
     85int irc_user_set_nick( irc_t *irc, const char *old, const char *new )
    8686{
    8787        irc_user_t *iu = irc_user_by_name( irc, old );
    8888        char key[strlen(new)+1];
     89        GSList *cl;
    8990       
    9091        strcpy( key, new );
    9192        if( iu == NULL || !nick_lc( key ) || irc_user_by_name( irc, new ) )
    9293                return 0;
     94       
     95        for( cl = irc->channels; cl; cl = cl->next )
     96        {
     97                irc_channel_t *ic = cl->data;
     98               
     99                /* Send a NICK update if we're renaming our user, or someone
     100                   who's in the same channel like our user. */
     101                if( iu == irc->user ||
     102                    ( irc_channel_has_user( ic, irc->user ) &&
     103                      irc_channel_has_user( ic, iu ) ) )
     104                {
     105                        irc_send_nick( iu, new );
     106                        break;
     107                }
     108        }
    93109       
    94110        irc->users = g_slist_remove( irc->users, iu );
Note: See TracChangeset for help on using the changeset viewer.