source: commands.c @ 7989fcf3

Last change on this file since 7989fcf3 was a1f17d4, checked in by Jelmer Vernooij <jelmer@…>, at 2005-12-08T14:14:28Z

Simplify storage API a bit

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