Blob


1 /*
2 * ngIRCd -- The Next Generation IRC Daemon
3 * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * Please read the file COPYING, README and AUTHORS for more information.
10 *
11 * IRC commands for mode changes (MODE, AWAY, ...)
12 */
15 #include "portab.h"
17 static char UNUSED id[] = "$Id: irc-mode.c,v 1.35 2004/04/25 15:42:05 alex Exp $";
19 #include "imp.h"
20 #include <assert.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
25 #include "conn.h"
26 #include "client.h"
27 #include "channel.h"
28 #include "defines.h"
29 #include "irc-write.h"
30 #include "lists.h"
31 #include "log.h"
32 #include "parse.h"
33 #include "messages.h"
34 #include "resolve.h"
35 #include "conf.h"
37 #include "exp.h"
38 #include "irc-mode.h"
41 LOCAL BOOLEAN Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
42 LOCAL BOOLEAN Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
44 LOCAL BOOLEAN Add_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
45 LOCAL BOOLEAN Add_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
47 LOCAL BOOLEAN Del_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
48 LOCAL BOOLEAN Del_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
50 LOCAL BOOLEAN Send_ListChange PARAMS(( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask ));
53 GLOBAL BOOLEAN
54 IRC_MODE( CLIENT *Client, REQUEST *Req )
55 {
56 CLIENT *cl, *origin;
57 CHANNEL *chan;
59 assert( Client != NULL );
60 assert( Req != NULL );
62 /* No parameters? */
63 if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
65 /* Origin for answers */
66 if( Client_Type( Client ) == CLIENT_SERVER )
67 {
68 origin = Client_Search( Req->prefix );
69 if( ! origin ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
70 }
71 else origin = Client;
73 /* Channel or user mode? */
74 cl = chan = NULL;
75 if( Client_IsValidNick( Req->argv[0] )) cl = Client_Search( Req->argv[0] );
76 if( Channel_IsValidName( Req->argv[0] )) chan = Channel_Search( Req->argv[0] );
78 if( cl ) return Client_Mode( Client, Req, origin, cl );
79 if( chan ) return Channel_Mode( Client, Req, origin, chan );
81 /* No target found! */
82 return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
83 } /* IRC_MODE */
86 LOCAL BOOLEAN
87 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
88 {
89 /* Handle client mode requests */
91 CHAR the_modes[COMMAND_LEN], x[2], *mode_ptr;
92 BOOLEAN ok, set;
93 INT mode_arg;
95 /* Is the client allowed to request or change the modes? */
96 if( Client_Type( Client ) == CLIENT_USER )
97 {
98 /* Users are only allowed to manipulate their own modes! */
99 if( Target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
102 /* Mode request: let's answer it :-) */
103 if( Req->argc == 1 ) return IRC_WriteStrClient( Origin, RPL_UMODEIS_MSG, Client_ID( Origin ), Client_Modes( Target ));
105 mode_arg = 1;
106 mode_ptr = Req->argv[mode_arg];
108 /* Initial state: set or unset modes? */
109 if( *mode_ptr == '+' ) set = TRUE;
110 else if( *mode_ptr == '-' ) set = FALSE;
111 else return IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Origin ));
113 /* Prepare reply string */
114 if( set ) strcpy( the_modes, "+" );
115 else strcpy( the_modes, "-" );
117 x[1] = '\0';
118 ok = CONNECTED;
119 while( mode_ptr )
121 mode_ptr++;
122 if( ! *mode_ptr )
124 /* Try next argument if there's any */
125 mode_arg++;
126 if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
127 else break;
130 switch( *mode_ptr )
132 case '+':
133 case '-':
134 if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
136 /* Action modifier ("+"/"-") must be changed ... */
137 if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
139 /* Adjust last action modifier in result */
140 the_modes[strlen( the_modes ) - 1] = *mode_ptr;
142 else
144 /* Append modifier character to result string */
145 x[0] = *mode_ptr;
146 strlcat( the_modes, x, sizeof( the_modes ));
148 if( *mode_ptr == '+' ) set = TRUE;
149 else set = FALSE;
151 continue;
154 /* Validate modes */
155 x[0] = '\0';
156 switch( *mode_ptr )
158 case 'a':
159 /* Away */
160 if( Client_Type( Client ) == CLIENT_SERVER )
162 x[0] = 'a';
163 Client_SetAway( Client, DEFAULT_AWAY_MSG );
165 else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
166 break;
167 case 'i':
168 /* Invisible */
169 x[0] = 'i';
170 break;
171 case 'o':
172 /* IRC operator (only unsetable!) */
173 if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
175 Client_SetOperByMe( Target, FALSE );
176 x[0] = 'o';
178 else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
179 break;
180 case 'r':
181 /* Restricted (only setable) */
182 if(( set ) || ( Client_Type( Client ) == CLIENT_SERVER )) x[0] = 'r';
183 else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
184 break;
185 case 's':
186 /* Server messages */
187 x[0] = 's';
188 break;
189 default:
190 Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ));
191 if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
192 x[0] = '\0';
193 goto client_exit;
195 if( ! ok ) break;
197 /* Is there a valid mode change? */
198 if( ! x[0] ) continue;
200 if( set )
202 /* Set mode */
203 if( Client_ModeAdd( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
206 else
208 /* Unset mode */
209 if( Client_ModeDel( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
212 client_exit:
214 /* Are there changed modes? */
215 if( the_modes[1] )
217 /* Remoce needless action modifier characters */
218 if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' )) the_modes[strlen( the_modes ) - 1] = '\0';
220 if( Client_Type( Client ) == CLIENT_SERVER )
222 /* Forward modes to other servers */
223 IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
225 else
227 /* Send reply to client and inform other servers */
228 ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
229 IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
231 Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( Target ), Client_Modes( Target ));
234 IRC_SetPenalty( Client, 1 );
235 return ok;
236 } /* Client_Mode */
239 LOCAL BOOLEAN
240 Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
242 /* Handle channel and channel-user modes */
244 CHAR the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
245 BOOLEAN ok, set, modeok, skiponce;
246 INT mode_arg, arg_arg;
247 CLIENT *client;
248 LONG l;
250 /* Mode request: let's answer it :-) */
251 if( Req->argc == 1 )
253 /* Member or not? -- That's the question! */
254 if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), Channel_Modes( Channel ));
256 /* The sender is a member: generate extended reply */
257 strlcpy( the_modes, Channel_Modes( Channel ), sizeof( the_modes ));
258 mode_ptr = the_modes;
259 strcpy( the_args, "" );
260 while( *mode_ptr )
262 switch( *mode_ptr )
264 case 'l':
265 snprintf( argadd, sizeof( argadd ), " %ld", Channel_MaxUsers( Channel ));
266 strlcat( the_args, argadd, sizeof( the_args ));
267 break;
268 case 'k':
269 strlcat( the_args, " ", sizeof( the_args ));
270 strlcat( the_args, Channel_Key( Channel ), sizeof( the_args ));
271 break;
273 mode_ptr++;
275 if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
277 return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
280 /* Is the user allowed to change modes? */
281 if( Client_Type( Client ) == CLIENT_USER )
283 /* Is the originating user on that channel? */
284 if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Channel_Name( Channel ));
286 /* Is he channel operator? */
287 if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = TRUE;
288 else modeok = FALSE;
289 if( Conf_OperCanMode )
291 /* auch IRC-Operatoren duerfen MODE verwenden */
292 if( Client_OperByMe( Origin )) modeok = TRUE;
295 else modeok = TRUE;
297 mode_arg = 1;
298 mode_ptr = Req->argv[mode_arg];
299 if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
300 else arg_arg = -1;
302 /* Initial state: set or unset modes? */
303 skiponce = FALSE;
304 if( *mode_ptr == '-' ) set = FALSE;
305 else if( *mode_ptr == '+' ) set = TRUE;
306 else set = skiponce = TRUE;
308 /* Prepare reply string */
309 if( set ) strcpy( the_modes, "+" );
310 else strcpy( the_modes, "-" );
311 strcpy( the_args, " " );
313 x[1] = '\0';
314 ok = CONNECTED;
315 while( mode_ptr )
317 if( ! skiponce ) mode_ptr++;
318 if( ! *mode_ptr )
320 /* Try next argument if there's any */
321 if( arg_arg > mode_arg ) mode_arg = arg_arg;
322 else mode_arg++;
323 if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
324 else break;
325 if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
326 else arg_arg = -1;
328 skiponce = FALSE;
330 switch( *mode_ptr )
332 case '+':
333 case '-':
334 if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
336 /* Action modifier ("+"/"-") must be changed ... */
337 if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
339 /* Adjust last action modifier in result */
340 the_modes[strlen( the_modes ) - 1] = *mode_ptr;
342 else
344 /* Append modifier character to result string */
345 x[0] = *mode_ptr;
346 strlcat( the_modes, x, sizeof( the_modes ));
348 if( *mode_ptr == '+' ) set = TRUE;
349 else set = FALSE;
351 continue;
354 /* Are there arguments left? */
355 if( arg_arg >= Req->argc ) arg_arg = -1;
357 /* Validate modes */
358 x[0] = '\0';
359 argadd[0] = '\0';
360 client = NULL;
361 switch( *mode_ptr )
363 /* Channel modes */
364 case 'i':
365 /* Invite-Only */
366 if( modeok ) x[0] = 'i';
367 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
368 break;
369 case 'm':
370 /* Moderated */
371 if( modeok ) x[0] = 'm';
372 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
373 break;
374 case 'n':
375 /* kein Schreiben in den Channel von aussen */
376 if( modeok ) x[0] = 'n';
377 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
378 break;
379 case 't':
380 /* Topic Lock */
381 if( modeok ) x[0] = 't';
382 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
383 break;
384 case 'P':
385 /* Persistent channel */
386 if( modeok )
388 if( set && ( ! Client_OperByMe( Client )))
390 /* Only IRC operators are allowed to set P mode */
391 ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
393 else x[0] = 'P';
395 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
396 break;
398 /* Channel user modes */
399 case 'o':
400 /* Channel operator */
401 case 'v':
402 /* Voice */
403 if( arg_arg > mode_arg )
405 if( modeok )
407 client = Client_Search( Req->argv[arg_arg] );
408 if( client ) x[0] = *mode_ptr;
409 else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
411 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
412 Req->argv[arg_arg][0] = '\0';
413 arg_arg++;
415 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
416 break;
417 case 'k':
418 /* Channel key */
419 if( ! set )
421 if( modeok ) x[0] = *mode_ptr;
422 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
423 break;
425 if( arg_arg > mode_arg )
427 if( modeok )
429 Channel_ModeDel( Channel, 'k' );
430 Channel_SetKey( Channel, Req->argv[arg_arg] );
431 strlcpy( argadd, Channel_Key( Channel ), sizeof( argadd ));
432 x[0] = *mode_ptr;
434 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
435 Req->argv[arg_arg][0] = '\0';
436 arg_arg++;
438 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
439 break;
440 case 'l':
441 /* Member limit */
442 if( ! set )
444 if( modeok ) x[0] = *mode_ptr;
445 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
446 break;
448 if( arg_arg > mode_arg )
450 if( modeok )
452 l = atol( Req->argv[arg_arg] );
453 if( l > 0 && l < 0xFFFF )
455 Channel_ModeDel( Channel, 'l' );
456 Channel_SetMaxUsers( Channel, l );
457 snprintf( argadd, sizeof( argadd ), "%ld", l );
458 x[0] = *mode_ptr;
461 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
462 Req->argv[arg_arg][0] = '\0';
463 arg_arg++;
465 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
466 break;
468 /* Channel lists */
469 case 'I':
470 /* Invite lists */
471 if( arg_arg > mode_arg )
473 /* modify list */
474 if( modeok )
476 if( set ) Add_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
477 else Del_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
479 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
480 Req->argv[arg_arg][0] = '\0';
481 arg_arg++;
483 else Lists_ShowInvites( Origin, Channel );
484 break;
485 case 'b':
486 /* Ban lists */
487 if( arg_arg > mode_arg )
489 /* modify list */
490 if( modeok )
492 if( set ) Add_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
493 else Del_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
495 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
496 Req->argv[arg_arg][0] = '\0';
497 arg_arg++;
499 else Lists_ShowBans( Origin, Channel );
500 break;
502 default:
503 Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\" on %s!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ), Channel_Name( Channel ));
504 if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
505 x[0] = '\0';
506 goto chan_exit;
508 if( ! ok ) break;
510 /* Is there a valid mode change? */
511 if( ! x[0] ) continue;
513 /* Validate target client */
514 if( client && ( ! Channel_IsMemberOf( Channel, client )))
516 if( ! IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( client ), Channel_Name( Channel ))) break;
517 continue;
520 if( set )
522 /* Set mode */
523 if( client )
525 /* Channel-User-Mode */
526 if( Channel_UserModeAdd( Channel, client, x[0] ))
528 strlcat( the_args, Client_ID( client ), sizeof( the_args ));
529 strlcat( the_args, " ", sizeof( the_args ));
530 strlcat( the_modes, x, sizeof( the_modes ));
531 Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
534 else
536 /* Channel-Mode */
537 if( Channel_ModeAdd( Channel, x[0] ))
539 strlcat( the_modes, x, sizeof( the_modes ));
540 Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
544 else
546 /* Unset mode */
547 if( client )
549 /* Channel-User-Mode */
550 if( Channel_UserModeDel( Channel, client, x[0] ))
552 strlcat( the_args, Client_ID( client ), sizeof( the_args ));
553 strlcat( the_args, " ", sizeof( the_args ));
554 strlcat( the_modes, x, sizeof( the_modes ));
555 Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
558 else
560 /* Channel-Mode */
561 if( Channel_ModeDel( Channel, x[0] ))
563 strlcat( the_modes, x, sizeof( the_modes ));
564 Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
569 /* Are there additional arguments to add? */
570 if( argadd[0] )
572 if( the_args[strlen( the_args ) - 1] != ' ' ) strlcat( the_args, " ", sizeof( the_args ));
573 strlcat( the_args, argadd, sizeof( the_args ));
576 chan_exit:
578 /* Are there changed modes? */
579 if( the_modes[1] )
581 /* Clean up mode string */
582 if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' )) the_modes[strlen( the_modes ) - 1] = '\0';
584 /* Clean up argument string if there are none */
585 if( ! the_args[1] ) the_args[0] = '\0';
587 if( Client_Type( Client ) == CLIENT_SERVER )
589 /* Forward mode changes to channel users and other servers */
590 IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
591 IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
593 else
595 /* Send reply to client and inform other servers and channel users */
596 ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
597 IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
598 IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
602 IRC_SetPenalty( Client, 1 );
603 return CONNECTED;
604 } /* Channel_Mode */
607 GLOBAL BOOLEAN
608 IRC_AWAY( CLIENT *Client, REQUEST *Req )
610 assert( Client != NULL );
611 assert( Req != NULL );
613 /* Falsche Anzahl Parameter? */
614 if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
616 if(( Req->argc == 1 ) && (Req->argv[0][0] ))
618 /* AWAY setzen */
619 Client_SetAway( Client, Req->argv[0] );
620 Client_ModeAdd( Client, 'a' );
621 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
622 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
624 else
626 /* AWAY loeschen */
627 Client_ModeDel( Client, 'a' );
628 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
629 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
631 } /* IRC_AWAY */
634 LOCAL BOOLEAN
635 Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
637 CHAR *mask;
638 BOOLEAN already;
640 assert( Client != NULL );
641 assert( Channel != NULL );
642 assert( Pattern != NULL );
644 mask = Lists_MakeMask( Pattern );
646 already = Lists_IsInviteEntry( mask, Channel );
648 if( ! Lists_AddInvited( mask, Channel, FALSE )) return CONNECTED;
650 if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == TRUE )) return CONNECTED;
652 return Send_ListChange( "+I", Prefix, Client, Channel, mask );
653 } /* Add_Invite */
656 LOCAL BOOLEAN
657 Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
659 CHAR *mask;
660 BOOLEAN already;
662 assert( Client != NULL );
663 assert( Channel != NULL );
664 assert( Pattern != NULL );
666 mask = Lists_MakeMask( Pattern );
668 already = Lists_IsBanEntry( mask, Channel );
670 if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
672 if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == TRUE )) return CONNECTED;
674 return Send_ListChange( "+b", Prefix, Client, Channel, mask );
675 } /* Add_Ban */
678 LOCAL BOOLEAN
679 Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
681 CHAR *mask;
683 assert( Client != NULL );
684 assert( Channel != NULL );
685 assert( Pattern != NULL );
687 mask = Lists_MakeMask( Pattern );
688 Lists_DelInvited( mask, Channel );
689 return Send_ListChange( "-I", Prefix, Client, Channel, mask );
690 } /* Del_Invite */
693 LOCAL BOOLEAN
694 Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
696 CHAR *mask;
698 assert( Client != NULL );
699 assert( Channel != NULL );
700 assert( Pattern != NULL );
702 mask = Lists_MakeMask( Pattern );
703 Lists_DelBanned( mask, Channel );
704 return Send_ListChange( "-b", Prefix, Client, Channel, mask );
705 } /* Del_Ban */
708 LOCAL BOOLEAN
709 Send_ListChange( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask )
711 /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
713 BOOLEAN ok;
715 if( Client_Type( Client ) == CLIENT_USER )
717 /* Bestaetigung an Client */
718 ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
720 else ok = TRUE;
722 /* an andere Server */
723 IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
725 /* und lokale User im Channel */
726 IRC_WriteStrChannelPrefix( Client, Channel, Prefix, FALSE, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
728 return ok;
729 } /* Send_ListChange */
732 /* -eof- */