]> arthur.barton.de Git - ngircd-alex.git/blob - src/ngircd/irc-mode.c
implement /WALLOPS as described in RFC 2812, section 4.7.
[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.49 2007/08/02 10:14:26 fw 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 "defines.h"
26 #include "conn.h"
27 #include "client.h"
28 #include "channel.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 static bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
42 static bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
43
44 static bool Add_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
45 static bool Add_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
46
47 static bool Del_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
48 static bool Del_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
49
50 static bool Send_ListChange PARAMS(( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask ));
51
52
53 GLOBAL bool
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 = NULL; chan = NULL;
75         if (Client_IsValidNick(Req->argv[0]))
76                 cl = Client_Search(Req->argv[0]);
77         if (Channel_IsValidName(Req->argv[0]))
78                 chan = Channel_Search(Req->argv[0]);
79
80         if (cl)
81                 return Client_Mode(Client, Req, origin, cl);
82         if (chan)
83                 return Channel_Mode(Client, Req, origin, chan);
84
85         /* No target found! */
86         return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
87                         Client_ID(Client), Req->argv[0]);
88 } /* IRC_MODE */
89
90
91 static bool
92 Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
93 {
94         /* Handle client mode requests */
95
96         char the_modes[COMMAND_LEN], x[2], *mode_ptr;
97         bool ok, set;
98         int mode_arg;
99         size_t len;
100
101         /* Is the client allowed to request or change the modes? */
102         if( Client_Type( Client ) == CLIENT_USER )
103         {
104                 /* Users are only allowed to manipulate their own modes! */
105                 if( Target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
106         }
107
108         /* Mode request: let's answer it :-) */
109         if( Req->argc == 1 ) return IRC_WriteStrClient( Origin, RPL_UMODEIS_MSG, Client_ID( Origin ), Client_Modes( Target ));
110
111         mode_arg = 1;
112         mode_ptr = Req->argv[mode_arg];
113
114         /* Initial state: set or unset modes? */
115         if( *mode_ptr == '+' ) set = true;
116         else if( *mode_ptr == '-' ) set = false;
117         else return IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Origin ));
118
119         /* Prepare reply string */
120         if( set ) strcpy( the_modes, "+" );
121         else strcpy( the_modes, "-" );
122
123         x[1] = '\0';
124         ok = CONNECTED;
125         while( mode_ptr )
126         {
127                 mode_ptr++;
128                 if( ! *mode_ptr )
129                 {
130                         /* Try next argument if there's any */
131                         mode_arg++;
132                         if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
133                         else break;
134                 }
135                 
136                 switch( *mode_ptr )
137                 {
138                         case '+':
139                         case '-':
140                                 if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
141                                 {
142                                         /* Action modifier ("+"/"-") must be changed ... */
143                                         len = strlen( the_modes ) - 1;
144                                         if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' ))
145                                         {
146                                                 /* Adjust last action modifier in result */
147                                                 the_modes[len] = *mode_ptr;
148                                         }
149                                         else
150                                         {
151                                                 /* Append modifier character to result string */
152                                                 x[0] = *mode_ptr;
153                                                 strlcat( the_modes, x, sizeof( the_modes ));
154                                         }
155                                         if( *mode_ptr == '+' ) set = true;
156                                         else set = false;
157                                 }
158                                 continue;
159                 }
160                 
161                 /* Validate modes */
162                 x[0] = '\0';
163                 switch( *mode_ptr )
164                 {
165                         case 'i': /* Invisible */
166                         case 's': /* Server messages */
167                         case 'w': /* Wallops messages */
168                                 x[0] = *mode_ptr;
169                                 break;
170
171                         case 'a': /* Away */
172                                 if( Client_Type( Client ) == CLIENT_SERVER )
173                                 {
174                                         x[0] = 'a';
175                                         Client_SetAway( Origin, DEFAULT_AWAY_MSG );
176                                 }
177                                 else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
178                                 break;
179
180                         case 'o': /* IRC operator (only unsettable!) */
181                                 if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
182                                 {
183                                         Client_SetOperByMe( Target, false );
184                                         x[0] = 'o';
185                                 }
186                                 else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
187                                 break;
188
189                         case 'r': /* Restricted (only settable) */
190                                 if(( set ) || ( Client_Type( Client ) == CLIENT_SERVER )) x[0] = 'r';
191                                 else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
192                                 break;
193
194                         default:
195                                 Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ));
196                                 if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
197                                 x[0] = '\0';
198                                 goto client_exit;
199                 }
200                 if( ! ok ) break;
201
202                 /* Is there a valid mode change? */
203                 if( ! x[0] ) continue;
204
205                 if( set )
206                 {
207                         /* Set mode */
208                         if( Client_ModeAdd( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
209
210                 }
211                 else
212                 {
213                         /* Unset mode */
214                         if( Client_ModeDel( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
215                 }               
216         }
217 client_exit:
218         
219         /* Are there changed modes? */
220         if( the_modes[1] )
221         {
222                 /* Remoce needless action modifier characters */
223                 len = strlen( the_modes ) - 1;
224                 if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' )) the_modes[len] = '\0';
225
226                 if( Client_Type( Client ) == CLIENT_SERVER )
227                 {
228                         /* Forward modes to other servers */
229                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
230                 }
231                 else
232                 {
233                         /* Send reply to client and inform other servers */
234                         ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
235                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
236                 }
237                 Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( Target ), Client_Modes( Target ));
238         }
239         
240         IRC_SetPenalty( Client, 1 );    
241         return ok;
242 } /* Client_Mode */
243
244
245 static bool
246 Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
247 {
248         /* Handle channel and channel-user modes */
249
250         char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
251         bool ok, set, modeok = false, skiponce, use_servermode = false;
252         int mode_arg, arg_arg;
253         CLIENT *client;
254         long l;
255         size_t len;
256
257         /* Mode request: let's answer it :-) */
258         if( Req->argc == 1 )
259         {
260                 /* Member or not? -- That's the question! */
261                 if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), Channel_Modes( Channel ));
262
263                 /* The sender is a member: generate extended reply */
264                 strlcpy( the_modes, Channel_Modes( Channel ), sizeof( the_modes ));
265                 mode_ptr = the_modes;
266                 the_args[0] = '\0';
267                 while( *mode_ptr )
268                 {
269                         switch( *mode_ptr )
270                         {
271                                 case 'l':
272                                         snprintf( argadd, sizeof( argadd ), " %lu", Channel_MaxUsers( Channel ));
273                                         strlcat( the_args, argadd, sizeof( the_args ));
274                                         break;
275                                 case 'k':
276                                         strlcat( the_args, " ", sizeof( the_args ));
277                                         strlcat( the_args, Channel_Key( Channel ), sizeof( the_args ));
278                                         break;
279                         }
280                         mode_ptr++;
281                 }
282                 if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
283
284                 return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
285         }
286
287         /* Is the user allowed to change modes? */
288         if( Client_Type( Client ) == CLIENT_USER )
289         {
290                 /* Is the originating user on that channel? */
291                 if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Channel_Name( Channel ));
292
293                 /* Is he channel operator? */
294                 if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = true;
295                 else if( Conf_OperCanMode )
296                 {
297                         /* IRC-Operators can use MODE as well */
298                         if( Client_OperByMe( Origin )) {
299                                 modeok = true;
300                                 if ( Conf_OperServerMode ) use_servermode = true; /* Change Origin to Server */
301                         }
302                 }
303         }
304         else modeok = true;
305
306         mode_arg = 1;
307         mode_ptr = Req->argv[mode_arg];
308         if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
309         else arg_arg = -1;
310
311         /* Initial state: set or unset modes? */
312         skiponce = false;
313         if( *mode_ptr == '-' ) set = false;
314         else if( *mode_ptr == '+' ) set = true;
315         else set = skiponce = true;
316
317         /* Prepare reply string */
318         if( set ) strcpy( the_modes, "+" );
319         else strcpy( the_modes, "-" );
320         strcpy( the_args, " " );
321
322         x[1] = '\0';
323         ok = CONNECTED;
324         while( mode_ptr )
325         {
326                 if( ! skiponce ) mode_ptr++;
327                 if( ! *mode_ptr )
328                 {
329                         /* Try next argument if there's any */
330                         if( arg_arg > mode_arg ) mode_arg = arg_arg;
331                         else mode_arg++;
332                         if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
333                         else break;
334                         if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
335                         else arg_arg = -1;
336                 }
337                 skiponce = false;
338
339                 switch( *mode_ptr )
340                 {
341                         case '+':
342                         case '-':
343                                 if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
344                                 {
345                                         /* Action modifier ("+"/"-") must be changed ... */
346                                         len = strlen( the_modes ) - 1;
347                                         if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' ))
348                                         {
349                                                 /* Adjust last action modifier in result */
350                                                 the_modes[len] = *mode_ptr;
351                                         }
352                                         else
353                                         {
354                                                 /* Append modifier character to result string */
355                                                 x[0] = *mode_ptr;
356                                                 strlcat( the_modes, x, sizeof( the_modes ));
357                                         }
358                                         if( *mode_ptr == '+' ) set = true;
359                                         else set = false;
360                                 }
361                                 continue;
362                 }
363
364                 /* Are there arguments left? */
365                 if( arg_arg >= Req->argc ) arg_arg = -1;
366
367                 /* Validate modes */
368                 x[0] = '\0';
369                 argadd[0] = '\0';
370                 client = NULL;
371                 switch( *mode_ptr )
372                 {
373                         /* --- Channel modes --- */
374
375                         case 'i': /* Invite only */
376                         case 'm': /* Moderated */
377                         case 'n': /* Only members can write */
378                         case 's': /* Secret channel */
379                         case 't': /* Topic locked */
380                                 if( modeok ) x[0] = *mode_ptr;
381                                 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
382                                 break;
383
384                         case 'k': /* Channel key */
385                                 if( ! set )
386                                 {
387                                         if( modeok ) x[0] = *mode_ptr;
388                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
389                                         break;
390                                 }
391                                 if( arg_arg > mode_arg )
392                                 {
393                                         if( modeok )
394                                         {
395                                                 Channel_ModeDel( Channel, 'k' );
396                                                 Channel_SetKey( Channel, Req->argv[arg_arg] );
397                                                 strlcpy( argadd, Channel_Key( Channel ), sizeof( argadd ));
398                                                 x[0] = *mode_ptr;
399                                         }
400                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
401                                         Req->argv[arg_arg][0] = '\0';
402                                         arg_arg++;
403                                 }
404                                 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
405                                 break;
406
407                         case 'l': /* Member limit */
408                                 if( ! set )
409                                 {
410                                         if( modeok ) x[0] = *mode_ptr;
411                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
412                                         break;
413                                 }
414                                 if( arg_arg > mode_arg )
415                                 {
416                                         if( modeok )
417                                         {
418                                                 l = atol( Req->argv[arg_arg] );
419                                                 if( l > 0 && l < 0xFFFF )
420                                                 {
421                                                         Channel_ModeDel( Channel, 'l' );
422                                                         Channel_SetMaxUsers( Channel, l );
423                                                         snprintf( argadd, sizeof( argadd ), "%ld", l );
424                                                         x[0] = *mode_ptr;
425                                                 }
426                                         }
427                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
428                                         Req->argv[arg_arg][0] = '\0';
429                                         arg_arg++;
430                                 }
431                                 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
432                                 break;
433
434                         case 'P': /* Persistent channel */
435                                 if( modeok )
436                                 {
437                                         if( set && ( ! Client_OperByMe( Client )))
438                                         {
439                                                 /* Only IRC operators are allowed to set P mode */
440                                                 ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
441                                         }
442                                         else x[0] = 'P';
443                                 }
444                                 else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
445                                 break;
446
447                         /* --- Channel user modes --- */
448
449                         case 'o': /* Channel operator */
450                         case 'v': /* Voice */
451                                 if( arg_arg > mode_arg )
452                                 {
453                                         if( modeok )
454                                         {
455                                                 client = Client_Search( Req->argv[arg_arg] );
456                                                 if( client ) x[0] = *mode_ptr;
457                                                 else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
458                                         }
459                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
460                                         Req->argv[arg_arg][0] = '\0';
461                                         arg_arg++;
462                                 }
463                                 else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
464                                 break;
465
466                         /* --- Channel lists --- */
467
468                         case 'I': /* Invite lists */
469                                 if( arg_arg > mode_arg )
470                                 {
471                                         /* modify list */
472                                         if( modeok )
473                                         {
474                                                 if( set ) Add_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
475                                                 else Del_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
476                                         }
477                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
478                                         Req->argv[arg_arg][0] = '\0';
479                                         arg_arg++;
480                                 }
481                                 else Channel_ShowInvites( Origin, Channel );
482                                 break;
483
484                         case 'b': /* Ban lists */
485                                 if( arg_arg > mode_arg )
486                                 {
487                                         /* modify list */
488                                         if( modeok )
489                                         {
490                                                 if( set ) Add_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
491                                                 else Del_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
492                                         }
493                                         else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
494                                         Req->argv[arg_arg][0] = '\0';
495                                         arg_arg++;
496                                 }
497                                 else Channel_ShowBans( Origin, Channel );
498                                 break;
499
500                         default:
501                                 Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\" on %s!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ), Channel_Name( Channel ));
502                                 if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
503                                 x[0] = '\0';
504                                 goto chan_exit;
505                 }
506                 if( ! ok ) break;
507
508                 /* Is there a valid mode change? */
509                 if( ! x[0] ) continue;
510
511                 /* Validate target client */
512                 if( client && ( ! Channel_IsMemberOf( Channel, client )))
513                 {
514                         if( ! IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( client ), Channel_Name( Channel ))) break;
515                         continue;
516                 }
517
518                 if( set )
519                 {
520                         /* Set mode */
521                         if( client )
522                         {
523                                 /* Channel-User-Mode */
524                                 if( Channel_UserModeAdd( Channel, client, x[0] ))
525                                 {
526                                         strlcat( the_args, Client_ID( client ), sizeof( the_args ));
527                                         strlcat( the_args, " ", sizeof( the_args ));
528                                         strlcat( the_modes, x, sizeof( the_modes ));
529                                         Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
530                                 }
531                         }
532                         else
533                         {
534                                 /* Channel-Mode */
535                                 if( Channel_ModeAdd( Channel, x[0] ))
536                                 {
537                                         strlcat( the_modes, x, sizeof( the_modes ));
538                                         Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
539                                 }
540                         }
541                 }
542                 else
543                 {
544                         /* Unset mode */
545                         if( client )
546                         {
547                                 /* Channel-User-Mode */
548                                 if( Channel_UserModeDel( Channel, client, x[0] ))
549                                 {
550                                         strlcat( the_args, Client_ID( client ), sizeof( the_args ));
551                                         strlcat( the_args, " ", sizeof( the_args ));
552                                         strlcat( the_modes, x, sizeof( the_modes ));
553                                         Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
554                                 }
555                         }
556                         else
557                         {
558                                 /* Channel-Mode */
559                                 if( Channel_ModeDel( Channel, x[0] ))
560                                 {
561                                         strlcat( the_modes, x, sizeof( the_modes ));
562                                         Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
563                                 }
564                         }
565                 }
566
567                 /* Are there additional arguments to add? */
568                 if( argadd[0] )
569                 {
570                         len = strlen( the_args ) - 1;
571                         if( the_args[len] != ' ' ) strlcat( the_args, " ", sizeof( the_args ));
572                         strlcat( the_args, argadd, sizeof( the_args ));
573                 }
574         }
575 chan_exit:
576
577         /* Are there changed modes? */
578         if( the_modes[1] )
579         {
580                 /* Clean up mode string */
581                 len = strlen( the_modes ) - 1;
582                 if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' )) the_modes[len] = '\0';
583
584                 /* Clean up argument string if there are none */
585                 if( ! the_args[1] ) the_args[0] = '\0';
586
587                 if( Client_Type( Client ) == CLIENT_SERVER )
588                 {
589                         /* Forward mode changes to channel users and other servers */
590                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
591                         IRC_WriteStrChannelPrefix( Client, Channel, Origin, false, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
592                 }
593                 else
594                 {
595                         if ( use_servermode ) Origin = Client_ThisServer();
596
597                         /* Send reply to client and inform other servers and channel users */
598                         ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
599                         IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
600                         IRC_WriteStrChannelPrefix( Client, Channel, Origin, false, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
601                 }
602         }
603
604         IRC_SetPenalty( Client, 1 );
605         return CONNECTED;
606 } /* Channel_Mode */
607
608
609 GLOBAL bool
610 IRC_AWAY( CLIENT *Client, REQUEST *Req )
611 {
612         assert( Client != NULL );
613         assert( Req != NULL );
614
615         /* Falsche Anzahl Parameter? */
616         if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
617
618         if(( Req->argc == 1 ) && (Req->argv[0][0] ))
619         {
620                 /* AWAY setzen */
621                 Client_SetAway( Client, Req->argv[0] );
622                 Client_ModeAdd( Client, 'a' );
623                 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
624                 return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
625         }
626         else
627         {
628                 /* AWAY loeschen */
629                 Client_ModeDel( Client, 'a' );
630                 IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
631                 return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
632         }
633 } /* IRC_AWAY */
634
635
636 static bool
637 Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
638 {
639         char *mask;
640         bool already;
641
642         assert( Client != NULL );
643         assert( Channel != NULL );
644         assert( Pattern != NULL );
645
646         mask = Lists_MakeMask( Pattern );
647
648         already = Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask );
649         if (!already) {
650                 if( ! Channel_AddInvite(Channel, mask, false ))
651                         return CONNECTED;
652         }
653         if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER ))
654                 return CONNECTED;
655
656         return Send_ListChange( "+I", Prefix, Client, Channel, mask );
657 } /* Add_Invite */
658
659
660 static bool
661 Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
662 {
663         char *mask;
664         bool already;
665
666         assert( Client != NULL );
667         assert( Channel != NULL );
668         assert( Pattern != NULL );
669
670         mask = Lists_MakeMask( Pattern );
671
672         already = Lists_CheckDupeMask(Channel_GetListBans(Channel), mask );
673         if (!already) {
674                 if( ! Channel_AddBan(Channel, mask))
675                         return CONNECTED;
676         }
677         if ( already && ( Client_Type( Prefix ) == CLIENT_SERVER ))
678                 return CONNECTED;
679
680         return Send_ListChange( "+b", Prefix, Client, Channel, mask );
681 } /* Add_Ban */
682
683
684 static bool
685 Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
686 {
687         char *mask;
688
689         assert( Client != NULL );
690         assert( Channel != NULL );
691         assert( Pattern != NULL );
692
693         mask = Lists_MakeMask( Pattern );
694         Lists_Del(Channel_GetListInvites(Channel), mask);
695         return Send_ListChange( "-I", Prefix, Client, Channel, mask );
696 } /* Del_Invite */
697
698
699 static bool
700 Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
701 {
702         char *mask;
703
704         assert( Client != NULL );
705         assert( Channel != NULL );
706         assert( Pattern != NULL );
707
708         mask = Lists_MakeMask( Pattern );
709         Lists_Del(Channel_GetListBans(Channel), mask);
710         return Send_ListChange( "-b", Prefix, Client, Channel, mask );
711 } /* Del_Ban */
712
713
714 static bool
715 Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask )
716 {
717         /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
718
719         bool ok;
720
721         if( Client_Type( Client ) == CLIENT_USER )
722         {
723                 /* Bestaetigung an Client */
724                 ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
725         }
726         else ok = true;
727
728         /* an andere Server */
729         IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
730
731         /* und lokale User im Channel */
732         IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
733         
734         return ok;
735 } /* Send_ListChange */
736
737
738 /* -eof- */