Blame


1 c23199d9 2002-02-27 alex /*
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)
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 df00b38a 2003-01-08 alex static char UNUSED id[] = "$Id: irc-mode.c,v 1.29 2003/01/08 23:00:12 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 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"
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 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 ));
43 80c6dc86 2002-12-15 alex
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 ));
46 19ac723e 2002-09-08 alex
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 ));
49 19ac723e 2002-09-08 alex
50 296ddebe 2002-09-08 alex LOCAL BOOLEAN 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 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
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 80c6dc86 2002-12-15 alex LOCAL BOOLEAN
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 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;
94 80c6dc86 2002-12-15 alex
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 )
97 19ac723e 2002-09-08 alex {
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 ));
100 19ac723e 2002-09-08 alex }
101 19ac723e 2002-09-08 alex
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 ));
104 80c6dc86 2002-12-15 alex
105 80c6dc86 2002-12-15 alex mode_arg = 1;
106 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
107 80c6dc86 2002-12-15 alex
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 ));
112 80c6dc86 2002-12-15 alex
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, "-" );
116 80c6dc86 2002-12-15 alex
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 )
120 80c6dc86 2002-12-15 alex {
121 80c6dc86 2002-12-15 alex mode_ptr++;
122 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
123 19ac723e 2002-09-08 alex {
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;
128 19ac723e 2002-09-08 alex }
129 80c6dc86 2002-12-15 alex
130 80c6dc86 2002-12-15 alex switch( *mode_ptr )
131 19ac723e 2002-09-08 alex {
132 80c6dc86 2002-12-15 alex case '+':
133 80c6dc86 2002-12-15 alex case '-':
134 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
135 c2aefbb3 2002-09-08 alex {
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] == '-' ))
138 80c6dc86 2002-12-15 alex {
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;
141 80c6dc86 2002-12-15 alex }
142 80c6dc86 2002-12-15 alex else
143 80c6dc86 2002-12-15 alex {
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 ));
147 80c6dc86 2002-12-15 alex }
148 80c6dc86 2002-12-15 alex if( *mode_ptr == '+' ) set = TRUE;
149 80c6dc86 2002-12-15 alex else set = FALSE;
150 c2aefbb3 2002-09-08 alex }
151 80c6dc86 2002-12-15 alex continue;
152 80c6dc86 2002-12-15 alex }
153 80c6dc86 2002-12-15 alex
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 )
157 80c6dc86 2002-12-15 alex {
158 8841d873 2002-12-18 alex case 'a':
159 8841d873 2002-12-18 alex /* Away */
160 8c1df9ef 2003-01-02 alex if( Client_Type( Client ) == CLIENT_SERVER )
161 8c1df9ef 2003-01-02 alex {
162 8c1df9ef 2003-01-02 alex x[0] = 'a';
163 8c1df9ef 2003-01-02 alex Client_SetAway( Client, DEFAULT_AWAY_MSG );
164 8c1df9ef 2003-01-02 alex }
165 8841d873 2002-12-18 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
166 8841d873 2002-12-18 alex break;
167 7f61f413 2002-12-16 alex case 'i':
168 7f61f413 2002-12-16 alex /* Invisible */
169 7f61f413 2002-12-16 alex x[0] = 'i';
170 7f61f413 2002-12-16 alex break;
171 7f61f413 2002-12-16 alex case 'o':
172 7f61f413 2002-12-16 alex /* IRC operator (only unsetable!) */
173 8841d873 2002-12-18 alex if(( ! set ) || ( Client_Type( Client ) == CLIENT_SERVER ))
174 7f61f413 2002-12-16 alex {
175 7f61f413 2002-12-16 alex Client_SetOperByMe( Target, FALSE );
176 7f61f413 2002-12-16 alex x[0] = 'o';
177 7f61f413 2002-12-16 alex }
178 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
179 7f61f413 2002-12-16 alex break;
180 7f61f413 2002-12-16 alex case 'r':
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 ));
184 7f61f413 2002-12-16 alex break;
185 7f61f413 2002-12-16 alex case 's':
186 7f61f413 2002-12-16 alex /* Server messages */
187 7f61f413 2002-12-16 alex x[0] = 's';
188 7f61f413 2002-12-16 alex break;
189 7f61f413 2002-12-16 alex default:
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;
194 19ac723e 2002-09-08 alex }
195 80c6dc86 2002-12-15 alex if( ! ok ) break;
196 80c6dc86 2002-12-15 alex
197 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
198 80c6dc86 2002-12-15 alex if( ! x[0] ) continue;
199 80c6dc86 2002-12-15 alex
200 80c6dc86 2002-12-15 alex if( set )
201 80c6dc86 2002-12-15 alex {
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 ));
204 80c6dc86 2002-12-15 alex
205 80c6dc86 2002-12-15 alex }
206 80c6dc86 2002-12-15 alex else
207 80c6dc86 2002-12-15 alex {
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 ));
210 80c6dc86 2002-12-15 alex }
211 19ac723e 2002-09-08 alex }
212 69ad0e38 2002-12-16 alex client_exit:
213 69ad0e38 2002-12-16 alex
214 80c6dc86 2002-12-15 alex /* Are there changed modes? */
215 80c6dc86 2002-12-15 alex if( the_modes[1] )
216 c23199d9 2002-02-27 alex {
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';
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 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 );
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 80c6dc86 2002-12-15 alex
234 80c6dc86 2002-12-15 alex return ok;
235 80c6dc86 2002-12-15 alex } /* Client_Mode */
236 c23199d9 2002-02-27 alex
237 c23199d9 2002-02-27 alex
238 80c6dc86 2002-12-15 alex LOCAL BOOLEAN
239 80c6dc86 2002-12-15 alex Channel_Mode( CLIENT *Client, REQUEST *Req, CLIENT *Origin, CHANNEL *Channel )
240 80c6dc86 2002-12-15 alex {
241 80c6dc86 2002-12-15 alex /* Handle channel and channel-user modes */
242 c23199d9 2002-02-27 alex
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;
247 69ad0e38 2002-12-16 alex LONG l;
248 80c6dc86 2002-12-15 alex
249 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
250 df00b38a 2003-01-08 alex if( Req->argc == 1 )
251 df00b38a 2003-01-08 alex {
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 ));
254 80c6dc86 2002-12-15 alex
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 )
260 df00b38a 2003-01-08 alex {
261 df00b38a 2003-01-08 alex switch( *mode_ptr )
262 df00b38a 2003-01-08 alex {
263 df00b38a 2003-01-08 alex case 'l':
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 ));
266 df00b38a 2003-01-08 alex break;
267 df00b38a 2003-01-08 alex case 'k':
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 ));
270 df00b38a 2003-01-08 alex break;
271 df00b38a 2003-01-08 alex }
272 df00b38a 2003-01-08 alex mode_ptr++;
273 df00b38a 2003-01-08 alex }
274 df00b38a 2003-01-08 alex if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
275 df00b38a 2003-01-08 alex
276 df00b38a 2003-01-08 alex return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
277 df00b38a 2003-01-08 alex }
278 df00b38a 2003-01-08 alex
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 )
281 c23199d9 2002-02-27 alex {
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 )
285 80c6dc86 2002-12-15 alex {
286 80c6dc86 2002-12-15 alex /* auch IRC-Operatoren duerfen MODE verwenden */
287 80c6dc86 2002-12-15 alex if( Client_OperByMe( Origin )) modeok = TRUE;
288 80c6dc86 2002-12-15 alex }
289 c23199d9 2002-02-27 alex }
290 80c6dc86 2002-12-15 alex else modeok = TRUE;
291 c23199d9 2002-02-27 alex
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;
296 80c6dc86 2002-12-15 alex
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;
302 80c6dc86 2002-12-15 alex
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, " " );
307 c23199d9 2002-02-27 alex
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 )
311 c23199d9 2002-02-27 alex {
312 80c6dc86 2002-12-15 alex if( ! skiponce ) mode_ptr++;
313 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
314 80c6dc86 2002-12-15 alex {
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;
322 80c6dc86 2002-12-15 alex }
323 80c6dc86 2002-12-15 alex skiponce = FALSE;
324 80c6dc86 2002-12-15 alex
325 80c6dc86 2002-12-15 alex switch( *mode_ptr )
326 80c6dc86 2002-12-15 alex {
327 80c6dc86 2002-12-15 alex case '+':
328 80c6dc86 2002-12-15 alex case '-':
329 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
330 80c6dc86 2002-12-15 alex {
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] == '-' ))
333 80c6dc86 2002-12-15 alex {
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;
336 80c6dc86 2002-12-15 alex }
337 80c6dc86 2002-12-15 alex else
338 80c6dc86 2002-12-15 alex {
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 ));
342 80c6dc86 2002-12-15 alex }
343 80c6dc86 2002-12-15 alex if( *mode_ptr == '+' ) set = TRUE;
344 80c6dc86 2002-12-15 alex else set = FALSE;
345 80c6dc86 2002-12-15 alex }
346 80c6dc86 2002-12-15 alex continue;
347 80c6dc86 2002-12-15 alex }
348 80c6dc86 2002-12-15 alex
349 80c6dc86 2002-12-15 alex /* Are there arguments left? */
350 80c6dc86 2002-12-15 alex if( arg_arg >= Req->argc ) arg_arg = -1;
351 80c6dc86 2002-12-15 alex
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 )
357 c23199d9 2002-02-27 alex {
358 7f61f413 2002-12-16 alex /* Channel modes */
359 7f61f413 2002-12-16 alex case 'i':
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 ));
363 7f61f413 2002-12-16 alex break;
364 7f61f413 2002-12-16 alex case 'm':
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 ));
368 7f61f413 2002-12-16 alex break;
369 7f61f413 2002-12-16 alex case 'n':
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 ));
373 7f61f413 2002-12-16 alex break;
374 7f61f413 2002-12-16 alex case 't':
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 ));
378 7f61f413 2002-12-16 alex break;
379 7f61f413 2002-12-16 alex case 'P':
380 7f61f413 2002-12-16 alex /* Persistent channel */
381 7f61f413 2002-12-16 alex if( modeok )
382 7f61f413 2002-12-16 alex {
383 7f61f413 2002-12-16 alex if( set && ( ! Client_OperByMe( Client )))
384 7f61f413 2002-12-16 alex {
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 ));
387 7f61f413 2002-12-16 alex }
388 7f61f413 2002-12-16 alex else x[0] = 'P';
389 7f61f413 2002-12-16 alex }
390 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
391 7f61f413 2002-12-16 alex break;
392 7f61f413 2002-12-16 alex
393 7f61f413 2002-12-16 alex /* Channel user modes */
394 7f61f413 2002-12-16 alex case 'o':
395 7f61f413 2002-12-16 alex /* Channel operator */
396 7f61f413 2002-12-16 alex case 'v':
397 7f61f413 2002-12-16 alex /* Voice */
398 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
399 7f61f413 2002-12-16 alex {
400 80c6dc86 2002-12-15 alex if( modeok )
401 80c6dc86 2002-12-15 alex {
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] );
405 80c6dc86 2002-12-15 alex }
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';
408 7f61f413 2002-12-16 alex arg_arg++;
409 7f61f413 2002-12-16 alex }
410 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
411 7f61f413 2002-12-16 alex break;
412 69ad0e38 2002-12-16 alex case 'k':
413 69ad0e38 2002-12-16 alex /* Channel key */
414 69ad0e38 2002-12-16 alex if( ! set )
415 69ad0e38 2002-12-16 alex {
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 ));
418 69ad0e38 2002-12-16 alex break;
419 69ad0e38 2002-12-16 alex }
420 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
421 69ad0e38 2002-12-16 alex {
422 69ad0e38 2002-12-16 alex if( modeok )
423 69ad0e38 2002-12-16 alex {
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;
428 69ad0e38 2002-12-16 alex }
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';
431 69ad0e38 2002-12-16 alex arg_arg++;
432 69ad0e38 2002-12-16 alex }
433 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
434 69ad0e38 2002-12-16 alex break;
435 69ad0e38 2002-12-16 alex case 'l':
436 69ad0e38 2002-12-16 alex /* Member limit */
437 69ad0e38 2002-12-16 alex if( ! set )
438 69ad0e38 2002-12-16 alex {
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 ));
441 69ad0e38 2002-12-16 alex break;
442 69ad0e38 2002-12-16 alex }
443 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
444 69ad0e38 2002-12-16 alex {
445 69ad0e38 2002-12-16 alex if( modeok )
446 69ad0e38 2002-12-16 alex {
447 69ad0e38 2002-12-16 alex l = atol( Req->argv[arg_arg] );
448 69ad0e38 2002-12-16 alex if( l > 0 && l < 0xFFFF )
449 69ad0e38 2002-12-16 alex {
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;
454 69ad0e38 2002-12-16 alex }
455 69ad0e38 2002-12-16 alex }
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';
458 69ad0e38 2002-12-16 alex arg_arg++;
459 69ad0e38 2002-12-16 alex }
460 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
461 69ad0e38 2002-12-16 alex break;
462 7e1b3b91 2002-09-02 alex
463 7f61f413 2002-12-16 alex /* Channel lists */
464 7f61f413 2002-12-16 alex case 'I':
465 7f61f413 2002-12-16 alex /* Invite lists */
466 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
467 7f61f413 2002-12-16 alex {
468 7f61f413 2002-12-16 alex /* modify list */
469 7f61f413 2002-12-16 alex if( modeok )
470 80c6dc86 2002-12-15 alex {
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] );
473 80c6dc86 2002-12-15 alex }
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';
476 7f61f413 2002-12-16 alex arg_arg++;
477 7f61f413 2002-12-16 alex }
478 7f61f413 2002-12-16 alex else Lists_ShowInvites( Origin, Channel );
479 7f61f413 2002-12-16 alex break;
480 7f61f413 2002-12-16 alex case 'b':
481 7f61f413 2002-12-16 alex /* Ban lists */
482 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
483 7f61f413 2002-12-16 alex {
484 7f61f413 2002-12-16 alex /* modify list */
485 7f61f413 2002-12-16 alex if( modeok )
486 c23199d9 2002-02-27 alex {
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] );
489 c23199d9 2002-02-27 alex }
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';
492 7f61f413 2002-12-16 alex arg_arg++;
493 7f61f413 2002-12-16 alex }
494 7f61f413 2002-12-16 alex else Lists_ShowBans( Origin, Channel );
495 7f61f413 2002-12-16 alex break;
496 80c6dc86 2002-12-15 alex
497 7f61f413 2002-12-16 alex default:
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;
502 c23199d9 2002-02-27 alex }
503 c23199d9 2002-02-27 alex if( ! ok ) break;
504 80c6dc86 2002-12-15 alex
505 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
506 c23199d9 2002-02-27 alex if( ! x[0] ) continue;
507 c23199d9 2002-02-27 alex
508 80c6dc86 2002-12-15 alex if( set )
509 c23199d9 2002-02-27 alex {
510 80c6dc86 2002-12-15 alex /* Set mode */
511 80c6dc86 2002-12-15 alex if( client )
512 c23199d9 2002-02-27 alex {
513 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
514 80c6dc86 2002-12-15 alex if( Channel_UserModeAdd( Channel, client, x[0] ))
515 80c6dc86 2002-12-15 alex {
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 ));
520 80c6dc86 2002-12-15 alex }
521 c23199d9 2002-02-27 alex }
522 c23199d9 2002-02-27 alex else
523 c23199d9 2002-02-27 alex {
524 80c6dc86 2002-12-15 alex /* Channel-Mode */
525 c0d74a38 2002-12-15 alex if( Channel_ModeAdd( Channel, x[0] ))
526 c0d74a38 2002-12-15 alex {
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 ));
529 c0d74a38 2002-12-15 alex }
530 c23199d9 2002-02-27 alex }
531 c23199d9 2002-02-27 alex }
532 80c6dc86 2002-12-15 alex else
533 c23199d9 2002-02-27 alex {
534 80c6dc86 2002-12-15 alex /* Unset mode */
535 80c6dc86 2002-12-15 alex if( client )
536 c23199d9 2002-02-27 alex {
537 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
538 80c6dc86 2002-12-15 alex if( Channel_UserModeDel( Channel, client, x[0] ))
539 c23199d9 2002-02-27 alex {
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 ));
544 c23199d9 2002-02-27 alex }
545 c23199d9 2002-02-27 alex }
546 c23199d9 2002-02-27 alex else
547 c23199d9 2002-02-27 alex {
548 c23199d9 2002-02-27 alex /* Channel-Mode */
549 c0d74a38 2002-12-15 alex if( Channel_ModeDel( Channel, x[0] ))
550 c0d74a38 2002-12-15 alex {
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 ));
553 c0d74a38 2002-12-15 alex }
554 c23199d9 2002-02-27 alex }
555 69ad0e38 2002-12-16 alex }
556 69ad0e38 2002-12-16 alex
557 69ad0e38 2002-12-16 alex /* Are there additional arguments to add? */
558 69ad0e38 2002-12-16 alex if( argadd[0] )
559 69ad0e38 2002-12-16 alex {
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 ));
562 69ad0e38 2002-12-16 alex }
563 c23199d9 2002-02-27 alex }
564 69ad0e38 2002-12-16 alex chan_exit:
565 c23199d9 2002-02-27 alex
566 80c6dc86 2002-12-15 alex /* Are there changed modes? */
567 c23199d9 2002-02-27 alex if( the_modes[1] )
568 c23199d9 2002-02-27 alex {
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';
571 c0d74a38 2002-12-15 alex
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';
574 80c6dc86 2002-12-15 alex
575 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
576 c23199d9 2002-02-27 alex {
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 );
580 c23199d9 2002-02-27 alex }
581 80c6dc86 2002-12-15 alex else
582 c23199d9 2002-02-27 alex {
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 );
587 c23199d9 2002-02-27 alex }
588 c23199d9 2002-02-27 alex }
589 c23199d9 2002-02-27 alex
590 80c6dc86 2002-12-15 alex return CONNECTED;
591 80c6dc86 2002-12-15 alex } /* Channel_Mode */
592 c23199d9 2002-02-27 alex
593 c23199d9 2002-02-27 alex
594 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
595 c2f60abe 2002-05-27 alex IRC_AWAY( CLIENT *Client, REQUEST *Req )
596 c23199d9 2002-02-27 alex {
597 c23199d9 2002-02-27 alex assert( Client != NULL );
598 c23199d9 2002-02-27 alex assert( Req != NULL );
599 c23199d9 2002-02-27 alex
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 );
602 c23199d9 2002-02-27 alex
603 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
604 c23199d9 2002-02-27 alex {
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 ));
610 c23199d9 2002-02-27 alex }
611 c23199d9 2002-02-27 alex else
612 c23199d9 2002-02-27 alex {
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 ));
617 c23199d9 2002-02-27 alex }
618 c23199d9 2002-02-27 alex } /* IRC_AWAY */
619 19ac723e 2002-09-08 alex
620 19ac723e 2002-09-08 alex
621 19ac723e 2002-09-08 alex LOCAL BOOLEAN
622 296ddebe 2002-09-08 alex Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
623 19ac723e 2002-09-08 alex {
624 19ac723e 2002-09-08 alex CHAR *mask;
625 19ac723e 2002-09-08 alex
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 );
629 c23199d9 2002-02-27 alex
630 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
631 c23199d9 2002-02-27 alex
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 */
635 19ac723e 2002-09-08 alex
636 19ac723e 2002-09-08 alex
637 19ac723e 2002-09-08 alex LOCAL BOOLEAN
638 296ddebe 2002-09-08 alex Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
639 19ac723e 2002-09-08 alex {
640 19ac723e 2002-09-08 alex CHAR *mask;
641 19ac723e 2002-09-08 alex
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 );
645 19ac723e 2002-09-08 alex
646 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
647 19ac723e 2002-09-08 alex
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 */
651 19ac723e 2002-09-08 alex
652 19ac723e 2002-09-08 alex
653 19ac723e 2002-09-08 alex LOCAL BOOLEAN
654 296ddebe 2002-09-08 alex Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
655 19ac723e 2002-09-08 alex {
656 19ac723e 2002-09-08 alex CHAR *mask;
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 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 */
666 19ac723e 2002-09-08 alex
667 19ac723e 2002-09-08 alex
668 19ac723e 2002-09-08 alex LOCAL BOOLEAN
669 296ddebe 2002-09-08 alex Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
670 19ac723e 2002-09-08 alex {
671 19ac723e 2002-09-08 alex CHAR *mask;
672 19ac723e 2002-09-08 alex
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 );
676 19ac723e 2002-09-08 alex
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 */
681 19ac723e 2002-09-08 alex
682 296ddebe 2002-09-08 alex
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 )
685 296ddebe 2002-09-08 alex {
686 296ddebe 2002-09-08 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
687 296ddebe 2002-09-08 alex
688 296ddebe 2002-09-08 alex BOOLEAN ok;
689 296ddebe 2002-09-08 alex
690 19ac723e 2002-09-08 alex if( Client_Type( Client ) == CLIENT_USER )
691 19ac723e 2002-09-08 alex {
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 );
694 19ac723e 2002-09-08 alex }
695 296ddebe 2002-09-08 alex else ok = TRUE;
696 19ac723e 2002-09-08 alex
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 );
699 19ac723e 2002-09-08 alex
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 );
702 296ddebe 2002-09-08 alex
703 296ddebe 2002-09-08 alex return ok;
704 296ddebe 2002-09-08 alex } /* Send_ListChange */
705 296ddebe 2002-09-08 alex
706 296ddebe 2002-09-08 alex
707 c23199d9 2002-02-27 alex /* -eof- */