source: irc_commands.c @ 0fbda193

Last change on this file since 0fbda193 was 0fbda193, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-02-02T21:48:09Z

Added help_free() and cleaned up some very stale help-related stuff I
wasn't even aware of. This closes bug #352.

  • Property mode set to 100644
File size: 17.5 KB
RevLine 
[0298d11]1  /********************************************************************\
2  * BitlBee -- An IRC to other IM-networks gateway                     *
3  *                                                                    *
4  * Copyright 2002-2006 Wilmer van der Gaast and others                *
5  \********************************************************************/
6
7/* IRC 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 "bitlbee.h"
[0431ea1]28#include "ipc.h"
[0298d11]29
[f73b969]30static void irc_cmd_pass( irc_t *irc, char **cmd )
[0298d11]31{
[edf9657]32        if( global.conf->auth_pass && strcmp( cmd[1], global.conf->auth_pass ) == 0 )
[0298d11]33        {
[79e826a]34                irc->status |= USTATUS_AUTHORIZED;
[de3e100]35                irc_check_login( irc );
[0298d11]36        }
37        else
38        {
[b23c5c7]39                irc_reply( irc, 464, ":Incorrect password" );
[0298d11]40        }
41}
42
[f73b969]43static void irc_cmd_user( irc_t *irc, char **cmd )
[0298d11]44{
[edf9657]45        irc->user = g_strdup( cmd[1] );
46        irc->realname = g_strdup( cmd[4] );
47       
48        irc_check_login( irc );
[0298d11]49}
50
[f73b969]51static void irc_cmd_nick( irc_t *irc, char **cmd )
[0298d11]52{
53        if( irc->nick )
54        {
55                irc_reply( irc, 438, ":The hand of the deity is upon thee, thy nick may not change" );
56        }
57        /* This is not clean, but for now it'll have to be like this... */
58        else if( ( nick_cmp( cmd[1], irc->mynick ) == 0 ) || ( nick_cmp( cmd[1], NS_NICK ) == 0 ) )
59        {
60                irc_reply( irc, 433, ":This nick is already in use" );
61        }
62        else if( !nick_ok( cmd[1] ) )
63        {
64                /* [SH] Invalid characters. */
65                irc_reply( irc, 432, ":This nick contains invalid characters" );
66        }
67        else
68        {
69                irc->nick = g_strdup( cmd[1] );
[edf9657]70               
71                irc_check_login( irc );
[0298d11]72        }
73}
74
[f73b969]75static void irc_cmd_quit( irc_t *irc, char **cmd )
[0298d11]76{
[f73b969]77        if( cmd[1] && *cmd[1] )
78                irc_abort( irc, 0, "Quit: %s", cmd[1] );
79        else
80                irc_abort( irc, 0, "Leaving..." );
[0298d11]81}
82
[f73b969]83static void irc_cmd_ping( irc_t *irc, char **cmd )
[0298d11]84{
85        irc_write( irc, ":%s PONG %s :%s", irc->myhost, irc->myhost, cmd[1]?cmd[1]:irc->myhost );
86}
87
[f73b969]88static void irc_cmd_oper( irc_t *irc, char **cmd )
[0298d11]89{
[c22c210]90        if( global.conf->oper_pass && strcmp( cmd[2], global.conf->oper_pass ) == 0 )
[b23c5c7]91        {
[0298d11]92                irc_umode_set( irc, "+o", 1 );
[b23c5c7]93                irc_reply( irc, 381, ":Password accepted" );
94        }
95        else
96        {
97                irc_reply( irc, 432, ":Incorrect password" );
98        }
[0298d11]99}
100
[f73b969]101static void irc_cmd_mode( irc_t *irc, char **cmd )
[0298d11]102{
103        if( *cmd[1] == '#' || *cmd[1] == '&' )
104        {
105                if( cmd[2] )
106                {
107                        if( *cmd[2] == '+' || *cmd[2] == '-' )
108                                irc_reply( irc, 477, "%s :Can't change channel modes", cmd[1] );
109                        else if( *cmd[2] == 'b' )
110                                irc_reply( irc, 368, "%s :No bans possible", cmd[1] );
111                }
112                else
113                        irc_reply( irc, 324, "%s +%s", cmd[1], CMODE );
114        }
115        else
116        {
117                if( nick_cmp( cmd[1], irc->nick ) == 0 )
118                {
119                        if( cmd[2] )
120                                irc_umode_set( irc, cmd[2], 0 );
[2f13222]121                        else
122                                irc_reply( irc, 221, "+%s", irc->umode );
[0298d11]123                }
124                else
125                        irc_reply( irc, 502, ":Don't touch their modes" );
126        }
127}
128
[f73b969]129static void irc_cmd_names( irc_t *irc, char **cmd )
[0298d11]130{
131        irc_names( irc, cmd[1]?cmd[1]:irc->channel );
132}
133
[f73b969]134static void irc_cmd_part( irc_t *irc, char **cmd )
[0298d11]135{
[0da65d5]136        struct groupchat *c;
[0298d11]137       
138        if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
139        {
140                user_t *u = user_find( irc, irc->nick );
141               
142                /* Not allowed to leave control channel */
143                irc_part( irc, u, irc->channel );
144                irc_join( irc, u, irc->channel );
145        }
[0e7ab64]146        else if( ( c = irc_chat_by_channel( irc, cmd[1] ) ) )
[0298d11]147        {
148                user_t *u = user_find( irc, irc->nick );
149               
150                irc_part( irc, u, c->channel );
151               
[0da65d5]152                if( c->ic )
[0298d11]153                {
154                        c->joined = 0;
[0da65d5]155                        c->ic->acc->prpl->chat_leave( c );
[0298d11]156                }
157        }
158        else
159        {
160                irc_reply( irc, 403, "%s :No such channel", cmd[1] );
161        }
162}
163
[f73b969]164static void irc_cmd_join( irc_t *irc, char **cmd )
[0298d11]165{
166        if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
167                ; /* Dude, you're already there...
168                     RFC doesn't have any reply for that though? */
169        else if( cmd[1] )
170        {
171                if( ( cmd[1][0] == '#' || cmd[1][0] == '&' ) && cmd[1][1] )
172                {
173                        user_t *u = user_find( irc, cmd[1] + 1 );
174                       
[0da65d5]175                        if( u && u->ic && u->ic->acc->prpl->chat_with )
[0298d11]176                        {
177                                irc_reply( irc, 403, "%s :Initializing groupchat in a different channel", cmd[1] );
178                               
[0da65d5]179                                if( !u->ic->acc->prpl->chat_with( u->ic, u->handle ) )
[0298d11]180                                {
[c38e965]181                                        irc_usermsg( irc, "Could not open a groupchat with %s.", u->nick );
[0298d11]182                                }
183                        }
184                        else if( u )
185                        {
186                                irc_reply( irc, 403, "%s :Groupchats are not possible with %s", cmd[1], cmd[1]+1 );
187                        }
188                        else
189                        {
190                                irc_reply( irc, 403, "%s :No such nick", cmd[1] );
191                        }
192                }
193                else
194                {
195                        irc_reply( irc, 403, "%s :No such channel", cmd[1] );
196                }
197        }
198}
199
[f73b969]200static void irc_cmd_invite( irc_t *irc, char **cmd )
[0298d11]201{
202        char *nick = cmd[1], *channel = cmd[2];
[0e7ab64]203        struct groupchat *c = irc_chat_by_channel( irc, channel );
[0298d11]204        user_t *u = user_find( irc, nick );
205       
[0da65d5]206        if( u && c && ( u->ic == c->ic ) )
207                if( c->ic && c->ic->acc->prpl->chat_invite )
[0298d11]208                {
[c058ff9]209                        c->ic->acc->prpl->chat_invite( c, u->handle, NULL );
[0298d11]210                        irc_reply( irc, 341, "%s %s", nick, channel );
[f73b969]211                        return;
[0298d11]212                }
213       
214        irc_reply( irc, 482, "%s :Invite impossible; User/Channel non-existent or incompatible", channel );
215}
216
[f73b969]217static void irc_cmd_privmsg( irc_t *irc, char **cmd )
[0298d11]218{
219        if ( !cmd[2] ) 
220        {
221                irc_reply( irc, 412, ":No text to send" );
222        }
223        else if ( irc->nick && g_strcasecmp( cmd[1], irc->nick ) == 0 ) 
224        {
225                irc_write( irc, ":%s!%s@%s %s %s :%s", irc->nick, irc->user, irc->host, cmd[0], cmd[1], cmd[2] ); 
226        }
227        else 
228        {
229                if( g_strcasecmp( cmd[1], irc->channel ) == 0 )
230                {
231                        unsigned int i;
[5c9512f]232                        char *t = set_getstr( &irc->set, "default_target" );
[0298d11]233                       
234                        if( g_strcasecmp( t, "last" ) == 0 && irc->last_target )
235                                cmd[1] = irc->last_target;
236                        else if( g_strcasecmp( t, "root" ) == 0 )
237                                cmd[1] = irc->mynick;
238                       
239                        for( i = 0; i < strlen( cmd[2] ); i ++ )
240                        {
241                                if( cmd[2][i] == ' ' ) break;
242                                if( cmd[2][i] == ':' || cmd[2][i] == ',' )
243                                {
244                                        cmd[1] = cmd[2];
245                                        cmd[2] += i;
246                                        *cmd[2] = 0;
247                                        while( *(++cmd[2]) == ' ' );
248                                        break;
249                                }
250                        }
251                       
252                        irc->is_private = 0;
253                       
254                        if( cmd[1] != irc->last_target )
255                        {
256                                if( irc->last_target )
257                                        g_free( irc->last_target );
258                                irc->last_target = g_strdup( cmd[1] );
259                        }
260                }
261                else
262                {
263                        irc->is_private = 1;
264                }
[6bbb939]265                irc_send( irc, cmd[1], cmd[2], ( g_strcasecmp( cmd[0], "NOTICE" ) == 0 ) ? OPT_AWAY : 0 );
[0298d11]266        }
267}
268
[f73b969]269static void irc_cmd_who( irc_t *irc, char **cmd )
[0298d11]270{
271        char *channel = cmd[1];
272        user_t *u = irc->users;
[0da65d5]273        struct groupchat *c;
[0298d11]274        GList *l;
275       
276        if( !channel || *channel == '0' || *channel == '*' || !*channel )
277                while( u )
278                {
279                        irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", u->online ? irc->channel : "*", u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
280                        u = u->next;
281                }
282        else if( g_strcasecmp( channel, irc->channel ) == 0 )
283                while( u )
284                {
285                        if( u->online )
286                                irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
287                        u = u->next;
288                }
[0e7ab64]289        else if( ( c = irc_chat_by_channel( irc, channel ) ) )
[0298d11]290                for( l = c->in_room; l; l = l->next )
291                {
[0da65d5]292                        if( ( u = user_findhandle( c->ic, l->data ) ) )
[0298d11]293                                irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->away ? 'G' : 'H', u->realname );
294                }
295        else if( ( u = user_find( irc, channel ) ) )
296                irc_reply( irc, 352, "%s %s %s %s %s %c :0 %s", channel, u->user, u->host, irc->myhost, u->nick, u->online ? ( u->away ? 'G' : 'H' ) : 'G', u->realname );
297       
[b23c5c7]298        irc_reply( irc, 315, "%s :End of /WHO list", channel?channel:"**" );
[0298d11]299}
300
[f73b969]301static void irc_cmd_userhost( irc_t *irc, char **cmd )
[0298d11]302{
303        user_t *u;
304        int i;
305       
306        /* [TV] Usable USERHOST-implementation according to
307                RFC1459. Without this, mIRC shows an error
308                while connecting, and the used way of rejecting
309                breaks standards.
310        */
311       
312        for( i = 1; cmd[i]; i ++ )
313                if( ( u = user_find( irc, cmd[i] ) ) )
314                {
315                        if( u->online && u->away )
316                                irc_reply( irc, 302, ":%s=-%s@%s", u->nick, u->user, u->host );
317                        else
318                                irc_reply( irc, 302, ":%s=+%s@%s", u->nick, u->user, u->host );
319                }
320}
321
[f73b969]322static void irc_cmd_ison( irc_t *irc, char **cmd )
[0298d11]323{
324        user_t *u;
[b4e4b95]325        char buff[IRC_MAX_LINE];
[0298d11]326        int lenleft, i;
327       
328        buff[0] = '\0';
329       
330        /* [SH] Leave room for : and \0 */
331        lenleft = IRC_MAX_LINE - 2;
332       
333        for( i = 1; cmd[i]; i ++ )
334        {
[42616d1]335                char *this, *next;
336               
337                this = cmd[i];
338                while( *this )
[0298d11]339                {
[42616d1]340                        if( ( next = strchr( this, ' ' ) ) )
341                                *next = 0;
[0298d11]342                       
[42616d1]343                        if( ( u = user_find( irc, this ) ) && u->online )
[0298d11]344                        {
[42616d1]345                                lenleft -= strlen( u->nick ) + 1;
346                               
347                                if( lenleft < 0 )
348                                        break;
349                               
350                                strcat( buff, u->nick );
351                                strcat( buff, " " );
[0298d11]352                        }
353                       
[42616d1]354                        if( next )
355                        {
356                                *next = ' ';
357                                this = next + 1;
358                        }
359                        else
360                        {
361                                break;
362                        }   
[0298d11]363                }
[42616d1]364               
365                /* *sigh* */
366                if( lenleft < 0 )
367                        break;
[0298d11]368        }
369       
370        if( strlen( buff ) > 0 )
371                buff[strlen(buff)-1] = '\0';
372       
373        irc_reply( irc, 303, ":%s", buff );
374}
375
[f73b969]376static void irc_cmd_watch( irc_t *irc, char **cmd )
[0298d11]377{
378        int i;
379       
380        /* Obviously we could also mark a user structure as being
381           watched, but what if the WATCH command is sent right
382           after connecting? The user won't exist yet then... */
383        for( i = 1; cmd[i]; i ++ )
384        {
385                char *nick;
386                user_t *u;
387               
388                if( !cmd[i][0] || !cmd[i][1] )
389                        break;
390               
391                nick = g_strdup( cmd[i] + 1 );
392                nick_lc( nick );
393               
394                u = user_find( irc, nick );
395               
396                if( cmd[i][0] == '+' )
397                {
398                        if( !g_hash_table_lookup( irc->watches, nick ) )
399                                g_hash_table_insert( irc->watches, nick, nick );
400                       
401                        if( u && u->online )
[fc630f9]402                                irc_reply( irc, 604, "%s %s %s %d :%s", u->nick, u->user, u->host, (int) time( NULL ), "is online" );
[0298d11]403                        else
[fc630f9]404                                irc_reply( irc, 605, "%s %s %s %d :%s", nick, "*", "*", (int) time( NULL ), "is offline" );
[0298d11]405                }
406                else if( cmd[i][0] == '-' )
407                {
408                        gpointer okey, ovalue;
409                       
410                        if( g_hash_table_lookup_extended( irc->watches, nick, &okey, &ovalue ) )
411                        {
412                                g_free( okey );
413                                g_hash_table_remove( irc->watches, okey );
414                               
415                                irc_reply( irc, 602, "%s %s %s %d :%s", nick, "*", "*", 0, "Stopped watching" );
416                        }
417                }
418        }
419}
420
[f73b969]421static void irc_cmd_topic( irc_t *irc, char **cmd )
[0298d11]422{
[50e1776]423        char *channel = cmd[1];
424        char *topic = cmd[2];
425       
426        if( topic )
427        {
428                /* Send the topic */
429                struct groupchat *c = irc_chat_by_channel( irc, channel );
430                if( c && c->ic && c->ic->acc->prpl->chat_topic )
431                        c->ic->acc->prpl->chat_topic( c, topic );
432        }
[0298d11]433        else
[50e1776]434        {
435                /* Get the topic */
436                irc_topic( irc, channel );
437        }
[0298d11]438}
439
[f73b969]440static void irc_cmd_away( irc_t *irc, char **cmd )
[0298d11]441{
442        user_t *u = user_find( irc, irc->nick );
443        char *away = cmd[1];
[a91ecee]444        account_t *a;
[0298d11]445       
[f73b969]446        if( !u ) return;
[0298d11]447       
448        if( away && *away )
449        {
450                int i, j;
451               
452                /* Copy away string, but skip control chars. Mainly because
453                   Jabber really doesn't like them. */
454                u->away = g_malloc( strlen( away ) + 1 );
455                for( i = j = 0; away[i]; i ++ )
456                        if( ( u->away[j] = away[i] ) >= ' ' )
457                                j ++;
458                u->away[j] = 0;
459               
460                irc_reply( irc, 306, ":You're now away: %s", u->away );
461                /* irc_umode_set( irc, irc->myhost, "+a" ); */
462        }
463        else
464        {
465                if( u->away ) g_free( u->away );
466                u->away = NULL;
467                /* irc_umode_set( irc, irc->myhost, "-a" ); */
468                irc_reply( irc, 305, ":Welcome back" );
469        }
470       
[a91ecee]471        for( a = irc->accounts; a; a = a->next )
[0298d11]472        {
[0da65d5]473                struct im_connection *ic = a->ic;
[0298d11]474               
[0da65d5]475                if( ic && ic->flags & OPT_LOGGED_IN )
[84b045d]476                        imc_set_away( ic, u->away );
[0298d11]477        }
478}
479
[f73b969]480static void irc_cmd_whois( irc_t *irc, char **cmd )
[0298d11]481{
482        char *nick = cmd[1];
483        user_t *u = user_find( irc, nick );
484       
485        if( u )
486        {
487                irc_reply( irc, 311, "%s %s %s * :%s", u->nick, u->user, u->host, u->realname );
488               
[0da65d5]489                if( u->ic )
490                        irc_reply( irc, 312, "%s %s.%s :%s network", u->nick, u->ic->acc->user,
491                                   u->ic->acc->server && *u->ic->acc->server ? u->ic->acc->server : "",
492                                   u->ic->acc->prpl->name );
[0298d11]493                else
494                        irc_reply( irc, 312, "%s %s :%s", u->nick, irc->myhost, IRCD_INFO );
495               
496                if( !u->online )
497                        irc_reply( irc, 301, "%s :%s", u->nick, "User is offline" );
498                else if( u->away )
499                        irc_reply( irc, 301, "%s :%s", u->nick, u->away );
500               
501                irc_reply( irc, 318, "%s :End of /WHOIS list", nick );
502        }
503        else
504        {
505                irc_reply( irc, 401, "%s :Nick does not exist", nick );
506        }
507}
508
[f73b969]509static void irc_cmd_whowas( irc_t *irc, char **cmd )
[0298d11]510{
511        /* For some reason irssi tries a whowas when whois fails. We can
512           ignore this, but then the user never gets a "user not found"
513           message from irssi which is a bit annoying. So just respond
514           with not-found and irssi users will get better error messages */
515       
516        irc_reply( irc, 406, "%s :Nick does not exist", cmd[1] );
517        irc_reply( irc, 369, "%s :End of WHOWAS", cmd[1] );
518}
519
[f73b969]520static void irc_cmd_nickserv( irc_t *irc, char **cmd )
[0298d11]521{
522        /* [SH] This aliases the NickServ command to PRIVMSG root */
523        /* [TV] This aliases the NS command to PRIVMSG root as well */
524        root_command( irc, cmd + 1 );
525}
526
[f73b969]527static void irc_cmd_motd( irc_t *irc, char **cmd )
[0298d11]528{
529        irc_motd( irc );
530}
531
[f73b969]532static void irc_cmd_pong( irc_t *irc, char **cmd )
[0298d11]533{
534        /* We could check the value we get back from the user, but in
535           fact we don't care, we're just happy he's still alive. */
536        irc->last_pong = gettime();
537        irc->pinging = 0;
538}
539
[82898af]540static void irc_cmd_version( irc_t *irc, char **cmd )
541{
542        irc_reply( irc, 351, "bitlbee-%s. %s :%s/%s ", BITLBEE_VERSION, irc->myhost, ARCH, CPU );
543}
544
[f73b969]545static void irc_cmd_completions( irc_t *irc, char **cmd )
[0298d11]546{
547        user_t *u = user_find( irc, irc->mynick );
548        help_t *h;
549        set_t *s;
550        int i;
551       
552        irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "OK" );
553       
554        for( i = 0; commands[i].command; i ++ )
555                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", commands[i].command );
556       
557        for( h = global.help; h; h = h->next )
[0fbda193]558                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS help ", h->title );
[0298d11]559       
560        for( s = irc->set; s; s = s->next )
561                irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS set ", s->key );
562       
563        irc_privmsg( irc, u, "NOTICE", irc->nick, "COMPLETIONS ", "END" );
564}
565
[f73b969]566static void irc_cmd_rehash( irc_t *irc, char **cmd )
[f4a5940]567{
[5424c76]568        if( global.conf->runmode == RUNMODE_INETD )
569                ipc_master_cmd_rehash( NULL, NULL );
570        else
571                ipc_to_master( cmd );
[f4a5940]572       
573        irc_reply( irc, 382, "%s :Rehashing", CONF_FILE );
574}
575
[0298d11]576static const command_t irc_commands[] = {
577        { "pass",        1, irc_cmd_pass,        IRC_CMD_PRE_LOGIN },
578        { "user",        4, irc_cmd_user,        IRC_CMD_PRE_LOGIN },
579        { "nick",        1, irc_cmd_nick,        0 },
580        { "quit",        0, irc_cmd_quit,        0 },
581        { "ping",        0, irc_cmd_ping,        0 },
582        { "oper",        2, irc_cmd_oper,        IRC_CMD_LOGGED_IN },
583        { "mode",        1, irc_cmd_mode,        IRC_CMD_LOGGED_IN },
584        { "names",       0, irc_cmd_names,       IRC_CMD_LOGGED_IN },
585        { "part",        1, irc_cmd_part,        IRC_CMD_LOGGED_IN },
586        { "join",        1, irc_cmd_join,        IRC_CMD_LOGGED_IN },
587        { "invite",      2, irc_cmd_invite,      IRC_CMD_LOGGED_IN },
588        { "privmsg",     1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
589        { "notice",      1, irc_cmd_privmsg,     IRC_CMD_LOGGED_IN },
590        { "who",         0, irc_cmd_who,         IRC_CMD_LOGGED_IN },
591        { "userhost",    1, irc_cmd_userhost,    IRC_CMD_LOGGED_IN },
592        { "ison",        1, irc_cmd_ison,        IRC_CMD_LOGGED_IN },
593        { "watch",       1, irc_cmd_watch,       IRC_CMD_LOGGED_IN },
594        { "topic",       1, irc_cmd_topic,       IRC_CMD_LOGGED_IN },
595        { "away",        0, irc_cmd_away,        IRC_CMD_LOGGED_IN },
596        { "whois",       1, irc_cmd_whois,       IRC_CMD_LOGGED_IN },
597        { "whowas",      1, irc_cmd_whowas,      IRC_CMD_LOGGED_IN },
598        { "nickserv",    1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
599        { "ns",          1, irc_cmd_nickserv,    IRC_CMD_LOGGED_IN },
600        { "motd",        0, irc_cmd_motd,        IRC_CMD_LOGGED_IN },
601        { "pong",        0, irc_cmd_pong,        IRC_CMD_LOGGED_IN },
[82898af]602        { "version",     0, irc_cmd_version,     IRC_CMD_LOGGED_IN },
[0298d11]603        { "completions", 0, irc_cmd_completions, IRC_CMD_LOGGED_IN },
[0431ea1]604        { "die",         0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
[48721c3]605        { "wallops",     1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
[dfc8a46]606        { "wall",        1, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
[f4a5940]607        { "rehash",      0, irc_cmd_rehash,      IRC_CMD_OPER_ONLY },
[54879ab]608        { "restart",     0, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
[48721c3]609        { "kill",        2, NULL,                IRC_CMD_OPER_ONLY | IRC_CMD_TO_MASTER },
[0298d11]610        { NULL }
611};
612
[f73b969]613void irc_exec( irc_t *irc, char *cmd[] )
[0298d11]614{       
[f1d38f2]615        int i, n_arg;
[0298d11]616       
617        if( !cmd[0] )
[f73b969]618                return;
[0298d11]619       
620        for( i = 0; irc_commands[i].command; i++ )
621                if( g_strcasecmp( irc_commands[i].command, cmd[0] ) == 0 )
622                {
[f1d38f2]623                        /* There should be no typo in the next line: */
624                        for( n_arg = 0; cmd[n_arg]; n_arg ++ ); n_arg --;
625                       
[79e826a]626                        if( irc_commands[i].flags & IRC_CMD_PRE_LOGIN && irc->status & USTATUS_LOGGED_IN )
[edf9657]627                        {
628                                irc_reply( irc, 462, ":Only allowed before logging in" );
629                        }
[3af70b0]630                        else if( irc_commands[i].flags & IRC_CMD_LOGGED_IN && !( irc->status & USTATUS_LOGGED_IN ) )
[edf9657]631                        {
632                                irc_reply( irc, 451, ":Register first" );
633                        }
[f73b969]634                        else if( irc_commands[i].flags & IRC_CMD_OPER_ONLY && !strchr( irc->umode, 'o' ) )
[edf9657]635                        {
636                                irc_reply( irc, 481, ":Permission denied - You're not an IRC operator" );
637                        }
[f1d38f2]638                        else if( n_arg < irc_commands[i].required_parameters )
[f73b969]639                        {
640                                irc_reply( irc, 461, "%s :Need more parameters", cmd[0] );
641                        }
642                        else if( irc_commands[i].flags & IRC_CMD_TO_MASTER )
643                        {
[5424c76]644                                /* IPC doesn't make sense in inetd mode,
645                                    but the function will catch that. */
[0431ea1]646                                ipc_to_master( cmd );
[f73b969]647                        }
[0431ea1]648                        else
[f73b969]649                        {
650                                irc_commands[i].execute( irc, cmd );
651                        }
652                       
[2f13222]653                        return;
[0298d11]654                }
[2f13222]655       
656        if( irc->status >= USTATUS_LOGGED_IN )
657                irc_reply( irc, 421, "%s :Unknown command", cmd[0] );
[0298d11]658}
Note: See TracBrowser for help on using the repository browser.