2 c23199d9 2002-02-27 alex * ngIRCd -- The Next Generation IRC Daemon
3 8579b2a1 2005-02-27 alex * Copyright (c)2001-2005 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 dd9b4bc9 2005-05-14 alex static char UNUSED id[] = "$Id: irc-mode.c,v 1.42 2005/05/14 20:29:34 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 aa25cd7d 2005-04-27 alex #include "defines.h"
26 c2f60abe 2002-05-27 alex #include "conn.h"
27 c2f60abe 2002-05-27 alex #include "client.h"
28 c23199d9 2002-02-27 alex #include "channel.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 8adff592 2005-03-19 fw LOCAL bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
42 8adff592 2005-03-19 fw LOCAL bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
44 8adff592 2005-03-19 fw LOCAL bool Add_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
45 8adff592 2005-03-19 fw LOCAL bool Add_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
47 8adff592 2005-03-19 fw LOCAL bool Del_Invite PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
48 8adff592 2005-03-19 fw LOCAL bool Del_Ban PARAMS(( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern ));
50 8adff592 2005-03-19 fw LOCAL bool Send_ListChange PARAMS(( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask ));
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 */
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 8adff592 2005-03-19 fw char the_modes[COMMAND_LEN], x[2], *mode_ptr;
96 80c6dc86 2002-12-15 alex /* Is the client allowed to request or change the modes? */
97 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_USER )
99 80c6dc86 2002-12-15 alex /* Users are only allowed to manipulate their own modes! */
100 80c6dc86 2002-12-15 alex if( Target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
103 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
104 80c6dc86 2002-12-15 alex if( Req->argc == 1 ) return IRC_WriteStrClient( Origin, RPL_UMODEIS_MSG, Client_ID( Origin ), Client_Modes( Target ));
106 80c6dc86 2002-12-15 alex mode_arg = 1;
107 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
109 80c6dc86 2002-12-15 alex /* Initial state: set or unset modes? */
110 8adff592 2005-03-19 fw if( *mode_ptr == '+' ) set = true;
111 8adff592 2005-03-19 fw else if( *mode_ptr == '-' ) set = false;
112 80c6dc86 2002-12-15 alex else return IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Origin ));
114 80c6dc86 2002-12-15 alex /* Prepare reply string */
115 80c6dc86 2002-12-15 alex if( set ) strcpy( the_modes, "+" );
116 80c6dc86 2002-12-15 alex else strcpy( the_modes, "-" );
118 80c6dc86 2002-12-15 alex x[1] = '\0';
119 80c6dc86 2002-12-15 alex ok = CONNECTED;
120 80c6dc86 2002-12-15 alex while( mode_ptr )
122 80c6dc86 2002-12-15 alex mode_ptr++;
123 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
125 80c6dc86 2002-12-15 alex /* Try next argument if there's any */
126 80c6dc86 2002-12-15 alex mode_arg++;
127 80c6dc86 2002-12-15 alex if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
128 80c6dc86 2002-12-15 alex else break;
131 80c6dc86 2002-12-15 alex switch( *mode_ptr )
135 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
137 80c6dc86 2002-12-15 alex /* Action modifier ("+"/"-") must be changed ... */
138 e6180411 2005-03-05 alex len = strlen( the_modes ) - 1;
139 e6180411 2005-03-05 alex if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' ))
141 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
142 e6180411 2005-03-05 alex the_modes[len] = *mode_ptr;
146 80c6dc86 2002-12-15 alex /* Append modifier character to result string */
147 6626395c 2002-12-26 alex x[0] = *mode_ptr;
148 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
150 8adff592 2005-03-19 fw if( *mode_ptr == '+' ) set = true;
151 8adff592 2005-03-19 fw else set = false;
156 7f61f413 2002-12-16 alex /* Validate modes */
157 80c6dc86 2002-12-15 alex x[0] = '\0';
158 7f61f413 2002-12-16 alex switch( *mode_ptr )
160 8579b2a1 2005-02-27 alex case 'i': /* Invisible */
161 8579b2a1 2005-02-27 alex case 's': /* Server messages */
162 8579b2a1 2005-02-27 alex x[0] = *mode_ptr;
165 8579b2a1 2005-02-27 alex case 'a': /* Away */
166 8c1df9ef 2003-01-02 alex if( Client_Type( Client ) == CLIENT_SERVER )
168 8c1df9ef 2003-01-02 alex x[0] = 'a';
169 dd9b4bc9 2005-05-14 alex Client_SetAway( Origin, DEFAULT_AWAY_MSG );
171 8841d873 2002-12-18 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
174 8579b2a1 2005-02-27 alex case 'o': /* IRC operator (only unsettable!) */
175 8841d873 2002-12-18 alex if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
177 8adff592 2005-03-19 fw Client_SetOperByMe( Target, false );
178 7f61f413 2002-12-16 alex x[0] = 'o';
180 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
183 8579b2a1 2005-02-27 alex case 'r': /* Restricted (only settable) */
184 8841d873 2002-12-18 alex if(( set ) || ( Client_Type( Client ) == CLIENT_SERVER )) x[0] = 'r';
185 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
189 7f61f413 2002-12-16 alex Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Origin ));
190 7f61f413 2002-12-16 alex if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
191 7f61f413 2002-12-16 alex x[0] = '\0';
192 69ad0e38 2002-12-16 alex goto client_exit;
194 80c6dc86 2002-12-15 alex if( ! ok ) break;
196 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
197 80c6dc86 2002-12-15 alex if( ! x[0] ) continue;
201 80c6dc86 2002-12-15 alex /* Set mode */
202 6626395c 2002-12-26 alex if( Client_ModeAdd( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
207 80c6dc86 2002-12-15 alex /* Unset mode */
208 6626395c 2002-12-26 alex if( Client_ModeDel( Target, x[0] )) strlcat( the_modes, x, sizeof( the_modes ));
211 69ad0e38 2002-12-16 alex client_exit:
213 80c6dc86 2002-12-15 alex /* Are there changed modes? */
214 80c6dc86 2002-12-15 alex if( the_modes[1] )
216 80c6dc86 2002-12-15 alex /* Remoce needless action modifier characters */
217 e6180411 2005-03-05 alex len = strlen( the_modes ) - 1;
218 e6180411 2005-03-05 alex if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' )) the_modes[len] = '\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 */
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 8adff592 2005-03-19 fw char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
245 8adff592 2005-03-19 fw bool ok, set, modeok = false, skiponce, use_servermode = false;
246 8adff592 2005-03-19 fw int mode_arg, arg_arg;
247 80c6dc86 2002-12-15 alex CLIENT *client;
249 e6180411 2005-03-05 alex size_t len;
251 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
252 df00b38a 2003-01-08 alex if( Req->argc == 1 )
254 df00b38a 2003-01-08 alex /* Member or not? -- That's the question! */
255 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 ));
257 df00b38a 2003-01-08 alex /* The sender is a member: generate extended reply */
258 df00b38a 2003-01-08 alex strlcpy( the_modes, Channel_Modes( Channel ), sizeof( the_modes ));
259 df00b38a 2003-01-08 alex mode_ptr = the_modes;
260 df00b38a 2003-01-08 alex strcpy( the_args, "" );
261 df00b38a 2003-01-08 alex while( *mode_ptr )
263 df00b38a 2003-01-08 alex switch( *mode_ptr )
266 df00b38a 2003-01-08 alex snprintf( argadd, sizeof( argadd ), " %ld", Channel_MaxUsers( Channel ));
267 df00b38a 2003-01-08 alex strlcat( the_args, argadd, sizeof( the_args ));
270 df00b38a 2003-01-08 alex strlcat( the_args, " ", sizeof( the_args ));
271 df00b38a 2003-01-08 alex strlcat( the_args, Channel_Key( Channel ), sizeof( the_args ));
274 df00b38a 2003-01-08 alex mode_ptr++;
276 df00b38a 2003-01-08 alex if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
278 df00b38a 2003-01-08 alex return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
281 80c6dc86 2002-12-15 alex /* Is the user allowed to change modes? */
282 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_USER )
284 e07542a1 2003-01-17 alex /* Is the originating user on that channel? */
285 e07542a1 2003-01-17 alex if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Channel_Name( Channel ));
287 e07542a1 2003-01-17 alex /* Is he channel operator? */
288 8adff592 2005-03-19 fw if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = true;
289 1d08d51e 2005-03-15 alex else if( Conf_OperCanMode )
291 1d08d51e 2005-03-15 alex /* IRC-Operators can use MODE as well */
292 1d08d51e 2005-03-15 alex if( Client_OperByMe( Origin )) {
293 8adff592 2005-03-19 fw modeok = true;
294 8adff592 2005-03-19 fw if ( Conf_OperServerMode ) use_servermode = true; /* Change Origin to Server */
298 8adff592 2005-03-19 fw else modeok = true;
300 80c6dc86 2002-12-15 alex mode_arg = 1;
301 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
302 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
303 80c6dc86 2002-12-15 alex else arg_arg = -1;
305 80c6dc86 2002-12-15 alex /* Initial state: set or unset modes? */
306 8adff592 2005-03-19 fw skiponce = false;
307 8adff592 2005-03-19 fw if( *mode_ptr == '-' ) set = false;
308 8adff592 2005-03-19 fw else if( *mode_ptr == '+' ) set = true;
309 8adff592 2005-03-19 fw else set = skiponce = true;
311 80c6dc86 2002-12-15 alex /* Prepare reply string */
312 c23199d9 2002-02-27 alex if( set ) strcpy( the_modes, "+" );
313 c23199d9 2002-02-27 alex else strcpy( the_modes, "-" );
314 80c6dc86 2002-12-15 alex strcpy( the_args, " " );
316 c23199d9 2002-02-27 alex x[1] = '\0';
317 80c6dc86 2002-12-15 alex ok = CONNECTED;
318 80c6dc86 2002-12-15 alex while( mode_ptr )
320 80c6dc86 2002-12-15 alex if( ! skiponce ) mode_ptr++;
321 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
323 80c6dc86 2002-12-15 alex /* Try next argument if there's any */
324 80c6dc86 2002-12-15 alex if( arg_arg > mode_arg ) mode_arg = arg_arg;
325 80c6dc86 2002-12-15 alex else mode_arg++;
326 80c6dc86 2002-12-15 alex if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
327 80c6dc86 2002-12-15 alex else break;
328 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
329 80c6dc86 2002-12-15 alex else arg_arg = -1;
331 8adff592 2005-03-19 fw skiponce = false;
333 80c6dc86 2002-12-15 alex switch( *mode_ptr )
337 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
339 80c6dc86 2002-12-15 alex /* Action modifier ("+"/"-") must be changed ... */
340 e6180411 2005-03-05 alex len = strlen( the_modes ) - 1;
341 e6180411 2005-03-05 alex if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' ))
343 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
344 e6180411 2005-03-05 alex the_modes[len] = *mode_ptr;
348 80c6dc86 2002-12-15 alex /* Append modifier character to result string */
349 6626395c 2002-12-26 alex x[0] = *mode_ptr;
350 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
352 8adff592 2005-03-19 fw if( *mode_ptr == '+' ) set = true;
353 8adff592 2005-03-19 fw else set = false;
358 80c6dc86 2002-12-15 alex /* Are there arguments left? */
359 80c6dc86 2002-12-15 alex if( arg_arg >= Req->argc ) arg_arg = -1;
361 7f61f413 2002-12-16 alex /* Validate modes */
362 c23199d9 2002-02-27 alex x[0] = '\0';
363 69ad0e38 2002-12-16 alex argadd[0] = '\0';
364 80c6dc86 2002-12-15 alex client = NULL;
365 7f61f413 2002-12-16 alex switch( *mode_ptr )
367 8579b2a1 2005-02-27 alex /* --- Channel modes --- */
369 8579b2a1 2005-02-27 alex case 'i': /* Invite only */
370 8579b2a1 2005-02-27 alex case 'm': /* Moderated */
371 8579b2a1 2005-02-27 alex case 'n': /* Only members can write */
372 4ef172d6 2005-03-02 alex case 's': /* Secret channel */
373 8579b2a1 2005-02-27 alex case 't': /* Topic locked */
374 8579b2a1 2005-02-27 alex if( modeok ) x[0] = *mode_ptr;
375 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
378 8579b2a1 2005-02-27 alex case 'k': /* Channel key */
379 69ad0e38 2002-12-16 alex if( ! set )
381 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
382 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
385 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
387 69ad0e38 2002-12-16 alex if( modeok )
389 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'k' );
390 69ad0e38 2002-12-16 alex Channel_SetKey( Channel, Req->argv[arg_arg] );
391 695631b2 2002-12-26 alex strlcpy( argadd, Channel_Key( Channel ), sizeof( argadd ));
392 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
394 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
395 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
398 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
401 8579b2a1 2005-02-27 alex case 'l': /* Member limit */
402 69ad0e38 2002-12-16 alex if( ! set )
404 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
405 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
408 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
410 69ad0e38 2002-12-16 alex if( modeok )
412 69ad0e38 2002-12-16 alex l = atol( Req->argv[arg_arg] );
413 69ad0e38 2002-12-16 alex if( l > 0 && l < 0xFFFF )
415 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'l' );
416 69ad0e38 2002-12-16 alex Channel_SetMaxUsers( Channel, l );
417 b316c380 2002-12-26 alex snprintf( argadd, sizeof( argadd ), "%ld", l );
418 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
421 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
422 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
425 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
428 8579b2a1 2005-02-27 alex case 'P': /* Persistent channel */
429 8579b2a1 2005-02-27 alex if( modeok )
431 8579b2a1 2005-02-27 alex if( set && ( ! Client_OperByMe( Client )))
433 8579b2a1 2005-02-27 alex /* Only IRC operators are allowed to set P mode */
434 8579b2a1 2005-02-27 alex ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
436 8579b2a1 2005-02-27 alex else x[0] = 'P';
438 8579b2a1 2005-02-27 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
441 8579b2a1 2005-02-27 alex /* --- Channel user modes --- */
443 8579b2a1 2005-02-27 alex case 'o': /* Channel operator */
444 8579b2a1 2005-02-27 alex case 'v': /* Voice */
445 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
447 8579b2a1 2005-02-27 alex if( modeok )
449 8579b2a1 2005-02-27 alex client = Client_Search( Req->argv[arg_arg] );
450 8579b2a1 2005-02-27 alex if( client ) x[0] = *mode_ptr;
451 8579b2a1 2005-02-27 alex else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
453 8579b2a1 2005-02-27 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
454 8579b2a1 2005-02-27 alex Req->argv[arg_arg][0] = '\0';
457 8579b2a1 2005-02-27 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
460 8579b2a1 2005-02-27 alex /* --- Channel lists --- */
462 8579b2a1 2005-02-27 alex case 'I': /* Invite lists */
463 8579b2a1 2005-02-27 alex if( arg_arg > mode_arg )
465 7f61f413 2002-12-16 alex /* modify list */
466 7f61f413 2002-12-16 alex if( modeok )
468 7f61f413 2002-12-16 alex if( set ) Add_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
469 7f61f413 2002-12-16 alex else Del_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
471 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
472 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
475 7f61f413 2002-12-16 alex else Lists_ShowInvites( Origin, Channel );
478 8579b2a1 2005-02-27 alex case 'b': /* Ban lists */
479 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
481 7f61f413 2002-12-16 alex /* modify list */
482 7f61f413 2002-12-16 alex if( modeok )
484 7f61f413 2002-12-16 alex if( set ) Add_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
485 7f61f413 2002-12-16 alex else Del_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
487 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
488 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
491 7f61f413 2002-12-16 alex else Lists_ShowBans( Origin, Channel );
495 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 ));
496 7f61f413 2002-12-16 alex if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
497 7f61f413 2002-12-16 alex x[0] = '\0';
498 69ad0e38 2002-12-16 alex goto chan_exit;
500 c23199d9 2002-02-27 alex if( ! ok ) break;
502 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
503 c23199d9 2002-02-27 alex if( ! x[0] ) continue;
505 fbec1f10 2003-01-21 alex /* Validate target client */
506 fbec1f10 2003-01-21 alex if( client && ( ! Channel_IsMemberOf( Channel, client )))
508 fbec1f10 2003-01-21 alex if( ! IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( client ), Channel_Name( Channel ))) break;
514 80c6dc86 2002-12-15 alex /* Set mode */
515 80c6dc86 2002-12-15 alex if( client )
517 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
518 80c6dc86 2002-12-15 alex if( Channel_UserModeAdd( Channel, client, x[0] ))
520 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
521 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
522 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
523 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 ));
528 80c6dc86 2002-12-15 alex /* Channel-Mode */
529 c0d74a38 2002-12-15 alex if( Channel_ModeAdd( Channel, x[0] ))
531 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
532 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
538 80c6dc86 2002-12-15 alex /* Unset mode */
539 80c6dc86 2002-12-15 alex if( client )
541 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
542 80c6dc86 2002-12-15 alex if( Channel_UserModeDel( Channel, client, x[0] ))
544 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
545 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
546 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
547 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 ));
552 c23199d9 2002-02-27 alex /* Channel-Mode */
553 c0d74a38 2002-12-15 alex if( Channel_ModeDel( Channel, x[0] ))
555 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
556 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
561 69ad0e38 2002-12-16 alex /* Are there additional arguments to add? */
562 69ad0e38 2002-12-16 alex if( argadd[0] )
564 e6180411 2005-03-05 alex len = strlen( the_args ) - 1;
565 e6180411 2005-03-05 alex if( the_args[len] != ' ' ) strlcat( the_args, " ", sizeof( the_args ));
566 6626395c 2002-12-26 alex strlcat( the_args, argadd, sizeof( the_args ));
571 80c6dc86 2002-12-15 alex /* Are there changed modes? */
572 c23199d9 2002-02-27 alex if( the_modes[1] )
574 c0d74a38 2002-12-15 alex /* Clean up mode string */
575 e6180411 2005-03-05 alex len = strlen( the_modes ) - 1;
576 e6180411 2005-03-05 alex if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' )) the_modes[len] = '\0';
578 80c6dc86 2002-12-15 alex /* Clean up argument string if there are none */
579 80c6dc86 2002-12-15 alex if( ! the_args[1] ) the_args[0] = '\0';
581 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
583 80c6dc86 2002-12-15 alex /* Forward mode changes to channel users and other servers */
584 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
585 8adff592 2005-03-19 fw IRC_WriteStrChannelPrefix( Client, Channel, Origin, false, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
589 1d08d51e 2005-03-15 alex if ( use_servermode ) Origin = Client_ThisServer();
591 80c6dc86 2002-12-15 alex /* Send reply to client and inform other servers and channel users */
592 80c6dc86 2002-12-15 alex ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
593 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
594 8adff592 2005-03-19 fw IRC_WriteStrChannelPrefix( Client, Channel, Origin, false, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
598 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
599 80c6dc86 2002-12-15 alex return CONNECTED;
600 80c6dc86 2002-12-15 alex } /* Channel_Mode */
604 c2f60abe 2002-05-27 alex IRC_AWAY( CLIENT *Client, REQUEST *Req )
606 c23199d9 2002-02-27 alex assert( Client != NULL );
607 c23199d9 2002-02-27 alex assert( Req != NULL );
609 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
610 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
612 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
614 c23199d9 2002-02-27 alex /* AWAY setzen */
615 c23199d9 2002-02-27 alex Client_SetAway( Client, Req->argv[0] );
616 8c1df9ef 2003-01-02 alex Client_ModeAdd( Client, 'a' );
617 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
618 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
622 c23199d9 2002-02-27 alex /* AWAY loeschen */
623 8c1df9ef 2003-01-02 alex Client_ModeDel( Client, 'a' );
624 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
625 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
627 c23199d9 2002-02-27 alex } /* IRC_AWAY */
631 8adff592 2005-03-19 fw Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
634 8adff592 2005-03-19 fw bool already;
636 19ac723e 2002-09-08 alex assert( Client != NULL );
637 19ac723e 2002-09-08 alex assert( Channel != NULL );
638 19ac723e 2002-09-08 alex assert( Pattern != NULL );
640 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
642 96747679 2004-04-25 alex already = Lists_IsInviteEntry( mask, Channel );
644 8adff592 2005-03-19 fw if( ! Lists_AddInvited( mask, Channel, false )) return CONNECTED;
646 8adff592 2005-03-19 fw if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
648 296ddebe 2002-09-08 alex return Send_ListChange( "+I", Prefix, Client, Channel, mask );
649 19ac723e 2002-09-08 alex } /* Add_Invite */
653 8adff592 2005-03-19 fw Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
656 8adff592 2005-03-19 fw bool already;
658 19ac723e 2002-09-08 alex assert( Client != NULL );
659 19ac723e 2002-09-08 alex assert( Channel != NULL );
660 19ac723e 2002-09-08 alex assert( Pattern != NULL );
662 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
664 96747679 2004-04-25 alex already = Lists_IsBanEntry( mask, Channel );
666 64d330b7 2004-04-09 alex if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
668 8adff592 2005-03-19 fw if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
670 296ddebe 2002-09-08 alex return Send_ListChange( "+b", Prefix, Client, Channel, mask );
671 19ac723e 2002-09-08 alex } /* Add_Ban */
675 8adff592 2005-03-19 fw Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
679 19ac723e 2002-09-08 alex assert( Client != NULL );
680 19ac723e 2002-09-08 alex assert( Channel != NULL );
681 19ac723e 2002-09-08 alex assert( Pattern != NULL );
683 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
684 19ac723e 2002-09-08 alex Lists_DelInvited( mask, Channel );
685 296ddebe 2002-09-08 alex return Send_ListChange( "-I", Prefix, Client, Channel, mask );
686 19ac723e 2002-09-08 alex } /* Del_Invite */
690 8adff592 2005-03-19 fw Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
694 19ac723e 2002-09-08 alex assert( Client != NULL );
695 19ac723e 2002-09-08 alex assert( Channel != NULL );
696 19ac723e 2002-09-08 alex assert( Pattern != NULL );
698 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
699 19ac723e 2002-09-08 alex Lists_DelBanned( mask, Channel );
700 296ddebe 2002-09-08 alex return Send_ListChange( "-b", Prefix, Client, Channel, mask );
701 296ddebe 2002-09-08 alex } /* Del_Ban */
705 8adff592 2005-03-19 fw Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask )
707 296ddebe 2002-09-08 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
711 19ac723e 2002-09-08 alex if( Client_Type( Client ) == CLIENT_USER )
713 296ddebe 2002-09-08 alex /* Bestaetigung an Client */
714 296ddebe 2002-09-08 alex ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
716 8adff592 2005-03-19 fw else ok = true;
718 296ddebe 2002-09-08 alex /* an andere Server */
719 296ddebe 2002-09-08 alex IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
721 296ddebe 2002-09-08 alex /* und lokale User im Channel */
722 8adff592 2005-03-19 fw IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
725 296ddebe 2002-09-08 alex } /* Send_ListChange */
728 c23199d9 2002-02-27 alex /* -eof- */