source: root_commands.c @ f8de26f

Last change on this file since f8de26f was f8de26f, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-04-03T21:34:45Z

Added "add -tmp" command, which you can use to temporary add a buddy to your
list, like the handle_unknown=add setting does.

  • Property mode set to 100644
File size: 19.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
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        int add_for_real = 1;
353       
354        if( g_strcasecmp( cmd[1], "-tmp" ) == 0 )
355        {
356                add_for_real = 0;
357                cmd ++;         /* So evil... :-D */
358        }
359       
360        if( !( a = account_get( irc, cmd[1] ) ) )
361        {
362                irc_usermsg( irc, "Invalid account" );
363                return;
364        }
365        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
366        {
367                irc_usermsg( irc, "That account is not on-line" );
368                return;
369        }
370       
371        if( cmd[3] )
372        {
373                if( !nick_ok( cmd[3] ) )
374                {
375                        irc_usermsg( irc, "The requested nick `%s' is invalid", cmd[3] );
376                        return;
377                }
378                else if( user_find( irc, cmd[3] ) )
379                {
380                        irc_usermsg( irc, "The requested nick `%s' already exists", cmd[3] );
381                        return;
382                }
383                else
384                {
385                        nick_set( irc, cmd[2], a->gc->prpl, cmd[3] );
386                }
387        }
388       
389        /* By making this optional, you can talk to people without having to
390           add them to your *real* (server-side) contact list. */
391        if( add_for_real )
392                a->gc->prpl->add_buddy( a->gc, cmd[2] );
393               
394        add_buddy( a->gc, NULL, cmd[2], cmd[2] );
395       
396        irc_usermsg( irc, "User `%s' added to your contact list as `%s'", cmd[2], user_findhandle( a->gc, cmd[2] )->nick );
397}
398
399static void cmd_info( irc_t *irc, char **cmd )
400{
401        struct gaim_connection *gc;
402        account_t *a;
403       
404        if( !cmd[2] )
405        {
406                user_t *u = user_find( irc, cmd[1] );
407                if( !u || !u->gc )
408                {
409                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
410                        return;
411                }
412                gc = u->gc;
413                cmd[2] = u->handle;
414        }
415        else if( !( a = account_get( irc, cmd[1] ) ) )
416        {
417                irc_usermsg( irc, "Invalid account" );
418                return;
419        }
420        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
421        {
422                irc_usermsg( irc, "That account is not on-line" );
423                return;
424        }
425       
426        if( !gc->prpl->get_info )
427        {
428                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
429        }
430        else
431        {
432                gc->prpl->get_info( gc, cmd[2] );
433        }
434}
435
436static void cmd_rename( irc_t *irc, char **cmd )
437{
438        user_t *u;
439       
440        if( g_strcasecmp( cmd[1], irc->nick ) == 0 )
441        {
442                irc_usermsg( irc, "Nick `%s' can't be changed", cmd[1] );
443        }
444        else if( user_find( irc, cmd[2] ) && ( nick_cmp( cmd[1], cmd[2] ) != 0 ) )
445        {
446                irc_usermsg( irc, "Nick `%s' already exists", cmd[2] );
447        }
448        else if( !nick_ok( cmd[2] ) )
449        {
450                irc_usermsg( irc, "Nick `%s' is invalid", cmd[2] );
451        }
452        else if( !( u = user_find( irc, cmd[1] ) ) )
453        {
454                irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
455        }
456        else
457        {
458                user_rename( irc, cmd[1], cmd[2] );
459                irc_write( irc, ":%s!%s@%s NICK %s", cmd[1], u->user, u->host, cmd[2] );
460                if( g_strcasecmp( cmd[1], irc->mynick ) == 0 )
461                {
462                        g_free( irc->mynick );
463                        irc->mynick = g_strdup( cmd[2] );
464                }
465                else if( u->send_handler == buddy_send_handler )
466                {
467                        nick_set( irc, u->handle, u->gc->prpl, cmd[2] );
468                }
469               
470                irc_usermsg( irc, "Nick successfully changed" );
471        }
472}
473
474static void cmd_remove( irc_t *irc, char **cmd )
475{
476        user_t *u;
477        char *s;
478       
479        if( !( u = user_find( irc, cmd[1] ) ) || !u->gc )
480        {
481                irc_usermsg( irc, "Buddy `%s' not found", cmd[1] );
482                return;
483        }
484        s = g_strdup( u->handle );
485       
486        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
487        user_del( irc, cmd[1] );
488        nick_del( irc, cmd[1] );
489       
490        irc_usermsg( irc, "Buddy `%s' (nick %s) removed from contact list", s, cmd[1] );
491        g_free( s );
492       
493        return;
494}
495
496static void cmd_block( irc_t *irc, char **cmd )
497{
498        struct gaim_connection *gc;
499        account_t *a;
500       
501        if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc )
502        {
503                char *format;
504                GSList *l;
505               
506                if( strchr( irc->umode, 'b' ) != NULL )
507                        format = "%s\t%s";
508                else
509                        format = "%-32.32s  %-16.16s";
510               
511                irc_usermsg( irc, format, "Handle", "Nickname" );
512                for( l = a->gc->deny; l; l = l->next )
513                {
514                        user_t *u = user_findhandle( a->gc, l->data );
515                        irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
516                }
517                irc_usermsg( irc, "End of list." );
518               
519                return;
520        }
521        else if( !cmd[2] )
522        {
523                user_t *u = user_find( irc, cmd[1] );
524                if( !u || !u->gc )
525                {
526                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
527                        return;
528                }
529                gc = u->gc;
530                cmd[2] = u->handle;
531        }
532        else if( !( a = account_get( irc, cmd[1] ) ) )
533        {
534                irc_usermsg( irc, "Invalid account" );
535                return;
536        }
537        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
538        {
539                irc_usermsg( irc, "That account is not on-line" );
540                return;
541        }
542       
543        if( !gc->prpl->add_deny || !gc->prpl->rem_permit )
544        {
545                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
546        }
547        else
548        {
549                gc->prpl->rem_permit( gc, cmd[2] );
550                gc->prpl->add_deny( gc, cmd[2] );
551                irc_usermsg( irc, "Buddy `%s' moved from your permit- to your deny-list", cmd[2] );
552        }
553}
554
555static void cmd_allow( irc_t *irc, char **cmd )
556{
557        struct gaim_connection *gc;
558        account_t *a;
559       
560        if( !cmd[2] && ( a = account_get( irc, cmd[1] ) ) && a->gc )
561        {
562                char *format;
563                GSList *l;
564               
565                if( strchr( irc->umode, 'b' ) != NULL )
566                        format = "%s\t%s";
567                else
568                        format = "%-32.32s  %-16.16s";
569               
570                irc_usermsg( irc, format, "Handle", "Nickname" );
571                for( l = a->gc->deny; l; l = l->next )
572                {
573                        user_t *u = user_findhandle( a->gc, l->data );
574                        irc_usermsg( irc, format, l->data, u ? u->nick : "(none)" );
575                }
576                irc_usermsg( irc, "End of list." );
577               
578                return;
579        }
580        else if( !cmd[2] )
581        {
582                user_t *u = user_find( irc, cmd[1] );
583                if( !u || !u->gc )
584                {
585                        irc_usermsg( irc, "Nick `%s' does not exist", cmd[1] );
586                        return;
587                }
588                gc = u->gc;
589                cmd[2] = u->handle;
590        }
591        else if( !( a = account_get( irc, cmd[1] ) ) )
592        {
593                irc_usermsg( irc, "Invalid account" );
594                return;
595        }
596        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
597        {
598                irc_usermsg( irc, "That account is not on-line" );
599                return;
600        }
601       
602        if( !gc->prpl->rem_deny || !gc->prpl->add_permit )
603        {
604                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
605        }
606        else
607        {
608                gc->prpl->rem_deny( gc, cmd[2] );
609                gc->prpl->add_permit( gc, cmd[2] );
610               
611                irc_usermsg( irc, "Buddy `%s' moved from your deny- to your permit-list", cmd[2] );
612        }
613}
614
615static void cmd_yesno( irc_t *irc, char **cmd )
616{
617        query_t *q = NULL;
618        int numq = 0;
619       
620        if( irc->queries == NULL )
621        {
622                irc_usermsg( irc, "Did I ask you something?" );
623                return;
624        }
625       
626        /* If there's an argument, the user seems to want to answer another question than the
627           first/last (depending on the query_order setting) one. */
628        if( cmd[1] )
629        {
630                if( sscanf( cmd[1], "%d", &numq ) != 1 )
631                {
632                        irc_usermsg( irc, "Invalid query number" );
633                        return;
634                }
635               
636                for( q = irc->queries; q; q = q->next, numq -- )
637                        if( numq == 0 )
638                                break;
639               
640                if( !q )
641                {
642                        irc_usermsg( irc, "Uhm, I never asked you something like that..." );
643                        return;
644                }
645        }
646       
647        if( g_strcasecmp( cmd[0], "yes" ) == 0 )
648                query_answer( irc, q, 1 );
649        else if( g_strcasecmp( cmd[0], "no" ) == 0 )
650                query_answer( irc, q, 0 );
651}
652
653static void cmd_set( irc_t *irc, char **cmd )
654{
655        if( cmd[1] && cmd[2] )
656        {
657                set_setstr( irc, cmd[1], cmd[2] );
658               
659                if( ( strcmp( cmd[2], "=" ) ) == 0 && cmd[3] )
660                        irc_usermsg( irc, "Warning: Correct syntax: \002set <variable> <value>\002 (without =)" );
661        }
662        if( cmd[1] ) /* else 'forgotten' on purpose.. Must show new value after changing */
663        {
664                char *s = set_getstr( irc, cmd[1] );
665                if( s )
666                        irc_usermsg( irc, "%s = `%s'", cmd[1], s );
667        }
668        else
669        {
670                set_t *s = irc->set;
671                while( s )
672                {
673                        if( s->value || s->def )
674                                irc_usermsg( irc, "%s = `%s'", s->key, s->value?s->value:s->def );
675                        s = s->next;
676                }
677        }
678}
679
680static void cmd_save( irc_t *irc, char **cmd )
681{
682        if( storage_save( irc, TRUE ) == STORAGE_OK )
683                irc_usermsg( irc, "Configuration saved" );
684        else
685                irc_usermsg( irc, "Configuration could not be saved!" );
686}
687
688static void cmd_blist( irc_t *irc, char **cmd )
689{
690        int online = 0, away = 0, offline = 0;
691        user_t *u;
692        char s[256];
693        char *format;
694        int n_online = 0, n_away = 0, n_offline = 0;
695       
696        if( cmd[1] && g_strcasecmp( cmd[1], "all" ) == 0 )
697                online = offline = away = 1;
698        else if( cmd[1] && g_strcasecmp( cmd[1], "offline" ) == 0 )
699                offline = 1;
700        else if( cmd[1] && g_strcasecmp( cmd[1], "away" ) == 0 )
701                away = 1;
702        else if( cmd[1] && g_strcasecmp( cmd[1], "online" ) == 0 )
703                online = 1;
704        else
705                online =  away = 1;
706       
707        if( strchr( irc->umode, 'b' ) != NULL )
708                format = "%s\t%s\t%s";
709        else
710                format = "%-16.16s  %-40.40s  %s";
711       
712        irc_usermsg( irc, format, "Nick", "User/Host/Network", "Status" );
713       
714        for( u = irc->users; u; u = u->next ) if( u->gc && u->online && !u->away )
715        {
716                if( online == 1 )
717                {
718                        g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
719                        irc_usermsg( irc, format, u->nick, s, "Online" );
720                }
721               
722                n_online ++;
723        }
724
725        for( u = irc->users; u; u = u->next ) if( u->gc && u->online && u->away )
726        {
727                if( away == 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, u->away );
731                }
732                n_away ++;
733        }
734       
735        for( u = irc->users; u; u = u->next ) if( u->gc && !u->online )
736        {
737                if( offline == 1 )
738                {
739                        g_snprintf( s, sizeof( s ) - 1, "%s@%s (%s)", u->user, u->host, u->gc->user->prpl->name );
740                        irc_usermsg( irc, format, u->nick, s, "Offline" );
741                }
742                n_offline ++;
743        }
744       
745        irc_usermsg( irc, "%d buddies (%d available, %d away, %d offline)", n_online + n_away + n_offline, n_online, n_away, n_offline );
746}
747
748static void cmd_nick( irc_t *irc, char **cmd ) 
749{
750        account_t *a;
751
752        if( !cmd[1] || !( a = account_get( irc, cmd[1] ) ) )
753        {
754                irc_usermsg( irc, "Invalid account");
755        }
756        else if( !( a->gc && ( a->gc->flags & OPT_LOGGED_IN ) ) )
757        {
758                irc_usermsg( irc, "That account is not on-line" );
759        }
760        else if ( !cmd[2] ) 
761        {
762                irc_usermsg( irc, "Your name is `%s'" , a->gc->displayname ? a->gc->displayname : "NULL" );
763        }
764        else if ( !a->gc->prpl->set_info ) 
765        {
766                irc_usermsg( irc, "Command `%s' not supported by this protocol", cmd[0] );
767        }
768        else
769        {
770                irc_usermsg( irc, "Setting your name to `%s'", cmd[2] );
771               
772                a->gc->prpl->set_info( a->gc, cmd[2] );
773        }
774}
775
776static void cmd_qlist( irc_t *irc, char **cmd )
777{
778        query_t *q = irc->queries;
779        int num;
780       
781        if( !q )
782        {
783                irc_usermsg( irc, "There are no pending questions." );
784                return;
785        }
786       
787        irc_usermsg( irc, "Pending queries:" );
788       
789        for( num = 0; q; q = q->next, num ++ )
790                if( q->gc ) /* Not necessary yet, but it might come later */
791                        irc_usermsg( irc, "%d, %s(%s): %s", num, q->gc->prpl->name, q->gc->username, q->question );
792                else
793                        irc_usermsg( irc, "%d, BitlBee: %s", num, q->question );
794}
795
796static void cmd_import_buddies( irc_t *irc, char **cmd )
797{
798        struct gaim_connection *gc;
799        account_t *a;
800        nick_t *n;
801       
802        if( !( a = account_get( irc, cmd[1] ) ) )
803        {
804                irc_usermsg( irc, "Invalid account" );
805                return;
806        }
807        else if( !( ( gc = a->gc ) && ( a->gc->flags & OPT_LOGGED_IN ) ) )
808        {
809                irc_usermsg( irc, "That account is not on-line" );
810                return;
811        }
812       
813        if( cmd[2] )
814        {
815                if( g_strcasecmp( cmd[2], "clear" ) == 0 )
816                {
817                        user_t *u;
818                       
819                        for( u = irc->users; u; u = u->next )
820                                if( u->gc == gc )
821                                {
822                                        u->gc->prpl->remove_buddy( u->gc, u->handle, NULL );
823                                        user_del( irc, u->nick );
824                                }
825                       
826                        irc_usermsg( irc, "Old buddy list cleared." );
827                }
828                else
829                {
830                        irc_usermsg( irc, "Invalid argument: %s", cmd[2] );
831                        return;
832                }
833        }
834       
835        for( n = gc->irc->nicks; n; n = n->next )
836        {
837                if( n->proto == gc->prpl && !user_findhandle( gc, n->handle ) )
838                {
839                        gc->prpl->add_buddy( gc, n->handle );
840                        add_buddy( gc, NULL, n->handle, NULL );
841                }
842        }
843       
844        irc_usermsg( irc, "Sent all add requests. Please wait for a while, the server needs some time to handle all the adds." );
845}
846
847const command_t commands[] = {
848        { "help",           0, cmd_help,           0 }, 
849        { "identify",       1, cmd_identify,       0 },
850        { "register",       1, cmd_register,       0 },
851        { "drop",           1, cmd_drop,           0 },
852        { "account",        1, cmd_account,        0 },
853        { "add",            2, cmd_add,            0 },
854        { "info",           1, cmd_info,           0 },
855        { "rename",         2, cmd_rename,         0 },
856        { "remove",         1, cmd_remove,         0 },
857        { "block",          1, cmd_block,          0 },
858        { "allow",          1, cmd_allow,          0 },
859        { "save",           0, cmd_save,           0 },
860        { "set",            0, cmd_set,            0 },
861        { "yes",            0, cmd_yesno,          0 },
862        { "no",             0, cmd_yesno,          0 },
863        { "blist",          0, cmd_blist,          0 },
864        { "nick",           1, cmd_nick,           0 },
865        { "import_buddies", 1, cmd_import_buddies, 0 },
866        { "qlist",          0, cmd_qlist,          0 },
867        { NULL }
868};
Note: See TracBrowser for help on using the repository browser.