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 df00b38a 2003-01-08 alex static char UNUSED id[] = "$Id: irc-mode.c,v 1.29 2003/01/08 23:00:12 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 80c6dc86 2002-12-15 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 ));
235 80c6dc86 2002-12-15 alex } /* Client_Mode */
238 80c6dc86 2002-12-15 alex LOCAL BOOLEAN
239 80c6dc86 2002-12-15 alex Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
241 80c6dc86 2002-12-15 alex /* Handle channel and channel-user modes */
243 69ad0e38 2002-12-16 alex CHAR the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
244 80c6dc86 2002-12-15 alex BOOLEAN ok, set, modeok, skiponce;
245 80c6dc86 2002-12-15 alex INT mode_arg, arg_arg;
246 80c6dc86 2002-12-15 alex CLIENT *client;
249 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
250 df00b38a 2003-01-08 alex if( Req->argc == 1 )
252 df00b38a 2003-01-08 alex /* Member or not? -- That's the question! */
253 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 ));
255 df00b38a 2003-01-08 alex /* The sender is a member: generate extended reply */
256 df00b38a 2003-01-08 alex strlcpy( the_modes, Channel_Modes( Channel ), sizeof( the_modes ));
257 df00b38a 2003-01-08 alex mode_ptr = the_modes;
258 df00b38a 2003-01-08 alex strcpy( the_args, "" );
259 df00b38a 2003-01-08 alex while( *mode_ptr )
261 df00b38a 2003-01-08 alex switch( *mode_ptr )
264 df00b38a 2003-01-08 alex snprintf( argadd, sizeof( argadd ), " %ld", Channel_MaxUsers( Channel ));
265 df00b38a 2003-01-08 alex strlcat( the_args, argadd, sizeof( the_args ));
268 df00b38a 2003-01-08 alex strlcat( the_args, " ", sizeof( the_args ));
269 df00b38a 2003-01-08 alex strlcat( the_args, Channel_Key( Channel ), sizeof( the_args ));
272 df00b38a 2003-01-08 alex mode_ptr++;
274 df00b38a 2003-01-08 alex if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
276 df00b38a 2003-01-08 alex return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
279 80c6dc86 2002-12-15 alex /* Is the user allowed to change modes? */
280 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_USER )
282 80c6dc86 2002-12-15 alex if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = TRUE;
283 80c6dc86 2002-12-15 alex else modeok = FALSE;
284 80c6dc86 2002-12-15 alex if( Conf_OperCanMode )
286 80c6dc86 2002-12-15 alex /* auch IRC-Operatoren duerfen MODE verwenden */
287 80c6dc86 2002-12-15 alex if( Client_OperByMe( Origin )) modeok = TRUE;
290 80c6dc86 2002-12-15 alex else modeok = TRUE;
292 80c6dc86 2002-12-15 alex mode_arg = 1;
293 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
294 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
295 80c6dc86 2002-12-15 alex else arg_arg = -1;
297 80c6dc86 2002-12-15 alex /* Initial state: set or unset modes? */
298 80c6dc86 2002-12-15 alex skiponce = FALSE;
299 80c6dc86 2002-12-15 alex if( *mode_ptr == '-' ) set = FALSE;
300 80c6dc86 2002-12-15 alex else if( *mode_ptr == '+' ) set = TRUE;
301 80c6dc86 2002-12-15 alex else set = skiponce = TRUE;
303 80c6dc86 2002-12-15 alex /* Prepare reply string */
304 c23199d9 2002-02-27 alex if( set ) strcpy( the_modes, "+" );
305 c23199d9 2002-02-27 alex else strcpy( the_modes, "-" );
306 80c6dc86 2002-12-15 alex strcpy( the_args, " " );
308 c23199d9 2002-02-27 alex x[1] = '\0';
309 80c6dc86 2002-12-15 alex ok = CONNECTED;
310 80c6dc86 2002-12-15 alex while( mode_ptr )
312 80c6dc86 2002-12-15 alex if( ! skiponce ) mode_ptr++;
313 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
315 80c6dc86 2002-12-15 alex /* Try next argument if there's any */
316 80c6dc86 2002-12-15 alex if( arg_arg > mode_arg ) mode_arg = arg_arg;
317 80c6dc86 2002-12-15 alex else mode_arg++;
318 80c6dc86 2002-12-15 alex if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
319 80c6dc86 2002-12-15 alex else break;
320 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
321 80c6dc86 2002-12-15 alex else arg_arg = -1;
323 80c6dc86 2002-12-15 alex skiponce = FALSE;
325 80c6dc86 2002-12-15 alex switch( *mode_ptr )
329 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
331 80c6dc86 2002-12-15 alex /* Action modifier ("+"/"-") must be changed ... */
332 80c6dc86 2002-12-15 alex if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
334 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
335 80c6dc86 2002-12-15 alex the_modes[strlen( the_modes ) - 1] = *mode_ptr;
339 80c6dc86 2002-12-15 alex /* Append modifier character to result string */
340 6626395c 2002-12-26 alex x[0] = *mode_ptr;
341 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
343 80c6dc86 2002-12-15 alex if( *mode_ptr == '+' ) set = TRUE;
344 80c6dc86 2002-12-15 alex else set = FALSE;
349 80c6dc86 2002-12-15 alex /* Are there arguments left? */
350 80c6dc86 2002-12-15 alex if( arg_arg >= Req->argc ) arg_arg = -1;
352 7f61f413 2002-12-16 alex /* Validate modes */
353 c23199d9 2002-02-27 alex x[0] = '\0';
354 69ad0e38 2002-12-16 alex argadd[0] = '\0';
355 80c6dc86 2002-12-15 alex client = NULL;
356 7f61f413 2002-12-16 alex switch( *mode_ptr )
358 7f61f413 2002-12-16 alex /* Channel modes */
360 7f61f413 2002-12-16 alex /* Invite-Only */
361 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'i';
362 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
365 7f61f413 2002-12-16 alex /* Moderated */
366 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'm';
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 /* kein Schreiben in den Channel von aussen */
371 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'n';
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 /* Topic Lock */
376 7f61f413 2002-12-16 alex if( modeok ) x[0] = 't';
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 /* Persistent channel */
381 7f61f413 2002-12-16 alex if( modeok )
383 7f61f413 2002-12-16 alex if( set && ( ! Client_OperByMe( Client )))
385 7f61f413 2002-12-16 alex /* Only IRC operators are allowed to set P mode */
386 7f61f413 2002-12-16 alex ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
388 7f61f413 2002-12-16 alex else x[0] = 'P';
390 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
393 7f61f413 2002-12-16 alex /* Channel user modes */
395 7f61f413 2002-12-16 alex /* Channel operator */
397 7f61f413 2002-12-16 alex /* Voice */
398 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
400 80c6dc86 2002-12-15 alex if( modeok )
402 7f61f413 2002-12-16 alex client = Client_Search( Req->argv[arg_arg] );
403 7f61f413 2002-12-16 alex if( client ) x[0] = *mode_ptr;
404 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
406 80c6dc86 2002-12-15 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
407 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
410 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
413 69ad0e38 2002-12-16 alex /* Channel key */
414 69ad0e38 2002-12-16 alex if( ! set )
416 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
417 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
420 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
422 69ad0e38 2002-12-16 alex if( modeok )
424 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'k' );
425 69ad0e38 2002-12-16 alex Channel_SetKey( Channel, Req->argv[arg_arg] );
426 695631b2 2002-12-26 alex strlcpy( argadd, Channel_Key( Channel ), sizeof( argadd ));
427 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
429 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
430 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
433 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
436 69ad0e38 2002-12-16 alex /* Member limit */
437 69ad0e38 2002-12-16 alex if( ! set )
439 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
440 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
443 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
445 69ad0e38 2002-12-16 alex if( modeok )
447 69ad0e38 2002-12-16 alex l = atol( Req->argv[arg_arg] );
448 69ad0e38 2002-12-16 alex if( l > 0 && l < 0xFFFF )
450 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'l' );
451 69ad0e38 2002-12-16 alex Channel_SetMaxUsers( Channel, l );
452 b316c380 2002-12-26 alex snprintf( argadd, sizeof( argadd ), "%ld", l );
453 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
456 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
457 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
460 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
463 7f61f413 2002-12-16 alex /* Channel lists */
465 7f61f413 2002-12-16 alex /* Invite lists */
466 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
468 7f61f413 2002-12-16 alex /* modify list */
469 7f61f413 2002-12-16 alex if( modeok )
471 7f61f413 2002-12-16 alex if( set ) Add_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
472 7f61f413 2002-12-16 alex else Del_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
474 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
475 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
478 7f61f413 2002-12-16 alex else Lists_ShowInvites( Origin, Channel );
481 7f61f413 2002-12-16 alex /* Ban lists */
482 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
484 7f61f413 2002-12-16 alex /* modify list */
485 7f61f413 2002-12-16 alex if( modeok )
487 7f61f413 2002-12-16 alex if( set ) Add_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
488 7f61f413 2002-12-16 alex else Del_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
490 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
491 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
494 7f61f413 2002-12-16 alex else Lists_ShowBans( Origin, Channel );
498 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 ));
499 7f61f413 2002-12-16 alex if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
500 7f61f413 2002-12-16 alex x[0] = '\0';
501 69ad0e38 2002-12-16 alex goto chan_exit;
503 c23199d9 2002-02-27 alex if( ! ok ) break;
505 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
506 c23199d9 2002-02-27 alex if( ! x[0] ) continue;
510 80c6dc86 2002-12-15 alex /* Set mode */
511 80c6dc86 2002-12-15 alex if( client )
513 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
514 80c6dc86 2002-12-15 alex if( Channel_UserModeAdd( Channel, client, x[0] ))
516 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
517 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
518 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
519 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 ));
524 80c6dc86 2002-12-15 alex /* Channel-Mode */
525 c0d74a38 2002-12-15 alex if( Channel_ModeAdd( Channel, x[0] ))
527 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
528 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
534 80c6dc86 2002-12-15 alex /* Unset mode */
535 80c6dc86 2002-12-15 alex if( client )
537 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
538 80c6dc86 2002-12-15 alex if( Channel_UserModeDel( Channel, client, x[0] ))
540 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
541 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
542 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
543 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 ));
548 c23199d9 2002-02-27 alex /* Channel-Mode */
549 c0d74a38 2002-12-15 alex if( Channel_ModeDel( Channel, x[0] ))
551 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
552 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
557 69ad0e38 2002-12-16 alex /* Are there additional arguments to add? */
558 69ad0e38 2002-12-16 alex if( argadd[0] )
560 6626395c 2002-12-26 alex if( the_args[strlen( the_args ) - 1] != ' ' ) strlcat( the_args, " ", sizeof( the_args ));
561 6626395c 2002-12-26 alex strlcat( the_args, argadd, sizeof( the_args ));
566 80c6dc86 2002-12-15 alex /* Are there changed modes? */
567 c23199d9 2002-02-27 alex if( the_modes[1] )
569 c0d74a38 2002-12-15 alex /* Clean up mode string */
570 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';
572 80c6dc86 2002-12-15 alex /* Clean up argument string if there are none */
573 80c6dc86 2002-12-15 alex if( ! the_args[1] ) the_args[0] = '\0';
575 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
577 80c6dc86 2002-12-15 alex /* Forward mode changes to channel users and other servers */
578 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
579 80c6dc86 2002-12-15 alex IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
583 80c6dc86 2002-12-15 alex /* Send reply to client and inform other servers and channel users */
584 80c6dc86 2002-12-15 alex ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
585 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
586 80c6dc86 2002-12-15 alex IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
590 80c6dc86 2002-12-15 alex return CONNECTED;
591 80c6dc86 2002-12-15 alex } /* Channel_Mode */
594 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
595 c2f60abe 2002-05-27 alex IRC_AWAY( CLIENT *Client, REQUEST *Req )
597 c23199d9 2002-02-27 alex assert( Client != NULL );
598 c23199d9 2002-02-27 alex assert( Req != NULL );
600 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
601 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
603 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
605 c23199d9 2002-02-27 alex /* AWAY setzen */
606 c23199d9 2002-02-27 alex Client_SetAway( Client, Req->argv[0] );
607 8c1df9ef 2003-01-02 alex Client_ModeAdd( Client, 'a' );
608 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
609 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
613 c23199d9 2002-02-27 alex /* AWAY loeschen */
614 8c1df9ef 2003-01-02 alex Client_ModeDel( Client, 'a' );
615 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
616 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
618 c23199d9 2002-02-27 alex } /* IRC_AWAY */
621 19ac723e 2002-09-08 alex LOCAL BOOLEAN
622 296ddebe 2002-09-08 alex Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
624 19ac723e 2002-09-08 alex CHAR *mask;
626 19ac723e 2002-09-08 alex assert( Client != NULL );
627 19ac723e 2002-09-08 alex assert( Channel != NULL );
628 19ac723e 2002-09-08 alex assert( Pattern != NULL );
630 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
632 f3c0c7c0 2002-09-08 alex if( ! Lists_AddInvited( Prefix, mask, Channel, FALSE )) return CONNECTED;
633 296ddebe 2002-09-08 alex return Send_ListChange( "+I", Prefix, Client, Channel, mask );
634 19ac723e 2002-09-08 alex } /* Add_Invite */
637 19ac723e 2002-09-08 alex LOCAL BOOLEAN
638 296ddebe 2002-09-08 alex Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
640 19ac723e 2002-09-08 alex CHAR *mask;
642 19ac723e 2002-09-08 alex assert( Client != NULL );
643 19ac723e 2002-09-08 alex assert( Channel != NULL );
644 19ac723e 2002-09-08 alex assert( Pattern != NULL );
646 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
648 f3c0c7c0 2002-09-08 alex if( ! Lists_AddBanned( Prefix, mask, Channel )) return CONNECTED;
649 296ddebe 2002-09-08 alex return Send_ListChange( "+b", Prefix, Client, Channel, mask );
650 19ac723e 2002-09-08 alex } /* Add_Ban */
653 19ac723e 2002-09-08 alex LOCAL BOOLEAN
654 296ddebe 2002-09-08 alex Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
656 19ac723e 2002-09-08 alex CHAR *mask;
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 );
663 19ac723e 2002-09-08 alex Lists_DelInvited( mask, Channel );
664 296ddebe 2002-09-08 alex return Send_ListChange( "-I", Prefix, Client, Channel, mask );
665 19ac723e 2002-09-08 alex } /* Del_Invite */
668 19ac723e 2002-09-08 alex LOCAL BOOLEAN
669 296ddebe 2002-09-08 alex Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
671 19ac723e 2002-09-08 alex CHAR *mask;
673 19ac723e 2002-09-08 alex assert( Client != NULL );
674 19ac723e 2002-09-08 alex assert( Channel != NULL );
675 19ac723e 2002-09-08 alex assert( Pattern != NULL );
677 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
678 19ac723e 2002-09-08 alex Lists_DelBanned( mask, Channel );
679 296ddebe 2002-09-08 alex return Send_ListChange( "-b", Prefix, Client, Channel, mask );
680 296ddebe 2002-09-08 alex } /* Del_Ban */
683 296ddebe 2002-09-08 alex LOCAL BOOLEAN
684 296ddebe 2002-09-08 alex Send_ListChange( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask )
686 296ddebe 2002-09-08 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
688 296ddebe 2002-09-08 alex BOOLEAN ok;
690 19ac723e 2002-09-08 alex if( Client_Type( Client ) == CLIENT_USER )
692 296ddebe 2002-09-08 alex /* Bestaetigung an Client */
693 296ddebe 2002-09-08 alex ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
695 296ddebe 2002-09-08 alex else ok = TRUE;
697 296ddebe 2002-09-08 alex /* an andere Server */
698 296ddebe 2002-09-08 alex IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
700 296ddebe 2002-09-08 alex /* und lokale User im Channel */
701 296ddebe 2002-09-08 alex IRC_WriteStrChannelPrefix( Client, Channel, Prefix, FALSE, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
704 296ddebe 2002-09-08 alex } /* Send_ListChange */
707 c23199d9 2002-02-27 alex /* -eof- */