source: commands.c @ fbc7844

Last change on this file since fbc7844 was 576d6d7, checked in by Wilmer van der Gaast <wilmer@…>, at 2005-11-07T18:39:57Z

Got rid of some debugging code we tried to use to track the 100% CPU bug.
Turned out it was very suitable DoS code. :-)

  • Property mode set to 100644
File size: 17.8 KB
Line 
1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2004 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* User manager (root) commands                                         */
8
9/*
10  This program is free software; you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation; either version 2 of the License, or
13  (at your option) any later version.
14
15  This program is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License with
21  the Debian GNU/Linux distribution in /usr/share/common-licenses/GPL;
22  if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23  Suite 330, Boston, MA  02111-1307  USA
24*/
25
26#define BITLBEE_CORE
27#include "commands.h"
28#include "crypting.h"
29#include "bitlbee.h"
30#include "help.h"
31
32#include <string.h>
33
34command_t commands[] = {
35        { "help",           0, cmd_help }, 
36        { "identify",       1, cmd_identify },
37        { "register",       1, cmd_register },
38        { "drop",           1, cmd_drop },
39        { "account",        1, cmd_account },
40        { "add",            2, cmd_add },
41        { "info",           1, cmd_info },
42        { "rename",         2, cmd_rename },
43        { "remove",         1, cmd_remove },
44        { "block",          1, cmd_block },
45        { "allow",          1, cmd_allow },
46        { "save",           0, cmd_save },
47        { "set",            0, cmd_set },
48        { "yes",            0, cmd_yesno },
49        { "no",             0, cmd_yesno },
50        { "blist",          0, cmd_blist },
51        { "nick",           1, cmd_nick },
52        { "import_buddies", 1, cmd_import_buddies },
53        { "qlist",          0, cmd_qlist },
54        { NULL }
55};
56
57int cmd_help( irc_t *irc, char **cmd )
58{
59        char param[80];
60        int i;
61        char *s;
62       
63        memset( param, 0, sizeof(param) );
64        for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) {
65                if ( i != 1 )   // prepend space except for the first parameter
66                        strcat(param, " ");
67                strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 );
68        }
69
70        s = help_get( &(global.help), param );
71        if( !s ) s = help_get( &(global.help), "" );
72       
73        if( s )
74        {
75                irc_usermsg( irc, "%s", s );
76                g_free( s );
77                return( 1 );
78        }
79        else
80        {
81                irc_usermsg( irc, "Error opening helpfile." );
82                return( 0 );
83        }
84}
85
86int cmd_identify( irc_t *irc, char **cmd )
87{
88        int checkie = bitlbee_load( irc, cmd[1] );
89       
90        if( checkie == -1 )
91        {
92                irc_usermsg( irc, "Incorrect password" );
93        }
94        else if( checkie == 0 )
95        {
96                irc_usermsg( irc, "The nick is (probably) not registered" );
97        }
98        else if( checkie == 1 )
99        {
100                irc_usermsg( irc, "Password accepted" );
101        }
102        else
103        {
104                irc_usermsg( irc, "Something very weird happened" );
105        }
106       
107        return( 0 );
108}
109
110int cmd_register( irc_t *irc, char **cmd )
111{
112        int checkie;
113        char path[512];
114       
115        if( global.conf->authmode == AUTHMODE_REGISTERED )
116        {
117                irc_usermsg( irc, "This server does not allow registering new accounts" );
118                return( 0 );
119        }
120       
121        g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
122        checkie = access( path, F_OK );
123       
124        g_snprintf( path, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
125        checkie += access( path, F_OK );
126       
127        if( checkie == -2 )
128        {
129                setpassnc( irc, cmd[1] );
130                root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 );
131                irc->status = USTATUS_IDENTIFIED;
132        }
133        else
134        {
135                irc_usermsg( irc, "Nick is already registered" );
136        }
137       
138        return( 0 );
139}
140
141int cmd_drop( irc_t *irc, char **cmd )
142{
143        char s[512];
144        FILE *fp;
145       
146        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
147        fp = fopen( s, "r" );
148        if( !fp )
149        {
150                irc_usermsg( irc, "That account does not exist" );
151                return( 0 );
152        }
153       
154        fscanf( fp, "%32[^\n]s", s );
155        fclose( fp );
156        if( setpass( irc, cmd[1], s ) < 0 )
157        {
158                irc_usermsg( irc, "Incorrect password" );
159                return( 0 );
160        }
161       
162        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".accounts" );
163        unlink( s );
164       
165        g_snprintf( s, 511, "%s%s%s", global.conf->configdir, irc->nick, ".nicks" );
166        unlink( s );
167       
168        setpassnc( irc, NULL );
169        irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick );
170       
171        return( 0 );
172}
173
174int cmd_account( irc_t *irc, char **cmd )
175{
176        account_t *a;
177       
178        if( global.conf->authmode == AUTHMODE_REGISTERED && irc->status < USTATUS_IDENTIFIED )
179        {
180                irc_usermsg( irc, "This server only accepts registered users" );
181                return( 0 );
182        }
183       
184        if( g_strcasecmp( cmd[1], "add" ) == 0 )
185        {
186                int prot;
187               
188                if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL )
189                {
190                        irc_usermsg( irc, "Not enough parameters" );
191                        return( 0 );
192                }
193               
194                for( prot = 0; prot < PROTO_MAX; prot ++ )
195                        if( proto_name[prot] && *proto_name[prot] && g_strcasecmp( proto_name[prot], cmd[2] ) == 0 )
196                                break;
197               
198                if( ( prot == PROTO_MAX ) || ( proto_prpl[prot] == NULL ) )
199                {
200                        irc_usermsg( irc, "Unknown protocol" );
201                        return( 0 );
202                }
203
204                if( prot == PROTO_OSCAR && cmd[5] == NULL )
205                {
206                        irc_usermsg( irc, "Not enough parameters" );
207                        return( 0 );
208                }
209               
210                a = account_add( irc, prot, cmd[3], cmd[4] );
211               
212                if( cmd[5] )
213                        a->server = g_strdup( cmd[5] );
214               
215                irc_usermsg( irc, "Account successfully added" );
216        }
217        else if( g_strcasecmp( cmd[1], "del" ) == 0 )
218        {
219                if( !cmd[2] )
220                {
221                        irc_usermsg( irc, "Not enough parameters given (need %d)", 2 );
222                }
223                else if( !( a = account_get( irc, cmd[2] ) ) )
224                {
225                        irc_usermsg( irc, "Invalid account" );
226                }
227                else if( a->gc )
228                {
229                        irc_usermsg( irc, "Account is still logged in, can't delete" );
230                }
231                else
232                {
233                        account_del( irc, a );
234                        irc_usermsg( irc, "Account deleted" );
235                }
236        }
237        else if( g_strcasecmp( cmd[1], "list" ) == 0 )
238        {
239                int i = 0;
240               
241                for( a = irc->accounts; a; a = a->next )
242                {
243                        char *con;
244                       
245                        if( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) )
246                                con = " (connected)";
247                        else if( a->gc )
248                                con = " (connecting)";
249                        else if( a->reconnect )
250                                con = " (awaiting reconnect)";
251                        else
252                                con = "";
253                       
254                        if( a->protocol == PROTO_OSCAR || a->protocol == PROTO_ICQ || a->protocol == PROTO_TOC )
255                                irc_usermsg( irc, "%2d. OSCAR, %s on %s%s", i, a->user, a->server, con );
256                        else
257                                irc_usermsg( irc, "%2d. %s, %s%s", i, proto_name[a->protocol], a->user, con );
258                       
259                        i ++;
260                }
261                irc_usermsg( irc, "End of account list" );
262        }
263        else if( g_strcasecmp( cmd[1], "on" ) == 0 )
264        {
265                if( cmd[2] )
266                {
267                        if( ( a = account_get( irc, cmd[2] ) ) )
268                        {
269                                if( a->gc )
270                                {
271                                        irc_usermsg( irc, "Account already online" );
272                                        return( 0 );
273                                }
274                                else
275                                {
276                                        account_on( irc, a );
277                                }
278                        }
279                        else
280                        {
281                                irc_usermsg( irc, "Invalid account" );
282                                return( 0 );
283                        }
284                }
285                else
286                {
287                        if ( irc->accounts ) {
288                                irc_usermsg( irc, "Trying to get all accounts connected..." );
289                       
290                                for( a = irc->accounts; a; a = a->next )
291                                        if( !a->gc )
292                                                account_on( irc, a );
293                        } 
294                        else
295                        {
296                                irc_usermsg( irc, "No accounts known. Use 'account add' to add one." );
297                        }
298                }
299        }
300        else if( g_strcasecmp( cmd[1], "off" ) == 0 )
301        {
302                if( !cmd[2] )
303                {
304                        irc_usermsg( irc, "Deactivating all active (re)connections..." );
305                       
306                        for( a = irc->accounts; a; a = a->next )
307                        {
308                                if( a->gc )
309                                        account_off( irc, a );
310                                else if( a->reconnect )
311                                        cancel_auto_reconnect( a );
312                        }
313                }
314                else if( ( a = account_get( irc, cmd[2] ) ) )
315                {
316                        if( a->gc )
317                        {
318                                account_off( irc, a );
319                        }
320                        else if( a->reconnect )
321                        {
322                                cancel_auto_reconnect( a );
323                                irc_usermsg( irc, "Reconnect cancelled" );
324                        }
325                        else
326                        {
327                                irc_usermsg( irc, "Account already offline" );
328                                return( 0 );
329                        }
330                }
331                else
332                {
333                        irc_usermsg( irc, "Invalid account" );
334                        return( 0 );
335                }
336        }
337        else
338        {
339                irc_usermsg( irc, "Unknown command: account %s. Please use help commands to get a list of available commands.", cmd[1] );
340        }
341       
342        return( 1 );
343}
344
345int cmd_add( irc_t *irc, char **cmd )
346{
347        account_t *a;
348       
349        if( !( a = account_get( irc, cmd[1] ) ) )
350        {
351                irc_usermsg( irc, "Invalid account" );
352                return( 1 );
353        }
354        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
355        {
356                irc_usermsg( irc, "That account is not on-line" );
357                return( 1 );
358        }
359       
360        if( cmd[3] )
361        {
362                if( !nick_ok( cmd[3] ) )
363                {
364                        irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] );
365                        return( 0 );
366                }
367                else if( user_find( irc, cmd[3] ) )
368                {
369                        irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] );
370                        return( 0 );
371                }
372                else
373                {
374                        nick_set( irc, cmd[2], a->gc->protocol, cmd[3] );
375                }
376        }
377        a->gc->prpl->add_buddy( a->gc, cmd[2] );
378        add_buddy( a->gc, NULL, cmd[2], cmd[2] );
379       
380        irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick );
381       
382        return( 0 );
383}
384
385int cmd_info( irc_t *irc, char **cmd )
386{
387        struct gaim_connection *gc;
388        account_t *a;
389       
390        if( !cmd[2] )
391        {
392                user_t *u = user_find( irc, cmd[1] );
393                if( !u || !u->gc )
394                {
395                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
396                        return( 1 );
397                }
398                gc = u->gc;
399                cmd[2] = u->handle;
400        }
401        else if( !( a = account_get( irc, cmd[1] ) ) )
402        {
403                irc_usermsg( irc, "Invalid account" );
404                return( 1 );
405        }
406        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
407        {
408                irc_usermsg( irc, "That account is not on-line" );
409                return( 1 );
410        }
411       
412        if( !gc->prpl->get_info )
413        {
414                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
415                return( 1 );
416        }
417        gc->prpl->get_info( gc, cmd[2] );
418       
419        return( 0 );
420}
421
422int cmd_rename( irc_t *irc, char **cmd )
423{
424        user_t *u;
425       
426        if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
427        {
428                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
429                return( 1 );
430        }
431        if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
432        {
433                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
434                return( 1 );
435        }
436        if( !nick_ok( cmd[2] ) )
437        {
438                irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
439                return( 1 );
440        }
441        if( !( u = user_find( irc, cmd[1] ) ) )
442        {
443                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
444                return( 1 );
445        }
446        user_rename( irc, cmd[1], cmd[2] );
447        irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
448        if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
449        {
450                g_free( irc->mynick );
451                irc->mynick = g_strdup( cmd[2] );
452        }
453        else if( u->send_handler == buddy_send_handler )
454        {
455                nick_set( irc, u->handle, u->gc->protocol, cmd[2] );
456        }
457       
458        irc_usermsg( irc, "Nick successfully changed" );
459       
460        return( 0 );
461}
462
463int cmd_remove( irc_t *irc, char **cmd )
464{
465        user_t *u;
466        char *s;
467       
468        if( !( u = user_find( irc, cmd[1] ) ) || !u->gc )
469        {
470                irc_usermsg( irc, "Buddy `%s' not found", cmd[1] );
471                return( 1 );
472        }
473        s = g_strdup( u->handle );
474       
475        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
476        user_del( irc, cmd[1] );
477        nick_del( irc, cmd[1] );
478       
479        irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] );
480        g_free( s );
481       
482        return( 0 );
483}
484
485int cmd_block( irc_t *irc, char **cmd )
486{
487        struct gaim_connection *gc;
488        account_t *a;
489       
490        if( !cmd[2] )
491        {
492                user_t *u = user_find( irc, cmd[1] );
493                if( !u || !u->gc )
494                {
495                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
496                        return( 1 );
497                }
498                gc = u->gc;
499                cmd[2] = u->handle;
500        }
501        else if( !( a = account_get( irc, cmd[1] ) ) )
502        {
503                irc_usermsg( irc, "Invalid account" );
504                return( 1 );
505        }
506        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
507        {
508                irc_usermsg( irc, "That account is not on-line" );
509                return( 1 );
510        }
511       
512        if( !gc->prpl->add_deny || !gc->prpl->rem_permit )
513        {
514                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
515        }
516        else
517        {
518                gc->prpl->rem_permit( gc, cmd[2] );
519                gc->prpl->add_deny( gc, cmd[2] );
520                irc_usermsg( irc, "Buddy `%s' moved from your permit- to your deny-list", cmd[2] );
521        }
522       
523        return( 0 );
524}
525
526int cmd_allow( irc_t *irc, char **cmd )
527{
528        struct gaim_connection *gc;
529        account_t *a;
530       
531        if( !cmd[2] )
532        {
533                user_t *u = user_find( irc, cmd[1] );
534                if( !u || !u->gc )
535                {
536                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
537                        return( 1 );
538                }
539                gc = u->gc;
540                cmd[2] = u->handle;
541        }
542        else if( !( a = account_get( irc, cmd[1] ) ) )
543        {
544                irc_usermsg( irc, "Invalid account" );
545                return( 1 );
546        }
547        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
548        {
549                irc_usermsg( irc, "That account is not on-line" );
550                return( 1 );
551        }
552       
553        if( !gc->prpl->rem_deny || !gc->prpl->add_permit )
554        {
555                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
556        }
557        else
558        {
559                gc->prpl->rem_deny( gc, cmd[2] );
560                gc->prpl->add_permit( gc, cmd[2] );
561               
562                irc_usermsg( irc, "Buddy `%s' moved from your deny- to your permit-list", cmd[2] );
563        }
564       
565        return( 0 );
566}
567
568int cmd_yesno( irc_t *irc, char **cmd )
569{
570        query_t *q = NULL;
571        int numq = 0;
572       
573        if( irc->queries == NULL )
574        {
575                irc_usermsg( irc, "Did I ask you something?" );
576                return( 0 );
577        }
578       
579        /* If there's an argument, the user seems to want to answer another question than the
580           first/last (depending on the query_order setting) one. */
581        if( cmd[1] )
582        {
583                if( sscanf( cmd[1], "%d", &numq ) != 1 )
584                {
585                        irc_usermsg( irc, "Invalid query number" );
586                        return( 0 );
587                }
588               
589                for( q = irc->queries; q; q = q->next, numq -- )
590                        if( numq == 0 )
591                                break;
592               
593                if( !q )
594                {
595                        irc_usermsg( irc, "Uhm, I never asked you something like that..." );
596                        return( 0 );
597                }
598        }
599       
600        if( g_strcasecmp( cmd[0], "yes" ) == 0 )
601                query_answer( irc, q, 1 );
602        else if( g_strcasecmp( cmd[0], "no" ) == 0 )
603                query_answer( irc, q, 0 );
604       
605        return( 1 );
606}
607
608int cmd_set( irc_t *irc, char **cmd )
609{
610        if( cmd[1] && cmd[2] )
611        {
612                set_setstr( irc, cmd[1], cmd[2] );
613        }
614        if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */
615        {
616                char *s = set_getstr( irc, cmd[1] );
617                if( s )
618                        irc_usermsg( irc, "%s = `%s'", cmd[1], s );
619        }
620        else
621        {
622                set_t *s = irc->set;
623                while( s )
624                {
625                        if( s->value || s->def )
626                                irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def );
627                        s = s->next;
628                }
629        }
630       
631        return( 0 );
632}
633
634int cmd_save( irc_t *irc, char **cmd )
635{
636        if( bitlbee_save( irc ) )
637                irc_usermsg( irc, "Configuration saved" );
638        else
639                irc_usermsg( irc, "Configuration could not be saved!" );
640       
641        return( 0 );
642}
643
644int cmd_blist( irc_t *irc, char **cmd )
645{
646        int online = 0, away = 0, offline = 0;
647        user_t *u;
648        char s[64];
649        int n_online = 0, n_away = 0, n_offline = 0;
650       
651        if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 )
652                online = offline = away = 1;
653        else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 )
654                offline = 1;
655        else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 )
656                away = 1;
657        else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 )
658                online = 1;
659        else
660                online =  away = 1;
661       
662        irc_usermsg( irc, "%-16.16s  %-40.40s  %s", "Nick", "User/Host/Network", "Status" );
663       
664        if( online == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away )
665        {
666                g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
667                irc_usermsg( irc, "%-16.16s  %-40.40s  %s", u->nick, s, "Online" );
668                n_online ++;
669        }
670
671        if( away == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away )
672        {
673                g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
674                irc_usermsg( irc, "%-16.16s  %-40.40s  %s", u->nick, s, u->away );
675                n_away ++;
676        }
677       
678        if( offline == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && !u->online )
679        {
680                g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
681                irc_usermsg( irc, "%-16.16s  %-40.40s  %s", u->nick, s, "Offline" );
682                n_offline ++;
683        }
684       
685        irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
686       
687        return( 0 );
688}
689
690int cmd_nick( irc_t *irc, char **cmd ) 
691{
692        account_t *a;
693
694        if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )
695        {
696                irc_usermsg( irc, "Invalid account");
697        }
698        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
699        {
700                irc_usermsg( irc, "That account is not on-line" );
701        }
702        else if ( !cmd[2] ) 
703        {
704                irc_usermsg( irc, "Your name is `%s'" , a->gc->displayname ? a->gc->displayname : "NULL" );
705        }
706        else if ( !a->gc->prpl->set_info ) 
707        {
708                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
709        }
710        else
711        {
712                char utf8[1024];
713               
714                irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );
715               
716                if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 &&
717                    do_iconv( set_getstr( irc, "charset" ), "UTF-8", cmd[2], utf8, 0, 1024 ) != -1 )
718                        a->gc->prpl->set_info( a->gc, utf8 );
719                else
720                        a->gc->prpl->set_info( a->gc, cmd[2] );
721        }
722       
723        return( 1 );
724}
725
726int cmd_qlist( irc_t *irc, char **cmd )
727{
728        query_t *q = irc->queries;
729        int num;
730       
731        if( !q )
732        {
733                irc_usermsg( irc, "There are no pending questions." );
734                return( 0 );
735        }
736       
737        irc_usermsg( irc, "Pending queries:" );
738       
739        for( num = 0; q; q = q->next, num ++ )
740                irc_usermsg( irc, "%d, %s", num, q->question );
741       
742        return( 0 );
743}
744
745int cmd_import_buddies( irc_t *irc, char **cmd )
746{
747        struct gaim_connection *gc;
748        account_t *a;
749        nick_t *n;
750       
751        if( !( a = account_get( irc, cmd[1] ) ) )
752        {
753                irc_usermsg( irc, "Invalid account" );
754                return( 0 );
755        }
756        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
757        {
758                irc_usermsg( irc, "That account is not on-line" );
759                return( 0 );
760        }
761       
762        if( cmd[2] )
763        {
764                if( g_strcasecmp( cmd[2], "clear" ) == 0 )
765                {
766                        user_t *u;
767                       
768                        for( u = irc->users; u; u = u->next )
769                                if( u->gc == gc )
770                                {
771                                        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
772                                        user_del( irc, u->nick );
773                                }
774                       
775                        irc_usermsg( irc, "Old buddy list cleared." );
776                }
777                else
778                {
779                        irc_usermsg( irc, "Invalid argument: %s", cmd[2] );
780                        return( 0 );
781                }
782        }
783       
784        for( n = gc->irc->nicks; n; n = n->next )
785        {
786                if( n->proto == gc->protocol && !user_findhandle( gc, n->handle ) )
787                {
788                        gc->prpl->add_buddy( gc, n->handle );
789                        add_buddy( gc, NULL, n->handle, NULL );
790                }
791        }
792       
793        irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." );
794       
795        return( 0 );
796}
Note: See TracBrowser for help on using the repository browser.