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