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