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