source: root_commands.c @ 57ef864

Last change on this file since 57ef864 was 57ef864, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-04-02T08:29:34Z

Format string problem in cmd_block/allow.

  • Property mode set to 100644
File size: 19.3 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
34void root_command_string( irc_t *irc, user_t *u, char *command, int flags )
35{
36        char *cmd[IRC_MAX_ARGS];
37        char *s;
38        int k;
39        char q = 0;
40       
41        memset( cmd, 0, sizeof( cmd ) );
42        cmd[0] = command;
43        k = 1;
44        for( s = command; *s && k < ( IRC_MAX_ARGS - 1 ); s ++ )
45                if( *s == ' ' && !q )
46                {
47                        *s = 0;
48                        while( *++s == ' ' );
49                        if( *s == '"' || *s == '\'' )
50                        {
51                                q = *s;
52                                s ++;
53                        }
54                        if( *s )
55                        {
56                                cmd[k++] = s;
57                                s --;
58                        }
59                }
60                else if( *s == q )
61                {
62                        q = *s = 0;
63                }
64        cmd[k] = NULL;
65       
66        root_command( irc, cmd );
67}
68
69void root_command( irc_t *irc, char *cmd[] )
70{       
71        int i;
72       
73        if( !cmd[0] )
74                return;
75       
76        for( i = 0; commands[i].command; i++ )
77                if( g_strcasecmp( commands[i].command, cmd[0] ) == 0 )
78                {
79                        if( !cmd[commands[i].required_parameters] )
80                        {
81                                irc_usermsg( irc, "Not enough parameters given (need %d)", commands[i].required_parameters );
82                                return;
83                        }
84                        commands[i].execute( irc, cmd );
85                        return;
86                }
87       
88        irc_usermsg( irc, "Unknown command: %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[0] );
89}
90
91static void cmd_help( irc_t *irc, char **cmd )
92{
93        char param[80];
94        int i;
95        char *s;
96       
97        memset( param, 0, sizeof(param) );
98        for ( i = 1; (cmd[i] != NULL && ( strlen(param) < (sizeof(param)-1) ) ); i++ ) {
99                if ( i != 1 )   // prepend space except for the first parameter
100                        strcat(param, " ");
101                strncat( param, cmd[i], sizeof(param) - strlen(param) - 1 );
102        }
103
104        s = help_get( &(global.help), param );
105        if( !s ) s = help_get( &(global.help), "" );
106       
107        if( s )
108        {
109                irc_usermsg( irc, "%s", s );
110                g_free( s );
111        }
112        else
113        {
114                irc_usermsg( irc, "Error opening helpfile." );
115        }
116}
117
118static void cmd_identify( irc_t *irc, char **cmd )
119{
120        storage_status_t status = storage_load( irc->nick, cmd[1], irc );
121       
122        switch (status) {
123        case STORAGE_INVALID_PASSWORD:
124                irc_usermsg( irc, "Incorrect password" );
125                break;
126        case STORAGE_NO_SUCH_USER:
127                irc_usermsg( irc, "The nick is (probably) not registered" );
128                break;
129        case STORAGE_OK:
130                irc_usermsg( irc, "Password accepted" );
131                irc_umode_set( irc, "+R", 1 );
132                break;
133        default:
134                irc_usermsg( irc, "Something very weird happened" );
135                break;
136        }
137}
138
139static void cmd_register( irc_t *irc, char **cmd )
140{
141        if( global.conf->authmode == AUTHMODE_REGISTERED )
142        {
143                irc_usermsg( irc, "This server does not allow registering new accounts" );
144                return;
145        }
146
147        irc_setpass( irc, cmd[1] );
148        switch( storage_save( irc, FALSE )) {
149                case STORAGE_ALREADY_EXISTS:
150                        irc_usermsg( irc, "Nick is already registered" );
151                        break;
152                       
153                case STORAGE_OK:
154                        irc->status = USTATUS_IDENTIFIED;
155                        irc_umode_set( irc, "+R", 1 );
156                        break;
157
158                default:
159                        irc_usermsg( irc, "Error registering" );
160                        break;
161        }
162}
163
164static void cmd_drop( irc_t *irc, char **cmd )
165{
166        storage_status_t status;
167       
168        status = storage_remove (irc->nick, cmd[1]);
169        switch (status) {
170        case STORAGE_NO_SUCH_USER:
171                irc_usermsg( irc, "That account does not exist" );
172                break;
173        case STORAGE_INVALID_PASSWORD:
174                irc_usermsg( irc, "Password invalid" );
175                break;
176        case STORAGE_OK:
177                irc_setpass( irc, NULL );
178                irc->status = USTATUS_LOGGED_IN;
179                irc_umode_set( irc, "-R", 1 );
180                irc_usermsg( irc, "Account `%s' removed", irc->nick );
181                break;
182        default:
183                irc_usermsg( irc, "Error: '%d'", status );
184                break;
185        }
186}
187
188static void cmd_account( irc_t *irc, char **cmd )
189{
190        account_t *a;
191       
192        if( global.conf->authmode == AUTHMODE_REGISTERED && irc->status < USTATUS_IDENTIFIED )
193        {
194                irc_usermsg( irc, "This server only accepts registered users" );
195                return;
196        }
197       
198        if( g_strcasecmp( cmd[1], "add" ) == 0 )
199        {
200                struct prpl *prpl;
201               
202                if( cmd[2] == NULL || cmd[3] == NULL || cmd[4] == NULL )
203                {
204                        irc_usermsg( irc, "Not enough parameters" );
205                        return;
206                }
207               
208                prpl = find_protocol(cmd[2]);
209               
210                if( prpl == NULL )
211                {
212                        irc_usermsg( irc, "Unknown protocol" );
213                        return;
214                }
215
216                a = account_add( irc, prpl, cmd[3], cmd[4] );
217               
218                if( cmd[5] )
219                        a->server = g_strdup( cmd[5] );
220               
221                irc_usermsg( irc, "Account successfully added" );
222        }
223        else if( g_strcasecmp( cmd[1], "del" ) == 0 )
224        {
225                if( !cmd[2] )
226                {
227                        irc_usermsg( irc, "Not enough parameters given (need %d)", 2 );
228                }
229                else if( !( a = account_get( irc, cmd[2] ) ) )
230                {
231                        irc_usermsg( irc, "Invalid account" );
232                }
233                else if( a->gc )
234                {
235                        irc_usermsg( irc, "Account is still logged in, can't delete" );
236                }
237                else
238                {
239                        account_del( irc, a );
240                        irc_usermsg( irc, "Account deleted" );
241                }
242        }
243        else if( g_strcasecmp( cmd[1], "list" ) == 0 )
244        {
245                int i = 0;
246               
247                if( strchr( irc->umode, 'b' ) )
248                        irc_usermsg( irc, "Account list:" );
249               
250                for( a = irc->accounts; a; a = a->next )
251                {
252                        char *con;
253                       
254                        if( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) )
255                                con = " (connected)";
256                        else if( a->gc )
257                                con = " (connecting)";
258                        else if( a->reconnect )
259                                con = " (awaiting reconnect)";
260                        else
261                                con = "";
262                       
263                        irc_usermsg( irc, "%2d. %s, %s%s", i, a->prpl->name, a->user, con );
264                       
265                        i ++;
266                }
267                irc_usermsg( irc, "End of account list" );
268        }
269        else if( g_strcasecmp( cmd[1], "on" ) == 0 )
270        {
271                if( cmd[2] )
272                {
273                        if( ( a = account_get( irc, cmd[2] ) ) )
274                        {
275                                if( a->gc )
276                                {
277                                        irc_usermsg( irc, "Account already online" );
278                                        return;
279                                }
280                                else
281                                {
282                                        account_on( irc, a );
283                                }
284                        }
285                        else
286                        {
287                                irc_usermsg( irc, "Invalid account" );
288                                return;
289                        }
290                }
291                else
292                {
293                        if ( irc->accounts ) {
294                                irc_usermsg( irc, "Trying to get all accounts connected..." );
295                       
296                                for( a = irc->accounts; a; a = a->next )
297                                        if( !a->gc )
298                                                account_on( irc, a );
299                        } 
300                        else
301                        {
302                                irc_usermsg( irc, "No accounts known. Use 'account add' to add one." );
303                        }
304                }
305        }
306        else if( g_strcasecmp( cmd[1], "off" ) == 0 )
307        {
308                if( !cmd[2] )
309                {
310                        irc_usermsg( irc, "Deactivating all active (re)connections..." );
311                       
312                        for( a = irc->accounts; a; a = a->next )
313                        {
314                                if( a->gc )
315                                        account_off( irc, a );
316                                else if( a->reconnect )
317                                        cancel_auto_reconnect( a );
318                        }
319                }
320                else if( ( a = account_get( irc, cmd[2] ) ) )
321                {
322                        if( a->gc )
323                        {
324                                account_off( irc, a );
325                        }
326                        else if( a->reconnect )
327                        {
328                                cancel_auto_reconnect( a );
329                                irc_usermsg( irc, "Reconnect cancelled" );
330                        }
331                        else
332                        {
333                                irc_usermsg( irc, "Account already offline" );
334                                return;
335                        }
336                }
337                else
338                {
339                        irc_usermsg( irc, "Invalid account" );
340                        return;
341                }
342        }
343        else
344        {
345                irc_usermsg( irc, "Unknown command: account %s. Please use \x02help commands\x02 to get a list of available commands.", cmd[1] );
346        }
347}
348
349static void cmd_add( irc_t *irc, char **cmd )
350{
351        account_t *a;
352       
353        if( !( a = account_get( irc, cmd[1] ) ) )
354        {
355                irc_usermsg( irc, "Invalid account" );
356                return;
357        }
358        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
359        {
360                irc_usermsg( irc, "That account is not on-line" );
361                return;
362        }
363       
364        if( cmd[3] )
365        {
366                if( !nick_ok( cmd[3] ) )
367                {
368                        irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] );
369                        return;
370                }
371                else if( user_find( irc, cmd[3] ) )
372                {
373                        irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] );
374                        return;
375                }
376                else
377                {
378                        nick_set( irc, cmd[2], a->gc->prpl, cmd[3] );
379                }
380        }
381        a->gc->prpl->add_buddy( a->gc, cmd[2] );
382        add_buddy( a->gc, NULL, cmd[2], cmd[2] );
383       
384        irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick );
385}
386
387static void cmd_info( irc_t *irc, char **cmd )
388{
389        struct gaim_connection *gc;
390        account_t *a;
391       
392        if( !cmd[2] )
393        {
394                user_t *u = user_find( irc, cmd[1] );
395                if( !u || !u->gc )
396                {
397                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
398                        return;
399                }
400                gc = u->gc;
401                cmd[2] = u->handle;
402        }
403        else if( !( a = account_get( irc, cmd[1] ) ) )
404        {
405                irc_usermsg( irc, "Invalid account" );
406                return;
407        }
408        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
409        {
410                irc_usermsg( irc, "That account is not on-line" );
411                return;
412        }
413       
414        if( !gc->prpl->get_info )
415        {
416                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
417        }
418        else
419        {
420                gc->prpl->get_info( gc, cmd[2] );
421        }
422}
423
424static void cmd_rename( irc_t *irc, char **cmd )
425{
426        user_t *u;
427       
428        if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
429        {
430                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
431        }
432        else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
433        {
434                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
435        }
436        else if( !nick_ok( cmd[2] ) )
437        {
438                irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
439        }
440        else if( !( u = user_find( irc, cmd[1] ) ) )
441        {
442                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
443        }
444        else
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->prpl, cmd[2] );
456                }
457               
458                irc_usermsg( irc, "Nick successfully changed" );
459        }
460}
461
462static void cmd_remove( irc_t *irc, char **cmd )
463{
464        user_t *u;
465        char *s;
466       
467        if( !( u = user_find( irc, cmd[1] ) ) || !u->gc )
468        {
469                irc_usermsg( irc, "Buddy `%s' not found", cmd[1] );
470                return;
471        }
472        s = g_strdup( u->handle );
473       
474        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
475        user_del( irc, cmd[1] );
476        nick_del( irc, cmd[1] );
477       
478        irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] );
479        g_free( s );
480       
481        return;
482}
483
484static void cmd_block( irc_t *irc, char **cmd )
485{
486        struct gaim_connection *gc;
487        account_t *a;
488       
489        if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc )
490        {
491                char *format;
492                GSList *l;
493               
494                if( strchr( irc->umode, 'b' ) != NULL )
495                        format = "%s\t%s";
496                else
497                        format = "%-32.32s  %-16.16s";
498               
499                irc_usermsg( irc, format, "Handle", "Nickname" );
500                for( l = a->gc->deny; l; l = l->next )
501                {
502                        user_t *u = user_findhandle( a->gc, l->data );
503                        irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
504                }
505                irc_usermsg( irc, "End of list." );
506               
507                return;
508        }
509        else if( !cmd[2] )
510        {
511                user_t *u = user_find( irc, cmd[1] );
512                if( !u || !u->gc )
513                {
514                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
515                        return;
516                }
517                gc = u->gc;
518                cmd[2] = u->handle;
519        }
520        else if( !( a = account_get( irc, cmd[1] ) ) )
521        {
522                irc_usermsg( irc, "Invalid account" );
523                return;
524        }
525        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
526        {
527                irc_usermsg( irc, "That account is not on-line" );
528                return;
529        }
530       
531        if( !gc->prpl->add_deny || !gc->prpl->rem_permit )
532        {
533                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
534        }
535        else
536        {
537                gc->prpl->rem_permit( gc, cmd[2] );
538                gc->prpl->add_deny( gc, cmd[2] );
539                irc_usermsg( irc, "Buddy `%s' moved from your permit- to your deny-list", cmd[2] );
540        }
541}
542
543static void cmd_allow( irc_t *irc, char **cmd )
544{
545        struct gaim_connection *gc;
546        account_t *a;
547       
548        if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc )
549        {
550                char *format;
551                GSList *l;
552               
553                if( strchr( irc->umode, 'b' ) != NULL )
554                        format = "%s\t%s";
555                else
556                        format = "%-32.32s  %-16.16s";
557               
558                irc_usermsg( irc, format, "Handle", "Nickname" );
559                for( l = a->gc->deny; l; l = l->next )
560                {
561                        user_t *u = user_findhandle( a->gc, l->data );
562                        irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
563                }
564                irc_usermsg( irc, "End of list." );
565               
566                return;
567        }
568        else if( !cmd[2] )
569        {
570                user_t *u = user_find( irc, cmd[1] );
571                if( !u || !u->gc )
572                {
573                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
574                        return;
575                }
576                gc = u->gc;
577                cmd[2] = u->handle;
578        }
579        else if( !( a = account_get( irc, cmd[1] ) ) )
580        {
581                irc_usermsg( irc, "Invalid account" );
582                return;
583        }
584        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
585        {
586                irc_usermsg( irc, "That account is not on-line" );
587                return;
588        }
589       
590        if( !gc->prpl->rem_deny || !gc->prpl->add_permit )
591        {
592                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
593        }
594        else
595        {
596                gc->prpl->rem_deny( gc, cmd[2] );
597                gc->prpl->add_permit( gc, cmd[2] );
598               
599                irc_usermsg( irc, "Buddy `%s' moved from your deny- to your permit-list", cmd[2] );
600        }
601}
602
603static void cmd_yesno( irc_t *irc, char **cmd )
604{
605        query_t *q = NULL;
606        int numq = 0;
607       
608        if( irc->queries == NULL )
609        {
610                irc_usermsg( irc, "Did I ask you something?" );
611                return;
612        }
613       
614        /* If there's an argument, the user seems to want to answer another question than the
615           first/last (depending on the query_order setting) one. */
616        if( cmd[1] )
617        {
618                if( sscanf( cmd[1], "%d", &numq ) != 1 )
619                {
620                        irc_usermsg( irc, "Invalid query number" );
621                        return;
622                }
623               
624                for( q = irc->queries; q; q = q->next, numq -- )
625                        if( numq == 0 )
626                                break;
627               
628                if( !q )
629                {
630                        irc_usermsg( irc, "Uhm, I never asked you something like that..." );
631                        return;
632                }
633        }
634       
635        if( g_strcasecmp( cmd[0], "yes" ) == 0 )
636                query_answer( irc, q, 1 );
637        else if( g_strcasecmp( cmd[0], "no" ) == 0 )
638                query_answer( irc, q, 0 );
639}
640
641static void cmd_set( irc_t *irc, char **cmd )
642{
643        if( cmd[1] && cmd[2] )
644        {
645                set_setstr( irc, cmd[1], cmd[2] );
646               
647                if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] )
648                        irc_usermsg( irc, "Warning: Correct syntax: \002set <variable> <value>\002 (without =)" );
649        }
650        if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */
651        {
652                char *s = set_getstr( irc, cmd[1] );
653                if( s )
654                        irc_usermsg( irc, "%s = `%s'", cmd[1], s );
655        }
656        else
657        {
658                set_t *s = irc->set;
659                while( s )
660                {
661                        if( s->value || s->def )
662                                irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def );
663                        s = s->next;
664                }
665        }
666}
667
668static void cmd_save( irc_t *irc, char **cmd )
669{
670        if( storage_save( irc, TRUE ) == STORAGE_OK )
671                irc_usermsg( irc, "Configuration saved" );
672        else
673                irc_usermsg( irc, "Configuration could not be saved!" );
674}
675
676static void cmd_blist( irc_t *irc, char **cmd )
677{
678        int online = 0, away = 0, offline = 0;
679        user_t *u;
680        char s[256];
681        char *format;
682        int n_online = 0, n_away = 0, n_offline = 0;
683       
684        if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 )
685                online = offline = away = 1;
686        else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 )
687                offline = 1;
688        else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 )
689                away = 1;
690        else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 )
691                online = 1;
692        else
693                online =  away = 1;
694       
695        if( strchr( irc->umode, 'b' ) != NULL )
696                format = "%s\t%s\t%s";
697        else
698                format = "%-16.16s  %-40.40s  %s";
699       
700        irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" );
701       
702        for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away )
703        {
704                if( online == 1 )
705                {
706                        g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
707                        irc_usermsg( irc, format, u->nick, s, "Online" );
708                }
709               
710                n_online ++;
711        }
712
713        for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away )
714        {
715                if( away == 1 )
716                {
717                        g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
718                        irc_usermsg( irc, format, u->nick, s, u->away );
719                }
720                n_away ++;
721        }
722       
723        for( u = irc->users; u; u = u->next ) if( u->gc && !u->online )
724        {
725                if( offline == 1 )
726                {
727                        g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
728                        irc_usermsg( irc, format, u->nick, s, "Offline" );
729                }
730                n_offline ++;
731        }
732       
733        irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
734}
735
736static void cmd_nick( irc_t *irc, char **cmd ) 
737{
738        account_t *a;
739
740        if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )
741        {
742                irc_usermsg( irc, "Invalid account");
743        }
744        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
745        {
746                irc_usermsg( irc, "That account is not on-line" );
747        }
748        else if ( !cmd[2] ) 
749        {
750                irc_usermsg( irc, "Your name is `%s'" , a->gc->displayname ? a->gc->displayname : "NULL" );
751        }
752        else if ( !a->gc->prpl->set_info ) 
753        {
754                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
755        }
756        else
757        {
758                irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );
759               
760                a->gc->prpl->set_info( a->gc, cmd[2] );
761        }
762}
763
764static void cmd_qlist( irc_t *irc, char **cmd )
765{
766        query_t *q = irc->queries;
767        int num;
768       
769        if( !q )
770        {
771                irc_usermsg( irc, "There are no pending questions." );
772                return;
773        }
774       
775        irc_usermsg( irc, "Pending queries:" );
776       
777        for( num = 0; q; q = q->next, num ++ )
778                if( q->gc ) /* Not necessary yet, but it might come later */
779                        irc_usermsg( irc, "%d, %s(%s): %s", num, q->gc->prpl->name, q->gc->username, q->question );
780                else
781                        irc_usermsg( irc, "%d, BitlBee: %s", num, q->question );
782}
783
784static void cmd_import_buddies( irc_t *irc, char **cmd )
785{
786        struct gaim_connection *gc;
787        account_t *a;
788        nick_t *n;
789       
790        if( !( a = account_get( irc, cmd[1] ) ) )
791        {
792                irc_usermsg( irc, "Invalid account" );
793                return;
794        }
795        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
796        {
797                irc_usermsg( irc, "That account is not on-line" );
798                return;
799        }
800       
801        if( cmd[2] )
802        {
803                if( g_strcasecmp( cmd[2], "clear" ) == 0 )
804                {
805                        user_t *u;
806                       
807                        for( u = irc->users; u; u = u->next )
808                                if( u->gc == gc )
809                                {
810                                        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
811                                        user_del( irc, u->nick );
812                                }
813                       
814                        irc_usermsg( irc, "Old buddy list cleared." );
815                }
816                else
817                {
818                        irc_usermsg( irc, "Invalid argument: %s", cmd[2] );
819                        return;
820                }
821        }
822       
823        for( n = gc->irc->nicks; n; n = n->next )
824        {
825                if( n->proto == gc->prpl && !user_findhandle( gc, n->handle ) )
826                {
827                        gc->prpl->add_buddy( gc, n->handle );
828                        add_buddy( gc, NULL, n->handle, NULL );
829                }
830        }
831       
832        irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." );
833}
834
835const command_t commands[] = {
836        { "help",           0, cmd_help,           0 }, 
837        { "identify",       1, cmd_identify,       0 },
838        { "register",       1, cmd_register,       0 },
839        { "drop",           1, cmd_drop,           0 },
840        { "account",        1, cmd_account,        0 },
841        { "add",            2, cmd_add,            0 },
842        { "info",           1, cmd_info,           0 },
843        { "rename",         2, cmd_rename,         0 },
844        { "remove",         1, cmd_remove,         0 },
845        { "block",          1, cmd_block,          0 },
846        { "allow",          1, cmd_allow,          0 },
847        { "save",           0, cmd_save,           0 },
848        { "set",            0, cmd_set,            0 },
849        { "yes",            0, cmd_yesno,          0 },
850        { "no",             0, cmd_yesno,          0 },
851        { "blist",          0, cmd_blist,          0 },
852        { "nick",           1, cmd_nick,           0 },
853        { "import_buddies", 1, cmd_import_buddies, 0 },
854        { "qlist",          0, cmd_qlist,          0 },
855        { NULL }
856};
Note: See TracBrowser for help on using the repository browser.