Changeset 3ddb7477 for irc_commands.c


Ignore:
Timestamp:
2010-03-26T12:14:37Z (14 years ago)
Author:
Wilmer van der Gaast <wilmer@…>
Branches:
master
Children:
ebaebfe
Parents:
ba7d16f
Message:

One total mess that doesn't do much yet, but reorganised some stuff and
untying the IRC and the core parts a little bit. Lots of work left to do.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_commands.c

    rba7d16f r3ddb7477  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2006 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2010 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    3939                   out we don't require it, which will break this feature.)
    4040                   Try to identify using the given password. */
    41                 return root_command( irc, send_cmd );
     41                /*return root_command( irc, send_cmd );*/
    4242        }
    4343        /* Handling in pre-logged-in state, first see if this server is
     
    5353        else if( global.conf->auth_pass )
    5454        {
    55                 irc_reply( irc, 464, ":Incorrect password" );
     55                irc_send_num( irc, 464, ":Incorrect password" );
    5656        }
    5757        else
    5858        {
    5959                /* Remember the password and try to identify after USER/NICK. */
    60                 irc_setpass( irc, cmd[1] );
     60                /*irc_setpass( irc, cmd[1] ); */
    6161                irc_check_login( irc );
    6262        }
     
    6565static void irc_cmd_user( irc_t *irc, char **cmd )
    6666{
    67         irc->user = g_strdup( cmd[1] );
    68         irc->realname = g_strdup( cmd[4] );
     67        irc->user->user = g_strdup( cmd[1] );
     68        irc->user->fullname = g_strdup( cmd[4] );
    6969       
    7070        irc_check_login( irc );
     
    7373static void irc_cmd_nick( irc_t *irc, char **cmd )
    7474{
    75         if( irc->nick )
    76         {
    77                 irc_reply( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" );
    78         }
    79         /* This is not clean, but for now it'll have to be like this... */
    80         else if( ( nick_cmp( cmd[1], irc->mynick ) == 0 ) || ( nick_cmp( cmd[1], NS_NICK ) == 0 ) )
    81         {
    82                 irc_reply( irc, 433, ":This nick is already in use" );
     75        if( irc->user->nick )
     76        {
     77                irc_send_num( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" );
     78        }
     79        else if( irc_user_find( irc, cmd[1] ) )
     80        {
     81                irc_send_num( irc, 433, ":This nick is already in use" );
    8382        }
    8483        else if( !nick_ok( cmd[1] ) )
    8584        {
    8685                /* [SH] Invalid characters. */
    87                 irc_reply( irc, 432, ":This nick contains invalid characters" );
    88         }
    89         else
    90         {
    91                 irc->nick = g_strdup( cmd[1] );
     86                irc_send_num( irc, 432, ":This nick contains invalid characters" );
     87        }
     88        else
     89        {
     90                irc->user->nick = g_strdup( cmd[1] );
    9291               
    9392                irc_check_login( irc );
     
    9594}
    9695
     96#if 0
    9797static void irc_cmd_quit( irc_t *irc, char **cmd )
    9898{
     
    116116        {
    117117                irc_umode_set( irc, "+o", 1 );
    118                 irc_reply( irc, 381, ":Password accepted" );
    119         }
    120         else
    121         {
    122                 irc_reply( irc, 432, ":Incorrect password" );
     118                irc_send_num( irc, 381, ":Password accepted" );
     119        }
     120        else
     121        {
     122                irc_send_num( irc, 432, ":Incorrect password" );
    123123        }
    124124}
     
    131131                {
    132132                        if( *cmd[2] == '+' || *cmd[2] == '-' )
    133                                 irc_reply( irc, 477, "%s :Can't change channel modes", cmd[1] );
     133                                irc_send_num( irc, 477, "%s :Can't change channel modes", cmd[1] );
    134134                        else if( *cmd[2] == 'b' )
    135                                 irc_reply( irc, 368, "%s :No bans possible", cmd[1] );
     135                                irc_send_num( irc, 368, "%s :No bans possible", cmd[1] );
    136136                }
    137137                else
    138                         irc_reply( irc, 324, "%s +%s", cmd[1], CMODE );
     138                        irc_send_num( irc, 324, "%s +%s", cmd[1], CMODE );
    139139        }
    140140        else
     
    145145                                irc_umode_set( irc, cmd[2], 0 );
    146146                        else
    147                                 irc_reply( irc, 221, "+%s", irc->umode );
     147                                irc_send_num( irc, 221, "+%s", irc->umode );
    148148                }
    149149                else
    150                         irc_reply( irc, 502, ":Don't touch their modes" );
     150                        irc_send_num( irc, 502, ":Don't touch their modes" );
    151151        }
    152152}
     
    183183        else
    184184        {
    185                 irc_reply( irc, 403, "%s :No such channel", cmd[1] );
     185                irc_send_num( irc, 403, "%s :No such channel", cmd[1] );
    186186        }
    187187}
     
    197197               
    198198                if( strchr( CTYPES, cmd[1][0] ) == NULL || cmd[1][1] == 0 )
    199                         irc_reply( irc, 479, "%s :Invalid channel name", cmd[1] );
     199                        irc_send_num( irc, 479, "%s :Invalid channel name", cmd[1] );
    200200                else if( ( c = chat_bychannel( irc, cmd[1] ) ) && c->acc && c->acc->ic )
    201201                        chat_join( irc, c, cmd[2] );
    202202                else
    203                         irc_reply( irc, 403, "%s :No such channel", cmd[1] );
     203                        irc_send_num( irc, 403, "%s :No such channel", cmd[1] );
    204204        }
    205205}
     
    215215                {
    216216                        c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
    217                         irc_reply( irc, 341, "%s %s", nick, channel );
     217                        irc_send_num( irc, 341, "%s %s", nick, channel );
    218218                        return;
    219219                }
    220220       
    221         irc_reply( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
     221        irc_send_num( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
    222222}
    223223
     
    226226        if ( !cmd[2] )
    227227        {
    228                 irc_reply( irc, 412, ":No text to send" );
     228                irc_send_num( irc, 412, ":No text to send" );
    229229        }
    230230        else if ( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 )
     
    283283                while( u )
    284284                {
    285                         irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", u->online ? irc->channel : "*", u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
     285                        irc_send_num( irc, 352, "%s %s %s %s %s %c :0 %s", u->online ? irc->channel : "*", u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
    286286                        u = u->next;
    287287                }
     
    290290                {
    291291                        if( u->online )
    292                                 irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
     292                                irc_send_num( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
    293293                        u = u->next;
    294294                }
     
    297297                {
    298298                        if( ( u = user_findhandle( c->ic, l->data ) ) )
    299                                 irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
     299                                irc_send_num( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
    300300                }
    301301        else if( ( u = user_find( irc, channel ) ) )
    302                 irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
    303        
    304         irc_reply( irc, 315, "%s :End of /WHO list", channel?channel:"**" );
     302                irc_send_num( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
     303       
     304        irc_send_num( irc, 315, "%s :End of /WHO list", channel?channel:"**" );
    305305}
    306306
     
    320320                {
    321321                        if( u->online && u->away )
    322                                 irc_reply( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host );
     322                                irc_send_num( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host );
    323323                        else
    324                                 irc_reply( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host );
     324                                irc_send_num( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host );
    325325                }
    326326}
     
    377377                buff[strlen(buff)-1] = '\0';
    378378       
    379         irc_reply( irc, 303, ":%s", buff );
     379        irc_send_num( irc, 303, ":%s", buff );
    380380}
    381381
     
    406406                       
    407407                        if( u && u->online )
    408                                 irc_reply( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "is online" );
     408                                irc_send_num( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "is online" );
    409409                        else
    410                                 irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" );
     410                                irc_send_num( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" );
    411411                }
    412412                else if( cmd[i][0] == '-' )
     
    419419                                g_free( okey );
    420420                               
    421                                 irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
     421                                irc_send_num( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
    422422                        }
    423423                }
     
    463463                u->away[j] = 0;
    464464               
    465                 irc_reply( irc, 306, ":You're now away: %s", u->away );
     465                irc_send_num( irc, 306, ":You're now away: %s", u->away );
    466466                /* irc_umode_set( irc, irc->myhost, "+a" ); */
    467467        }
     
    471471                u->away = NULL;
    472472                /* irc_umode_set( irc, irc->myhost, "-a" ); */
    473                 irc_reply( irc, 305, ":Welcome back" );
     473                irc_send_num( irc, 305, ":Welcome back" );
    474474        }
    475475       
     
    484484        if( u )
    485485        {
    486                 irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
     486                irc_send_num( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
    487487               
    488488                if( u->ic )
    489                         irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
     489                        irc_send_num( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
    490490                                   u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "",
    491491                                   u->ic->acc->prpl->name );
    492492                else
    493                         irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
     493                        irc_send_num( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
    494494               
    495495                if( !u->online )
    496                         irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" );
     496                        irc_send_num( irc, 301, "%s :%s", u->nick, "User is offline" );
    497497                else if( u->away )
    498                         irc_reply( irc, 301, "%s :%s", u->nick, u->away );
     498                        irc_send_num( irc, 301, "%s :%s", u->nick, u->away );
    499499                if( u->status_msg )
    500                         irc_reply( irc, 333, "%s :Status: %s", u->nick, u->status_msg );
    501                
    502                 irc_reply( irc, 318, "%s :End of /WHOIS list", nick );
    503         }
    504         else
    505         {
    506                 irc_reply( irc, 401, "%s :Nick does not exist", nick );
     500                        irc_send_num( irc, 333, "%s :Status: %s", u->nick, u->status_msg );
     501               
     502                irc_send_num( irc, 318, "%s :End of /WHOIS list", nick );
     503        }
     504        else
     505        {
     506                irc_send_num( irc, 401, "%s :Nick does not exist", nick );
    507507        }
    508508}
     
    515515           with not-found and irssi users will get better error messages */
    516516       
    517         irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] );
    518         irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] );
     517        irc_send_num( irc, 406, "%s :Nick does not exist", cmd[1] );
     518        irc_send_num( irc, 369, "%s :End of WHOWAS", cmd[1] );
    519519}
    520520
     
    541541static void irc_cmd_version( irc_t *irc, char **cmd )
    542542{
    543         irc_reply( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU );
     543        irc_send_num( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU );
    544544}
    545545
     
    572572                ipc_to_master( cmd );
    573573       
    574         irc_reply( irc, 382, "%s :Rehashing", global.conf_file );
    575 }
     574        irc_send_num( irc, 382, "%s :Rehashing", global.conf_file );
     575}
     576#endif
    576577
    577578static const command_t irc_commands[] = {
     
    579580        { "user",        4, irc_cmd_user,        IRC_CMD_PRE_LOGIN },
    580581        { "nick",        1, irc_cmd_nick,        0 },
     582#if 0
    581583        { "quit",        0, irc_cmd_quit,        0 },
    582584        { "ping",        0, irc_cmd_ping,        0 },
     
    610612        { "restart",     0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    611613        { "kill",        2, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
     614#endif
    612615        { NULL }
    613616};
     
    628631                        if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
    629632                        {
    630                                 irc_reply( irc, 462, ":Only allowed before logging in" );
     633                                irc_send_num( irc, 462, ":Only allowed before logging in" );
    631634                        }
    632635                        else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
    633636                        {
    634                                 irc_reply( irc, 451, ":Register first" );
     637                                irc_send_num( irc, 451, ":Register first" );
    635638                        }
    636639                        else if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) )
    637640                        {
    638                                 irc_reply( irc, 481, ":Permission denied - You're not an IRC operator" );
     641                                irc_send_num( irc, 481, ":Permission denied - You're not an IRC operator" );
    639642                        }
    640643                        else if( n_arg < irc_commands[i].required_parameters )
    641644                        {
    642                                 irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
     645                                irc_send_num( irc, 461, "%s :Need more parameters", cmd[0] );
    643646                        }
    644647                        else if( irc_commands[i].flags & IRC_CMD_TO_MASTER )
     
    657660       
    658661        if( irc->status >= USTATUS_LOGGED_IN )
    659                 irc_reply( irc, 421, "%s :Unknown command", cmd[0] );
    660 }
     662                irc_send_num( irc, 421, "%s :Unknown command", cmd[0] );
     663}
Note: See TracChangeset for help on using the changeset viewer.