2 c23199d9 2002-02-27 alex * ngIRCd -- The Next Generation IRC Daemon
3 c23199d9 2002-02-27 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
11 490f28ff 2002-12-12 alex * IRC commands for mode changes (MODE, AWAY, ...)
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 96747679 2004-04-25 alex static char UNUSED id[] = "$Id: irc-mode.c,v 1.35 2004/04/25 15:42:05 alex Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 c23199d9 2002-02-27 alex #include <assert.h>
21 69ad0e38 2002-12-16 alex #include <stdio.h>
22 69ad0e38 2002-12-16 alex #include <stdlib.h>
23 c23199d9 2002-02-27 alex #include <string.h>
25 c2f60abe 2002-05-27 alex #include "conn.h"
26 c2f60abe 2002-05-27 alex #include "client.h"
27 c23199d9 2002-02-27 alex #include "channel.h"
28 ca33cbda 2002-03-12 alex #include "defines.h"
29 c23199d9 2002-02-27 alex #include "irc-write.h"
30 19ac723e 2002-09-08 alex #include "lists.h"
31 c23199d9 2002-02-27 alex #include "log.h"
32 c2f60abe 2002-05-27 alex #include "parse.h"
33 c23199d9 2002-02-27 alex #include "messages.h"
34 7e1b3b91 2002-09-02 alex #include "resolve.h"
35 7e1b3b91 2002-09-02 alex #include "conf.h"
37 ca33cbda 2002-03-12 alex #include "exp.h"
38 c23199d9 2002-02-27 alex #include "irc-mode.h"
41 80c6dc86 2002-12-15 alex LOCAL BOOLEAN Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
42 80c6dc86 2002-12-15 alex LOCAL BOOLEAN Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
44 296ddebe 2002-09-08 alex LOCAL BOOLEAN Add_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
45 296ddebe 2002-09-08 alex LOCAL BOOLEAN Add_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
47 296ddebe 2002-09-08 alex LOCAL BOOLEAN Del_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
48 296ddebe 2002-09-08 alex LOCAL BOOLEAN Del_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern ));
50 296ddebe 2002-09-08 alex LOCAL BOOLEAN Send_ListChange PARAMS(( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask ));
53 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
54 c2f60abe 2002-05-27 alex IRC_MODE( CLIENT *Client, REQUEST *Req )
56 80c6dc86 2002-12-15 alex CLIENT *cl, *origin;
57 c23199d9 2002-02-27 alex CHANNEL *chan;
59 c23199d9 2002-02-27 alex assert( Client != NULL );
60 c23199d9 2002-02-27 alex assert( Req != NULL );
62 80c6dc86 2002-12-15 alex /* No parameters? */
63 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
65 80c6dc86 2002-12-15 alex /* Origin for answers */
66 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
68 80c6dc86 2002-12-15 alex origin = Client_Search( Req->prefix );
69 80c6dc86 2002-12-15 alex if( ! origin ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
71 80c6dc86 2002-12-15 alex else origin = Client;
73 80c6dc86 2002-12-15 alex /* Channel or user mode? */
74 80c6dc86 2002-12-15 alex cl = chan = NULL;
75 c23199d9 2002-02-27 alex if( Client_IsValidNick( Req->argv[0] )) cl = Client_Search( Req->argv[0] );
76 c23199d9 2002-02-27 alex if( Channel_IsValidName( Req->argv[0] )) chan = Channel_Search( Req->argv[0] );
78 80c6dc86 2002-12-15 alex if( cl ) return Client_Mode( Client, Req, origin, cl );
79 80c6dc86 2002-12-15 alex if( chan ) return Channel_Mode( Client, Req, origin, chan );
81 80c6dc86 2002-12-15 alex /* No target found! */
82 80c6dc86 2002-12-15 alex return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
83 80c6dc86 2002-12-15 alex } /* IRC_MODE */
86 80c6dc86 2002-12-15 alex LOCAL BOOLEAN
87 80c6dc86 2002-12-15 alex Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
89 80c6dc86 2002-12-15 alex /* Handle client mode requests */
91 80c6dc86 2002-12-15 alex CHAR the_modes[COMMAND_LEN], x[2], *mode_ptr;
92 80c6dc86 2002-12-15 alex BOOLEAN ok, set;
93 80c6dc86 2002-12-15 alex INT mode_arg;
95 80c6dc86 2002-12-15 alex /* Is the client allowed to request or change the modes? */
96 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_USER )
98 80c6dc86 2002-12-15 alex /* Users are only allowed to manipulate their own modes! */
99 80c6dc86 2002-12-15 alex if( Target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
102 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
103 80c6dc86 2002-12-15 alex if( Req->argc == 1 ) return IRC_WriteStrClient( Origin, RPL_UMODEIS_MSG, Client_ID( Origin ), Client_Modes( Target ));
105 80c6dc86 2002-12-15 alex mode_arg = 1;
106 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
108 80c6dc86 2002-12-15 alex /* Initial state: set or unset modes? */
109 80c6dc86 2002-12-15 alex if( *mode_ptr == '+' ) set = TRUE;
110 80c6dc86 2002-12-15 alex else if( *mode_ptr == '-' ) set = FALSE;
111 80c6dc86 2002-12-15 alex else return IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Origin ));
113 80c6dc86 2002-12-15 alex /* Prepare reply string */
114 80c6dc86 2002-12-15 alex if( set ) strcpy( the_modes, "+" );
115 80c6dc86 2002-12-15 alex else strcpy( the_modes, "-" );
117 80c6dc86 2002-12-15 alex x[1] = '\0';
118 80c6dc86 2002-12-15 alex ok = CONNECTED;
119 80c6dc86 2002-12-15 alex while( mode_ptr )
121 80c6dc86 2002-12-15 alex mode_ptr++;
122 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
124 80c6dc86 2002-12-15 alex /* Try next argument if there's any */
125 80c6dc86 2002-12-15 alex mode_arg++;
126 80c6dc86 2002-12-15 alex if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
127 80c6dc86 2002-12-15 alex else break;
130 80c6dc86 2002-12-15 alex switch( *mode_ptr )
134 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
136 80c6dc86 2002-12-15 alex /* Action modifier ("+"/"-") must be changed ... */
137 80c6dc86 2002-12-15 alex if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
139 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
140 80c6dc86 2002-12-15 alex the_modes[strlen( the_modes ) - 1] = *mode_ptr;
144 80c6dc86 2002-12-15 alex /* Append modifier character to result string */
145 6626395c 2002-12-26 alex x[0] = *mode_ptr;
146 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
148 80c6dc86 2002-12-15 alex if( *mode_ptr == '+' ) set = TRUE;
149 80c6dc86 2002-12-15 alex else set = FALSE;
154 7f61f413 2002-12-16 alex /* Validate modes */
155 80c6dc86 2002-12-15 alex x[0] = '\0';
156 7f61f413 2002-12-16 alex switch( *mode_ptr )
160 8c1df9ef 2003-01-02 alex if( Client_Type( Client ) == CLIENT_SERVER )
162 8c1df9ef 2003-01-02 alex x[0] = 'a';
163 8c1df9ef 2003-01-02 alex Client_SetAway( Client, DEFAULT_AWAY_MSG );
165 8841d873 2002-12-18 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
168 7f61f413 2002-12-16 alex /* Invisible */
169 7f61f413 2002-12-16 alex x[0] = 'i';
172 7f61f413 2002-12-16 alex /* IRC operator (only unsetable!) */
173 8841d873 2002-12-18 alex if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
175 7f61f413 2002-12-16 alex Client_SetOperByMe( Target, FALSE );
176 7f61f413 2002-12-16 alex x[0] = 'o';
178 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
181 7f61f413 2002-12-16 alex /* Restricted (only setable) */
182 8841d873 2002-12-18 alex if(( set ) || ( Client_Type( Client ) == CLIENT_SERVER )) x[0] = 'r';
183 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
186 7f61f413 2002-12-16 alex /* Server messages */
187 7f61f413 2002-12-16 alex x[0] = 's';
190 7f61f413 2002-12-16 alex Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ));
191 7f61f413 2002-12-16 alex if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
192 7f61f413 2002-12-16 alex x[0] = '\0';
193 69ad0e38 2002-12-16 alex goto client_exit;
195 80c6dc86 2002-12-15 alex if( ! ok ) break;
197 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
198 80c6dc86 2002-12-15 alex if( ! x[0] ) continue;
202 80c6dc86 2002-12-15 alex /* Set mode */
203 6626395c 2002-12-26 alex if( Client_ModeAdd( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
208 80c6dc86 2002-12-15 alex /* Unset mode */
209 6626395c 2002-12-26 alex if( Client_ModeDel( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
212 69ad0e38 2002-12-16 alex client_exit:
214 80c6dc86 2002-12-15 alex /* Are there changed modes? */
215 80c6dc86 2002-12-15 alex if( the_modes[1] )
217 80c6dc86 2002-12-15 alex /* Remoce needless action modifier characters */
218 80c6dc86 2002-12-15 alex if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' )) the_modes[strlen( the_modes ) - 1] = '\0';
220 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
222 80c6dc86 2002-12-15 alex /* Forward modes to other servers */
223 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
227 80c6dc86 2002-12-15 alex /* Send reply to client and inform other servers */
228 56227abc 2004-02-29 alex ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
229 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
231 80c6dc86 2002-12-15 alex Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( Target ), Client_Modes( Target ));
234 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
236 80c6dc86 2002-12-15 alex } /* Client_Mode */
239 80c6dc86 2002-12-15 alex LOCAL BOOLEAN
240 80c6dc86 2002-12-15 alex Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
242 80c6dc86 2002-12-15 alex /* Handle channel and channel-user modes */
244 69ad0e38 2002-12-16 alex CHAR the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
245 80c6dc86 2002-12-15 alex BOOLEAN ok, set, modeok, skiponce;
246 80c6dc86 2002-12-15 alex INT mode_arg, arg_arg;
247 80c6dc86 2002-12-15 alex CLIENT *client;
250 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
251 df00b38a 2003-01-08 alex if( Req->argc == 1 )
253 df00b38a 2003-01-08 alex /* Member or not? -- That's the question! */
254 df00b38a 2003-01-08 alex if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), Channel_Modes( Channel ));
256 df00b38a 2003-01-08 alex /* The sender is a member: generate extended reply */
257 df00b38a 2003-01-08 alex strlcpy( the_modes, Channel_Modes( Channel ), sizeof( the_modes ));
258 df00b38a 2003-01-08 alex mode_ptr = the_modes;
259 df00b38a 2003-01-08 alex strcpy( the_args, "" );
260 df00b38a 2003-01-08 alex while( *mode_ptr )
262 df00b38a 2003-01-08 alex switch( *mode_ptr )
265 df00b38a 2003-01-08 alex snprintf( argadd, sizeof( argadd ), " %ld", Channel_MaxUsers( Channel ));
266 df00b38a 2003-01-08 alex strlcat( the_args, argadd, sizeof( the_args ));
269 df00b38a 2003-01-08 alex strlcat( the_args, " ", sizeof( the_args ));
270 df00b38a 2003-01-08 alex strlcat( the_args, Channel_Key( Channel ), sizeof( the_args ));
273 df00b38a 2003-01-08 alex mode_ptr++;
275 df00b38a 2003-01-08 alex if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
277 df00b38a 2003-01-08 alex return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
280 80c6dc86 2002-12-15 alex /* Is the user allowed to change modes? */
281 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_USER )
283 e07542a1 2003-01-17 alex /* Is the originating user on that channel? */
284 e07542a1 2003-01-17 alex if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Channel_Name( Channel ));
286 e07542a1 2003-01-17 alex /* Is he channel operator? */
287 80c6dc86 2002-12-15 alex if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = TRUE;
288 80c6dc86 2002-12-15 alex else modeok = FALSE;
289 80c6dc86 2002-12-15 alex if( Conf_OperCanMode )
291 80c6dc86 2002-12-15 alex /* auch IRC-Operatoren duerfen MODE verwenden */
292 80c6dc86 2002-12-15 alex if( Client_OperByMe( Origin )) modeok = TRUE;
295 80c6dc86 2002-12-15 alex else modeok = TRUE;
297 80c6dc86 2002-12-15 alex mode_arg = 1;
298 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
299 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
300 80c6dc86 2002-12-15 alex else arg_arg = -1;
302 80c6dc86 2002-12-15 alex /* Initial state: set or unset modes? */
303 80c6dc86 2002-12-15 alex skiponce = FALSE;
304 80c6dc86 2002-12-15 alex if( *mode_ptr == '-' ) set = FALSE;
305 80c6dc86 2002-12-15 alex else if( *mode_ptr == '+' ) set = TRUE;
306 80c6dc86 2002-12-15 alex else set = skiponce = TRUE;
308 80c6dc86 2002-12-15 alex /* Prepare reply string */
309 c23199d9 2002-02-27 alex if( set ) strcpy( the_modes, "+" );
310 c23199d9 2002-02-27 alex else strcpy( the_modes, "-" );
311 80c6dc86 2002-12-15 alex strcpy( the_args, " " );
313 c23199d9 2002-02-27 alex x[1] = '\0';
314 80c6dc86 2002-12-15 alex ok = CONNECTED;
315 80c6dc86 2002-12-15 alex while( mode_ptr )
317 80c6dc86 2002-12-15 alex if( ! skiponce ) mode_ptr++;
318 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
320 80c6dc86 2002-12-15 alex /* Try next argument if there's any */
321 80c6dc86 2002-12-15 alex if( arg_arg > mode_arg ) mode_arg = arg_arg;
322 80c6dc86 2002-12-15 alex else mode_arg++;
323 80c6dc86 2002-12-15 alex if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
324 80c6dc86 2002-12-15 alex else break;
325 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
326 80c6dc86 2002-12-15 alex else arg_arg = -1;
328 80c6dc86 2002-12-15 alex skiponce = FALSE;
330 80c6dc86 2002-12-15 alex switch( *mode_ptr )
334 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
336 80c6dc86 2002-12-15 alex /* Action modifier ("+"/"-") must be changed ... */
337 80c6dc86 2002-12-15 alex if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
339 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
340 80c6dc86 2002-12-15 alex the_modes[strlen( the_modes ) - 1] = *mode_ptr;
344 80c6dc86 2002-12-15 alex /* Append modifier character to result string */
345 6626395c 2002-12-26 alex x[0] = *mode_ptr;
346 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
348 80c6dc86 2002-12-15 alex if( *mode_ptr == '+' ) set = TRUE;
349 80c6dc86 2002-12-15 alex else set = FALSE;
354 80c6dc86 2002-12-15 alex /* Are there arguments left? */
355 80c6dc86 2002-12-15 alex if( arg_arg >= Req->argc ) arg_arg = -1;
357 7f61f413 2002-12-16 alex /* Validate modes */
358 c23199d9 2002-02-27 alex x[0] = '\0';
359 69ad0e38 2002-12-16 alex argadd[0] = '\0';
360 80c6dc86 2002-12-15 alex client = NULL;
361 7f61f413 2002-12-16 alex switch( *mode_ptr )
363 7f61f413 2002-12-16 alex /* Channel modes */
365 7f61f413 2002-12-16 alex /* Invite-Only */
366 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'i';
367 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
370 7f61f413 2002-12-16 alex /* Moderated */
371 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'm';
372 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
375 7f61f413 2002-12-16 alex /* kein Schreiben in den Channel von aussen */
376 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'n';
377 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
380 7f61f413 2002-12-16 alex /* Topic Lock */
381 7f61f413 2002-12-16 alex if( modeok ) x[0] = 't';
382 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
385 7f61f413 2002-12-16 alex /* Persistent channel */
386 7f61f413 2002-12-16 alex if( modeok )
388 7f61f413 2002-12-16 alex if( set && ( ! Client_OperByMe( Client )))
390 7f61f413 2002-12-16 alex /* Only IRC operators are allowed to set P mode */
391 7f61f413 2002-12-16 alex ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
393 7f61f413 2002-12-16 alex else x[0] = 'P';
395 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
398 7f61f413 2002-12-16 alex /* Channel user modes */
400 7f61f413 2002-12-16 alex /* Channel operator */
402 7f61f413 2002-12-16 alex /* Voice */
403 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
405 80c6dc86 2002-12-15 alex if( modeok )
407 7f61f413 2002-12-16 alex client = Client_Search( Req->argv[arg_arg] );
408 7f61f413 2002-12-16 alex if( client ) x[0] = *mode_ptr;
409 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
411 80c6dc86 2002-12-15 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
412 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
415 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
418 69ad0e38 2002-12-16 alex /* Channel key */
419 69ad0e38 2002-12-16 alex if( ! set )
421 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
422 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
425 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
427 69ad0e38 2002-12-16 alex if( modeok )
429 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'k' );
430 69ad0e38 2002-12-16 alex Channel_SetKey( Channel, Req->argv[arg_arg] );
431 695631b2 2002-12-26 alex strlcpy( argadd, Channel_Key( Channel ), sizeof( argadd ));
432 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
434 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
435 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
438 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
441 69ad0e38 2002-12-16 alex /* Member limit */
442 69ad0e38 2002-12-16 alex if( ! set )
444 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
445 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
448 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
450 69ad0e38 2002-12-16 alex if( modeok )
452 69ad0e38 2002-12-16 alex l = atol( Req->argv[arg_arg] );
453 69ad0e38 2002-12-16 alex if( l > 0 && l < 0xFFFF )
455 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'l' );
456 69ad0e38 2002-12-16 alex Channel_SetMaxUsers( Channel, l );
457 b316c380 2002-12-26 alex snprintf( argadd, sizeof( argadd ), "%ld", l );
458 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
461 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
462 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
465 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
468 7f61f413 2002-12-16 alex /* Channel lists */
470 7f61f413 2002-12-16 alex /* Invite lists */
471 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
473 7f61f413 2002-12-16 alex /* modify list */
474 7f61f413 2002-12-16 alex if( modeok )
476 7f61f413 2002-12-16 alex if( set ) Add_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
477 7f61f413 2002-12-16 alex else Del_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
479 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
480 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
483 7f61f413 2002-12-16 alex else Lists_ShowInvites( Origin, Channel );
486 7f61f413 2002-12-16 alex /* Ban lists */
487 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
489 7f61f413 2002-12-16 alex /* modify list */
490 7f61f413 2002-12-16 alex if( modeok )
492 7f61f413 2002-12-16 alex if( set ) Add_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
493 7f61f413 2002-12-16 alex else Del_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
495 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
496 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
499 7f61f413 2002-12-16 alex else Lists_ShowBans( Origin, Channel );
503 7f61f413 2002-12-16 alex Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\" on %s!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ), Channel_Name( Channel ));
504 7f61f413 2002-12-16 alex if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
505 7f61f413 2002-12-16 alex x[0] = '\0';
506 69ad0e38 2002-12-16 alex goto chan_exit;
508 c23199d9 2002-02-27 alex if( ! ok ) break;
510 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
511 c23199d9 2002-02-27 alex if( ! x[0] ) continue;
513 fbec1f10 2003-01-21 alex /* Validate target client */
514 fbec1f10 2003-01-21 alex if( client && ( ! Channel_IsMemberOf( Channel, client )))
516 fbec1f10 2003-01-21 alex if( ! IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( client ), Channel_Name( Channel ))) break;
522 80c6dc86 2002-12-15 alex /* Set mode */
523 80c6dc86 2002-12-15 alex if( client )
525 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
526 80c6dc86 2002-12-15 alex if( Channel_UserModeAdd( Channel, client, x[0] ))
528 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
529 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
530 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
531 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
536 80c6dc86 2002-12-15 alex /* Channel-Mode */
537 c0d74a38 2002-12-15 alex if( Channel_ModeAdd( Channel, x[0] ))
539 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
540 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
546 80c6dc86 2002-12-15 alex /* Unset mode */
547 80c6dc86 2002-12-15 alex if( client )
549 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
550 80c6dc86 2002-12-15 alex if( Channel_UserModeDel( Channel, client, x[0] ))
552 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
553 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
554 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
555 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"", Client_Mask( client ), Channel_Name( Channel ), Channel_UserModes( Channel, client ));
560 c23199d9 2002-02-27 alex /* Channel-Mode */
561 c0d74a38 2002-12-15 alex if( Channel_ModeDel( Channel, x[0] ))
563 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
564 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
569 69ad0e38 2002-12-16 alex /* Are there additional arguments to add? */
570 69ad0e38 2002-12-16 alex if( argadd[0] )
572 6626395c 2002-12-26 alex if( the_args[strlen( the_args ) - 1] != ' ' ) strlcat( the_args, " ", sizeof( the_args ));
573 6626395c 2002-12-26 alex strlcat( the_args, argadd, sizeof( the_args ));
578 80c6dc86 2002-12-15 alex /* Are there changed modes? */
579 c23199d9 2002-02-27 alex if( the_modes[1] )
581 c0d74a38 2002-12-15 alex /* Clean up mode string */
582 c0d74a38 2002-12-15 alex if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' )) the_modes[strlen( the_modes ) - 1] = '\0';
584 80c6dc86 2002-12-15 alex /* Clean up argument string if there are none */
585 80c6dc86 2002-12-15 alex if( ! the_args[1] ) the_args[0] = '\0';
587 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
589 80c6dc86 2002-12-15 alex /* Forward mode changes to channel users and other servers */
590 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
591 80c6dc86 2002-12-15 alex IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
595 80c6dc86 2002-12-15 alex /* Send reply to client and inform other servers and channel users */
596 80c6dc86 2002-12-15 alex ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
597 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
598 80c6dc86 2002-12-15 alex IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
602 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
603 80c6dc86 2002-12-15 alex return CONNECTED;
604 80c6dc86 2002-12-15 alex } /* Channel_Mode */
607 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
608 c2f60abe 2002-05-27 alex IRC_AWAY( CLIENT *Client, REQUEST *Req )
610 c23199d9 2002-02-27 alex assert( Client != NULL );
611 c23199d9 2002-02-27 alex assert( Req != NULL );
613 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
614 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
616 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
618 c23199d9 2002-02-27 alex /* AWAY setzen */
619 c23199d9 2002-02-27 alex Client_SetAway( Client, Req->argv[0] );
620 8c1df9ef 2003-01-02 alex Client_ModeAdd( Client, 'a' );
621 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
622 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
626 c23199d9 2002-02-27 alex /* AWAY loeschen */
627 8c1df9ef 2003-01-02 alex Client_ModeDel( Client, 'a' );
628 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
629 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
631 c23199d9 2002-02-27 alex } /* IRC_AWAY */
634 19ac723e 2002-09-08 alex LOCAL BOOLEAN
635 296ddebe 2002-09-08 alex Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
637 19ac723e 2002-09-08 alex CHAR *mask;
638 96747679 2004-04-25 alex BOOLEAN already;
640 19ac723e 2002-09-08 alex assert( Client != NULL );
641 19ac723e 2002-09-08 alex assert( Channel != NULL );
642 19ac723e 2002-09-08 alex assert( Pattern != NULL );
644 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
646 96747679 2004-04-25 alex already = Lists_IsInviteEntry( mask, Channel );
648 64d330b7 2004-04-09 alex if( ! Lists_AddInvited( mask, Channel, FALSE )) return CONNECTED;
650 96747679 2004-04-25 alex if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == TRUE )) return CONNECTED;
652 296ddebe 2002-09-08 alex return Send_ListChange( "+I", Prefix, Client, Channel, mask );
653 19ac723e 2002-09-08 alex } /* Add_Invite */
656 19ac723e 2002-09-08 alex LOCAL BOOLEAN
657 296ddebe 2002-09-08 alex Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
659 19ac723e 2002-09-08 alex CHAR *mask;
660 96747679 2004-04-25 alex BOOLEAN already;
662 19ac723e 2002-09-08 alex assert( Client != NULL );
663 19ac723e 2002-09-08 alex assert( Channel != NULL );
664 19ac723e 2002-09-08 alex assert( Pattern != NULL );
666 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
668 96747679 2004-04-25 alex already = Lists_IsBanEntry( mask, Channel );
670 64d330b7 2004-04-09 alex if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
672 96747679 2004-04-25 alex if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == TRUE )) return CONNECTED;
674 296ddebe 2002-09-08 alex return Send_ListChange( "+b", Prefix, Client, Channel, mask );
675 19ac723e 2002-09-08 alex } /* Add_Ban */
678 19ac723e 2002-09-08 alex LOCAL BOOLEAN
679 296ddebe 2002-09-08 alex Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
681 19ac723e 2002-09-08 alex CHAR *mask;
683 19ac723e 2002-09-08 alex assert( Client != NULL );
684 19ac723e 2002-09-08 alex assert( Channel != NULL );
685 19ac723e 2002-09-08 alex assert( Pattern != NULL );
687 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
688 19ac723e 2002-09-08 alex Lists_DelInvited( mask, Channel );
689 296ddebe 2002-09-08 alex return Send_ListChange( "-I", Prefix, Client, Channel, mask );
690 19ac723e 2002-09-08 alex } /* Del_Invite */
693 19ac723e 2002-09-08 alex LOCAL BOOLEAN
694 296ddebe 2002-09-08 alex Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
696 19ac723e 2002-09-08 alex CHAR *mask;
698 19ac723e 2002-09-08 alex assert( Client != NULL );
699 19ac723e 2002-09-08 alex assert( Channel != NULL );
700 19ac723e 2002-09-08 alex assert( Pattern != NULL );
702 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
703 19ac723e 2002-09-08 alex Lists_DelBanned( mask, Channel );
704 296ddebe 2002-09-08 alex return Send_ListChange( "-b", Prefix, Client, Channel, mask );
705 296ddebe 2002-09-08 alex } /* Del_Ban */
708 296ddebe 2002-09-08 alex LOCAL BOOLEAN
709 296ddebe 2002-09-08 alex Send_ListChange( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask )
711 296ddebe 2002-09-08 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
713 296ddebe 2002-09-08 alex BOOLEAN ok;
715 19ac723e 2002-09-08 alex if( Client_Type( Client ) == CLIENT_USER )
717 296ddebe 2002-09-08 alex /* Bestaetigung an Client */
718 296ddebe 2002-09-08 alex ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
720 296ddebe 2002-09-08 alex else ok = TRUE;
722 296ddebe 2002-09-08 alex /* an andere Server */
723 296ddebe 2002-09-08 alex IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
725 296ddebe 2002-09-08 alex /* und lokale User im Channel */
726 296ddebe 2002-09-08 alex IRC_WriteStrChannelPrefix( Client, Channel, Prefix, FALSE, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
729 296ddebe 2002-09-08 alex } /* Send_ListChange */
732 c23199d9 2002-02-27 alex /* -eof- */