Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_commands.c

    r47fae0f rec2ebcc  
    22  * BitlBee -- An IRC to other IM-networks gateway                     *
    33  *                                                                    *
    4   * Copyright 2002-2010 Wilmer van der Gaast and others                *
     4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
    55  \********************************************************************/
    66
     
    5353        else if( global.conf->auth_pass )
    5454        {
    55                 irc_send_num( irc, 464, ":Incorrect password" );
     55                irc_reply( 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->user = g_strdup( cmd[1] );
    68         irc->user->fullname = g_strdup( cmd[4] );
     67        irc->user = g_strdup( cmd[1] );
     68        irc->realname = g_strdup( cmd[4] );
    6969       
    7070        irc_check_login( irc );
     
    7373static void irc_cmd_nick( irc_t *irc, char **cmd )
    7474{
    75         if( irc_user_by_name( irc, cmd[1] ) )
    76         {
    77                 irc_send_num( irc, 433, ":This nick is already in use" );
     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" );
    7883        }
    7984        else if( !nick_ok( cmd[1] ) )
    8085        {
    8186                /* [SH] Invalid characters. */
    82                 irc_send_num( irc, 432, ":This nick contains invalid characters" );
    83         }
    84         else if( irc->user->nick )
    85         {
    86                 if( irc->status & USTATUS_IDENTIFIED )
    87                 {
    88                         irc_setpass( irc, NULL );
    89                         irc->status &= ~USTATUS_IDENTIFIED;
    90                         irc_umode_set( irc, "-R", 1 );
    91                 }
    92                
    93                 irc_user_set_nick( irc->user, cmd[1] );
    94         }
    95         else
    96         {
    97                 irc->user->nick = g_strdup( cmd[1] );
     87                irc_reply( irc, 432, ":This nick contains invalid characters" );
     88        }
     89        else
     90        {
     91                irc->nick = g_strdup( cmd[1] );
    9892               
    9993                irc_check_login( irc );
     
    111105static void irc_cmd_ping( irc_t *irc, char **cmd )
    112106{
    113         irc_write( irc, ":%s PONG %s :%s", irc->root->host,
    114                    irc->root->host, cmd[1]?cmd[1]:irc->root->host );
    115 }
    116 
    117 static void irc_cmd_pong( irc_t *irc, char **cmd )
    118 {
    119         /* We could check the value we get back from the user, but in
    120            fact we don't care, we're just happy s/he's still alive. */
    121         irc->last_pong = gettime();
    122         irc->pinging = 0;
    123 }
    124 
    125 static void irc_cmd_join( irc_t *irc, char **cmd )
    126 {
    127         irc_channel_t *ic;
    128        
    129         if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL )
    130                 ic = irc_channel_new( irc, cmd[1] );
    131        
    132         if( ic == NULL )
    133         {
    134                 irc_send_num( irc, 479, "%s :Invalid channel name", cmd[1] );
    135                 return;
    136         }
    137        
    138         if( ic->flags & IRC_CHANNEL_JOINED )
    139                 return; /* Dude, you're already there...
    140                            RFC doesn't have any reply for that though? */
    141        
    142         irc_channel_add_user( ic, irc->user );
    143 }
    144 
    145 static void irc_cmd_names( irc_t *irc, char **cmd )
    146 {
    147         irc_channel_t *ic;
    148        
    149         if( cmd[1] && ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
    150                 irc_send_names( ic );
    151         /* With no args, we should show /names of all chans. Make the code
    152            below work well if necessary.
    153         else
    154         {
    155                 GSList *l;
    156                
    157                 for( l = irc->channels; l; l = l->next )
    158                         irc_send_names( l->data );
    159         }
    160         */
    161 }
    162 
    163 static void irc_cmd_part( irc_t *irc, char **cmd )
    164 {
    165         irc_channel_t *ic;
    166        
    167         if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL )
    168         {
    169                 irc_send_num( irc, 403, "%s :No such channel", cmd[1] );
    170         }
    171         else if( irc_channel_del_user( ic, irc->user ) )
    172         {
    173                 if( ic->f->part )
    174                         ic->f->part( ic, NULL );
    175         }
    176         else
    177         {
    178                 irc_send_num( irc, 442, "%s :You're not on that channel", cmd[1] );
    179         }
    180 }
    181 
    182 static void irc_cmd_whois( irc_t *irc, char **cmd )
    183 {
    184         char *nick = cmd[1];
    185         irc_user_t *iu = irc_user_by_name( irc, nick );
    186        
    187         if( iu )
    188                 irc_send_whois( iu );
    189         else
    190                 irc_send_num( irc, 401, "%s :Nick does not exist", nick );
    191 }
    192 
    193 static void irc_cmd_whowas( irc_t *irc, char **cmd )
    194 {
    195         /* For some reason irssi tries a whowas when whois fails. We can
    196            ignore this, but then the user never gets a "user not found"
    197            message from irssi which is a bit annoying. So just respond
    198            with not-found and irssi users will get better error messages */
    199        
    200         irc_send_num( irc, 406, "%s :Nick does not exist", cmd[1] );
    201         irc_send_num( irc, 369, "%s :End of WHOWAS", cmd[1] );
    202 }
    203 
    204 static void irc_cmd_motd( irc_t *irc, char **cmd )
    205 {
    206         irc_send_motd( irc );
     107        irc_write( irc, ":%s PONG %s :%s", irc->myhost, irc->myhost, cmd[1]?cmd[1]:irc->myhost );
     108}
     109
     110static void irc_cmd_oper( irc_t *irc, char **cmd )
     111{
     112        if( global.conf->oper_pass &&
     113            ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
     114                md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
     115                strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
     116        {
     117                irc_umode_set( irc, "+o", 1 );
     118                irc_reply( irc, 381, ":Password accepted" );
     119        }
     120        else
     121        {
     122                irc_reply( irc, 432, ":Incorrect password" );
     123        }
    207124}
    208125
    209126static void irc_cmd_mode( irc_t *irc, char **cmd )
    210127{
    211         if( irc_channel_name_ok( cmd[1] ) )
    212         {
    213                 irc_channel_t *ic;
    214                
    215                 if( ( ic = irc_channel_by_name( irc, cmd[1] ) ) == NULL )
    216                         irc_send_num( irc, 403, "%s :No such channel", cmd[1] );
    217                 else if( cmd[2] )
     128        if( strchr( CTYPES, *cmd[1] ) )
     129        {
     130                if( cmd[2] )
    218131                {
    219132                        if( *cmd[2] == '+' || *cmd[2] == '-' )
    220                                 irc_send_num( irc, 477, "%s :Can't change channel modes", cmd[1] );
     133                                irc_reply( irc, 477, "%s :Can't change channel modes", cmd[1] );
    221134                        else if( *cmd[2] == 'b' )
    222                                 irc_send_num( irc, 368, "%s :No bans possible", cmd[1] );
     135                                irc_reply( irc, 368, "%s :No bans possible", cmd[1] );
    223136                }
    224137                else
    225                         irc_send_num( irc, 324, "%s +%s", cmd[1], ic->mode );
    226         }
    227         else
    228         {
    229                 if( nick_cmp( cmd[1], irc->user->nick ) == 0 )
     138                        irc_reply( irc, 324, "%s +%s", cmd[1], CMODE );
     139        }
     140        else
     141        {
     142                if( nick_cmp( cmd[1], irc->nick ) == 0 )
    230143                {
    231144                        if( cmd[2] )
    232145                                irc_umode_set( irc, cmd[2], 0 );
    233146                        else
    234                                 irc_send_num( irc, 221, "+%s", irc->umode );
     147                                irc_reply( irc, 221, "+%s", irc->umode );
    235148                }
    236149                else
    237                         irc_send_num( irc, 502, ":Don't touch their modes" );
    238         }
    239 }
    240 
    241 static void irc_cmd_who( irc_t *irc, char **cmd )
    242 {
    243         char *channel = cmd[1];
    244         irc_channel_t *ic;
    245        
    246         if( !channel || *channel == '0' || *channel == '*' || !*channel )
    247                 irc_send_who( irc, irc->users, "**" );
    248         else if( ( ic = irc_channel_by_name( irc, channel ) ) )
    249                 irc_send_who( irc, ic->users, channel );
    250         else
    251                 irc_send_num( irc, 403, "%s :No such channel", channel );
     150                        irc_reply( irc, 502, ":Don't touch their modes" );
     151        }
     152}
     153
     154static void irc_cmd_names( irc_t *irc, char **cmd )
     155{
     156        irc_names( irc, cmd[1]?cmd[1]:irc->channel );
     157}
     158
     159static void irc_cmd_part( irc_t *irc, char **cmd )
     160{
     161        struct groupchat *c;
     162       
     163        if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
     164        {
     165                user_t *u = user_find( irc, irc->nick );
     166               
     167                /* Not allowed to leave control channel */
     168                irc_part( irc, u, irc->channel );
     169                irc_join( irc, u, irc->channel );
     170        }
     171        else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) )
     172        {
     173                user_t *u = user_find( irc, irc->nick );
     174               
     175                irc_part( irc, u, c->channel );
     176               
     177                if( c->ic )
     178                {
     179                        c->joined = 0;
     180                        c->ic->acc->prpl->chat_leave( c );
     181                }
     182        }
     183        else
     184        {
     185                irc_reply( irc, 403, "%s :No such channel", cmd[1] );
     186        }
     187}
     188
     189static void irc_cmd_join( irc_t *irc, char **cmd )
     190{
     191        if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
     192                ; /* Dude, you're already there...
     193                     RFC doesn't have any reply for that though? */
     194        else if( cmd[1] )
     195        {
     196                struct chat *c;
     197               
     198                if( strchr( CTYPES, cmd[1][0] ) == NULL || cmd[1][1] == 0 )
     199                        irc_reply( irc, 479, "%s :Invalid channel name", cmd[1] );
     200                else if( ( c = chat_bychannel( irc, cmd[1] ) ) && c->acc && c->acc->ic )
     201                        chat_join( irc, c, cmd[2] );
     202                else
     203                        irc_reply( irc, 403, "%s :No such channel", cmd[1] );
     204        }
     205}
     206
     207static void irc_cmd_invite( irc_t *irc, char **cmd )
     208{
     209        char *nick = cmd[1], *channel = cmd[2];
     210        struct groupchat *c = irc_chat_by_channel( irc, channel );
     211        user_t *u = user_find( irc, nick );
     212       
     213        if( u && c && ( u->ic == c->ic ) )
     214                if( c->ic && c->ic->acc->prpl->chat_invite )
     215                {
     216                        c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
     217                        irc_reply( irc, 341, "%s %s", nick, channel );
     218                        return;
     219                }
     220       
     221        irc_reply( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
    252222}
    253223
    254224static void irc_cmd_privmsg( irc_t *irc, char **cmd )
    255225{
    256         irc_channel_t *ic;
    257         irc_user_t *iu;
    258        
    259         if( !cmd[2] )
    260         {
    261                 irc_send_num( irc, 412, ":No text to send" );
    262                 return;
    263         }
    264        
    265         /* Don't treat CTCP actions as real CTCPs, just convert them right now. */
    266         if( g_strncasecmp( cmd[2], "\001ACTION", 7 ) == 0 )
    267         {
    268                 cmd[2] += 4;
    269                 strcpy( cmd[2], "/me" );
    270                 if( cmd[2][strlen(cmd[2])-1] == '\001' )
    271                         cmd[2][strlen(cmd[2])-1] = '\0';
    272         }
    273        
    274         if( irc_channel_name_ok( cmd[1] ) &&
    275             ( ic = irc_channel_by_name( irc, cmd[1] ) ) )
    276         {
    277                 if( ic->f->privmsg )
    278                         ic->f->privmsg( ic, cmd[2] );
    279         }
    280         else if( ( iu = irc_user_by_name( irc, cmd[1] ) ) )
    281         {
    282                 if( cmd[2][0] == '\001' )
    283                 {
    284                         char **ctcp;
    285                        
    286                         if( iu->f->ctcp == NULL )
    287                                 return;
    288                         if( cmd[2][strlen(cmd[2])-1] == '\001' )
    289                                 cmd[2][strlen(cmd[2])-1] = '\0';
    290                        
    291                         ctcp = split_command_parts( cmd[2] + 1 );
    292                         iu->f->ctcp( iu, ctcp );
    293                 }
    294                 else if( iu->f->privmsg )
    295                 {
    296                         iu->flags |= IRC_USER_PRIVATE;
    297                         iu->f->privmsg( iu, cmd[2] );
    298                 }
    299         }
    300         else
    301         {
    302                 irc_send_num( irc, 401, "%s :No such nick/channel", cmd[1] );
    303         }
    304 
    305 
    306 #if 0
    307         else if( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 )
    308         {
     226        if ( !cmd[2] )
     227        {
     228                irc_reply( irc, 412, ":No text to send" );
     229        }
     230        else if ( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 )
     231        {
     232                irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] );
    309233        }
    310234        else
     
    347271                irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 );
    348272        }
    349 #endif
    350 }
    351 
    352 static void irc_cmd_nickserv( irc_t *irc, char **cmd )
    353 {
    354         /* [SH] This aliases the NickServ command to PRIVMSG root */
    355         /* [TV] This aliases the NS command to PRIVMSG root as well */
    356         root_command( irc, cmd + 1 );
    357 }
    358 
    359 
    360 
    361 static void irc_cmd_oper( irc_t *irc, char **cmd )
    362 {
    363         if( global.conf->oper_pass &&
    364             ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
    365                 md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
    366                 strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
    367         {
    368                 irc_umode_set( irc, "+o", 1 );
    369                 irc_send_num( irc, 381, ":Password accepted" );
    370         }
    371         else
    372         {
    373                 irc_send_num( irc, 432, ":Incorrect password" );
    374         }
    375 }
    376 
    377 static void irc_cmd_invite( irc_t *irc, char **cmd )
    378 {
    379         irc_channel_t *ic;
    380         irc_user_t *iu;
    381        
    382         if( ( iu = irc_user_by_name( irc, cmd[1] ) ) == NULL )
    383         {
    384                 irc_send_num( irc, 401, "%s :No such nick", cmd[1] );
    385                 return;
    386         }
    387         else if( ( ic = irc_channel_by_name( irc, cmd[2] ) ) == NULL )
    388         {
    389                 irc_send_num( irc, 403, "%s :No such channel", cmd[2] );
    390                 return;
    391         }
    392        
    393         if( ic->f->invite )
    394                 ic->f->invite( ic, iu );
    395         else
    396                 irc_send_num( irc, 482, "%s :Can't invite people here", cmd[2] );
     273}
     274
     275static void irc_cmd_who( irc_t *irc, char **cmd )
     276{
     277        char *channel = cmd[1];
     278        user_t *u = irc->users;
     279        struct groupchat *c;
     280        GList *l;
     281       
     282        if( !channel || *channel == '0' || *channel == '*' || !*channel )
     283                while( u )
     284                {
     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 );
     286                        u = u->next;
     287                }
     288        else if( g_strcasecmp( channel, irc->channel ) == 0 )
     289                while( u )
     290                {
     291                        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 );
     293                        u = u->next;
     294                }
     295        else if( ( c = irc_chat_by_channel( irc, channel ) ) )
     296                for( l = c->in_room; l; l = l->next )
     297                {
     298                        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 );
     300                }
     301        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:"**" );
    397305}
    398306
    399307static void irc_cmd_userhost( irc_t *irc, char **cmd )
    400308{
     309        user_t *u;
    401310        int i;
    402311       
     
    408317       
    409318        for( i = 1; cmd[i]; i ++ )
    410         {
    411                 irc_user_t *iu = irc_user_by_name( irc, cmd[i] );
    412                
    413                 if( iu )
    414                         irc_send_num( irc, 302, ":%s=%c%s@%s", iu->nick,
    415                                       irc_user_get_away( iu ) ? '-' : '+',
    416                                       iu->user, iu->host );
    417         }
     319                if( ( u = user_find( irc, cmd[i] ) ) )
     320                {
     321                        if( u->online && u->away )
     322                                irc_reply( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host );
     323                        else
     324                                irc_reply( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host );
     325                }
    418326}
    419327
    420328static void irc_cmd_ison( irc_t *irc, char **cmd )
    421329{
     330        user_t *u;
    422331        char buff[IRC_MAX_LINE];
    423332        int lenleft, i;
     
    435344                while( *this )
    436345                {
    437                         irc_user_t *iu;
    438                        
    439346                        if( ( next = strchr( this, ' ' ) ) )
    440347                                *next = 0;
    441348                       
    442                         if( ( iu = irc_user_by_name( irc, this ) ) &&
    443                             iu->bu && iu->bu->flags & BEE_USER_ONLINE )
    444                         {
    445                                 lenleft -= strlen( iu->nick ) + 1;
     349                        if( ( u = user_find( irc, this ) ) && u->online )
     350                        {
     351                                lenleft -= strlen( u->nick ) + 1;
    446352                               
    447353                                if( lenleft < 0 )
    448354                                        break;
    449355                               
    450                                 strcat( buff, iu->nick );
     356                                strcat( buff, u->nick );
    451357                                strcat( buff, " " );
    452358                        }
     
    471377                buff[strlen(buff)-1] = '\0';
    472378       
    473         irc_send_num( irc, 303, ":%s", buff );
     379        irc_reply( irc, 303, ":%s", buff );
    474380}
    475381
     
    484390        {
    485391                char *nick;
    486                 irc_user_t *iu;
     392                user_t *u;
    487393               
    488394                if( !cmd[i][0] || !cmd[i][1] )
     
    492398                nick_lc( nick );
    493399               
    494                 iu = irc_user_by_name( irc, nick );
     400                u = user_find( irc, nick );
    495401               
    496402                if( cmd[i][0] == '+' )
     
    499405                                g_hash_table_insert( irc->watches, nick, nick );
    500406                       
    501                         if( iu && iu->bu && iu->bu->flags & BEE_USER_ONLINE )
    502                                 irc_send_num( irc, 604, "%s %s %s %d :%s", iu->nick, iu->user,
    503                                               iu->host, (int) time( NULL ), "is online" );
     407                        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" );
    504409                        else
    505                                 irc_send_num( irc, 605, "%s %s %s %d :%s", nick, "*", "*",
    506                                               (int) time( NULL ), "is offline" );
     410                                irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" );
    507411                }
    508412                else if( cmd[i][0] == '-' )
     
    515419                                g_free( okey );
    516420                               
    517                                 irc_send_num( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
    518                         }
    519                 }
    520         }
    521 }
    522 
    523 #if 0
     421                                irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
     422                        }
     423                }
     424        }
     425}
     426
    524427static void irc_cmd_topic( irc_t *irc, char **cmd )
    525428{
     
    540443        }
    541444}
    542 #endif
    543445
    544446static void irc_cmd_away( irc_t *irc, char **cmd )
    545447{
    546         if( cmd[1] && *cmd[1] )
    547         {
    548                 char away[strlen(cmd[1])+1];
     448        user_t *u = user_find( irc, irc->nick );
     449        char *away = cmd[1];
     450       
     451        if( !u ) return;
     452       
     453        if( away && *away )
     454        {
    549455                int i, j;
    550456               
    551457                /* Copy away string, but skip control chars. Mainly because
    552458                   Jabber really doesn't like them. */
    553                 for( i = j = 0; cmd[1][i]; i ++ )
    554                         if( ( away[j] = cmd[1][i] ) >= ' ' )
     459                u->away = g_malloc( strlen( away ) + 1 );
     460                for( i = j = 0; away[i]; i ++ )
     461                        if( ( u->away[j] = away[i] ) >= ' ' )
    555462                                j ++;
    556                 away[j] = '\0';
    557                
    558                 irc_send_num( irc, 306, ":You're now away: %s", away );
    559                 set_setstr( &irc->b->set, "away", away );
    560         }
    561         else
    562         {
    563                 irc_send_num( irc, 305, ":Welcome back" );
    564                 set_setstr( &irc->b->set, "away", NULL );
    565         }
     463                u->away[j] = 0;
     464               
     465                irc_reply( irc, 306, ":You're now away: %s", u->away );
     466                /* irc_umode_set( irc, irc->myhost, "+a" ); */
     467        }
     468        else
     469        {
     470                if( u->away ) g_free( u->away );
     471                u->away = NULL;
     472                /* irc_umode_set( irc, irc->myhost, "-a" ); */
     473                irc_reply( irc, 305, ":Welcome back" );
     474        }
     475       
     476        set_setstr( &irc->set, "away", u->away );
     477}
     478
     479static void irc_cmd_whois( irc_t *irc, char **cmd )
     480{
     481        char *nick = cmd[1];
     482        user_t *u = user_find( irc, nick );
     483       
     484        if( u )
     485        {
     486                irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
     487               
     488                if( u->ic )
     489                        irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
     490                                   u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "",
     491                                   u->ic->acc->prpl->name );
     492                else
     493                        irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
     494               
     495                if( !u->online )
     496                        irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" );
     497                else if( u->away )
     498                        irc_reply( irc, 301, "%s :%s", u->nick, u->away );
     499                if( u->status_msg )
     500                        irc_reply( irc, 320, "%s :%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 );
     507        }
     508}
     509
     510static void irc_cmd_whowas( irc_t *irc, char **cmd )
     511{
     512        /* For some reason irssi tries a whowas when whois fails. We can
     513           ignore this, but then the user never gets a "user not found"
     514           message from irssi which is a bit annoying. So just respond
     515           with not-found and irssi users will get better error messages */
     516       
     517        irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] );
     518        irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] );
     519}
     520
     521static void irc_cmd_nickserv( irc_t *irc, char **cmd )
     522{
     523        /* [SH] This aliases the NickServ command to PRIVMSG root */
     524        /* [TV] This aliases the NS command to PRIVMSG root as well */
     525        root_command( irc, cmd + 1 );
     526}
     527
     528static void irc_cmd_motd( irc_t *irc, char **cmd )
     529{
     530        irc_motd( irc );
     531}
     532
     533static void irc_cmd_pong( irc_t *irc, char **cmd )
     534{
     535        /* We could check the value we get back from the user, but in
     536           fact we don't care, we're just happy he's still alive. */
     537        irc->last_pong = gettime();
     538        irc->pinging = 0;
    566539}
    567540
    568541static void irc_cmd_version( irc_t *irc, char **cmd )
    569542{
    570         irc_send_num( irc, 351, "bitlbee-%s. %s :%s/%s ",
    571                       BITLBEE_VERSION, irc->root->host, ARCH, CPU );
     543        irc_reply( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU );
    572544}
    573545
    574546static void irc_cmd_completions( irc_t *irc, char **cmd )
    575547{
     548        user_t *u = user_find( irc, irc->mynick );
    576549        help_t *h;
    577550        set_t *s;
    578551        int i;
    579552       
    580         irc_send_msg_raw( irc->root, "NOTICE", irc->user->nick, "COMPLETIONS OK" );
     553        irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "OK" );
    581554       
    582555        for( i = 0; commands[i].command; i ++ )
    583                 irc_send_msg_f( irc->root, "NOTICE", irc->user->nick, "COMPLETIONS %s", commands[i].command );
     556                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", commands[i].command );
    584557       
    585558        for( h = global.help; h; h = h->next )
    586                 irc_send_msg_f( irc->root, "NOTICE", irc->user->nick, "COMPLETIONS help %s", h->title );
    587        
    588         for( s = irc->b->set; s; s = s->next )
    589                 irc_send_msg_f( irc->root, "NOTICE", irc->user->nick, "COMPLETIONS set %s", s->key );
    590        
    591         irc_send_msg_raw( irc->root, "NOTICE", irc->user->nick, "COMPLETIONS END" );
     559                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title );
     560       
     561        for( s = irc->set; s; s = s->next )
     562                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS set ", s->key );
     563       
     564        irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" );
    592565}
    593566
     
    599572                ipc_to_master( cmd );
    600573       
    601         irc_send_num( irc, 382, "%s :Rehashing", global.conf_file );
     574        irc_reply( irc, 382, "%s :Rehashing", global.conf_file );
    602575}
    603576
     
    608581        { "quit",        0, irc_cmd_quit,        0 },
    609582        { "ping",        0, irc_cmd_ping,        0 },
    610         { "pong",        0, irc_cmd_pong,        IRC_CMD_LOGGED_IN },
     583        { "oper",        2, irc_cmd_oper,        IRC_CMD_LOGGED_IN },
     584        { "mode",        1, irc_cmd_mode,        IRC_CMD_LOGGED_IN },
     585        { "names",       0, irc_cmd_names,       IRC_CMD_LOGGED_IN },
     586        { "part",        1, irc_cmd_part,        IRC_CMD_LOGGED_IN },
    611587        { "join",        1, irc_cmd_join,        IRC_CMD_LOGGED_IN },
    612         { "names",       1, irc_cmd_names,       IRC_CMD_LOGGED_IN },
    613         { "part",        1, irc_cmd_part,        IRC_CMD_LOGGED_IN },
    614         { "whois",       1, irc_cmd_whois,       IRC_CMD_LOGGED_IN },
    615         { "whowas",      1, irc_cmd_whowas,      IRC_CMD_LOGGED_IN },
    616         { "motd",        0, irc_cmd_motd,        IRC_CMD_LOGGED_IN },
    617         { "mode",        1, irc_cmd_mode,        IRC_CMD_LOGGED_IN },
     588        { "invite",      2, irc_cmd_invite,      IRC_CMD_LOGGED_IN },
     589        { "privmsg",     1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
     590        { "notice",      1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
    618591        { "who",         0, irc_cmd_who,         IRC_CMD_LOGGED_IN },
    619         { "privmsg",     1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
    620         { "nickserv",    1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
    621         { "ns",          1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
    622         { "away",        0, irc_cmd_away,        IRC_CMD_LOGGED_IN },
    623         { "version",     0, irc_cmd_version,     IRC_CMD_LOGGED_IN },
    624         { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN },
    625592        { "userhost",    1, irc_cmd_userhost,    IRC_CMD_LOGGED_IN },
    626593        { "ison",        1, irc_cmd_ison,        IRC_CMD_LOGGED_IN },
    627594        { "watch",       1, irc_cmd_watch,       IRC_CMD_LOGGED_IN },
    628         { "invite",      2, irc_cmd_invite,      IRC_CMD_LOGGED_IN },
    629 #if 0
    630         { "notice",      1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
    631595        { "topic",       1, irc_cmd_topic,       IRC_CMD_LOGGED_IN },
    632 #endif
    633         { "oper",        2, irc_cmd_oper,        IRC_CMD_LOGGED_IN },
     596        { "away",        0, irc_cmd_away,        IRC_CMD_LOGGED_IN },
     597        { "whois",       1, irc_cmd_whois,       IRC_CMD_LOGGED_IN },
     598        { "whowas",      1, irc_cmd_whowas,      IRC_CMD_LOGGED_IN },
     599        { "nickserv",    1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
     600        { "ns",          1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
     601        { "motd",        0, irc_cmd_motd,        IRC_CMD_LOGGED_IN },
     602        { "pong",        0, irc_cmd_pong,        IRC_CMD_LOGGED_IN },
     603        { "version",     0, irc_cmd_version,     IRC_CMD_LOGGED_IN },
     604        { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN },
    634605        { "die",         0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    635606        { "deaf",        0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
     
    657628                        if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
    658629                        {
    659                                 irc_send_num( irc, 462, ":Only allowed before logging in" );
     630                                irc_reply( irc, 462, ":Only allowed before logging in" );
    660631                        }
    661632                        else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
    662633                        {
    663                                 irc_send_num( irc, 451, ":Register first" );
     634                                irc_reply( irc, 451, ":Register first" );
    664635                        }
    665636                        else if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) )
    666637                        {
    667                                 irc_send_num( irc, 481, ":Permission denied - You're not an IRC operator" );
     638                                irc_reply( irc, 481, ":Permission denied - You're not an IRC operator" );
    668639                        }
    669640                        else if( n_arg < irc_commands[i].required_parameters )
    670641                        {
    671                                 irc_send_num( irc, 461, "%s :Need more parameters", cmd[0] );
     642                                irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
    672643                        }
    673644                        else if( irc_commands[i].flags & IRC_CMD_TO_MASTER )
     
    686657       
    687658        if( irc->status >= USTATUS_LOGGED_IN )
    688                 irc_send_num( irc, 421, "%s :Unknown command", cmd[0] );
    689 }
     659                irc_reply( irc, 421, "%s :Unknown command", cmd[0] );
     660}
Note: See TracChangeset for help on using the changeset viewer.