Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_commands.c

    rf9756bd r1cda4f3  
    3030static void irc_cmd_pass( irc_t *irc, char **cmd )
    3131{
    32         if( irc->status & USTATUS_LOGGED_IN )
    33         {
    34                 char *send_cmd[] = { "identify", cmd[1], NULL };
    35                
    36                 /* We're already logged in, this client seems to send the PASS
    37                    command last. (Possibly it won't send it at all if it turns
    38                    out we don't require it, which will break this feature.)
    39                    Try to identify using the given password. */
    40                 return root_command( irc, send_cmd );
    41         }
    42         /* Handling in pre-logged-in state, first see if this server is
    43            password-protected: */
    44         else if( global.conf->auth_pass &&
    45             ( strncmp( global.conf->auth_pass, "md5:", 4 ) == 0 ?
    46                 md5_verify_password( cmd[1], global.conf->auth_pass + 4 ) == 0 :
    47                 strcmp( cmd[1], global.conf->auth_pass ) == 0 ) )
    48         {
    49                 irc->status |= USTATUS_AUTHORIZED;
     32        if( global.conf->auth_pass && strcmp( cmd[1], global.conf->auth_pass ) == 0 )
     33        {
     34                irc->status = USTATUS_AUTHORIZED;
    5035                irc_check_login( irc );
    5136        }
    52         else if( global.conf->auth_pass )
     37        else
    5338        {
    5439                irc_reply( irc, 464, ":Incorrect password" );
    55         }
    56         else
    57         {
    58                 /* Remember the password and try to identify after USER/NICK. */
    59                 irc_setpass( irc, cmd[1] );
    60                 irc_check_login( irc );
    6140        }
    6241}
     
    10988static void irc_cmd_oper( irc_t *irc, char **cmd )
    11089{
    111         if( global.conf->oper_pass &&
    112             ( strncmp( global.conf->oper_pass, "md5:", 4 ) == 0 ?
    113                 md5_verify_password( cmd[2], global.conf->oper_pass + 4 ) == 0 :
    114                 strcmp( cmd[2], global.conf->oper_pass ) == 0 ) )
     90        if( global.conf->oper_pass && strcmp( cmd[2], global.conf->oper_pass ) == 0 )
    11591        {
    11692                irc_umode_set( irc, "+o", 1 );
     
    143119                        if( cmd[2] )
    144120                                irc_umode_set( irc, cmd[2], 0 );
    145                         else
    146                                 irc_reply( irc, 221, "+%s", irc->umode );
    147121                }
    148122                else
     
    158132static void irc_cmd_part( irc_t *irc, char **cmd )
    159133{
    160         struct groupchat *c;
     134        struct conversation *c;
    161135       
    162136        if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
     
    168142                irc_join( irc, u, irc->channel );
    169143        }
    170         else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) )
     144        else if( ( c = conv_findchannel( cmd[1] ) ) )
    171145        {
    172146                user_t *u = user_find( irc, irc->nick );
     
    174148                irc_part( irc, u, c->channel );
    175149               
    176                 if( c->ic )
     150                if( c->gc && c->gc->prpl )
    177151                {
    178152                        c->joined = 0;
    179                         c->ic->acc->prpl->chat_leave( c );
     153                        c->gc->prpl->chat_leave( c->gc, c->id );
    180154                }
    181155        }
     
    197171                        user_t *u = user_find( irc, cmd[1] + 1 );
    198172                       
    199                         if( u && u->ic && u->ic->acc->prpl->chat_with )
     173                        if( u && u->gc && u->gc->prpl && u->gc->prpl->chat_open )
    200174                        {
    201175                                irc_reply( irc, 403, "%s :Initializing groupchat in a different channel", cmd[1] );
    202176                               
    203                                 if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) )
     177                                if( !u->gc->prpl->chat_open( u->gc, u->handle ) )
    204178                                {
    205                                         irc_usermsg( irc, "Could not open a groupchat with %s.", u->nick );
     179                                        irc_usermsg( irc, "Could not open a groupchat with %s, maybe you don't have a connection to him/her yet?", u->nick );
    206180                                }
    207181                        }
     
    225199{
    226200        char *nick = cmd[1], *channel = cmd[2];
    227         struct groupchat *c = irc_chat_by_channel( irc, channel );
     201        struct conversation *c = conv_findchannel( channel );
    228202        user_t *u = user_find( irc, nick );
    229203       
    230         if( u && c && ( u->ic == c->ic ) )
    231                 if( c->ic && c->ic->acc->prpl->chat_invite )
    232                 {
    233                         c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
     204        if( u && c && ( u->gc == c->gc ) )
     205                if( c->gc && c->gc->prpl && c->gc->prpl->chat_invite )
     206                {
     207                        c->gc->prpl->chat_invite( c->gc, c->id, "", u->handle );
    234208                        irc_reply( irc, 341, "%s %s", nick, channel );
    235209                        return;
     
    254228                {
    255229                        unsigned int i;
    256                         char *t = set_getstr( &irc->set, "default_target" );
     230                        char *t = set_getstr( irc, "default_target" );
    257231                       
    258232                        if( g_strcasecmp( t, "last" ) == 0 && irc->last_target )
     
    278252                        if( cmd[1] != irc->last_target )
    279253                        {
    280                                 g_free( irc->last_target );
     254                                if( irc->last_target )
     255                                        g_free( irc->last_target );
    281256                                irc->last_target = g_strdup( cmd[1] );
    282257                        }
     
    286261                        irc->is_private = 1;
    287262                }
    288                 irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 );
     263                irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? IM_FLAG_AWAY : 0 );
    289264        }
    290265}
     
    294269        char *channel = cmd[1];
    295270        user_t *u = irc->users;
    296         struct groupchat *c;
     271        struct conversation *c;
    297272        GList *l;
    298273       
     
    310285                        u = u->next;
    311286                }
    312         else if( ( c = irc_chat_by_channel( irc, channel ) ) )
     287        else if( ( c = conv_findchannel( channel ) ) )
    313288                for( l = c->in_room; l; l = l->next )
    314289                {
    315                         if( ( u = user_findhandle( c->ic, l->data ) ) )
     290                        if( ( u = user_findhandle( c->gc, l->data ) ) )
    316291                                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 );
    317292                }
     
    356331        for( i = 1; cmd[i]; i ++ )
    357332        {
    358                 char *this, *next;
    359                
    360                 this = cmd[i];
    361                 while( *this )
    362                 {
    363                         if( ( next = strchr( this, ' ' ) ) )
    364                                 *next = 0;
    365                        
    366                         if( ( u = user_find( irc, this ) ) && u->online )
    367                         {
    368                                 lenleft -= strlen( u->nick ) + 1;
    369                                
    370                                 if( lenleft < 0 )
    371                                         break;
    372                                
    373                                 strcat( buff, u->nick );
    374                                 strcat( buff, " " );
    375                         }
    376                        
    377                         if( next )
    378                         {
    379                                 *next = ' ';
    380                                 this = next + 1;
    381                         }
    382                         else
     333                if( ( u = user_find( irc, cmd[i] ) ) && u->online )
     334                {
     335                        /* [SH] Make sure we don't use too much buffer space. */
     336                        lenleft -= strlen( u->nick ) + 1;
     337                       
     338                        if( lenleft < 0 )
    383339                        {
    384340                                break;
    385                         }   
    386                 }
    387                
    388                 /* *sigh* */
    389                 if( lenleft < 0 )
    390                         break;
    391         }
    392        
     341                        }
     342                       
     343                        /* [SH] Add the nick to the buffer. Note
     344                         * that an extra space is always added. Even
     345                         * if it's the last nick in the list. Who
     346                         * cares?
     347                         */
     348                       
     349                        strcat( buff, u->nick );
     350                        strcat( buff, " " );
     351                }
     352        }
     353       
     354        /* [WvG] Well, maybe someone cares, so why not remove it? */
    393355        if( strlen( buff ) > 0 )
    394356                buff[strlen(buff)-1] = '\0';
     
    444406static void irc_cmd_topic( irc_t *irc, char **cmd )
    445407{
    446         char *channel = cmd[1];
    447         char *topic = cmd[2];
    448        
    449         if( topic )
    450         {
    451                 /* Send the topic */
    452                 struct groupchat *c = irc_chat_by_channel( irc, channel );
    453                 if( c && c->ic && c->ic->acc->prpl->chat_topic )
    454                         c->ic->acc->prpl->chat_topic( c, topic );
    455         }
    456         else
    457         {
    458                 /* Get the topic */
    459                 irc_topic( irc, channel );
    460         }
     408        if( cmd[2] )
     409                irc_reply( irc, 482, "%s :Cannot change topic", cmd[1] );
     410        else
     411                irc_topic( irc, cmd[1] );
    461412}
    462413
     
    494445        for( a = irc->accounts; a; a = a->next )
    495446        {
    496                 struct im_connection *ic = a->ic;
    497                
    498                 if( ic && ic->flags & OPT_LOGGED_IN )
    499                         imc_set_away( ic, u->away );
     447                struct gaim_connection *gc = a->gc;
     448               
     449                if( gc && gc->flags & OPT_LOGGED_IN )
     450                        bim_set_away( gc, u->away );
    500451        }
    501452}
     
    510461                irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
    511462               
    512                 if( u->ic )
    513                         irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
    514                                    u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "",
    515                                    u->ic->acc->prpl->name );
     463                if( u->gc )
     464                        irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->gc->user->username,
     465                                   *u->gc->user->proto_opt[0] ? u->gc->user->proto_opt[0] : "", u->gc->prpl->name );
    516466                else
    517467                        irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
     
    579529       
    580530        for( h = global.help; h; h = h->next )
    581                 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title );
     531                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->string );
    582532       
    583533        for( s = irc->set; s; s = s->next )
     
    594544                ipc_to_master( cmd );
    595545       
    596         irc_reply( irc, 382, "%s :Rehashing", global.conf_file );
     546#ifndef _WIN32
     547        irc_reply( irc, 382, "%s :Rehashing", CONF_FILE );
     548#endif
    597549}
    598550
    599551static const command_t irc_commands[] = {
    600         { "pass",        1, irc_cmd_pass,        0 },
     552        { "pass",        1, irc_cmd_pass,        IRC_CMD_PRE_LOGIN },
    601553        { "user",        4, irc_cmd_user,        IRC_CMD_PRE_LOGIN },
    602554        { "nick",        1, irc_cmd_nick,        0 },
     
    627579        { "die",         0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    628580        { "wallops",     1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    629         { "wall",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
     581        { "lilo",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    630582        { "rehash",      0, irc_cmd_rehash,      IRC_CMD_OPER_ONLY },
    631583        { "restart",     0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
     
    647599                        for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --;
    648600                       
    649                         if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
     601                        if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >= USTATUS_LOGGED_IN )
    650602                        {
    651603                                irc_reply( irc, 462, ":Only allowed before logging in" );
    652604                        }
    653                         else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
     605                        else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN )
    654606                        {
    655607                                irc_reply( irc, 451, ":Register first" );
     
    674626                        }
    675627                       
    676                         return;
    677                 }
    678        
    679         if( irc->status >= USTATUS_LOGGED_IN )
    680                 irc_reply( irc, 421, "%s :Unknown command", cmd[0] );
    681 }
     628                        break;
     629                }
     630}
Note: See TracChangeset for help on using the changeset viewer.