Changeset 4be8239


Ignore:
Timestamp:
2010-03-27T02:39:08Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
b9e020a
Parents:
ebaebfe
Message:

Simple IRC channel interface, use it to represent the control channel.

Files:
1 added
1 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • Makefile

    rebaebfe r4be8239  
    1111# Program variables
    1212#objects = bitlbee.o chat.o dcc.o help.o ipc.o irc.o irc_commands.o nick.o query.o root_commands.o set.o storage.o $(STORAGE_OBJS)
    13 objects = bitlbee.o help.o ipc.o irc.o irc_commands.o irc_send.o irc_user.o nick.o set.o
     13objects = bitlbee.o help.o ipc.o irc.o irc_channel.o irc_commands.o irc_send.o irc_user.o nick.o set.o
    1414headers = account.h bitlbee.h commands.h conf.h config.h help.h ipc.h irc.h log.h nick.h query.h set.h sock.h storage.h user.h lib/events.h lib/ftutil.h lib/http_client.h lib/ini.h lib/md5.h lib/misc.h lib/proxy.h lib/sha1.h lib/ssl_client.h lib/url.h protocols/ft.h protocols/nogaim.h
    1515subdirs = lib protocols
  • irc.c

    rebaebfe r4be8239  
    586586                else
    587587                {
     588                        irc_channel_t *ic;
     589                        irc_user_t *iu = irc->user;
     590                       
     591                        irc->user = irc_user_new( irc, iu->nick );
     592                        irc->user->user = iu->user;
     593                        irc->user->fullname = iu->fullname;
     594                        g_free( iu->nick );
     595                        g_free( iu );
     596                       
     597                        irc->umode[0] = '\0';
     598                        /*irc_umode_set( irc, "+" UMODE, 1 );*/
     599                       
     600                        if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
     601                                ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname );
     602                       
     603                        irc->status |= USTATUS_LOGGED_IN;
     604                       
     605                        /* This is for bug #209 (use PASS to identify to NickServ). */
     606                        if( irc->password != NULL )
     607                        {
     608                                char *send_cmd[] = { "identify", g_strdup( irc->password ), NULL };
     609                               
     610                                /*irc_setpass( irc, NULL );*/
     611                                /*root_command( irc, send_cmd );*/
     612                                g_free( send_cmd[1] );
     613                        }
     614                       
    588615                        irc_send_login( irc );
     616                       
     617                        ic = irc_channel_new( irc, ROOT_CHAN );
     618                        irc_channel_set_topic( ic, CONTROL_TOPIC );
     619                        irc_channel_add_user( ic, irc->user );
     620                       
    589621                        return 1;
    590622                }
  • irc.h

    rebaebfe r4be8239  
    7373        struct account *accounts;
    7474        GSList *file_transfers;
    75         struct chat *chatrooms;
    7675       
    77         GSList *users;
     76        GSList *users, *channels;
    7877        GHashTable *nick_user_hash;
    7978        GHashTable *watches;
     
    106105} irc_user_t;
    107106
     107typedef enum
     108{
     109        IRC_CHANNEL_JOINED = 1,
     110} irc_channel_flags_t;
     111
     112typedef struct irc_channel
     113{
     114        irc_t *irc;
     115        int flags;
     116        char *name;
     117        char *topic;
     118        char mode[8];
     119        GSList *users;
     120        struct set *set;
     121} irc_channel_t;
     122
    108123#include "user.h"
    109124
     
    125140int irc_check_login( irc_t *irc );
    126141
     142/* irc_channel.c */
     143irc_channel_t *irc_channel_new( irc_t *irc, const char *name );
     144int irc_channel_add_user( irc_channel_t *ic, irc_user_t *iu );
     145int irc_channel_del_user( irc_channel_t *ic, irc_user_t *iu );
     146int irc_channel_set_topic( irc_channel_t *ic, const char *topic );
     147
    127148/* irc_commands.c */
    128149void irc_exec( irc_t *irc, char **cmd );
     
    132153void irc_send_login( irc_t *irc );
    133154void irc_send_motd( irc_t *irc );
    134 int irc_usermsg( irc_t *irc, char *format, ... );
     155void irc_usermsg( irc_t *irc, char *format, ... );
     156void irc_send_join( irc_channel_t *ic, irc_user_t *iu );
     157void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason );
     158void irc_send_names( irc_channel_t *ic );
     159void irc_send_topic( irc_channel_t *ic );
    135160
    136161/* irc_user.c */
  • irc_send.c

    rebaebfe r4be8239  
    3434        g_vsnprintf( text, IRC_MAX_LINE, format, params );
    3535        va_end( params );
     36       
    3637        irc_write( irc, ":%s %03d %s %s", irc->root->host, code, irc->user->nick ? : "*", text );
    37        
    38         return;
    3938}
    4039
    4140void irc_send_login( irc_t *irc )
    4241{
    43         irc_user_t *iu = irc->user;
    44        
    45         irc->user = irc_user_new( irc, iu->nick );
    46         irc->user->user = iu->user;
    47         irc->user->fullname = iu->fullname;
    48         g_free( iu->nick );
    49         g_free( iu );
    50        
    5142        irc_send_num( irc,   1, ":Welcome to the BitlBee gateway, %s", irc->user->nick );
    5243        irc_send_num( irc,   2, ":Host %s is running BitlBee " BITLBEE_VERSION " " ARCH "/" CPU ".", irc->root->host );
     
    5748                                CTYPES, CMODES, MAX_NICK_LENGTH - 1 );
    5849        irc_send_motd( irc );
    59         irc->umode[0] = '\0';
    60         /*irc_umode_set( irc, "+" UMODE, 1 );*/
    6150       
    6251        irc_usermsg( irc, "Welcome to the BitlBee gateway!\n\n"
     
    6655                          "If you already have an account on this server, just use the "
    6756                          "\x02identify\x02 command to identify yourself." );
    68        
    69         if( global.conf->runmode == RUNMODE_FORKDAEMON || global.conf->runmode == RUNMODE_DAEMON )
    70                 ipc_to_master_str( "CLIENT %s %s :%s\r\n", irc->user->host, irc->user->nick, irc->user->fullname );
    71        
    72         irc->status |= USTATUS_LOGGED_IN;
    73        
    74         /* This is for bug #209 (use PASS to identify to NickServ). */
    75         if( irc->password != NULL )
    76         {
    77                 char *send_cmd[] = { "identify", g_strdup( irc->password ), NULL };
    78                
    79                 /*irc_setpass( irc, NULL );*/
    80                 /*root_command( irc, send_cmd );*/
    81                 g_free( send_cmd[1] );
    82         }
    8357}
    8458
     
    136110
    137111/* FIXME/REPLACEME */
    138 int irc_usermsg( irc_t *irc, char *format, ... )
     112void irc_usermsg( irc_t *irc, char *format, ... )
    139113{
    140114        char text[1024];
     
    148122        fprintf( stderr, "%s\n", text );
    149123       
    150         return 1;
    151        
    152124        /*return( irc_msgfrom( irc, u->nick, text ) );*/
    153125}
     126
     127void irc_send_join( irc_channel_t *ic, irc_user_t *iu )
     128{
     129        irc_t *irc = ic->irc;
     130       
     131        irc_write( irc, ":%s!%s@%s JOIN :%s", iu->nick, iu->user, iu->host, ic->name );
     132       
     133        if( iu == irc->user )
     134        {
     135                irc_write( irc, ":%s MODE %s +%s", irc->root->host, ic->name, ic->mode );
     136                irc_send_names( ic );
     137                irc_send_topic( ic );
     138        }
     139}
     140
     141void irc_send_part( irc_channel_t *ic, irc_user_t *iu, const char *reason )
     142{
     143        irc_write( ic->irc, ":%s!%s@%s PART %s :%s", iu->nick, iu->user, iu->host, ic->name, reason );
     144}
     145
     146void irc_send_names( irc_channel_t *ic )
     147{
     148        GSList *l;
     149        irc_user_t *iu;
     150        char namelist[385] = "";
     151        struct groupchat *c = NULL;
     152        char *ops = set_getstr( &ic->irc->b->set, "ops" );
     153       
     154        /* RFCs say there is no error reply allowed on NAMES, so when the
     155           channel is invalid, just give an empty reply. */
     156        for( l = ic->users; l; l = l->next )
     157        {
     158                irc_user_t *iu = l->data;
     159               
     160                if( strlen( namelist ) + strlen( iu->nick ) > sizeof( namelist ) - 4 )
     161                {
     162                        irc_send_num( ic->irc, 353, "= %s :%s", ic->name, namelist );
     163                        *namelist = 0;
     164                }
     165               
     166                /*
     167                if( u->ic && !u->away && set_getbool( &irc->set, "away_devoice" ) )
     168                        strcat( namelist, "+" );
     169                else if( ( strcmp( u->nick, irc->mynick ) == 0 && ( strcmp( ops, "root" ) == 0 || strcmp( ops, "both" ) == 0 ) ) ||
     170                         ( strcmp( u->nick, irc->nick ) == 0 && ( strcmp( ops, "user" ) == 0 || strcmp( ops, "both" ) == 0 ) ) )
     171                        strcat( namelist, "@" );
     172                */
     173               
     174                strcat( namelist, iu->nick );
     175                strcat( namelist, " " );
     176        }
     177       
     178        if( *namelist )
     179                irc_send_num( ic->irc, 353, "= %s :%s", ic->name, namelist );
     180       
     181        irc_send_num( ic->irc, 366, "%s :End of /NAMES list", ic->name );
     182}
     183
     184void irc_send_topic( irc_channel_t *ic )
     185{
     186        if( ic->topic )
     187                irc_send_num( ic->irc, 332, "%s :%s", ic->name, ic->topic );
     188        else
     189                irc_send_num( ic->irc, 331, "%s :No topic for this channel", ic->name );
     190}
Note: See TracChangeset for help on using the changeset viewer.