source: irc_commands.c @ 0182773

Last change on this file since 0182773 was 94acdd0, checked in by Wilmer van der Gaast <wilmer@…>, at 2008-09-28T11:18:19Z

Restored support for password-protected chatrooms (for now only by accepting
a password in the IRC JOIN command).

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