source: commands.c @ 1ee6c18

Last change on this file since 1ee6c18 was 1ee6c18, checked in by Jelmer Vernooij <jelmer@…>, at 2005-12-08T13:41:53Z

Add abstraction layer for storage

  • Property mode set to 100644
File size: 17.5 KB
RevLine 
[b7d3cc34]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{
[1ee6c18]88        int checkie = global.storage->load( irc->nick, cmd[1], irc );
[b7d3cc34]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        if( global.conf->authmode == AUTHMODE_REGISTERED )
113        {
114                irc_usermsg( irc, "This server does not allow registering new accounts" );
115                return( 0 );
116        }
[1ee6c18]117
118        if( !global.storage->exists( irc->nick )) 
[b7d3cc34]119        {
120                setpassnc( irc, cmd[1] );
121                root_command_string( irc, user_find( irc, irc->mynick ), "save", 0 );
122                irc->status = USTATUS_IDENTIFIED;
123        }
124        else
125        {
126                irc_usermsg( irc, "Nick is already registered" );
127        }
128       
129        return( 0 );
130}
131
132int cmd_drop( irc_t *irc, char **cmd )
133{
[1ee6c18]134        if( ! global.storage->exists (irc->nick) )
[b7d3cc34]135        {
136                irc_usermsg( irc, "That account does not exist" );
137                return( 0 );
138        }
[1ee6c18]139
140        if ( global.storage->check_pass (irc->nick, cmd[1]) ) 
[b7d3cc34]141        {
[1ee6c18]142                irc_usermsg( irc, "Password invalid" );
[b7d3cc34]143                return( 0 );
144        }
145       
[1ee6c18]146        global.storage->remove (irc->nick);
[b7d3cc34]147       
148        setpassnc( irc, NULL );
149        irc_usermsg( irc, "Files belonging to account `%s' removed", irc->nick );
150       
151        return( 0 );
152}
153
154int cmd_account( irc_t *irc, char **cmd )
155{
156        account_t *a;
157       
158        if( global.conf->authmode == AUTHMODE_REGISTERED && irc->status < USTATUS_IDENTIFIED )
159        {
160                irc_usermsg( irc, "This server only accepts registered users" );
161                return( 0 );
162        }
163       
164        if( g_strcasecmp( cmd[1], "add" ) == 0 )
165        {
166                int prot;
167               
168                if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL )
169                {
170                        irc_usermsg( irc, "Not enough parameters" );
171                        return( 0 );
172                }
173               
174                for( prot = 0; prot < PROTO_MAX; prot ++ )
175                        if( proto_name[prot] && *proto_name[prot] && g_strcasecmp( proto_name[prot], cmd[2] ) == 0 )
176                                break;
177               
178                if( ( prot == PROTO_MAX ) || ( proto_prpl[prot] == NULL ) )
179                {
180                        irc_usermsg( irc, "Unknown protocol" );
181                        return( 0 );
182                }
183
184                if( prot == PROTO_OSCAR && cmd[5] == NULL )
185                {
186                        irc_usermsg( irc, "Not enough parameters" );
187                        return( 0 );
188                }
189               
190                a = account_add( irc, prot, cmd[3], cmd[4] );
191               
192                if( cmd[5] )
193                        a->server = g_strdup( cmd[5] );
194               
195                irc_usermsg( irc, "Account successfully added" );
196        }
197        else if( g_strcasecmp( cmd[1], "del" ) == 0 )
198        {
199                if( !cmd[2] )
200                {
201                        irc_usermsg( irc, "Not enough parameters given (need %d)", 2 );
202                }
203                else if( !( a = account_get( irc, cmd[2] ) ) )
204                {
205                        irc_usermsg( irc, "Invalid account" );
206                }
207                else if( a->gc )
208                {
209                        irc_usermsg( irc, "Account is still logged in, can't delete" );
210                }
211                else
212                {
213                        account_del( irc, a );
214                        irc_usermsg( irc, "Account deleted" );
215                }
216        }
217        else if( g_strcasecmp( cmd[1], "list" ) == 0 )
218        {
219                int i = 0;
220               
221                for( a = irc->accounts; a; a = a->next )
222                {
223                        char *con;
224                       
225                        if( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) )
226                                con = " (connected)";
227                        else if( a->gc )
228                                con = " (connecting)";
229                        else if( a->reconnect )
230                                con = " (awaiting reconnect)";
231                        else
232                                con = "";
233                       
234                        if( a->protocol == PROTO_OSCAR || a->protocol == PROTO_ICQ || a->protocol == PROTO_TOC )
235                                irc_usermsg( irc, "%2d. OSCAR, %s on %s%s", i, a->user, a->server, con );
236                        else
237                                irc_usermsg( irc, "%2d. %s, %s%s", i, proto_name[a->protocol], a->user, con );
238                       
239                        i ++;
240                }
241                irc_usermsg( irc, "End of account list" );
242        }
243        else if( g_strcasecmp( cmd[1], "on" ) == 0 )
244        {
245                if( cmd[2] )
246                {
247                        if( ( a = account_get( irc, cmd[2] ) ) )
248                        {
249                                if( a->gc )
250                                {
251                                        irc_usermsg( irc, "Account already online" );
252                                        return( 0 );
253                                }
254                                else
255                                {
256                                        account_on( irc, a );
257                                }
258                        }
259                        else
260                        {
261                                irc_usermsg( irc, "Invalid account" );
262                                return( 0 );
263                        }
264                }
265                else
266                {
267                        if ( irc->accounts ) {
268                                irc_usermsg( irc, "Trying to get all accounts connected..." );
269                       
270                                for( a = irc->accounts; a; a = a->next )
271                                        if( !a->gc )
272                                                account_on( irc, a );
273                        } 
274                        else
275                        {
276                                irc_usermsg( irc, "No accounts known. Use 'account add' to add one." );
277                        }
278                }
279        }
280        else if( g_strcasecmp( cmd[1], "off" ) == 0 )
281        {
282                if( !cmd[2] )
283                {
284                        irc_usermsg( irc, "Deactivating all active (re)connections..." );
285                       
286                        for( a = irc->accounts; a; a = a->next )
287                        {
288                                if( a->gc )
289                                        account_off( irc, a );
290                                else if( a->reconnect )
291                                        cancel_auto_reconnect( a );
292                        }
293                }
294                else if( ( a = account_get( irc, cmd[2] ) ) )
295                {
296                        if( a->gc )
297                        {
298                                account_off( irc, a );
299                        }
300                        else if( a->reconnect )
301                        {
302                                cancel_auto_reconnect( a );
303                                irc_usermsg( irc, "Reconnect cancelled" );
304                        }
305                        else
306                        {
307                                irc_usermsg( irc, "Account already offline" );
308                                return( 0 );
309                        }
310                }
311                else
312                {
313                        irc_usermsg( irc, "Invalid account" );
314                        return( 0 );
315                }
316        }
317        else
318        {
[5c09a59]319                irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] );
[b7d3cc34]320        }
321       
322        return( 1 );
323}
324
325int cmd_add( irc_t *irc, char **cmd )
326{
327        account_t *a;
328       
329        if( !( a = account_get( irc, cmd[1] ) ) )
330        {
331                irc_usermsg( irc, "Invalid account" );
332                return( 1 );
333        }
334        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
335        {
336                irc_usermsg( irc, "That account is not on-line" );
337                return( 1 );
338        }
339       
340        if( cmd[3] )
341        {
342                if( !nick_ok( cmd[3] ) )
343                {
344                        irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] );
345                        return( 0 );
346                }
347                else if( user_find( irc, cmd[3] ) )
348                {
349                        irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] );
350                        return( 0 );
351                }
352                else
353                {
354                        nick_set( irc, cmd[2], a->gc->protocol, cmd[3] );
355                }
356        }
357        a->gc->prpl->add_buddy( a->gc, cmd[2] );
358        add_buddy( a->gc, NULL, cmd[2], cmd[2] );
359       
360        irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick );
361       
362        return( 0 );
363}
364
365int cmd_info( irc_t *irc, char **cmd )
366{
367        struct gaim_connection *gc;
368        account_t *a;
369       
370        if( !cmd[2] )
371        {
372                user_t *u = user_find( irc, cmd[1] );
373                if( !u || !u->gc )
374                {
375                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
376                        return( 1 );
377                }
378                gc = u->gc;
379                cmd[2] = u->handle;
380        }
381        else if( !( a = account_get( irc, cmd[1] ) ) )
382        {
383                irc_usermsg( irc, "Invalid account" );
384                return( 1 );
385        }
386        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
387        {
388                irc_usermsg( irc, "That account is not on-line" );
389                return( 1 );
390        }
391       
392        if( !gc->prpl->get_info )
393        {
394                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
395                return( 1 );
396        }
397        gc->prpl->get_info( gc, cmd[2] );
398       
399        return( 0 );
400}
401
402int cmd_rename( irc_t *irc, char **cmd )
403{
404        user_t *u;
405       
406        if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
407        {
408                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
409                return( 1 );
410        }
411        if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
412        {
413                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
414                return( 1 );
415        }
416        if( !nick_ok( cmd[2] ) )
417        {
418                irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
419                return( 1 );
420        }
421        if( !( u = user_find( irc, cmd[1] ) ) )
422        {
423                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
424                return( 1 );
425        }
426        user_rename( irc, cmd[1], cmd[2] );
427        irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
428        if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
429        {
430                g_free( irc->mynick );
431                irc->mynick = g_strdup( cmd[2] );
432        }
433        else if( u->send_handler == buddy_send_handler )
434        {
435                nick_set( irc, u->handle, u->gc->protocol, cmd[2] );
436        }
437       
438        irc_usermsg( irc, "Nick successfully changed" );
439       
440        return( 0 );
441}
442
443int cmd_remove( irc_t *irc, char **cmd )
444{
445        user_t *u;
446        char *s;
447       
448        if( !( u = user_find( irc, cmd[1] ) ) || !u->gc )
449        {
450                irc_usermsg( irc, "Buddy `%s' not found", cmd[1] );
451                return( 1 );
452        }
453        s = g_strdup( u->handle );
454       
455        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
456        user_del( irc, cmd[1] );
457        nick_del( irc, cmd[1] );
458       
459        irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] );
460        g_free( s );
461       
462        return( 0 );
463}
464
465int cmd_block( irc_t *irc, char **cmd )
466{
467        struct gaim_connection *gc;
468        account_t *a;
469       
470        if( !cmd[2] )
471        {
472                user_t *u = user_find( irc, cmd[1] );
473                if( !u || !u->gc )
474                {
475                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
476                        return( 1 );
477                }
478                gc = u->gc;
479                cmd[2] = u->handle;
480        }
481        else if( !( a = account_get( irc, cmd[1] ) ) )
482        {
483                irc_usermsg( irc, "Invalid account" );
484                return( 1 );
485        }
486        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
487        {
488                irc_usermsg( irc, "That account is not on-line" );
489                return( 1 );
490        }
491       
492        if( !gc->prpl->add_deny || !gc->prpl->rem_permit )
493        {
494                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
495        }
496        else
497        {
498                gc->prpl->rem_permit( gc, cmd[2] );
499                gc->prpl->add_deny( gc, cmd[2] );
500                irc_usermsg( irc, "Buddy `%s' moved from your permit- to your deny-list", cmd[2] );
501        }
502       
503        return( 0 );
504}
505
506int cmd_allow( irc_t *irc, char **cmd )
507{
508        struct gaim_connection *gc;
509        account_t *a;
510       
511        if( !cmd[2] )
512        {
513                user_t *u = user_find( irc, cmd[1] );
514                if( !u || !u->gc )
515                {
516                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
517                        return( 1 );
518                }
519                gc = u->gc;
520                cmd[2] = u->handle;
521        }
522        else if( !( a = account_get( irc, cmd[1] ) ) )
523        {
524                irc_usermsg( irc, "Invalid account" );
525                return( 1 );
526        }
527        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
528        {
529                irc_usermsg( irc, "That account is not on-line" );
530                return( 1 );
531        }
532       
533        if( !gc->prpl->rem_deny || !gc->prpl->add_permit )
534        {
535                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
536        }
537        else
538        {
539                gc->prpl->rem_deny( gc, cmd[2] );
540                gc->prpl->add_permit( gc, cmd[2] );
541               
542                irc_usermsg( irc, "Buddy `%s' moved from your deny- to your permit-list", cmd[2] );
543        }
544       
545        return( 0 );
546}
547
548int cmd_yesno( irc_t *irc, char **cmd )
549{
550        query_t *q = NULL;
551        int numq = 0;
552       
553        if( irc->queries == NULL )
554        {
555                irc_usermsg( irc, "Did I ask you something?" );
556                return( 0 );
557        }
558       
559        /* If there's an argument, the user seems to want to answer another question than the
560           first/last (depending on the query_order setting) one. */
561        if( cmd[1] )
562        {
563                if( sscanf( cmd[1], "%d", &numq ) != 1 )
564                {
565                        irc_usermsg( irc, "Invalid query number" );
566                        return( 0 );
567                }
568               
569                for( q = irc->queries; q; q = q->next, numq -- )
570                        if( numq == 0 )
571                                break;
572               
573                if( !q )
574                {
575                        irc_usermsg( irc, "Uhm, I never asked you something like that..." );
576                        return( 0 );
577                }
578        }
579       
580        if( g_strcasecmp( cmd[0], "yes" ) == 0 )
581                query_answer( irc, q, 1 );
582        else if( g_strcasecmp( cmd[0], "no" ) == 0 )
583                query_answer( irc, q, 0 );
584       
585        return( 1 );
586}
587
588int cmd_set( irc_t *irc, char **cmd )
589{
590        if( cmd[1] && cmd[2] )
591        {
592                set_setstr( irc, cmd[1], cmd[2] );
593        }
594        if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */
595        {
596                char *s = set_getstr( irc, cmd[1] );
597                if( s )
598                        irc_usermsg( irc, "%s = `%s'", cmd[1], s );
599        }
600        else
601        {
602                set_t *s = irc->set;
603                while( s )
604                {
605                        if( s->value || s->def )
606                                irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def );
607                        s = s->next;
608                }
609        }
610       
611        return( 0 );
612}
613
614int cmd_save( irc_t *irc, char **cmd )
615{
[1ee6c18]616        if( global.storage->save( irc ) )
[b7d3cc34]617                irc_usermsg( irc, "Configuration saved" );
618        else
619                irc_usermsg( irc, "Configuration could not be saved!" );
620       
621        return( 0 );
622}
623
624int cmd_blist( irc_t *irc, char **cmd )
625{
626        int online = 0, away = 0, offline = 0;
627        user_t *u;
628        char s[64];
629        int n_online = 0, n_away = 0, n_offline = 0;
630       
631        if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 )
632                online = offline = away = 1;
633        else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 )
634                offline = 1;
635        else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 )
636                away = 1;
637        else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 )
638                online = 1;
639        else
640                online =  away = 1;
641       
642        irc_usermsg( irc, "%-16.16s  %-40.40s  %s", "Nick", "User/Host/Network", "Status" );
643       
644        if( online == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away )
645        {
646                g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
647                irc_usermsg( irc, "%-16.16s  %-40.40s  %s", u->nick, s, "Online" );
648                n_online ++;
649        }
650
651        if( away == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away )
652        {
653                g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
654                irc_usermsg( irc, "%-16.16s  %-40.40s  %s", u->nick, s, u->away );
655                n_away ++;
656        }
657       
658        if( offline == 1 ) for( u = irc->users; u; u = u->next ) if( u->gc && !u->online )
659        {
660                g_snprintf( s, 63, "%s@%s (%s)", u->user, u->host, proto_name[u->gc->user->protocol] );
661                irc_usermsg( irc, "%-16.16s  %-40.40s  %s", u->nick, s, "Offline" );
662                n_offline ++;
663        }
664       
665        irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
666       
667        return( 0 );
668}
669
670int cmd_nick( irc_t *irc, char **cmd ) 
671{
672        account_t *a;
673
674        if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )
675        {
676                irc_usermsg( irc, "Invalid account");
677        }
678        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
679        {
680                irc_usermsg( irc, "That account is not on-line" );
681        }
682        else if ( !cmd[2] ) 
683        {
684                irc_usermsg( irc, "Your name is `%s'" , a->gc->displayname ? a->gc->displayname : "NULL" );
685        }
686        else if ( !a->gc->prpl->set_info ) 
687        {
688                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
689        }
690        else
691        {
692                char utf8[1024];
693               
694                irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );
695               
696                if( g_strncasecmp( set_getstr( irc, "charset" ), "none", 4 ) != 0 &&
697                    do_iconv( set_getstr( irc, "charset" ), "UTF-8", cmd[2], utf8, 0, 1024 ) != -1 )
698                        a->gc->prpl->set_info( a->gc, utf8 );
699                else
700                        a->gc->prpl->set_info( a->gc, cmd[2] );
701        }
702       
703        return( 1 );
704}
705
706int cmd_qlist( irc_t *irc, char **cmd )
707{
708        query_t *q = irc->queries;
709        int num;
710       
711        if( !q )
712        {
713                irc_usermsg( irc, "There are no pending questions." );
714                return( 0 );
715        }
716       
717        irc_usermsg( irc, "Pending queries:" );
718       
719        for( num = 0; q; q = q->next, num ++ )
[5c09a59]720                if( q->gc ) /* Not necessary yet, but it might come later */
721                        irc_usermsg( irc, "%d, %s(%s): %s", num, proto_name[q->gc->protocol], q->gc->username, q->question );
722                else
723                        irc_usermsg( irc, "%d, BitlBee: %s", num, q->question );
[b7d3cc34]724       
725        return( 0 );
726}
727
728int cmd_import_buddies( irc_t *irc, char **cmd )
729{
730        struct gaim_connection *gc;
731        account_t *a;
732        nick_t *n;
733       
734        if( !( a = account_get( irc, cmd[1] ) ) )
735        {
736                irc_usermsg( irc, "Invalid account" );
737                return( 0 );
738        }
739        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
740        {
741                irc_usermsg( irc, "That account is not on-line" );
742                return( 0 );
743        }
744       
745        if( cmd[2] )
746        {
747                if( g_strcasecmp( cmd[2], "clear" ) == 0 )
748                {
749                        user_t *u;
750                       
751                        for( u = irc->users; u; u = u->next )
752                                if( u->gc == gc )
753                                {
754                                        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
755                                        user_del( irc, u->nick );
756                                }
757                       
758                        irc_usermsg( irc, "Old buddy list cleared." );
759                }
760                else
761                {
762                        irc_usermsg( irc, "Invalid argument: %s", cmd[2] );
763                        return( 0 );
764                }
765        }
766       
767        for( n = gc->irc->nicks; n; n = n->next )
768        {
769                if( n->proto == gc->protocol && !user_findhandle( gc, n->handle ) )
770                {
771                        gc->prpl->add_buddy( gc, n->handle );
772                        add_buddy( gc, NULL, n->handle, NULL );
773                }
774        }
775       
776        irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." );
777       
778        return( 0 );
779}
Note: See TracBrowser for help on using the repository browser.