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 ca33cbda 2002-03-12 alex #include "imp.h"
18 c23199d9 2002-02-27 alex #include <assert.h>
19 69ad0e38 2002-12-16 alex #include <stdio.h>
20 69ad0e38 2002-12-16 alex #include <stdlib.h>
21 c23199d9 2002-02-27 alex #include <string.h>
23 aa25cd7d 2005-04-27 alex #include "defines.h"
24 c2f60abe 2002-05-27 alex #include "conn.h"
25 c2f60abe 2002-05-27 alex #include "client.h"
26 c23199d9 2002-02-27 alex #include "channel.h"
27 c23199d9 2002-02-27 alex #include "irc-write.h"
28 19ac723e 2002-09-08 alex #include "lists.h"
29 c23199d9 2002-02-27 alex #include "log.h"
30 c2f60abe 2002-05-27 alex #include "parse.h"
31 c23199d9 2002-02-27 alex #include "messages.h"
32 7e1b3b91 2002-09-02 alex #include "resolve.h"
33 7e1b3b91 2002-09-02 alex #include "conf.h"
35 ca33cbda 2002-03-12 alex #include "exp.h"
36 c23199d9 2002-02-27 alex #include "irc-mode.h"
39 77f54693 2005-07-31 alex static bool Client_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target ));
40 77f54693 2005-07-31 alex static bool Channel_Mode PARAMS(( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel ));
42 6b0c0948 2008-04-19 fw static bool Add_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern));
43 6b0c0948 2008-04-19 fw static bool Del_Ban_Invite PARAMS((int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern));
45 2dd51a98 2008-04-19 fw static bool Send_ListChange PARAMS(( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Mask ));
49 c2f60abe 2002-05-27 alex IRC_MODE( CLIENT *Client, REQUEST *Req )
51 80c6dc86 2002-12-15 alex CLIENT *cl, *origin;
52 c23199d9 2002-02-27 alex CHANNEL *chan;
54 c23199d9 2002-02-27 alex assert( Client != NULL );
55 c23199d9 2002-02-27 alex assert( Req != NULL );
57 80c6dc86 2002-12-15 alex /* No parameters? */
58 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
60 80c6dc86 2002-12-15 alex /* Origin for answers */
61 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
63 80c6dc86 2002-12-15 alex origin = Client_Search( Req->prefix );
64 80c6dc86 2002-12-15 alex if( ! origin ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
66 80c6dc86 2002-12-15 alex else origin = Client;
68 80c6dc86 2002-12-15 alex /* Channel or user mode? */
69 dd3a3bc6 2006-05-10 alex cl = NULL; chan = NULL;
70 dd3a3bc6 2006-05-10 alex if (Client_IsValidNick(Req->argv[0]))
71 dd3a3bc6 2006-05-10 alex cl = Client_Search(Req->argv[0]);
72 dd3a3bc6 2006-05-10 alex if (Channel_IsValidName(Req->argv[0]))
73 dd3a3bc6 2006-05-10 alex chan = Channel_Search(Req->argv[0]);
76 dd3a3bc6 2006-05-10 alex return Client_Mode(Client, Req, origin, cl);
78 dd3a3bc6 2006-05-10 alex return Channel_Mode(Client, Req, origin, chan);
80 80c6dc86 2002-12-15 alex /* No target found! */
81 dd3a3bc6 2006-05-10 alex return IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG,
82 dd3a3bc6 2006-05-10 alex 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 4b9e52eb 2007-08-02 fw case 'w': /* Wallops messages */
163 8579b2a1 2005-02-27 alex x[0] = *mode_ptr;
166 8579b2a1 2005-02-27 alex case 'a': /* Away */
167 8c1df9ef 2003-01-02 alex if( Client_Type( Client ) == CLIENT_SERVER )
169 8c1df9ef 2003-01-02 alex x[0] = 'a';
170 dd9b4bc9 2005-05-14 alex Client_SetAway( Origin, DEFAULT_AWAY_MSG );
172 8841d873 2002-12-18 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
175 8579b2a1 2005-02-27 alex case 'o': /* IRC operator (only unsettable!) */
176 8841d873 2002-12-18 alex if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
178 8adff592 2005-03-19 fw Client_SetOperByMe( Target, false );
179 7f61f413 2002-12-16 alex x[0] = 'o';
181 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
184 8579b2a1 2005-02-27 alex case 'r': /* Restricted (only settable) */
185 8841d873 2002-12-18 alex if(( set ) || ( Client_Type( Client ) == CLIENT_SERVER )) x[0] = 'r';
186 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_RESTRICTED_MSG, Client_ID( Origin ));
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 e6180411 2005-03-05 alex len = strlen( the_modes ) - 1;
219 e6180411 2005-03-05 alex if(( the_modes[len] == '+' ) || ( the_modes[len] == '-' )) the_modes[len] = '\0';
221 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
223 80c6dc86 2002-12-15 alex /* Forward modes to other servers */
224 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
228 80c6dc86 2002-12-15 alex /* Send reply to client and inform other servers */
229 56227abc 2004-02-29 alex ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
230 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s :%s", Client_ID( Target ), the_modes );
232 d93030ad 2008-09-23 alex LogDebug("%s \"%s\": Mode change, now \"%s\".",
233 d93030ad 2008-09-23 alex Client_TypeText(Target), Client_Mask(Target),
234 d93030ad 2008-09-23 alex Client_Modes(Target));
237 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
239 80c6dc86 2002-12-15 alex } /* Client_Mode */
243 e710e8ae 2008-02-26 fw Channel_Mode_Answer_Request(CLIENT *Origin, CHANNEL *Channel)
245 e710e8ae 2008-02-26 fw char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], argadd[CLIENT_PASS_LEN];
246 e710e8ae 2008-02-26 fw const char *mode_ptr;
248 e710e8ae 2008-02-26 fw /* Member or not? -- That's the question! */
249 e710e8ae 2008-02-26 fw if (!Channel_IsMemberOf(Channel, Origin))
250 e710e8ae 2008-02-26 fw return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
251 e710e8ae 2008-02-26 fw Client_ID(Origin), Channel_Name(Channel), Channel_Modes(Channel));
253 e710e8ae 2008-02-26 fw /* The sender is a member: generate extended reply */
254 e710e8ae 2008-02-26 fw strlcpy(the_modes, Channel_Modes(Channel), sizeof(the_modes));
255 e710e8ae 2008-02-26 fw mode_ptr = the_modes;
256 e710e8ae 2008-02-26 fw the_args[0] = '\0';
258 e710e8ae 2008-02-26 fw while(*mode_ptr) {
259 e710e8ae 2008-02-26 fw switch(*mode_ptr) {
261 e710e8ae 2008-02-26 fw snprintf(argadd, sizeof(argadd), " %lu", Channel_MaxUsers(Channel));
262 e710e8ae 2008-02-26 fw strlcat(the_args, argadd, sizeof(the_args));
265 e710e8ae 2008-02-26 fw strlcat(the_args, " ", sizeof(the_args));
266 e710e8ae 2008-02-26 fw strlcat(the_args, Channel_Key(Channel), sizeof(the_args));
271 e710e8ae 2008-02-26 fw if (the_args[0])
272 e710e8ae 2008-02-26 fw strlcat(the_modes, the_args, sizeof(the_modes));
274 e710e8ae 2008-02-26 fw return IRC_WriteStrClient(Origin, RPL_CHANNELMODEIS_MSG,
275 e710e8ae 2008-02-26 fw Client_ID(Origin), Channel_Name(Channel), the_modes);
279 77f54693 2005-07-31 alex static bool
280 80c6dc86 2002-12-15 alex Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
282 80c6dc86 2002-12-15 alex /* Handle channel and channel-user modes */
284 8adff592 2005-03-19 fw char the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
285 8df44531 2008-04-19 fw bool ok, set, modeok = true, skiponce, use_servermode = false, retval;
286 8adff592 2005-03-19 fw int mode_arg, arg_arg;
287 80c6dc86 2002-12-15 alex CLIENT *client;
289 e6180411 2005-03-05 alex size_t len;
291 530112b1 2008-05-01 alex /* Are modes allowed on channel? */
292 530112b1 2008-05-01 alex if (Channel_Name(Channel)[0] == '+')
293 530112b1 2008-05-01 alex return IRC_WriteStrClient(Client, ERR_NOCHANMODES_MSG,
294 530112b1 2008-05-01 alex Client_ID(Client), Channel_Name(Channel));
296 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
297 e710e8ae 2008-02-26 fw if (Req->argc <= 1)
298 e710e8ae 2008-02-26 fw return Channel_Mode_Answer_Request(Origin, Channel);
300 80c6dc86 2002-12-15 alex /* Is the user allowed to change modes? */
301 e710e8ae 2008-02-26 fw if (Client_Type(Client) == CLIENT_USER) {
302 e07542a1 2003-01-17 alex /* Is the originating user on that channel? */
303 e710e8ae 2008-02-26 fw if (!Channel_IsMemberOf(Channel, Origin))
304 e710e8ae 2008-02-26 fw return IRC_WriteStrClient(Origin, ERR_NOTONCHANNEL_MSG,
305 e710e8ae 2008-02-26 fw Client_ID(Origin), Channel_Name(Channel));
306 e710e8ae 2008-02-26 fw modeok = false;
307 e710e8ae 2008-02-26 fw /* channel operator? */
308 e710e8ae 2008-02-26 fw if (strchr(Channel_UserModes(Channel, Origin), 'o'))
309 e710e8ae 2008-02-26 fw modeok = true;
310 e710e8ae 2008-02-26 fw else if(Conf_OperCanMode) {
311 1d08d51e 2005-03-15 alex /* IRC-Operators can use MODE as well */
312 e710e8ae 2008-02-26 fw if (Client_OperByMe(Origin)) {
313 8adff592 2005-03-19 fw modeok = true;
314 e710e8ae 2008-02-26 fw if (Conf_OperServerMode)
315 e710e8ae 2008-02-26 fw use_servermode = true; /* Change Origin to Server */
320 80c6dc86 2002-12-15 alex mode_arg = 1;
321 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
322 e710e8ae 2008-02-26 fw if (Req->argc > mode_arg + 1)
323 e710e8ae 2008-02-26 fw arg_arg = mode_arg + 1;
325 e710e8ae 2008-02-26 fw arg_arg = -1;
327 80c6dc86 2002-12-15 alex /* Initial state: set or unset modes? */
328 8adff592 2005-03-19 fw skiponce = false;
329 e710e8ae 2008-02-26 fw switch (*mode_ptr) {
330 e710e8ae 2008-02-26 fw case '-': set = false; break;
331 e710e8ae 2008-02-26 fw case '+': set = true; break;
334 e710e8ae 2008-02-26 fw skiponce = true;
337 80c6dc86 2002-12-15 alex /* Prepare reply string */
338 e710e8ae 2008-02-26 fw strcpy(the_modes, set ? "+" : "-");
339 1784180b 2008-02-26 fw the_args[0] = '\0';
341 c23199d9 2002-02-27 alex x[1] = '\0';
342 80c6dc86 2002-12-15 alex ok = CONNECTED;
343 e710e8ae 2008-02-26 fw while (mode_ptr) {
344 e710e8ae 2008-02-26 fw if (! skiponce)
346 e710e8ae 2008-02-26 fw if (!*mode_ptr) {
347 80c6dc86 2002-12-15 alex /* Try next argument if there's any */
348 e710e8ae 2008-02-26 fw if (arg_arg > mode_arg)
349 e710e8ae 2008-02-26 fw mode_arg = arg_arg;
353 e710e8ae 2008-02-26 fw if (mode_arg >= Req->argc)
355 e710e8ae 2008-02-26 fw mode_ptr = Req->argv[mode_arg];
357 e710e8ae 2008-02-26 fw if (Req->argc > mode_arg + 1)
358 e710e8ae 2008-02-26 fw arg_arg = mode_arg + 1;
360 e710e8ae 2008-02-26 fw arg_arg = -1;
362 8adff592 2005-03-19 fw skiponce = false;
364 e710e8ae 2008-02-26 fw switch (*mode_ptr) {
367 e710e8ae 2008-02-26 fw if (((*mode_ptr == '+') && !set) || ((*mode_ptr == '-') && set)) {
368 e710e8ae 2008-02-26 fw /* Action modifier ("+"/"-") must be changed ... */
369 e710e8ae 2008-02-26 fw len = strlen( the_modes ) - 1;
370 e710e8ae 2008-02-26 fw if ((the_modes[len] == '+') || (the_modes[len] == '-')) {
371 e710e8ae 2008-02-26 fw /* Adjust last action modifier in result */
372 e710e8ae 2008-02-26 fw the_modes[len] = *mode_ptr;
374 e710e8ae 2008-02-26 fw /* Append modifier character to result string */
375 e710e8ae 2008-02-26 fw x[0] = *mode_ptr;
376 e710e8ae 2008-02-26 fw strlcat(the_modes, x, sizeof(the_modes));
378 e710e8ae 2008-02-26 fw set = *mode_ptr == '+';
383 80c6dc86 2002-12-15 alex /* Are there arguments left? */
384 80c6dc86 2002-12-15 alex if( arg_arg >= Req->argc ) arg_arg = -1;
386 7f61f413 2002-12-16 alex /* Validate modes */
387 c23199d9 2002-02-27 alex x[0] = '\0';
388 69ad0e38 2002-12-16 alex argadd[0] = '\0';
389 80c6dc86 2002-12-15 alex client = NULL;
390 55381155 2008-04-19 fw switch (*mode_ptr) {
391 55381155 2008-04-19 fw /* --- Channel modes --- */
392 55381155 2008-04-19 fw case 'i': /* Invite only */
393 55381155 2008-04-19 fw case 'm': /* Moderated */
394 55381155 2008-04-19 fw case 'n': /* Only members can write */
395 55381155 2008-04-19 fw case 's': /* Secret channel */
396 55381155 2008-04-19 fw case 't': /* Topic locked */
398 55381155 2008-04-19 fw x[0] = *mode_ptr;
400 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(Origin), Channel_Name(Channel));
402 55381155 2008-04-19 fw case 'k': /* Channel key */
405 55381155 2008-04-19 fw x[0] = *mode_ptr;
407 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(Origin), Channel_Name(Channel));
410 55381155 2008-04-19 fw if (arg_arg > mode_arg) {
411 55381155 2008-04-19 fw if (modeok) {
412 55381155 2008-04-19 fw Channel_ModeDel(Channel, 'k');
413 55381155 2008-04-19 fw Channel_SetKey(Channel, Req->argv[arg_arg]);
414 55381155 2008-04-19 fw strlcpy(argadd, Channel_Key(Channel), sizeof(argadd));
415 55381155 2008-04-19 fw x[0] = *mode_ptr;
417 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(Origin), Channel_Name(Channel));
419 55381155 2008-04-19 fw Req->argv[arg_arg][0] = '\0';
422 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID(Origin), Req->command);
425 55381155 2008-04-19 fw case 'l': /* Member limit */
428 55381155 2008-04-19 fw x[0] = *mode_ptr;
430 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(Origin), Channel_Name(Channel));
433 55381155 2008-04-19 fw if (arg_arg > mode_arg) {
434 55381155 2008-04-19 fw if (modeok) {
435 55381155 2008-04-19 fw l = atol(Req->argv[arg_arg]);
436 55381155 2008-04-19 fw if (l > 0 && l < 0xFFFF) {
437 55381155 2008-04-19 fw Channel_ModeDel(Channel, 'l');
438 55381155 2008-04-19 fw Channel_SetMaxUsers(Channel, l);
439 55381155 2008-04-19 fw snprintf(argadd, sizeof(argadd), "%ld", l);
440 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
443 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(Origin), Channel_Name(Channel));
445 55381155 2008-04-19 fw Req->argv[arg_arg][0] = '\0';
448 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID(Origin), Req->command);
451 55381155 2008-04-19 fw case 'P': /* Persistent channel */
452 55381155 2008-04-19 fw if (modeok) {
453 55381155 2008-04-19 fw /* Only IRC operators are allowed to
454 55381155 2008-04-19 fw * set the 'P' channel mode! */
455 55381155 2008-04-19 fw if (set && !(Client_OperByMe(Client) || Client_Type(Client) == CLIENT_SERVER))
456 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_NOPRIVILEGES_MSG, Client_ID(Origin));
460 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(Origin), Channel_Name(Channel));
462 55381155 2008-04-19 fw /* --- Channel user modes --- */
463 55381155 2008-04-19 fw case 'o': /* Channel operator */
464 55381155 2008-04-19 fw case 'v': /* Voice */
465 55381155 2008-04-19 fw if (arg_arg > mode_arg) {
466 55381155 2008-04-19 fw if (modeok) {
467 55381155 2008-04-19 fw client = Client_Search(Req->argv[arg_arg]);
469 55381155 2008-04-19 fw x[0] = *mode_ptr;
471 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Client, ERR_NOSUCHNICK_MSG, Client_ID(Client), Req->argv[arg_arg]);
473 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID(Origin), Channel_Name(Channel));
475 55381155 2008-04-19 fw Req->argv[arg_arg][0] = '\0';
478 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID(Origin), Req->command);
481 55381155 2008-04-19 fw /* --- Channel lists --- */
482 55381155 2008-04-19 fw case 'I': /* Invite lists */
483 55381155 2008-04-19 fw case 'b': /* Ban lists */
484 55381155 2008-04-19 fw if (arg_arg > mode_arg) {
485 55381155 2008-04-19 fw /* modify list */
486 55381155 2008-04-19 fw if (modeok) {
487 55381155 2008-04-19 fw ok = set ? Add_Ban_Invite(*mode_ptr, Origin, Client, Channel, Req->argv[arg_arg])
488 55381155 2008-04-19 fw : Del_Ban_Invite(*mode_ptr, Origin, Client, Channel, Req->argv[arg_arg]);
490 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_CHANOPRIVSNEEDED_MSG,
491 55381155 2008-04-19 fw Client_ID(Origin), Channel_Name(Channel));
493 55381155 2008-04-19 fw Req->argv[arg_arg][0] = '\0';
496 55381155 2008-04-19 fw if (*mode_ptr == 'I')
497 55381155 2008-04-19 fw Channel_ShowInvites(Origin, Channel);
499 55381155 2008-04-19 fw Channel_ShowBans(Origin, Channel);
503 55381155 2008-04-19 fw Log(LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\" on %s!?",
504 55381155 2008-04-19 fw set ? '+' : '-', *mode_ptr, Client_ID(Origin), Channel_Name(Channel));
505 55381155 2008-04-19 fw if (Client_Type(Client) != CLIENT_SERVER)
506 55381155 2008-04-19 fw ok = IRC_WriteStrClient(Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID(Origin), set ? '+' : '-', *mode_ptr);
508 55381155 2008-04-19 fw goto chan_exit;
509 55381155 2008-04-19 fw } /* switch() */
514 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
518 fbec1f10 2003-01-21 alex /* Validate target client */
519 55381155 2008-04-19 fw if (client && (!Channel_IsMemberOf(Channel, client))) {
520 55381155 2008-04-19 fw if (!IRC_WriteStrClient(Origin, ERR_USERNOTINCHANNEL_MSG,
521 55381155 2008-04-19 fw Client_ID(Origin), Client_ID(client), Channel_Name(Channel)))
527 11af3246 2008-04-19 fw if (client) {
528 11af3246 2008-04-19 fw /* Channel-User-Mode */
529 8df44531 2008-04-19 fw retval = set ? Channel_UserModeAdd(Channel, client, x[0]) : Channel_UserModeDel(Channel, client, x[0]);
530 8df44531 2008-04-19 fw if (retval) {
531 8df44531 2008-04-19 fw strlcat(the_args, " ", sizeof(the_args));
532 8df44531 2008-04-19 fw strlcat(the_args, Client_ID(client), sizeof(the_args));
533 8df44531 2008-04-19 fw strlcat(the_modes, x, sizeof(the_modes));
534 8df44531 2008-04-19 fw Log(LOG_DEBUG, "User \"%s\": Mode change on %s, now \"%s\"",
535 8df44531 2008-04-19 fw Client_Mask(client), Channel_Name(Channel), Channel_UserModes(Channel, client));
538 11af3246 2008-04-19 fw /* Channel-Mode */
539 8df44531 2008-04-19 fw retval = set ? Channel_ModeAdd(Channel, x[0]) : Channel_ModeDel(Channel, x[0]);
540 8df44531 2008-04-19 fw if (retval) {
541 8df44531 2008-04-19 fw strlcat(the_modes, x, sizeof(the_modes));
542 8df44531 2008-04-19 fw Log(LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name(Channel), Channel_Modes(Channel));
546 69ad0e38 2002-12-16 alex /* Are there additional arguments to add? */
547 55381155 2008-04-19 fw if (argadd[0]) {
548 55381155 2008-04-19 fw strlcat(the_args, " ", sizeof(the_args));
549 55381155 2008-04-19 fw strlcat(the_args, argadd, sizeof(the_args));
553 80c6dc86 2002-12-15 alex /* Are there changed modes? */
554 e710e8ae 2008-02-26 fw if (the_modes[1]) {
555 c0d74a38 2002-12-15 alex /* Clean up mode string */
556 e710e8ae 2008-02-26 fw len = strlen(the_modes) - 1;
557 e710e8ae 2008-02-26 fw if ((the_modes[len] == '+') || (the_modes[len] == '-'))
558 e710e8ae 2008-02-26 fw the_modes[len] = '\0';
560 e710e8ae 2008-02-26 fw if (Client_Type(Client) == CLIENT_SERVER) {
561 80c6dc86 2002-12-15 alex /* Forward mode changes to channel users and other servers */
562 e710e8ae 2008-02-26 fw IRC_WriteStrServersPrefix(Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args);
563 55381155 2008-04-19 fw IRC_WriteStrChannelPrefix(Client, Channel, Origin, false, "MODE %s %s%s", Channel_Name(Channel), the_modes, the_args);
565 e710e8ae 2008-02-26 fw if (use_servermode)
566 e710e8ae 2008-02-26 fw Origin = Client_ThisServer();
567 80c6dc86 2002-12-15 alex /* Send reply to client and inform other servers and channel users */
568 55381155 2008-04-19 fw ok = IRC_WriteStrClientPrefix(Client, Origin, "MODE %s %s%s",
569 55381155 2008-04-19 fw Channel_Name(Channel), the_modes, the_args);
570 55381155 2008-04-19 fw IRC_WriteStrServersPrefix(Client, Origin, "MODE %s %s%s",
571 55381155 2008-04-19 fw Channel_Name(Channel), the_modes, the_args);
572 55381155 2008-04-19 fw IRC_WriteStrChannelPrefix(Client, Channel, Origin, false, "MODE %s %s%s",
573 55381155 2008-04-19 fw Channel_Name(Channel), the_modes, the_args);
577 55381155 2008-04-19 fw IRC_SetPenalty(Client, 1);
578 80c6dc86 2002-12-15 alex return CONNECTED;
579 80c6dc86 2002-12-15 alex } /* Channel_Mode */
583 c2f60abe 2002-05-27 alex IRC_AWAY( CLIENT *Client, REQUEST *Req )
585 c23199d9 2002-02-27 alex assert( Client != NULL );
586 c23199d9 2002-02-27 alex assert( Req != NULL );
588 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
589 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
591 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
593 c23199d9 2002-02-27 alex /* AWAY setzen */
594 c23199d9 2002-02-27 alex Client_SetAway( Client, Req->argv[0] );
595 8c1df9ef 2003-01-02 alex Client_ModeAdd( Client, 'a' );
596 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
597 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
601 c23199d9 2002-02-27 alex /* AWAY loeschen */
602 8c1df9ef 2003-01-02 alex Client_ModeDel( Client, 'a' );
603 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
604 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
606 c23199d9 2002-02-27 alex } /* IRC_AWAY */
609 77f54693 2005-07-31 alex static bool
610 6b0c0948 2008-04-19 fw Add_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern)
612 2dd51a98 2008-04-19 fw const char *mask;
613 8adff592 2005-03-19 fw bool already;
616 19ac723e 2002-09-08 alex assert( Client != NULL );
617 19ac723e 2002-09-08 alex assert( Channel != NULL );
618 19ac723e 2002-09-08 alex assert( Pattern != NULL );
619 2dd51a98 2008-04-19 fw assert(what == 'I' || what == 'b');
621 2dd51a98 2008-04-19 fw mask = Lists_MakeMask(Pattern);
623 2dd51a98 2008-04-19 fw already = Lists_CheckDupeMask(Channel_GetListInvites(Channel), mask);
624 2dd51a98 2008-04-19 fw if (!already) {
625 2dd51a98 2008-04-19 fw if (what == 'I')
626 2dd51a98 2008-04-19 fw ret = Channel_AddInvite(Channel, mask, false);
628 2dd51a98 2008-04-19 fw ret = Channel_AddBan(Channel, mask);
630 fa7bb279 2006-12-07 fw return CONNECTED;
632 2dd51a98 2008-04-19 fw if (already && (Client_Type(Prefix) == CLIENT_SERVER))
633 fa7bb279 2006-12-07 fw return CONNECTED;
635 2dd51a98 2008-04-19 fw if (what == 'I')
636 2dd51a98 2008-04-19 fw return Send_ListChange("+I", Prefix, Client, Channel, mask);
637 2dd51a98 2008-04-19 fw return Send_ListChange("+b", Prefix, Client, Channel, mask);
641 77f54693 2005-07-31 alex static bool
642 6b0c0948 2008-04-19 fw Del_Ban_Invite(int what, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Pattern)
644 6b0c0948 2008-04-19 fw const char *mask;
645 6b0c0948 2008-04-19 fw struct list_head *list;
647 19ac723e 2002-09-08 alex assert( Client != NULL );
648 19ac723e 2002-09-08 alex assert( Channel != NULL );
649 19ac723e 2002-09-08 alex assert( Pattern != NULL );
650 6b0c0948 2008-04-19 fw assert(what == 'I' || what == 'b');
652 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
654 6b0c0948 2008-04-19 fw if (what == 'I')
655 6b0c0948 2008-04-19 fw list = Channel_GetListInvites(Channel);
657 6b0c0948 2008-04-19 fw list = Channel_GetListBans(Channel);
659 6b0c0948 2008-04-19 fw Lists_Del(list, mask);
660 6b0c0948 2008-04-19 fw if (what == 'I')
661 6b0c0948 2008-04-19 fw return Send_ListChange( "-I", Prefix, Client, Channel, mask );
662 296ddebe 2002-09-08 alex return Send_ListChange( "-b", Prefix, Client, Channel, mask );
666 77f54693 2005-07-31 alex static bool
667 2dd51a98 2008-04-19 fw Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, const char *Mask )
669 296ddebe 2002-09-08 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
673 19ac723e 2002-09-08 alex if( Client_Type( Client ) == CLIENT_USER )
675 296ddebe 2002-09-08 alex /* Bestaetigung an Client */
676 296ddebe 2002-09-08 alex ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
678 8adff592 2005-03-19 fw else ok = true;
680 296ddebe 2002-09-08 alex /* an andere Server */
681 296ddebe 2002-09-08 alex IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
683 296ddebe 2002-09-08 alex /* und lokale User im Channel */
684 8adff592 2005-03-19 fw IRC_WriteStrChannelPrefix( Client, Channel, Prefix, false, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
687 296ddebe 2002-09-08 alex } /* Send_ListChange */
690 c23199d9 2002-02-27 alex /* -eof- */