Blame


1 c23199d9 2002-02-27 alex /*
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)
4 c23199d9 2002-02-27 alex *
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.
10 c23199d9 2002-02-27 alex *
11 490f28ff 2002-12-12 alex * IRC commands for mode changes (MODE, AWAY, ...)
12 c23199d9 2002-02-27 alex */
13 c23199d9 2002-02-27 alex
14 c23199d9 2002-02-27 alex
15 ca33cbda 2002-03-12 alex #include "portab.h"
16 490f28ff 2002-12-12 alex
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 $";
18 c23199d9 2002-02-27 alex
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>
24 c23199d9 2002-02-27 alex
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"
36 c23199d9 2002-02-27 alex
37 ca33cbda 2002-03-12 alex #include "exp.h"
38 c23199d9 2002-02-27 alex #include "irc-mode.h"
39 c23199d9 2002-02-27 alex
40 c23199d9 2002-02-27 alex
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 ));
43 80c6dc86 2002-12-15 alex
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 ));
46 19ac723e 2002-09-08 alex
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 ));
49 19ac723e 2002-09-08 alex
50 8adff592 2005-03-19 fw LOCAL bool Send_ListChange PARAMS(( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask ));
51 19ac723e 2002-09-08 alex
52 296ddebe 2002-09-08 alex
53 8adff592 2005-03-19 fw GLOBAL bool
54 c2f60abe 2002-05-27 alex IRC_MODE( CLIENT *Client, REQUEST *Req )
55 c23199d9 2002-02-27 alex {
56 80c6dc86 2002-12-15 alex CLIENT *cl, *origin;
57 c23199d9 2002-02-27 alex CHANNEL *chan;
58 80c6dc86 2002-12-15 alex
59 c23199d9 2002-02-27 alex assert( Client != NULL );
60 c23199d9 2002-02-27 alex assert( Req != NULL );
61 c23199d9 2002-02-27 alex
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 );
64 c23199d9 2002-02-27 alex
65 80c6dc86 2002-12-15 alex /* Origin for answers */
66 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
67 80c6dc86 2002-12-15 alex {
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 );
70 80c6dc86 2002-12-15 alex }
71 80c6dc86 2002-12-15 alex else origin = Client;
72 80c6dc86 2002-12-15 alex
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] );
77 c23199d9 2002-02-27 alex
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 );
80 c23199d9 2002-02-27 alex
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 */
84 c23199d9 2002-02-27 alex
85 19ac723e 2002-09-08 alex
86 8adff592 2005-03-19 fw LOCAL bool
87 80c6dc86 2002-12-15 alex Client_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CLIENT *Target )
88 80c6dc86 2002-12-15 alex {
89 80c6dc86 2002-12-15 alex /* Handle client mode requests */
90 80c6dc86 2002-12-15 alex
91 8adff592 2005-03-19 fw char the_modes[COMMAND_LEN], x[2], *mode_ptr;
92 8adff592 2005-03-19 fw bool ok, set;
93 8adff592 2005-03-19 fw int mode_arg;
94 e6180411 2005-03-05 alex size_t len;
95 80c6dc86 2002-12-15 alex
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 )
98 19ac723e 2002-09-08 alex {
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 ));
101 19ac723e 2002-09-08 alex }
102 19ac723e 2002-09-08 alex
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 ));
105 80c6dc86 2002-12-15 alex
106 80c6dc86 2002-12-15 alex mode_arg = 1;
107 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
108 80c6dc86 2002-12-15 alex
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 ));
113 80c6dc86 2002-12-15 alex
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, "-" );
117 80c6dc86 2002-12-15 alex
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 )
121 80c6dc86 2002-12-15 alex {
122 80c6dc86 2002-12-15 alex mode_ptr++;
123 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
124 19ac723e 2002-09-08 alex {
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;
129 19ac723e 2002-09-08 alex }
130 80c6dc86 2002-12-15 alex
131 80c6dc86 2002-12-15 alex switch( *mode_ptr )
132 19ac723e 2002-09-08 alex {
133 80c6dc86 2002-12-15 alex case '+':
134 80c6dc86 2002-12-15 alex case '-':
135 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
136 c2aefbb3 2002-09-08 alex {
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] == '-' ))
140 80c6dc86 2002-12-15 alex {
141 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
142 e6180411 2005-03-05 alex the_modes[len] = *mode_ptr;
143 80c6dc86 2002-12-15 alex }
144 80c6dc86 2002-12-15 alex else
145 80c6dc86 2002-12-15 alex {
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 ));
149 80c6dc86 2002-12-15 alex }
150 8adff592 2005-03-19 fw if( *mode_ptr == '+' ) set = true;
151 8adff592 2005-03-19 fw else set = false;
152 c2aefbb3 2002-09-08 alex }
153 80c6dc86 2002-12-15 alex continue;
154 80c6dc86 2002-12-15 alex }
155 80c6dc86 2002-12-15 alex
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 )
159 80c6dc86 2002-12-15 alex {
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;
163 8579b2a1 2005-02-27 alex break;
164 8579b2a1 2005-02-27 alex
165 8579b2a1 2005-02-27 alex case 'a': /* Away */
166 8c1df9ef 2003-01-02 alex if( Client_Type( Client ) == CLIENT_SERVER )
167 8c1df9ef 2003-01-02 alex {
168 8c1df9ef 2003-01-02 alex x[0] = 'a';
169 dd9b4bc9 2005-05-14 alex Client_SetAway( Origin, DEFAULT_AWAY_MSG );
170 8c1df9ef 2003-01-02 alex }
171 8841d873 2002-12-18 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
172 8841d873 2002-12-18 alex break;
173 8579b2a1 2005-02-27 alex
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 ))
176 7f61f413 2002-12-16 alex {
177 8adff592 2005-03-19 fw Client_SetOperByMe( Target, false );
178 7f61f413 2002-12-16 alex x[0] = 'o';
179 7f61f413 2002-12-16 alex }
180 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
181 7f61f413 2002-12-16 alex break;
182 8579b2a1 2005-02-27 alex
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 ));
186 7f61f413 2002-12-16 alex break;
187 8579b2a1 2005-02-27 alex
188 7f61f413 2002-12-16 alex default:
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;
193 19ac723e 2002-09-08 alex }
194 80c6dc86 2002-12-15 alex if( ! ok ) break;
195 80c6dc86 2002-12-15 alex
196 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
197 80c6dc86 2002-12-15 alex if( ! x[0] ) continue;
198 80c6dc86 2002-12-15 alex
199 80c6dc86 2002-12-15 alex if( set )
200 80c6dc86 2002-12-15 alex {
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 ));
203 80c6dc86 2002-12-15 alex
204 80c6dc86 2002-12-15 alex }
205 80c6dc86 2002-12-15 alex else
206 80c6dc86 2002-12-15 alex {
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 ));
209 80c6dc86 2002-12-15 alex }
210 19ac723e 2002-09-08 alex }
211 69ad0e38 2002-12-16 alex client_exit:
212 69ad0e38 2002-12-16 alex
213 80c6dc86 2002-12-15 alex /* Are there changed modes? */
214 80c6dc86 2002-12-15 alex if( the_modes[1] )
215 c23199d9 2002-02-27 alex {
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';
219 80c6dc86 2002-12-15 alex
220 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
221 c23199d9 2002-02-27 alex {
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 );
224 c23199d9 2002-02-27 alex }
225 80c6dc86 2002-12-15 alex else
226 c23199d9 2002-02-27 alex {
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 );
230 c23199d9 2002-02-27 alex }
231 80c6dc86 2002-12-15 alex Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( Target ), Client_Modes( Target ));
232 c23199d9 2002-02-27 alex }
233 7b6e2662 2003-11-05 alex
234 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
235 80c6dc86 2002-12-15 alex return ok;
236 80c6dc86 2002-12-15 alex } /* Client_Mode */
237 c23199d9 2002-02-27 alex
238 c23199d9 2002-02-27 alex
239 8adff592 2005-03-19 fw LOCAL bool
240 80c6dc86 2002-12-15 alex Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
241 80c6dc86 2002-12-15 alex {
242 80c6dc86 2002-12-15 alex /* Handle channel and channel-user modes */
243 c23199d9 2002-02-27 alex
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;
248 8adff592 2005-03-19 fw long l;
249 e6180411 2005-03-05 alex size_t len;
250 80c6dc86 2002-12-15 alex
251 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
252 df00b38a 2003-01-08 alex if( Req->argc == 1 )
253 df00b38a 2003-01-08 alex {
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 ));
256 80c6dc86 2002-12-15 alex
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 )
262 df00b38a 2003-01-08 alex {
263 df00b38a 2003-01-08 alex switch( *mode_ptr )
264 df00b38a 2003-01-08 alex {
265 df00b38a 2003-01-08 alex case 'l':
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 ));
268 df00b38a 2003-01-08 alex break;
269 df00b38a 2003-01-08 alex case 'k':
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 ));
272 df00b38a 2003-01-08 alex break;
273 df00b38a 2003-01-08 alex }
274 df00b38a 2003-01-08 alex mode_ptr++;
275 df00b38a 2003-01-08 alex }
276 df00b38a 2003-01-08 alex if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
277 df00b38a 2003-01-08 alex
278 df00b38a 2003-01-08 alex return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
279 df00b38a 2003-01-08 alex }
280 df00b38a 2003-01-08 alex
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 )
283 c23199d9 2002-02-27 alex {
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 ));
286 e07542a1 2003-01-17 alex
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 )
290 80c6dc86 2002-12-15 alex {
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 */
295 1d08d51e 2005-03-15 alex }
296 80c6dc86 2002-12-15 alex }
297 c23199d9 2002-02-27 alex }
298 8adff592 2005-03-19 fw else modeok = true;
299 c23199d9 2002-02-27 alex
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;
304 80c6dc86 2002-12-15 alex
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;
310 80c6dc86 2002-12-15 alex
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, " " );
315 c23199d9 2002-02-27 alex
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 )
319 c23199d9 2002-02-27 alex {
320 80c6dc86 2002-12-15 alex if( ! skiponce ) mode_ptr++;
321 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
322 80c6dc86 2002-12-15 alex {
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;
330 80c6dc86 2002-12-15 alex }
331 8adff592 2005-03-19 fw skiponce = false;
332 80c6dc86 2002-12-15 alex
333 80c6dc86 2002-12-15 alex switch( *mode_ptr )
334 80c6dc86 2002-12-15 alex {
335 80c6dc86 2002-12-15 alex case '+':
336 80c6dc86 2002-12-15 alex case '-':
337 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
338 80c6dc86 2002-12-15 alex {
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] == '-' ))
342 80c6dc86 2002-12-15 alex {
343 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
344 e6180411 2005-03-05 alex the_modes[len] = *mode_ptr;
345 80c6dc86 2002-12-15 alex }
346 80c6dc86 2002-12-15 alex else
347 80c6dc86 2002-12-15 alex {
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 ));
351 80c6dc86 2002-12-15 alex }
352 8adff592 2005-03-19 fw if( *mode_ptr == '+' ) set = true;
353 8adff592 2005-03-19 fw else set = false;
354 80c6dc86 2002-12-15 alex }
355 80c6dc86 2002-12-15 alex continue;
356 80c6dc86 2002-12-15 alex }
357 80c6dc86 2002-12-15 alex
358 80c6dc86 2002-12-15 alex /* Are there arguments left? */
359 80c6dc86 2002-12-15 alex if( arg_arg >= Req->argc ) arg_arg = -1;
360 80c6dc86 2002-12-15 alex
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 )
366 c23199d9 2002-02-27 alex {
367 8579b2a1 2005-02-27 alex /* --- Channel modes --- */
368 8579b2a1 2005-02-27 alex
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 ));
376 7f61f413 2002-12-16 alex break;
377 7f61f413 2002-12-16 alex
378 8579b2a1 2005-02-27 alex case 'k': /* Channel key */
379 69ad0e38 2002-12-16 alex if( ! set )
380 69ad0e38 2002-12-16 alex {
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 ));
383 69ad0e38 2002-12-16 alex break;
384 69ad0e38 2002-12-16 alex }
385 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
386 69ad0e38 2002-12-16 alex {
387 69ad0e38 2002-12-16 alex if( modeok )
388 69ad0e38 2002-12-16 alex {
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;
393 69ad0e38 2002-12-16 alex }
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';
396 69ad0e38 2002-12-16 alex arg_arg++;
397 69ad0e38 2002-12-16 alex }
398 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
399 69ad0e38 2002-12-16 alex break;
400 8579b2a1 2005-02-27 alex
401 8579b2a1 2005-02-27 alex case 'l': /* Member limit */
402 69ad0e38 2002-12-16 alex if( ! set )
403 69ad0e38 2002-12-16 alex {
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 ));
406 69ad0e38 2002-12-16 alex break;
407 69ad0e38 2002-12-16 alex }
408 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
409 69ad0e38 2002-12-16 alex {
410 69ad0e38 2002-12-16 alex if( modeok )
411 69ad0e38 2002-12-16 alex {
412 69ad0e38 2002-12-16 alex l = atol( Req->argv[arg_arg] );
413 69ad0e38 2002-12-16 alex if( l > 0 && l < 0xFFFF )
414 69ad0e38 2002-12-16 alex {
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;
419 69ad0e38 2002-12-16 alex }
420 69ad0e38 2002-12-16 alex }
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';
423 69ad0e38 2002-12-16 alex arg_arg++;
424 69ad0e38 2002-12-16 alex }
425 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
426 69ad0e38 2002-12-16 alex break;
427 7e1b3b91 2002-09-02 alex
428 8579b2a1 2005-02-27 alex case 'P': /* Persistent channel */
429 8579b2a1 2005-02-27 alex if( modeok )
430 8579b2a1 2005-02-27 alex {
431 8579b2a1 2005-02-27 alex if( set && ( ! Client_OperByMe( Client )))
432 8579b2a1 2005-02-27 alex {
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 ));
435 8579b2a1 2005-02-27 alex }
436 8579b2a1 2005-02-27 alex else x[0] = 'P';
437 8579b2a1 2005-02-27 alex }
438 8579b2a1 2005-02-27 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
439 8579b2a1 2005-02-27 alex break;
440 8579b2a1 2005-02-27 alex
441 8579b2a1 2005-02-27 alex /* --- Channel user modes --- */
442 8579b2a1 2005-02-27 alex
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 )
446 7f61f413 2002-12-16 alex {
447 8579b2a1 2005-02-27 alex if( modeok )
448 8579b2a1 2005-02-27 alex {
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] );
452 8579b2a1 2005-02-27 alex }
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';
455 8579b2a1 2005-02-27 alex arg_arg++;
456 8579b2a1 2005-02-27 alex }
457 8579b2a1 2005-02-27 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
458 8579b2a1 2005-02-27 alex break;
459 8579b2a1 2005-02-27 alex
460 8579b2a1 2005-02-27 alex /* --- Channel lists --- */
461 8579b2a1 2005-02-27 alex
462 8579b2a1 2005-02-27 alex case 'I': /* Invite lists */
463 8579b2a1 2005-02-27 alex if( arg_arg > mode_arg )
464 8579b2a1 2005-02-27 alex {
465 7f61f413 2002-12-16 alex /* modify list */
466 7f61f413 2002-12-16 alex if( modeok )
467 80c6dc86 2002-12-15 alex {
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] );
470 80c6dc86 2002-12-15 alex }
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';
473 7f61f413 2002-12-16 alex arg_arg++;
474 7f61f413 2002-12-16 alex }
475 7f61f413 2002-12-16 alex else Lists_ShowInvites( Origin, Channel );
476 7f61f413 2002-12-16 alex break;
477 8579b2a1 2005-02-27 alex
478 8579b2a1 2005-02-27 alex case 'b': /* Ban lists */
479 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
480 7f61f413 2002-12-16 alex {
481 7f61f413 2002-12-16 alex /* modify list */
482 7f61f413 2002-12-16 alex if( modeok )
483 c23199d9 2002-02-27 alex {
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] );
486 c23199d9 2002-02-27 alex }
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';
489 7f61f413 2002-12-16 alex arg_arg++;
490 7f61f413 2002-12-16 alex }
491 7f61f413 2002-12-16 alex else Lists_ShowBans( Origin, Channel );
492 7f61f413 2002-12-16 alex break;
493 80c6dc86 2002-12-15 alex
494 7f61f413 2002-12-16 alex default:
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;
499 c23199d9 2002-02-27 alex }
500 c23199d9 2002-02-27 alex if( ! ok ) break;
501 80c6dc86 2002-12-15 alex
502 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
503 c23199d9 2002-02-27 alex if( ! x[0] ) continue;
504 c23199d9 2002-02-27 alex
505 fbec1f10 2003-01-21 alex /* Validate target client */
506 fbec1f10 2003-01-21 alex if( client && ( ! Channel_IsMemberOf( Channel, client )))
507 fbec1f10 2003-01-21 alex {
508 fbec1f10 2003-01-21 alex if( ! IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( client ), Channel_Name( Channel ))) break;
509 fbec1f10 2003-01-21 alex continue;
510 fbec1f10 2003-01-21 alex }
511 fbec1f10 2003-01-21 alex
512 80c6dc86 2002-12-15 alex if( set )
513 c23199d9 2002-02-27 alex {
514 80c6dc86 2002-12-15 alex /* Set mode */
515 80c6dc86 2002-12-15 alex if( client )
516 c23199d9 2002-02-27 alex {
517 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
518 80c6dc86 2002-12-15 alex if( Channel_UserModeAdd( Channel, client, x[0] ))
519 80c6dc86 2002-12-15 alex {
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 ));
524 80c6dc86 2002-12-15 alex }
525 c23199d9 2002-02-27 alex }
526 c23199d9 2002-02-27 alex else
527 c23199d9 2002-02-27 alex {
528 80c6dc86 2002-12-15 alex /* Channel-Mode */
529 c0d74a38 2002-12-15 alex if( Channel_ModeAdd( Channel, x[0] ))
530 c0d74a38 2002-12-15 alex {
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 ));
533 c0d74a38 2002-12-15 alex }
534 c23199d9 2002-02-27 alex }
535 c23199d9 2002-02-27 alex }
536 80c6dc86 2002-12-15 alex else
537 c23199d9 2002-02-27 alex {
538 80c6dc86 2002-12-15 alex /* Unset mode */
539 80c6dc86 2002-12-15 alex if( client )
540 c23199d9 2002-02-27 alex {
541 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
542 80c6dc86 2002-12-15 alex if( Channel_UserModeDel( Channel, client, x[0] ))
543 c23199d9 2002-02-27 alex {
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 ));
548 c23199d9 2002-02-27 alex }
549 c23199d9 2002-02-27 alex }
550 c23199d9 2002-02-27 alex else
551 c23199d9 2002-02-27 alex {
552 c23199d9 2002-02-27 alex /* Channel-Mode */
553 c0d74a38 2002-12-15 alex if( Channel_ModeDel( Channel, x[0] ))
554 c0d74a38 2002-12-15 alex {
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 ));
557 c0d74a38 2002-12-15 alex }
558 c23199d9 2002-02-27 alex }
559 69ad0e38 2002-12-16 alex }
560 69ad0e38 2002-12-16 alex
561 69ad0e38 2002-12-16 alex /* Are there additional arguments to add? */
562 69ad0e38 2002-12-16 alex if( argadd[0] )
563 69ad0e38 2002-12-16 alex {
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 ));
567 69ad0e38 2002-12-16 alex }
568 c23199d9 2002-02-27 alex }
569 69ad0e38 2002-12-16 alex chan_exit:
570 c23199d9 2002-02-27 alex
571 80c6dc86 2002-12-15 alex /* Are there changed modes? */
572 c23199d9 2002-02-27 alex if( the_modes[1] )
573 c23199d9 2002-02-27 alex {
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';
577 c0d74a38 2002-12-15 alex
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';
580 80c6dc86 2002-12-15 alex
581 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
582 c23199d9 2002-02-27 alex {
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 );
586 c23199d9 2002-02-27 alex }
587 80c6dc86 2002-12-15 alex else
588 c23199d9 2002-02-27 alex {
589 1d08d51e 2005-03-15 alex if ( use_servermode ) Origin = Client_ThisServer();
590 1d08d51e 2005-03-15 alex
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 );
595 c23199d9 2002-02-27 alex }
596 c23199d9 2002-02-27 alex }
597 c23199d9 2002-02-27 alex
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 */
601 c23199d9 2002-02-27 alex
602 c23199d9 2002-02-27 alex
603 8adff592 2005-03-19 fw GLOBAL bool
604 c2f60abe 2002-05-27 alex IRC_AWAY( CLIENT *Client, REQUEST *Req )
605 c23199d9 2002-02-27 alex {
606 c23199d9 2002-02-27 alex assert( Client != NULL );
607 c23199d9 2002-02-27 alex assert( Req != NULL );
608 c23199d9 2002-02-27 alex
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 );
611 c23199d9 2002-02-27 alex
612 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
613 c23199d9 2002-02-27 alex {
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 ));
619 c23199d9 2002-02-27 alex }
620 c23199d9 2002-02-27 alex else
621 c23199d9 2002-02-27 alex {
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 ));
626 c23199d9 2002-02-27 alex }
627 c23199d9 2002-02-27 alex } /* IRC_AWAY */
628 19ac723e 2002-09-08 alex
629 19ac723e 2002-09-08 alex
630 8adff592 2005-03-19 fw LOCAL bool
631 8adff592 2005-03-19 fw Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
632 19ac723e 2002-09-08 alex {
633 8adff592 2005-03-19 fw char *mask;
634 8adff592 2005-03-19 fw bool already;
635 19ac723e 2002-09-08 alex
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 );
639 c23199d9 2002-02-27 alex
640 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
641 c23199d9 2002-02-27 alex
642 96747679 2004-04-25 alex already = Lists_IsInviteEntry( mask, Channel );
643 96747679 2004-04-25 alex
644 8adff592 2005-03-19 fw if( ! Lists_AddInvited( mask, Channel, false )) return CONNECTED;
645 96747679 2004-04-25 alex
646 8adff592 2005-03-19 fw if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
647 64d330b7 2004-04-09 alex
648 296ddebe 2002-09-08 alex return Send_ListChange( "+I", Prefix, Client, Channel, mask );
649 19ac723e 2002-09-08 alex } /* Add_Invite */
650 19ac723e 2002-09-08 alex
651 19ac723e 2002-09-08 alex
652 8adff592 2005-03-19 fw LOCAL bool
653 8adff592 2005-03-19 fw Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
654 19ac723e 2002-09-08 alex {
655 8adff592 2005-03-19 fw char *mask;
656 8adff592 2005-03-19 fw bool already;
657 19ac723e 2002-09-08 alex
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 );
661 19ac723e 2002-09-08 alex
662 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
663 19ac723e 2002-09-08 alex
664 96747679 2004-04-25 alex already = Lists_IsBanEntry( mask, Channel );
665 96747679 2004-04-25 alex
666 64d330b7 2004-04-09 alex if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
667 64d330b7 2004-04-09 alex
668 8adff592 2005-03-19 fw if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == true)) return CONNECTED;
669 96747679 2004-04-25 alex
670 296ddebe 2002-09-08 alex return Send_ListChange( "+b", Prefix, Client, Channel, mask );
671 19ac723e 2002-09-08 alex } /* Add_Ban */
672 19ac723e 2002-09-08 alex
673 19ac723e 2002-09-08 alex
674 8adff592 2005-03-19 fw LOCAL bool
675 8adff592 2005-03-19 fw Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
676 19ac723e 2002-09-08 alex {
677 8adff592 2005-03-19 fw char *mask;
678 19ac723e 2002-09-08 alex
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 );
682 19ac723e 2002-09-08 alex
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 */
687 19ac723e 2002-09-08 alex
688 19ac723e 2002-09-08 alex
689 8adff592 2005-03-19 fw LOCAL bool
690 8adff592 2005-03-19 fw Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Pattern )
691 19ac723e 2002-09-08 alex {
692 8adff592 2005-03-19 fw char *mask;
693 19ac723e 2002-09-08 alex
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 );
697 19ac723e 2002-09-08 alex
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 */
702 19ac723e 2002-09-08 alex
703 296ddebe 2002-09-08 alex
704 8adff592 2005-03-19 fw LOCAL bool
705 8adff592 2005-03-19 fw Send_ListChange( char *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, char *Mask )
706 296ddebe 2002-09-08 alex {
707 296ddebe 2002-09-08 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
708 296ddebe 2002-09-08 alex
709 8adff592 2005-03-19 fw bool ok;
710 296ddebe 2002-09-08 alex
711 19ac723e 2002-09-08 alex if( Client_Type( Client ) == CLIENT_USER )
712 19ac723e 2002-09-08 alex {
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 );
715 19ac723e 2002-09-08 alex }
716 8adff592 2005-03-19 fw else ok = true;
717 19ac723e 2002-09-08 alex
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 );
720 19ac723e 2002-09-08 alex
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 );
723 296ddebe 2002-09-08 alex
724 296ddebe 2002-09-08 alex return ok;
725 296ddebe 2002-09-08 alex } /* Send_ListChange */
726 296ddebe 2002-09-08 alex
727 296ddebe 2002-09-08 alex
728 c23199d9 2002-02-27 alex /* -eof- */