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