Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • irc_commands.c

    r1cda4f3 rf9756bd  
    3030static void irc_cmd_pass( irc_t *irc, char **cmd )
    3131{
    32         if( global.conf->auth_pass && strcmp( cmd[1], global.conf->auth_pass ) == 0 )
    33         {
    34                 irc->status = USTATUS_AUTHORIZED;
     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;
    3550                irc_check_login( irc );
    3651        }
    37         else
     52        else if( global.conf->auth_pass )
    3853        {
    3954                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 );
    4061        }
    4162}
     
    88109static void irc_cmd_oper( irc_t *irc, char **cmd )
    89110{
    90         if( global.conf->oper_pass && strcmp( cmd[2], global.conf->oper_pass ) == 0 )
     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 ) )
    91115        {
    92116                irc_umode_set( irc, "+o", 1 );
     
    119143                        if( cmd[2] )
    120144                                irc_umode_set( irc, cmd[2], 0 );
     145                        else
     146                                irc_reply( irc, 221, "+%s", irc->umode );
    121147                }
    122148                else
     
    132158static void irc_cmd_part( irc_t *irc, char **cmd )
    133159{
    134         struct conversation *c;
     160        struct groupchat *c;
    135161       
    136162        if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
     
    142168                irc_join( irc, u, irc->channel );
    143169        }
    144         else if( ( c = conv_findchannel( cmd[1] ) ) )
     170        else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) )
    145171        {
    146172                user_t *u = user_find( irc, irc->nick );
     
    148174                irc_part( irc, u, c->channel );
    149175               
    150                 if( c->gc && c->gc->prpl )
     176                if( c->ic )
    151177                {
    152178                        c->joined = 0;
    153                         c->gc->prpl->chat_leave( c->gc, c->id );
     179                        c->ic->acc->prpl->chat_leave( c );
    154180                }
    155181        }
     
    171197                        user_t *u = user_find( irc, cmd[1] + 1 );
    172198                       
    173                         if( u && u->gc && u->gc->prpl && u->gc->prpl->chat_open )
     199                        if( u && u->ic && u->ic->acc->prpl->chat_with )
    174200                        {
    175201                                irc_reply( irc, 403, "%s :Initializing groupchat in a different channel", cmd[1] );
    176202                               
    177                                 if( !u->gc->prpl->chat_open( u->gc, u->handle ) )
     203                                if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) )
    178204                                {
    179                                         irc_usermsg( irc, "Could not open a groupchat with %s, maybe you don't have a connection to him/her yet?", u->nick );
     205                                        irc_usermsg( irc, "Could not open a groupchat with %s.", u->nick );
    180206                                }
    181207                        }
     
    199225{
    200226        char *nick = cmd[1], *channel = cmd[2];
    201         struct conversation *c = conv_findchannel( channel );
     227        struct groupchat *c = irc_chat_by_channel( irc, channel );
    202228        user_t *u = user_find( irc, nick );
    203229       
    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 );
     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 );
    208234                        irc_reply( irc, 341, "%s %s", nick, channel );
    209235                        return;
     
    228254                {
    229255                        unsigned int i;
    230                         char *t = set_getstr( irc, "default_target" );
     256                        char *t = set_getstr( &irc->set, "default_target" );
    231257                       
    232258                        if( g_strcasecmp( t, "last" ) == 0 && irc->last_target )
     
    252278                        if( cmd[1] != irc->last_target )
    253279                        {
    254                                 if( irc->last_target )
    255                                         g_free( irc->last_target );
     280                                g_free( irc->last_target );
    256281                                irc->last_target = g_strdup( cmd[1] );
    257282                        }
     
    261286                        irc->is_private = 1;
    262287                }
    263                 irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? IM_FLAG_AWAY : 0 );
     288                irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 );
    264289        }
    265290}
     
    269294        char *channel = cmd[1];
    270295        user_t *u = irc->users;
    271         struct conversation *c;
     296        struct groupchat *c;
    272297        GList *l;
    273298       
     
    285310                        u = u->next;
    286311                }
    287         else if( ( c = conv_findchannel( channel ) ) )
     312        else if( ( c = irc_chat_by_channel( irc, channel ) ) )
    288313                for( l = c->in_room; l; l = l->next )
    289314                {
    290                         if( ( u = user_findhandle( c->gc, l->data ) ) )
     315                        if( ( u = user_findhandle( c->ic, l->data ) ) )
    291316                                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 );
    292317                }
     
    331356        for( i = 1; cmd[i]; i ++ )
    332357        {
    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 )
     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
    339383                        {
    340384                                break;
    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? */
     385                        }   
     386                }
     387               
     388                /* *sigh* */
     389                if( lenleft < 0 )
     390                        break;
     391        }
     392       
    355393        if( strlen( buff ) > 0 )
    356394                buff[strlen(buff)-1] = '\0';
     
    406444static void irc_cmd_topic( irc_t *irc, char **cmd )
    407445{
    408         if( cmd[2] )
    409                 irc_reply( irc, 482, "%s :Cannot change topic", cmd[1] );
    410         else
    411                 irc_topic( irc, cmd[1] );
     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        }
    412461}
    413462
     
    445494        for( a = irc->accounts; a; a = a->next )
    446495        {
    447                 struct gaim_connection *gc = a->gc;
    448                
    449                 if( gc && gc->flags & OPT_LOGGED_IN )
    450                         bim_set_away( gc, u->away );
     496                struct im_connection *ic = a->ic;
     497               
     498                if( ic && ic->flags & OPT_LOGGED_IN )
     499                        imc_set_away( ic, u->away );
    451500        }
    452501}
     
    461510                irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
    462511               
    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 );
     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 );
    466516                else
    467517                        irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
     
    529579       
    530580        for( h = global.help; h; h = h->next )
    531                 irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->string );
     581                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title );
    532582       
    533583        for( s = irc->set; s; s = s->next )
     
    544594                ipc_to_master( cmd );
    545595       
    546 #ifndef _WIN32
    547         irc_reply( irc, 382, "%s :Rehashing", CONF_FILE );
    548 #endif
     596        irc_reply( irc, 382, "%s :Rehashing", global.conf_file );
    549597}
    550598
    551599static const command_t irc_commands[] = {
    552         { "pass",        1, irc_cmd_pass,        IRC_CMD_PRE_LOGIN },
     600        { "pass",        1, irc_cmd_pass,        0 },
    553601        { "user",        4, irc_cmd_user,        IRC_CMD_PRE_LOGIN },
    554602        { "nick",        1, irc_cmd_nick,        0 },
     
    579627        { "die",         0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    580628        { "wallops",     1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    581         { "lilo",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
     629        { "wall",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
    582630        { "rehash",      0, irc_cmd_rehash,      IRC_CMD_OPER_ONLY },
    583631        { "restart",     0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
     
    599647                        for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --;
    600648                       
    601                         if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status >= USTATUS_LOGGED_IN )
     649                        if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
    602650                        {
    603651                                irc_reply( irc, 462, ":Only allowed before logging in" );
    604652                        }
    605                         else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && irc->status < USTATUS_LOGGED_IN )
     653                        else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
    606654                        {
    607655                                irc_reply( irc, 451, ":Register first" );
     
    626674                        }
    627675                       
    628                         break;
    629                 }
    630 }
     676                        return;
     677                }
     678       
     679        if( irc->status >= USTATUS_LOGGED_IN )
     680                irc_reply( irc, 421, "%s :Unknown command", cmd[0] );
     681}
Note: See TracChangeset for help on using the changeset viewer.