Changeset e54112f


Ignore:
Timestamp:
2010-05-02T23:44:33Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
6a9d068
Parents:
bce78c8
Message:

Put a channel userlist in irc_channel_user elements so we can save flags
(i.e. modes).

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • irc.h

    rbce78c8 re54112f  
    153153};
    154154
     155typedef enum
     156{
     157        IRC_CHANNEL_USER_OP = 1,
     158        IRC_CHANNEL_USER_HALFOP = 2,
     159        IRC_CHANNEL_USER_VOICE = 4,
     160} irc_channel_user_flags_t;
     161
     162typedef struct irc_channel_user
     163{
     164        irc_user_t *iu;
     165        int flags;
     166} irc_channel_user_t;
     167
    155168extern const struct bee_ui_funcs irc_ui_funcs;
    156169
     
    181194int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu );
    182195int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu );
    183 gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu );
     196irc_channel_user_t *irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu );
    184197int irc_channel_set_topic( irc_channel_t *ic, const char *topic, const irc_user_t *who );
    185198gboolean irc_channel_name_ok( const char *name );
  • irc_channel.c

    rbce78c8 re54112f  
    2626#include "bitlbee.h"
    2727
     28static gint irc_channel_user_cmp( gconstpointer a_, gconstpointer b_ );
    2829static const struct irc_channel_funcs control_channel_funcs;
    2930
     
    7172       
    7273        irc->channels = g_slist_remove( irc->channels, ic );
    73         g_slist_free( ic->users );
     74        while( ic->users )
     75        {
     76                g_free( ic->users->data );
     77                ic->users = g_slist_remove( ic->users, ic->users->data );
     78        }
    7479       
    7580        g_free( ic->name );
     
    8287int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu )
    8388{
     89        irc_channel_user_t *icu;
     90       
    8491        if( irc_channel_has_user( ic, iu ) )
    8592                return 0;
    8693       
    87         ic->users = g_slist_insert_sorted( ic->users, iu, irc_user_cmp );
     94        icu = g_new0( irc_channel_user_t, 1 );
     95        icu->iu = iu;
     96       
     97        ic->users = g_slist_insert_sorted( ic->users, icu, irc_channel_user_cmp );
    8898       
    8999        if( iu == ic->irc->user || ic->flags & IRC_CHANNEL_JOINED )
     
    98108int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu )
    99109{
    100         if( !irc_channel_has_user( ic, iu ) )
     110        irc_channel_user_t *icu;
     111       
     112        if( !( icu = irc_channel_has_user( ic, iu ) ) )
    101113                return 0;
    102114       
    103         ic->users = g_slist_remove( ic->users, iu );
     115        ic->users = g_slist_remove( ic->users, icu );
     116        g_free( icu );
    104117       
    105118        if( ic->flags & IRC_CHANNEL_JOINED )
     
    112125}
    113126
    114 /* Currently a fairly stupid one-liner but I fear it's going to get worse. :-) */
    115 gboolean irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu )
    116 {
    117         return g_slist_find( ic->users, iu ) != NULL;
     127irc_channel_user_t *irc_channel_has_user( irc_channel_t *ic, irc_user_t *iu )
     128{
     129        GSList *l;
     130       
     131        for( l = ic->users; l; l = l->next )
     132        {
     133                irc_channel_user_t *icu = l->data;
     134               
     135                if( icu->iu == iu )
     136                        return icu;
     137        }
     138       
     139        return NULL;
    118140}
    119141
     
    140162{
    141163        return strchr( CTYPES, name[0] ) != NULL && nick_ok( name + 1 );
     164}
     165
     166static gint irc_channel_user_cmp( gconstpointer a_, gconstpointer b_ )
     167{
     168        const irc_channel_user_t *a = a_, *b = b_;
     169       
     170        return irc_user_cmp( a->iu, b->iu );
    142171}
    143172
  • irc_send.c

    rbce78c8 re54112f  
    163163        for( l = ic->users; l; l = l->next )
    164164        {
    165                 irc_user_t *iu = l->data;
     165                irc_channel_user_t *icu = l->data;
     166                irc_user_t *iu = icu->iu;
    166167               
    167168                if( strlen( namelist ) + strlen( iu->nick ) > sizeof( namelist ) - 4 )
     
    243244void irc_send_who( irc_t *irc, GSList *l, const char *channel )
    244245{
     246        gboolean is_channel = strcmp( channel, "**" ) != 0;
     247       
    245248        while( l )
    246249        {
    247250                irc_user_t *iu = l->data;
     251                if( is_channel )
     252                        iu = ((irc_channel_user_t*)iu)->iu;
    248253                /* TODO(wilmer): Restore away/channel information here */
    249254                irc_send_num( irc, 352, "%s %s %s %s %s %c :0 %s",
Note: See TracChangeset for help on using the changeset viewer.