Changeset 4be8239 for irc_send.c


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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.