]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-mode.c
148698ac48096ab562fb28f393e9eaea968e53d6
[ngircd-alex.git] / src / ngircd / irc-mode.c
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  */
13
14
15 #include "portab.h"
16
17 static char UNUSED id[] = "$Id: irc-mode.c,v 1.23 2002/12/16 23:06:46 alex Exp $";
18
19 #include "imp.h"
20 #include <assert.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24
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"
36
37 #include "exp.h"
38 #include "irc-mode.h"
39
40
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 ));
43
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 ));
46
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 ));
49
50 LOCAL BOOLEAN Send_ListChange PARAMS(( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask ));
51
52
53 GLOBAL BOOLEAN
54 IRC_MODE( CLIENT *Client, REQUEST *Req )
55 {
56         CLIENT *cl, *origin;
57         CHANNEL *chan;
58
59         assert( Client != NULL );
60         assert( Req != NULL );
61
62         /* No parameters? */
63         if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
64
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;
72         
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] );
77
78         if( cl ) return Client_Mode( Client, Req, origin, cl );
79         if( chan ) return Channel_Mode( Client, Req, origin, chan );
80
81         /* No target found! */
82         return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
83 } /* IRC_MODE */
84
85
86 LOCAL BOOLEAN
87 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
88 {
89         /* Handle client mode requests */
90
91         CHAR the_modes[COMMAND_LEN], x[2], *mode_ptr;
92         BOOLEAN ok, set;
93         INT mode_arg;
94
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 ));
100         }
101
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 ));
104
105         mode_arg = 1;
106         mode_ptr = Req->argv[mode_arg];
107
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 ));
112
113         /* Prepare reply string */
114         if( set ) strcpy( the_modes, "+" );
115         else strcpy( the_modes, "-" );
116
117         x[1] = '\0';
118         ok = CONNECTED;
119         while( mode_ptr )
120         {
121                 mode_ptr++;
122                 if( ! *mode_ptr )
123                 {
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;
128                 }
129                 
130                 switch( *mode_ptr )
131                 {
132                         case '+':
133                         case '-':
134                                 if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
135                                 {
136                                         /* Action modifier ("+"/"-") must be changed ... */
137                                         if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
138                                         {
139                                                 /* Adjust last action modifier in result */
140                                                 the_modes[strlen( the_modes ) - 1] = *mode_ptr;
141                                         }
142                                         else
143                                         {
144                                                 /* Append modifier character to result string */
145                                                 x[0] = *mode_ptr; strcat( the_modes, x );
146                                         }
147                                         if( *mode_ptr == '+' ) set = TRUE;
148                                         else set = FALSE;
149                                 }
150                                 continue;
151                 }
152                 
153                 /* Validate modes */
154                 x[0] = '\0';
155                 switch( *mode_ptr )
156                 {
157                         case 'i':
158                                 /* Invisible */
159                                 x[0] = 'i';
160                                 break;
161                         case 'o':
162                                 /* IRC operator (only unsetable!) */
163                                 if( ! set )
164                                 {
165                                         Client_SetOperByMe( Target, FALSE );
166                                         x[0] = 'o';
167                                 }
168                                 else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
169                                 break;
170                         case 'r':
171                                 /* Restricted (only setable) */
172                                 if( set ) x[0] = 'r';
173                                 else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
174                                 break;
175                         case 's':
176                                 /* Server messages */
177                                 x[0] = 's';
178                                 break;
179                         default:
180                                 Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ));
181                                 if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
182                                 x[0] = '\0';
183                                 goto client_exit;
184                 }
185                 if( ! ok ) break;
186
187                 /* Is there a valid mode change? */
188                 if( ! x[0] ) continue;
189
190                 if( set )
191                 {
192                         /* Set mode */
193                         if( Client_ModeAdd( Target, x[0] )) strcat( the_modes, x );
194
195                 }
196                 else
197                 {
198                         /* Unset mode */
199                         if( Client_ModeDel( Target, x[0] )) strcat( the_modes, x );
200                 }               
201         }
202 client_exit:
203         
204         /* Are there changed modes? */
205         if( the_modes[1] )
206         {
207                 /* Remoce needless action modifier characters */
208                 if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' )) the_modes[strlen( the_modes ) - 1] = '\0';
209
210                 if( Client_Type( Client ) == CLIENT_SERVER )
211                 {
212                         /* Forward modes to other servers */
213                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
214                 }
215                 else
216                 {
217                         /* Send reply to client and inform other servers */
218                         ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s", Client_ID( Target ), the_modes );
219                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
220                 }
221                 Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( Target ), Client_Modes( Target ));
222         }
223                 
224         return ok;
225 } /* Client_Mode */
226
227
228 LOCAL BOOLEAN
229 Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
230 {
231         /* Handle channel and channel-user modes */
232
233         CHAR the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
234         BOOLEAN ok, set, modeok, skiponce;
235         INT mode_arg, arg_arg;
236         CLIENT *client;
237         LONG l;
238
239         /* Mode request: let's answer it :-) */
240         if( Req->argc == 1 ) return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), Channel_Modes( Channel ));
241
242         /* Is the user allowed to change modes? */
243         if( Client_Type( Client ) == CLIENT_USER )
244         {
245                 if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = TRUE;
246                 else modeok = FALSE;
247                 if( Conf_OperCanMode )
248                 {
249                         /* auch IRC-Operatoren duerfen MODE verwenden */
250                         if( Client_OperByMe( Origin )) modeok = TRUE;
251                 }
252         }
253         else modeok = TRUE;
254
255         mode_arg = 1;
256         mode_ptr = Req->argv[mode_arg];
257         if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
258         else arg_arg = -1;
259
260         /* Initial state: set or unset modes? */
261         skiponce = FALSE;
262         if( *mode_ptr == '-' ) set = FALSE;
263         else if( *mode_ptr == '+' ) set = TRUE;
264         else set = skiponce = TRUE;
265
266         /* Prepare reply string */
267         if( set ) strcpy( the_modes, "+" );
268         else strcpy( the_modes, "-" );
269         strcpy( the_args, " " );
270
271         x[1] = '\0';
272         ok = CONNECTED;
273         while( mode_ptr )
274         {
275                 if( ! skiponce ) mode_ptr++;
276                 if( ! *mode_ptr )
277                 {
278                         /* Try next argument if there's any */
279                         if( arg_arg > mode_arg ) mode_arg = arg_arg;
280                         else mode_arg++;
281                         if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
282                         else break;
283                         if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
284                         else arg_arg = -1;
285                 }
286                 skiponce = FALSE;
287
288                 switch( *mode_ptr )
289                 {
290                         case '+':
291                         case '-':
292                                 if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
293                                 {
294                                         /* Action modifier ("+"/"-") must be changed ... */
295                                         if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
296                                         {
297                                                 /* Adjust last action modifier in result */
298                                                 the_modes[strlen( the_modes ) - 1] = *mode_ptr;
299                                         }
300                                         else
301                                         {
302                                                 /* Append modifier character to result string */
303                                                 x[0] = *mode_ptr; strcat( the_modes, x );
304                                         }
305                                         if( *mode_ptr == '+' ) set = TRUE;
306                                         else set = FALSE;
307                                 }
308                                 continue;
309                 }
310
311                 /* Are there arguments left? */
312                 if( arg_arg >= Req->argc ) arg_arg = -1;
313
314                 /* Validate modes */
315                 x[0] = '\0';
316                 argadd[0] = '\0';
317                 client = NULL;
318                 switch( *mode_ptr )
319                 {
320                         /* Channel modes */
321                         case 'i':
322                                 /* Invite-Only */
323                                 if( modeok ) x[0] = 'i';
324                                 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
325                                 break;
326                         case 'm':
327                                 /* Moderated */
328                                 if( modeok ) x[0] = 'm';
329                                 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
330                                 break;
331                         case 'n':
332                                 /* kein Schreiben in den Channel von aussen */
333                                 if( modeok ) x[0] = 'n';
334                                 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
335                                 break;
336                         case 't':
337                                 /* Topic Lock */
338                                 if( modeok ) x[0] = 't';
339                                 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
340                                 break;
341                         case 'P':
342                                 /* Persistent channel */
343                                 if( modeok )
344                                 {
345                                         if( set && ( ! Client_OperByMe( Client )))
346                                         {
347                                                 /* Only IRC operators are allowed to set P mode */
348                                                 ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
349                                         }
350                                         else x[0] = 'P';
351                                 }
352                                 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
353                                 break;
354
355                         /* Channel user modes */
356                         case 'o':
357                                 /* Channel operator */
358                         case 'v':
359                                 /* Voice */
360                                 if( arg_arg > mode_arg )
361                                 {
362                                         if( modeok )
363                                         {
364                                                 client = Client_Search( Req->argv[arg_arg] );
365                                                 if( client ) x[0] = *mode_ptr;
366                                                 else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
367                                         }
368                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
369                                         Req->argv[arg_arg][0] = '\0';
370                                         arg_arg++;
371                                 }
372                                 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
373                                 break;
374                         case 'k':
375                                 /* Channel key */
376                                 if( ! set )
377                                 {
378                                         if( modeok ) x[0] = *mode_ptr;
379                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
380                                         break;
381                                 }
382                                 if( arg_arg > mode_arg )
383                                 {
384                                         if( modeok )
385                                         {
386                                                 Channel_ModeDel( Channel, 'k' );
387                                                 Channel_SetKey( Channel, Req->argv[arg_arg] );
388                                                 strcpy( argadd, Channel_Key( Channel ));
389                                                 x[0] = *mode_ptr;
390                                         }
391                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
392                                         Req->argv[arg_arg][0] = '\0';
393                                         arg_arg++;
394                                 }
395                                 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
396                                 break;
397                         case 'l':
398                                 /* Member limit */
399                                 if( ! set )
400                                 {
401                                         if( modeok ) x[0] = *mode_ptr;
402                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
403                                         break;
404                                 }
405                                 if( arg_arg > mode_arg )
406                                 {
407                                         if( modeok )
408                                         {
409                                                 l = atol( Req->argv[arg_arg] );
410                                                 if( l > 0 && l < 0xFFFF )
411                                                 {
412                                                         Channel_ModeDel( Channel, 'l' );
413                                                         Channel_SetMaxUsers( Channel, l );
414                                                         sprintf( argadd, "%ld", l );
415                                                         x[0] = *mode_ptr;
416                                                 }
417                                         }
418                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
419                                         Req->argv[arg_arg][0] = '\0';
420                                         arg_arg++;
421                                 }
422                                 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
423                                 break;
424
425                         /* Channel lists */
426                         case 'I':
427                                 /* Invite lists */
428                                 if( arg_arg > mode_arg )
429                                 {
430                                         /* modify list */
431                                         if( modeok )
432                                         {
433                                                 if( set ) Add_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
434                                                 else Del_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
435                                         }
436                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
437                                         Req->argv[arg_arg][0] = '\0';
438                                         arg_arg++;
439                                 }
440                                 else Lists_ShowInvites( Origin, Channel );
441                                 break;
442                         case 'b':
443                                 /* Ban lists */
444                                 if( arg_arg > mode_arg )
445                                 {
446                                         /* modify list */
447                                         if( modeok )
448                                         {
449                                                 if( set ) Add_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
450                                                 else Del_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
451                                         }
452                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
453                                         Req->argv[arg_arg][0] = '\0';
454                                         arg_arg++;
455                                 }
456                                 else Lists_ShowBans( Origin, Channel );
457                                 break;
458
459                         default:
460                                 Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\" on %s!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ), Channel_Name( Channel ));
461                                 if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
462                                 x[0] = '\0';
463                                 goto chan_exit;
464                 }
465                 if( ! ok ) break;
466
467                 /* Is there a valid mode change? */
468                 if( ! x[0] ) continue;
469
470                 if( set )
471                 {
472                         /* Set mode */
473                         if( client )
474                         {
475                                 /* Channel-User-Mode */
476                                 if( Channel_UserModeAdd( Channel, client, x[0] ))
477                                 {
478                                         strcat( the_args, Client_ID( client ));
479                                         strcat( the_args, " " ); strcat( the_modes, x );
480                                         Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
481                                 }
482                         }
483                         else
484                         {
485                                 /* Channel-Mode */
486                                 if( Channel_ModeAdd( Channel, x[0] ))
487                                 {
488                                         strcat( the_modes, x );
489                                         Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
490                                 }
491                         }
492                 }
493                 else
494                 {
495                         /* Unset mode */
496                         if( client )
497                         {
498                                 /* Channel-User-Mode */
499                                 if( Channel_UserModeDel( Channel, client, x[0] ))
500                                 {
501                                         strcat( the_args, Client_ID( client ));
502                                         strcat( the_args, " " ); strcat( the_modes, x );
503                                         Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
504                                 }
505                         }
506                         else
507                         {
508                                 /* Channel-Mode */
509                                 if( Channel_ModeDel( Channel, x[0] ))
510                                 {
511                                         strcat( the_modes, x );
512                                         Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
513                                 }
514                         }
515                 }
516
517                 /* Are there additional arguments to add? */
518                 if( argadd[0] )
519                 {
520                         if( the_args[strlen( the_args ) - 1] != ' ' ) strcat( the_args, " " );
521                         strcat( the_args, argadd );
522                 }
523         }
524 chan_exit:
525
526         /* Are there changed modes? */
527         if( the_modes[1] )
528         {
529                 /* Clean up mode string */
530                 if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' )) the_modes[strlen( the_modes ) - 1] = '\0';
531
532                 /* Clean up argument string if there are none */
533                 if( ! the_args[1] ) the_args[0] = '\0';
534
535                 if( Client_Type( Client ) == CLIENT_SERVER )
536                 {
537                         /* Forward mode changes to channel users and other servers */
538                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
539                         IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
540                 }
541                 else
542                 {
543                         /* Send reply to client and inform other servers and channel users */
544                         ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
545                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
546                         IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
547                 }
548         }
549
550         return CONNECTED;
551 } /* Channel_Mode */
552
553
554 GLOBAL BOOLEAN
555 IRC_AWAY( CLIENT *Client, REQUEST *Req )
556 {
557         assert( Client != NULL );
558         assert( Req != NULL );
559
560         /* Falsche Anzahl Parameter? */
561         if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
562
563         if(( Req->argc == 1 ) && (Req->argv[0][0] ))
564         {
565                 /* AWAY setzen */
566                 Client_SetAway( Client, Req->argv[0] );
567                 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
568                 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
569         }
570         else
571         {
572                 /* AWAY loeschen */
573                 Client_SetAway( Client, NULL );
574                 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
575                 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
576         }
577 } /* IRC_AWAY */
578
579
580 LOCAL BOOLEAN
581 Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
582 {
583         CHAR *mask;
584
585         assert( Client != NULL );
586         assert( Channel != NULL );
587         assert( Pattern != NULL );
588
589         mask = Lists_MakeMask( Pattern );
590
591         if( ! Lists_AddInvited( Prefix, mask, Channel, FALSE )) return CONNECTED;
592         return Send_ListChange( "+I", Prefix, Client, Channel, mask );
593 } /* Add_Invite */
594
595
596 LOCAL BOOLEAN
597 Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
598 {
599         CHAR *mask;
600
601         assert( Client != NULL );
602         assert( Channel != NULL );
603         assert( Pattern != NULL );
604
605         mask = Lists_MakeMask( Pattern );
606
607         if( ! Lists_AddBanned( Prefix, mask, Channel )) return CONNECTED;
608         return Send_ListChange( "+b", Prefix, Client, Channel, mask );
609 } /* Add_Ban */
610
611
612 LOCAL BOOLEAN
613 Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
614 {
615         CHAR *mask;
616
617         assert( Client != NULL );
618         assert( Channel != NULL );
619         assert( Pattern != NULL );
620
621         mask = Lists_MakeMask( Pattern );
622         Lists_DelInvited( mask, Channel );
623         return Send_ListChange( "-I", Prefix, Client, Channel, mask );
624 } /* Del_Invite */
625
626
627 LOCAL BOOLEAN
628 Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
629 {
630         CHAR *mask;
631
632         assert( Client != NULL );
633         assert( Channel != NULL );
634         assert( Pattern != NULL );
635
636         mask = Lists_MakeMask( Pattern );
637         Lists_DelBanned( mask, Channel );
638         return Send_ListChange( "-b", Prefix, Client, Channel, mask );
639 } /* Del_Ban */
640
641
642 LOCAL BOOLEAN
643 Send_ListChange( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask )
644 {
645         /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
646
647         BOOLEAN ok;
648
649         if( Client_Type( Client ) == CLIENT_USER )
650         {
651                 /* Bestaetigung an Client */
652                 ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
653         }
654         else ok = TRUE;
655
656         /* an andere Server */
657         IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
658
659         /* und lokale User im Channel */
660         IRC_WriteStrChannelPrefix( Client, Channel, Prefix, FALSE, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
661         
662         return ok;
663 } /* Send_ListChange */
664
665
666 /* -eof- */