source: root_commands.c @ c2fa827

Last change on this file since c2fa827 was 3af70b0, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-06-15T12:37:05Z

!x&y == (!x)&y, not !(x&y).

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