Changeset 24b8bbb


Ignore:
Timestamp:
2010-04-12T00:06:49Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
89c11e7
Parents:
e21c0f8
Message:

Start handling CTCPs, in a saner way than before.

Files:
6 edited

Legend:

Unmodified
Added
Removed
  • irc.h

    re21c0f8 r24b8bbb  
    120120{
    121121        gboolean (*privmsg)( irc_user_t *iu, const char *msg );
     122        gboolean (*ctcp)( irc_user_t *iu, char * const* ctcp );
    122123};
    123124
  • irc_commands.c

    re21c0f8 r24b8bbb  
    255255        {
    256256                irc_send_num( irc, 412, ":No text to send" );
    257         }
    258         else if( irc_channel_name_ok( cmd[1] ) &&
    259                  ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
     257                return;
     258        }
     259       
     260        /* Don't treat CTCP actions as real CTCPs, just convert them right now. */
     261        if( g_strncasecmp( cmd[2], "\001ACTION", 7 ) == 0 )
     262        {
     263                cmd[2] += 4;
     264                strcpy( cmd[2], "/me" );
     265                if( cmd[2][strlen(cmd[2])-1] == '\001' )
     266                        cmd[2][strlen(cmd[2])-1] = '\0';
     267        }
     268       
     269        if( irc_channel_name_ok( cmd[1] ) &&
     270            ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
    260271        {
    261272                if( ic->f->privmsg )
     
    264275        else if( ( iu = irc_user_by_name( irc, cmd[1] ) ) )
    265276        {
    266                 if( iu->f->privmsg )
     277                if( cmd[2][0] == '\001' )
     278                {
     279                        char **ctcp;
     280                       
     281                        if( iu->f->ctcp == NULL )
     282                                return;
     283                        if( cmd[2][strlen(cmd[2])-1] == '\001' )
     284                                cmd[2][strlen(cmd[2])-1] = '\0';
     285                       
     286                        ctcp = split_command_parts( cmd[2] + 1 );
     287                        iu->f->ctcp( iu, ctcp );
     288                }
     289                else if( iu->f->privmsg )
    267290                        iu->f->privmsg( iu, cmd[2] );
    268291        }
  • irc_user.c

    re21c0f8 r24b8bbb  
    147147}
    148148
     149static gboolean root_ctcp( irc_user_t *iu, char * const *ctcp )
     150{
     151        if( g_strcasecmp( ctcp[0], "VERSION" ) == 0 )
     152        {
     153        }
     154       
     155        return TRUE;
     156}
     157
    149158const struct irc_user_funcs irc_user_root_funcs = {
    150159        root_privmsg,
     160        root_ctcp,
    151161};
    152162
  • lib/misc.c

    re21c0f8 r24b8bbb  
    614614        return ret;
    615615}
     616
     617char **split_command_parts( char *command )
     618{
     619        static char *cmd[IRC_MAX_ARGS+1];
     620        char *s, q = 0;
     621        int k;
     622       
     623        memset( cmd, 0, sizeof( cmd ) );
     624        cmd[0] = command;
     625        k = 1;
     626        for( s = command; *s && k < IRC_MAX_ARGS; s ++ )
     627                if( *s == ' ' && !q )
     628                {
     629                        *s = 0;
     630                        while( *++s == ' ' );
     631                        if( *s == '"' || *s == '\'' )
     632                        {
     633                                q = *s;
     634                                s ++;
     635                        }
     636                        if( *s )
     637                        {
     638                                cmd[k++] = s;
     639                                s --;
     640                        }
     641                        else
     642                        {
     643                                break;
     644                        }
     645                }
     646                else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) )
     647                {
     648                        char *cpy;
     649                       
     650                        for( cpy = s; *cpy; cpy ++ )
     651                                cpy[0] = cpy[1];
     652                }
     653                else if( *s == q )
     654                {
     655                        q = *s = 0;
     656                }
     657        cmd[k] = NULL;
     658       
     659        return cmd;
     660}
  • lib/misc.h

    re21c0f8 r24b8bbb  
    6868G_MODULE_EXPORT int md5_verify_password( char *password, char *hash );
    6969
     70G_MODULE_EXPORT char **split_command_parts( char *command );
     71
    7072#endif
  • root_commands.c

    re21c0f8 r24b8bbb  
    3434void root_command_string( irc_t *irc, char *command )
    3535{
    36         char *cmd[IRC_MAX_ARGS];
    37         char *s;
    38         int k;
    39         char q = 0;
    40        
    41         memset( cmd, 0, sizeof( cmd ) );
    42         cmd[0] = command;
    43         k = 1;
    44         for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
    45                 if( *s == ' ' && !q )
    46                 {
    47                         *s = 0;
    48                         while( *++s == ' ' );
    49                         if( *s == '"' || *s == '\'' )
    50                         {
    51                                 q = *s;
    52                                 s ++;
    53                         }
    54                         if( *s )
    55                         {
    56                                 cmd[k++] = s;
    57                                 s --;
    58                         }
    59                         else
    60                         {
    61                                 break;
    62                         }
    63                 }
    64                 else if( *s == '\\' && ( ( !q && s[1] ) || ( q && q == s[1] ) ) )
    65                 {
    66                         char *cpy;
    67                        
    68                         for( cpy = s; *cpy; cpy ++ )
    69                                 cpy[0] = cpy[1];
    70                 }
    71                 else if( *s == q )
    72                 {
    73                         q = *s = 0;
    74                 }
    75         cmd[k] = NULL;
    76        
    77         root_command( irc, cmd );
     36        root_command( irc, split_command_parts( command ) );
    7837}
    7938
Note: See TracChangeset for help on using the changeset viewer.