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 96747679 2004-04-25 alex static char UNUSED id[] = "$Id: irc-mode.c,v 1.35 2004/04/25 15:42:05 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 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 80c6dc86 2002-12-15 alex LOCAL BOOLEAN
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 69ad0e38 2002-12-16 alex CHAR the_modes[COMMAND_LEN], the_args[COMMAND_LEN], x[2], argadd[CLIENT_PASS_LEN], *mode_ptr;
245 80c6dc86 2002-12-15 alex BOOLEAN ok, set, modeok, skiponce;
246 80c6dc86 2002-12-15 alex INT mode_arg, arg_arg;
247 80c6dc86 2002-12-15 alex CLIENT *client;
248 69ad0e38 2002-12-16 alex LONG l;
249 80c6dc86 2002-12-15 alex
250 80c6dc86 2002-12-15 alex /* Mode request: let's answer it :-) */
251 df00b38a 2003-01-08 alex if( Req->argc == 1 )
252 df00b38a 2003-01-08 alex {
253 df00b38a 2003-01-08 alex /* Member or not? -- That's the question! */
254 df00b38a 2003-01-08 alex if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), Channel_Modes( Channel ));
255 80c6dc86 2002-12-15 alex
256 df00b38a 2003-01-08 alex /* The sender is a member: generate extended reply */
257 df00b38a 2003-01-08 alex strlcpy( the_modes, Channel_Modes( Channel ), sizeof( the_modes ));
258 df00b38a 2003-01-08 alex mode_ptr = the_modes;
259 df00b38a 2003-01-08 alex strcpy( the_args, "" );
260 df00b38a 2003-01-08 alex while( *mode_ptr )
261 df00b38a 2003-01-08 alex {
262 df00b38a 2003-01-08 alex switch( *mode_ptr )
263 df00b38a 2003-01-08 alex {
264 df00b38a 2003-01-08 alex case 'l':
265 df00b38a 2003-01-08 alex snprintf( argadd, sizeof( argadd ), " %ld", Channel_MaxUsers( Channel ));
266 df00b38a 2003-01-08 alex strlcat( the_args, argadd, sizeof( the_args ));
267 df00b38a 2003-01-08 alex break;
268 df00b38a 2003-01-08 alex case 'k':
269 df00b38a 2003-01-08 alex strlcat( the_args, " ", sizeof( the_args ));
270 df00b38a 2003-01-08 alex strlcat( the_args, Channel_Key( Channel ), sizeof( the_args ));
271 df00b38a 2003-01-08 alex break;
272 df00b38a 2003-01-08 alex }
273 df00b38a 2003-01-08 alex mode_ptr++;
274 df00b38a 2003-01-08 alex }
275 df00b38a 2003-01-08 alex if( the_args[0] ) strlcat( the_modes, the_args, sizeof( the_modes ));
276 df00b38a 2003-01-08 alex
277 df00b38a 2003-01-08 alex return IRC_WriteStrClient( Origin, RPL_CHANNELMODEIS_MSG, Client_ID( Origin ), Channel_Name( Channel ), the_modes );
278 df00b38a 2003-01-08 alex }
279 df00b38a 2003-01-08 alex
280 80c6dc86 2002-12-15 alex /* Is the user allowed to change modes? */
281 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_USER )
282 c23199d9 2002-02-27 alex {
283 e07542a1 2003-01-17 alex /* Is the originating user on that channel? */
284 e07542a1 2003-01-17 alex if( ! Channel_IsMemberOf( Channel, Origin )) return IRC_WriteStrClient( Origin, ERR_NOTONCHANNEL_MSG, Client_ID( Origin ), Channel_Name( Channel ));
285 e07542a1 2003-01-17 alex
286 e07542a1 2003-01-17 alex /* Is he channel operator? */
287 80c6dc86 2002-12-15 alex if( strchr( Channel_UserModes( Channel, Origin ), 'o' )) modeok = TRUE;
288 80c6dc86 2002-12-15 alex else modeok = FALSE;
289 80c6dc86 2002-12-15 alex if( Conf_OperCanMode )
290 80c6dc86 2002-12-15 alex {
291 80c6dc86 2002-12-15 alex /* auch IRC-Operatoren duerfen MODE verwenden */
292 80c6dc86 2002-12-15 alex if( Client_OperByMe( Origin )) modeok = TRUE;
293 80c6dc86 2002-12-15 alex }
294 c23199d9 2002-02-27 alex }
295 80c6dc86 2002-12-15 alex else modeok = TRUE;
296 c23199d9 2002-02-27 alex
297 80c6dc86 2002-12-15 alex mode_arg = 1;
298 80c6dc86 2002-12-15 alex mode_ptr = Req->argv[mode_arg];
299 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
300 80c6dc86 2002-12-15 alex else arg_arg = -1;
301 80c6dc86 2002-12-15 alex
302 80c6dc86 2002-12-15 alex /* Initial state: set or unset modes? */
303 80c6dc86 2002-12-15 alex skiponce = FALSE;
304 80c6dc86 2002-12-15 alex if( *mode_ptr == '-' ) set = FALSE;
305 80c6dc86 2002-12-15 alex else if( *mode_ptr == '+' ) set = TRUE;
306 80c6dc86 2002-12-15 alex else set = skiponce = TRUE;
307 80c6dc86 2002-12-15 alex
308 80c6dc86 2002-12-15 alex /* Prepare reply string */
309 c23199d9 2002-02-27 alex if( set ) strcpy( the_modes, "+" );
310 c23199d9 2002-02-27 alex else strcpy( the_modes, "-" );
311 80c6dc86 2002-12-15 alex strcpy( the_args, " " );
312 c23199d9 2002-02-27 alex
313 c23199d9 2002-02-27 alex x[1] = '\0';
314 80c6dc86 2002-12-15 alex ok = CONNECTED;
315 80c6dc86 2002-12-15 alex while( mode_ptr )
316 c23199d9 2002-02-27 alex {
317 80c6dc86 2002-12-15 alex if( ! skiponce ) mode_ptr++;
318 80c6dc86 2002-12-15 alex if( ! *mode_ptr )
319 80c6dc86 2002-12-15 alex {
320 80c6dc86 2002-12-15 alex /* Try next argument if there's any */
321 80c6dc86 2002-12-15 alex if( arg_arg > mode_arg ) mode_arg = arg_arg;
322 80c6dc86 2002-12-15 alex else mode_arg++;
323 80c6dc86 2002-12-15 alex if( mode_arg < Req->argc ) mode_ptr = Req->argv[mode_arg];
324 80c6dc86 2002-12-15 alex else break;
325 80c6dc86 2002-12-15 alex if( Req->argc > mode_arg + 1 ) arg_arg = mode_arg + 1;
326 80c6dc86 2002-12-15 alex else arg_arg = -1;
327 80c6dc86 2002-12-15 alex }
328 80c6dc86 2002-12-15 alex skiponce = FALSE;
329 80c6dc86 2002-12-15 alex
330 80c6dc86 2002-12-15 alex switch( *mode_ptr )
331 80c6dc86 2002-12-15 alex {
332 80c6dc86 2002-12-15 alex case '+':
333 80c6dc86 2002-12-15 alex case '-':
334 80c6dc86 2002-12-15 alex if((( *mode_ptr == '+' ) && ( ! set )) || (( *mode_ptr == '-' ) && ( set )))
335 80c6dc86 2002-12-15 alex {
336 80c6dc86 2002-12-15 alex /* Action modifier ("+"/"-") must be changed ... */
337 80c6dc86 2002-12-15 alex if(( the_modes[strlen( the_modes ) - 1] == '+' ) || ( the_modes[strlen( the_modes ) - 1] == '-' ))
338 80c6dc86 2002-12-15 alex {
339 80c6dc86 2002-12-15 alex /* Adjust last action modifier in result */
340 80c6dc86 2002-12-15 alex the_modes[strlen( the_modes ) - 1] = *mode_ptr;
341 80c6dc86 2002-12-15 alex }
342 80c6dc86 2002-12-15 alex else
343 80c6dc86 2002-12-15 alex {
344 80c6dc86 2002-12-15 alex /* Append modifier character to result string */
345 6626395c 2002-12-26 alex x[0] = *mode_ptr;
346 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
347 80c6dc86 2002-12-15 alex }
348 80c6dc86 2002-12-15 alex if( *mode_ptr == '+' ) set = TRUE;
349 80c6dc86 2002-12-15 alex else set = FALSE;
350 80c6dc86 2002-12-15 alex }
351 80c6dc86 2002-12-15 alex continue;
352 80c6dc86 2002-12-15 alex }
353 80c6dc86 2002-12-15 alex
354 80c6dc86 2002-12-15 alex /* Are there arguments left? */
355 80c6dc86 2002-12-15 alex if( arg_arg >= Req->argc ) arg_arg = -1;
356 80c6dc86 2002-12-15 alex
357 7f61f413 2002-12-16 alex /* Validate modes */
358 c23199d9 2002-02-27 alex x[0] = '\0';
359 69ad0e38 2002-12-16 alex argadd[0] = '\0';
360 80c6dc86 2002-12-15 alex client = NULL;
361 7f61f413 2002-12-16 alex switch( *mode_ptr )
362 c23199d9 2002-02-27 alex {
363 7f61f413 2002-12-16 alex /* Channel modes */
364 7f61f413 2002-12-16 alex case 'i':
365 7f61f413 2002-12-16 alex /* Invite-Only */
366 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'i';
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 'm':
370 7f61f413 2002-12-16 alex /* Moderated */
371 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'm';
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 'n':
375 7f61f413 2002-12-16 alex /* kein Schreiben in den Channel von aussen */
376 7f61f413 2002-12-16 alex if( modeok ) x[0] = 'n';
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 't':
380 7f61f413 2002-12-16 alex /* Topic Lock */
381 7f61f413 2002-12-16 alex if( modeok ) x[0] = 't';
382 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
383 7f61f413 2002-12-16 alex break;
384 7f61f413 2002-12-16 alex case 'P':
385 7f61f413 2002-12-16 alex /* Persistent channel */
386 7f61f413 2002-12-16 alex if( modeok )
387 7f61f413 2002-12-16 alex {
388 7f61f413 2002-12-16 alex if( set && ( ! Client_OperByMe( Client )))
389 7f61f413 2002-12-16 alex {
390 7f61f413 2002-12-16 alex /* Only IRC operators are allowed to set P mode */
391 7f61f413 2002-12-16 alex ok = IRC_WriteStrClient( Origin, ERR_NOPRIVILEGES_MSG, Client_ID( Origin ));
392 7f61f413 2002-12-16 alex }
393 7f61f413 2002-12-16 alex else x[0] = 'P';
394 7f61f413 2002-12-16 alex }
395 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
396 7f61f413 2002-12-16 alex break;
397 7f61f413 2002-12-16 alex
398 7f61f413 2002-12-16 alex /* Channel user modes */
399 7f61f413 2002-12-16 alex case 'o':
400 7f61f413 2002-12-16 alex /* Channel operator */
401 7f61f413 2002-12-16 alex case 'v':
402 7f61f413 2002-12-16 alex /* Voice */
403 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
404 7f61f413 2002-12-16 alex {
405 80c6dc86 2002-12-15 alex if( modeok )
406 80c6dc86 2002-12-15 alex {
407 7f61f413 2002-12-16 alex client = Client_Search( Req->argv[arg_arg] );
408 7f61f413 2002-12-16 alex if( client ) x[0] = *mode_ptr;
409 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[arg_arg] );
410 80c6dc86 2002-12-15 alex }
411 80c6dc86 2002-12-15 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
412 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
413 7f61f413 2002-12-16 alex arg_arg++;
414 7f61f413 2002-12-16 alex }
415 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
416 7f61f413 2002-12-16 alex break;
417 69ad0e38 2002-12-16 alex case 'k':
418 69ad0e38 2002-12-16 alex /* Channel key */
419 69ad0e38 2002-12-16 alex if( ! set )
420 69ad0e38 2002-12-16 alex {
421 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
422 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
423 69ad0e38 2002-12-16 alex break;
424 69ad0e38 2002-12-16 alex }
425 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
426 69ad0e38 2002-12-16 alex {
427 69ad0e38 2002-12-16 alex if( modeok )
428 69ad0e38 2002-12-16 alex {
429 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'k' );
430 69ad0e38 2002-12-16 alex Channel_SetKey( Channel, Req->argv[arg_arg] );
431 695631b2 2002-12-26 alex strlcpy( argadd, Channel_Key( Channel ), sizeof( argadd ));
432 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
433 69ad0e38 2002-12-16 alex }
434 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
435 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
436 69ad0e38 2002-12-16 alex arg_arg++;
437 69ad0e38 2002-12-16 alex }
438 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
439 69ad0e38 2002-12-16 alex break;
440 69ad0e38 2002-12-16 alex case 'l':
441 69ad0e38 2002-12-16 alex /* Member limit */
442 69ad0e38 2002-12-16 alex if( ! set )
443 69ad0e38 2002-12-16 alex {
444 69ad0e38 2002-12-16 alex if( modeok ) x[0] = *mode_ptr;
445 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
446 69ad0e38 2002-12-16 alex break;
447 69ad0e38 2002-12-16 alex }
448 69ad0e38 2002-12-16 alex if( arg_arg > mode_arg )
449 69ad0e38 2002-12-16 alex {
450 69ad0e38 2002-12-16 alex if( modeok )
451 69ad0e38 2002-12-16 alex {
452 69ad0e38 2002-12-16 alex l = atol( Req->argv[arg_arg] );
453 69ad0e38 2002-12-16 alex if( l > 0 && l < 0xFFFF )
454 69ad0e38 2002-12-16 alex {
455 69ad0e38 2002-12-16 alex Channel_ModeDel( Channel, 'l' );
456 69ad0e38 2002-12-16 alex Channel_SetMaxUsers( Channel, l );
457 b316c380 2002-12-26 alex snprintf( argadd, sizeof( argadd ), "%ld", l );
458 69ad0e38 2002-12-16 alex x[0] = *mode_ptr;
459 69ad0e38 2002-12-16 alex }
460 69ad0e38 2002-12-16 alex }
461 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
462 69ad0e38 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
463 69ad0e38 2002-12-16 alex arg_arg++;
464 69ad0e38 2002-12-16 alex }
465 69ad0e38 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_NEEDMOREPARAMS_MSG, Client_ID( Origin ), Req->command );
466 69ad0e38 2002-12-16 alex break;
467 7e1b3b91 2002-09-02 alex
468 7f61f413 2002-12-16 alex /* Channel lists */
469 7f61f413 2002-12-16 alex case 'I':
470 7f61f413 2002-12-16 alex /* Invite lists */
471 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
472 7f61f413 2002-12-16 alex {
473 7f61f413 2002-12-16 alex /* modify list */
474 7f61f413 2002-12-16 alex if( modeok )
475 80c6dc86 2002-12-15 alex {
476 7f61f413 2002-12-16 alex if( set ) Add_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
477 7f61f413 2002-12-16 alex else Del_Invite( Origin, Client, Channel, Req->argv[arg_arg] );
478 80c6dc86 2002-12-15 alex }
479 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
480 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
481 7f61f413 2002-12-16 alex arg_arg++;
482 7f61f413 2002-12-16 alex }
483 7f61f413 2002-12-16 alex else Lists_ShowInvites( Origin, Channel );
484 7f61f413 2002-12-16 alex break;
485 7f61f413 2002-12-16 alex case 'b':
486 7f61f413 2002-12-16 alex /* Ban lists */
487 7f61f413 2002-12-16 alex if( arg_arg > mode_arg )
488 7f61f413 2002-12-16 alex {
489 7f61f413 2002-12-16 alex /* modify list */
490 7f61f413 2002-12-16 alex if( modeok )
491 c23199d9 2002-02-27 alex {
492 7f61f413 2002-12-16 alex if( set ) Add_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
493 7f61f413 2002-12-16 alex else Del_Ban( Origin, Client, Channel, Req->argv[arg_arg] );
494 c23199d9 2002-02-27 alex }
495 7f61f413 2002-12-16 alex else ok = IRC_WriteStrClient( Origin, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Origin ), Channel_Name( Channel ));
496 7f61f413 2002-12-16 alex Req->argv[arg_arg][0] = '\0';
497 7f61f413 2002-12-16 alex arg_arg++;
498 7f61f413 2002-12-16 alex }
499 7f61f413 2002-12-16 alex else Lists_ShowBans( Origin, Channel );
500 7f61f413 2002-12-16 alex break;
501 80c6dc86 2002-12-15 alex
502 7f61f413 2002-12-16 alex default:
503 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 ));
504 7f61f413 2002-12-16 alex if( Client_Type( Client ) != CLIENT_SERVER ) ok = IRC_WriteStrClient( Origin, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Origin ), set ? '+' : '-', *mode_ptr );
505 7f61f413 2002-12-16 alex x[0] = '\0';
506 69ad0e38 2002-12-16 alex goto chan_exit;
507 c23199d9 2002-02-27 alex }
508 c23199d9 2002-02-27 alex if( ! ok ) break;
509 80c6dc86 2002-12-15 alex
510 80c6dc86 2002-12-15 alex /* Is there a valid mode change? */
511 c23199d9 2002-02-27 alex if( ! x[0] ) continue;
512 c23199d9 2002-02-27 alex
513 fbec1f10 2003-01-21 alex /* Validate target client */
514 fbec1f10 2003-01-21 alex if( client && ( ! Channel_IsMemberOf( Channel, client )))
515 fbec1f10 2003-01-21 alex {
516 fbec1f10 2003-01-21 alex if( ! IRC_WriteStrClient( Origin, ERR_USERNOTINCHANNEL_MSG, Client_ID( Origin ), Client_ID( client ), Channel_Name( Channel ))) break;
517 fbec1f10 2003-01-21 alex continue;
518 fbec1f10 2003-01-21 alex }
519 fbec1f10 2003-01-21 alex
520 80c6dc86 2002-12-15 alex if( set )
521 c23199d9 2002-02-27 alex {
522 80c6dc86 2002-12-15 alex /* Set mode */
523 80c6dc86 2002-12-15 alex if( client )
524 c23199d9 2002-02-27 alex {
525 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
526 80c6dc86 2002-12-15 alex if( Channel_UserModeAdd( Channel, client, x[0] ))
527 80c6dc86 2002-12-15 alex {
528 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
529 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
530 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
531 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 ));
532 80c6dc86 2002-12-15 alex }
533 c23199d9 2002-02-27 alex }
534 c23199d9 2002-02-27 alex else
535 c23199d9 2002-02-27 alex {
536 80c6dc86 2002-12-15 alex /* Channel-Mode */
537 c0d74a38 2002-12-15 alex if( Channel_ModeAdd( Channel, x[0] ))
538 c0d74a38 2002-12-15 alex {
539 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
540 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
541 c0d74a38 2002-12-15 alex }
542 c23199d9 2002-02-27 alex }
543 c23199d9 2002-02-27 alex }
544 80c6dc86 2002-12-15 alex else
545 c23199d9 2002-02-27 alex {
546 80c6dc86 2002-12-15 alex /* Unset mode */
547 80c6dc86 2002-12-15 alex if( client )
548 c23199d9 2002-02-27 alex {
549 80c6dc86 2002-12-15 alex /* Channel-User-Mode */
550 80c6dc86 2002-12-15 alex if( Channel_UserModeDel( Channel, client, x[0] ))
551 c23199d9 2002-02-27 alex {
552 6626395c 2002-12-26 alex strlcat( the_args, Client_ID( client ), sizeof( the_args ));
553 6626395c 2002-12-26 alex strlcat( the_args, " ", sizeof( the_args ));
554 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
555 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 ));
556 c23199d9 2002-02-27 alex }
557 c23199d9 2002-02-27 alex }
558 c23199d9 2002-02-27 alex else
559 c23199d9 2002-02-27 alex {
560 c23199d9 2002-02-27 alex /* Channel-Mode */
561 c0d74a38 2002-12-15 alex if( Channel_ModeDel( Channel, x[0] ))
562 c0d74a38 2002-12-15 alex {
563 6626395c 2002-12-26 alex strlcat( the_modes, x, sizeof( the_modes ));
564 c0d74a38 2002-12-15 alex Log( LOG_DEBUG, "Channel %s: Mode change, now \"%s\".", Channel_Name( Channel ), Channel_Modes( Channel ));
565 c0d74a38 2002-12-15 alex }
566 c23199d9 2002-02-27 alex }
567 69ad0e38 2002-12-16 alex }
568 69ad0e38 2002-12-16 alex
569 69ad0e38 2002-12-16 alex /* Are there additional arguments to add? */
570 69ad0e38 2002-12-16 alex if( argadd[0] )
571 69ad0e38 2002-12-16 alex {
572 6626395c 2002-12-26 alex if( the_args[strlen( the_args ) - 1] != ' ' ) strlcat( the_args, " ", sizeof( the_args ));
573 6626395c 2002-12-26 alex strlcat( the_args, argadd, sizeof( the_args ));
574 69ad0e38 2002-12-16 alex }
575 c23199d9 2002-02-27 alex }
576 69ad0e38 2002-12-16 alex chan_exit:
577 c23199d9 2002-02-27 alex
578 80c6dc86 2002-12-15 alex /* Are there changed modes? */
579 c23199d9 2002-02-27 alex if( the_modes[1] )
580 c23199d9 2002-02-27 alex {
581 c0d74a38 2002-12-15 alex /* Clean up mode string */
582 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';
583 c0d74a38 2002-12-15 alex
584 80c6dc86 2002-12-15 alex /* Clean up argument string if there are none */
585 80c6dc86 2002-12-15 alex if( ! the_args[1] ) the_args[0] = '\0';
586 80c6dc86 2002-12-15 alex
587 80c6dc86 2002-12-15 alex if( Client_Type( Client ) == CLIENT_SERVER )
588 c23199d9 2002-02-27 alex {
589 80c6dc86 2002-12-15 alex /* Forward mode changes to channel users and other servers */
590 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
591 80c6dc86 2002-12-15 alex IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
592 c23199d9 2002-02-27 alex }
593 80c6dc86 2002-12-15 alex else
594 c23199d9 2002-02-27 alex {
595 80c6dc86 2002-12-15 alex /* Send reply to client and inform other servers and channel users */
596 80c6dc86 2002-12-15 alex ok = IRC_WriteStrClientPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
597 80c6dc86 2002-12-15 alex IRC_WriteStrServersPrefix( Client, Origin, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
598 80c6dc86 2002-12-15 alex IRC_WriteStrChannelPrefix( Client, Channel, Origin, FALSE, "MODE %s %s%s", Channel_Name( Channel ), the_modes, the_args );
599 c23199d9 2002-02-27 alex }
600 c23199d9 2002-02-27 alex }
601 c23199d9 2002-02-27 alex
602 7b6e2662 2003-11-05 alex IRC_SetPenalty( Client, 1 );
603 80c6dc86 2002-12-15 alex return CONNECTED;
604 80c6dc86 2002-12-15 alex } /* Channel_Mode */
605 c23199d9 2002-02-27 alex
606 c23199d9 2002-02-27 alex
607 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
608 c2f60abe 2002-05-27 alex IRC_AWAY( CLIENT *Client, REQUEST *Req )
609 c23199d9 2002-02-27 alex {
610 c23199d9 2002-02-27 alex assert( Client != NULL );
611 c23199d9 2002-02-27 alex assert( Req != NULL );
612 c23199d9 2002-02-27 alex
613 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
614 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
615 c23199d9 2002-02-27 alex
616 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
617 c23199d9 2002-02-27 alex {
618 c23199d9 2002-02-27 alex /* AWAY setzen */
619 c23199d9 2002-02-27 alex Client_SetAway( Client, Req->argv[0] );
620 8c1df9ef 2003-01-02 alex Client_ModeAdd( Client, 'a' );
621 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
622 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
623 c23199d9 2002-02-27 alex }
624 c23199d9 2002-02-27 alex else
625 c23199d9 2002-02-27 alex {
626 c23199d9 2002-02-27 alex /* AWAY loeschen */
627 8c1df9ef 2003-01-02 alex Client_ModeDel( Client, 'a' );
628 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
629 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
630 c23199d9 2002-02-27 alex }
631 c23199d9 2002-02-27 alex } /* IRC_AWAY */
632 19ac723e 2002-09-08 alex
633 19ac723e 2002-09-08 alex
634 19ac723e 2002-09-08 alex LOCAL BOOLEAN
635 296ddebe 2002-09-08 alex Add_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
636 19ac723e 2002-09-08 alex {
637 19ac723e 2002-09-08 alex CHAR *mask;
638 96747679 2004-04-25 alex BOOLEAN already;
639 19ac723e 2002-09-08 alex
640 19ac723e 2002-09-08 alex assert( Client != NULL );
641 19ac723e 2002-09-08 alex assert( Channel != NULL );
642 19ac723e 2002-09-08 alex assert( Pattern != NULL );
643 c23199d9 2002-02-27 alex
644 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
645 c23199d9 2002-02-27 alex
646 96747679 2004-04-25 alex already = Lists_IsInviteEntry( mask, Channel );
647 96747679 2004-04-25 alex
648 64d330b7 2004-04-09 alex if( ! Lists_AddInvited( mask, Channel, FALSE )) return CONNECTED;
649 96747679 2004-04-25 alex
650 96747679 2004-04-25 alex if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == TRUE )) return CONNECTED;
651 64d330b7 2004-04-09 alex
652 296ddebe 2002-09-08 alex return Send_ListChange( "+I", Prefix, Client, Channel, mask );
653 19ac723e 2002-09-08 alex } /* Add_Invite */
654 19ac723e 2002-09-08 alex
655 19ac723e 2002-09-08 alex
656 19ac723e 2002-09-08 alex LOCAL BOOLEAN
657 296ddebe 2002-09-08 alex Add_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
658 19ac723e 2002-09-08 alex {
659 19ac723e 2002-09-08 alex CHAR *mask;
660 96747679 2004-04-25 alex BOOLEAN already;
661 19ac723e 2002-09-08 alex
662 19ac723e 2002-09-08 alex assert( Client != NULL );
663 19ac723e 2002-09-08 alex assert( Channel != NULL );
664 19ac723e 2002-09-08 alex assert( Pattern != NULL );
665 19ac723e 2002-09-08 alex
666 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
667 19ac723e 2002-09-08 alex
668 96747679 2004-04-25 alex already = Lists_IsBanEntry( mask, Channel );
669 96747679 2004-04-25 alex
670 64d330b7 2004-04-09 alex if( ! Lists_AddBanned( mask, Channel )) return CONNECTED;
671 64d330b7 2004-04-09 alex
672 96747679 2004-04-25 alex if(( Client_Type( Prefix ) == CLIENT_SERVER ) && ( already == TRUE )) return CONNECTED;
673 96747679 2004-04-25 alex
674 296ddebe 2002-09-08 alex return Send_ListChange( "+b", Prefix, Client, Channel, mask );
675 19ac723e 2002-09-08 alex } /* Add_Ban */
676 19ac723e 2002-09-08 alex
677 19ac723e 2002-09-08 alex
678 19ac723e 2002-09-08 alex LOCAL BOOLEAN
679 296ddebe 2002-09-08 alex Del_Invite( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
680 19ac723e 2002-09-08 alex {
681 19ac723e 2002-09-08 alex CHAR *mask;
682 19ac723e 2002-09-08 alex
683 19ac723e 2002-09-08 alex assert( Client != NULL );
684 19ac723e 2002-09-08 alex assert( Channel != NULL );
685 19ac723e 2002-09-08 alex assert( Pattern != NULL );
686 19ac723e 2002-09-08 alex
687 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
688 19ac723e 2002-09-08 alex Lists_DelInvited( mask, Channel );
689 296ddebe 2002-09-08 alex return Send_ListChange( "-I", Prefix, Client, Channel, mask );
690 19ac723e 2002-09-08 alex } /* Del_Invite */
691 19ac723e 2002-09-08 alex
692 19ac723e 2002-09-08 alex
693 19ac723e 2002-09-08 alex LOCAL BOOLEAN
694 296ddebe 2002-09-08 alex Del_Ban( CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Pattern )
695 19ac723e 2002-09-08 alex {
696 19ac723e 2002-09-08 alex CHAR *mask;
697 19ac723e 2002-09-08 alex
698 19ac723e 2002-09-08 alex assert( Client != NULL );
699 19ac723e 2002-09-08 alex assert( Channel != NULL );
700 19ac723e 2002-09-08 alex assert( Pattern != NULL );
701 19ac723e 2002-09-08 alex
702 19ac723e 2002-09-08 alex mask = Lists_MakeMask( Pattern );
703 19ac723e 2002-09-08 alex Lists_DelBanned( mask, Channel );
704 296ddebe 2002-09-08 alex return Send_ListChange( "-b", Prefix, Client, Channel, mask );
705 296ddebe 2002-09-08 alex } /* Del_Ban */
706 19ac723e 2002-09-08 alex
707 296ddebe 2002-09-08 alex
708 296ddebe 2002-09-08 alex LOCAL BOOLEAN
709 296ddebe 2002-09-08 alex Send_ListChange( CHAR *Mode, CLIENT *Prefix, CLIENT *Client, CHANNEL *Channel, CHAR *Mask )
710 296ddebe 2002-09-08 alex {
711 296ddebe 2002-09-08 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
712 296ddebe 2002-09-08 alex
713 296ddebe 2002-09-08 alex BOOLEAN ok;
714 296ddebe 2002-09-08 alex
715 19ac723e 2002-09-08 alex if( Client_Type( Client ) == CLIENT_USER )
716 19ac723e 2002-09-08 alex {
717 296ddebe 2002-09-08 alex /* Bestaetigung an Client */
718 296ddebe 2002-09-08 alex ok = IRC_WriteStrClientPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
719 19ac723e 2002-09-08 alex }
720 296ddebe 2002-09-08 alex else ok = TRUE;
721 19ac723e 2002-09-08 alex
722 296ddebe 2002-09-08 alex /* an andere Server */
723 296ddebe 2002-09-08 alex IRC_WriteStrServersPrefix( Client, Prefix, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
724 19ac723e 2002-09-08 alex
725 296ddebe 2002-09-08 alex /* und lokale User im Channel */
726 296ddebe 2002-09-08 alex IRC_WriteStrChannelPrefix( Client, Channel, Prefix, FALSE, "MODE %s %s %s", Channel_Name( Channel ), Mode, Mask );
727 296ddebe 2002-09-08 alex
728 296ddebe 2002-09-08 alex return ok;
729 296ddebe 2002-09-08 alex } /* Send_ListChange */
730 296ddebe 2002-09-08 alex
731 296ddebe 2002-09-08 alex
732 c23199d9 2002-02-27 alex /* -eof- */