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