Changeset 8e419cb for commands.c


Ignore:
Timestamp:
2006-01-10T21:35:08Z (18 years ago)
Author:
Jelmer Vernooij <jelmer@…>
Branches:
master
Children:
a4dc9f7
Parents:
3e91c3e (diff), dd8d4c5 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge Wilmer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • commands.c

    r3e91c3e r8e419cb  
    3232#include <string.h>
    3333
    34 command_t commands[] = {
     34const command_t commands[] = {
    3535        { "help",           0, cmd_help },
    3636        { "identify",       1, cmd_identify },
     
    5555};
    5656
     57int root_command_string( irc_t *irc, user_t *u, char *command, int flags )
     58{
     59        char *cmd[IRC_MAX_ARGS];
     60        char *s;
     61        int k;
     62        char q = 0;
     63       
     64        memset( cmd, 0, sizeof( cmd ) );
     65        cmd[0] = command;
     66        k = 1;
     67        for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
     68                if( *s == ' ' && !q )
     69                {
     70                        *s = 0;
     71                        while( *++s == ' ' );
     72                        if( *s == '"' || *s == '\'' )
     73                        {
     74                                q = *s;
     75                                s ++;
     76                        }
     77                        if( *s )
     78                        {
     79                                cmd[k++] = s;
     80                                s --;
     81                        }
     82                }
     83                else if( *s == q )
     84                {
     85                        q = *s = 0;
     86                }
     87        cmd[k] = NULL;
     88       
     89        return( root_command( irc, cmd ) );
     90}
     91
     92int root_command( irc_t *irc, char *cmd[] )
     93{       
     94        int i;
     95       
     96        if( !cmd[0] )
     97                return( 0 );
     98       
     99        for( i = 0; commands[i].command; i++ )
     100                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
     101                {
     102                        if( !cmd[commands[i].required_parameters] )
     103                        {
     104                                irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
     105                                return( 0 );
     106                        }
     107                        commands[i].execute( irc, cmd );
     108                        return( 1 );
     109                }
     110       
     111        irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] );
     112       
     113        return( 1 );
     114}
     115
    57116int cmd_help( irc_t *irc, char **cmd )
    58117{
     
    97156        case STORAGE_OK:
    98157                irc_usermsg( irc, "Password accepted" );
     158                irc_umode_set( irc, "+R", 1 );
    99159                break;
    100160        default:
     
    122182                case STORAGE_OK:
    123183                        irc->status = USTATUS_IDENTIFIED;
     184                        irc_umode_set( irc, "+R", 1 );
    124185                        break;
    125186
     
    146207        case STORAGE_OK:
    147208                irc_setpass( irc, NULL );
     209                irc->status = USTATUS_LOGGED_IN;
     210                irc_umode_set( irc, "-R", 1 );
    148211                irc_usermsg( irc, "Account `%s' removed", irc->nick );
    149212                return( 0 );
Note: See TracChangeset for help on using the changeset viewer.