Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_send.c

    ra72af0d red320e8  
    5353void irc_send_motd( irc_t *irc )
    5454{
     55        char motd[2048];
     56        size_t len;
    5557        int fd;
    5658       
    5759        fd = open( global.conf->motdfile, O_RDONLY );
    58         if( fd == -1 )
     60        if( fd == -1 || ( len = read( fd, motd, sizeof( motd ) - 1 ) ) <= 0 )
    5961        {
    6062                irc_send_num( irc, 422, ":We don't need MOTDs." );
     
    6264        else
    6365        {
    64                 char linebuf[80];       /* Max. line length for MOTD's is 79 chars. It's what most IRC networks seem to do. */
    65                 char *add, max;
    66                 int len;
    67                
     66                char linebuf[80];
     67                char *add = "", max, *in;
     68               
     69                in = motd;
     70                motd[len] = '\0';
    6871                linebuf[79] = len = 0;
    6972                max = sizeof( linebuf ) - 1;
    7073               
    7174                irc_send_num( irc, 375, ":- %s Message Of The Day - ", irc->root->host );
    72                 while( read( fd, linebuf + len, 1 ) == 1 )
     75                while( ( linebuf[len] = *(in++) ) )
    7376                {
    7477                        if( linebuf[len] == '\n' || len == max )
     
    8083                        else if( linebuf[len] == '%' )
    8184                        {
    82                                 read( fd, linebuf + len, 1 );
     85                                linebuf[len] = *(in++);
    8386                                if( linebuf[len] == 'h' )
    8487                                        add = irc->root->host;
     
    8790                                else if( linebuf[len] == 'n' )
    8891                                        add = irc->user->nick;
     92                                else if( linebuf[len] == '\0' )
     93                                        in --;
    8994                                else
    9095                                        add = "%";
     
    99104                }
    100105                irc_send_num( irc, 376, ":End of MOTD" );
     106        }
     107       
     108        if( fd != -1 )
    101109                close( fd );
    102         }
    103110}
    104111
Note: See TracChangeset for help on using the changeset viewer.