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