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 c23199d9 2002-02-27 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 c23199d9 2002-02-27 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 c23199d9 2002-02-27 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 c23199d9 2002-02-27 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 c23199d9 2002-02-27 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 c23199d9 2002-02-27 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11 c23199d9 2002-02-27 alex *
12 d4fca86a 2002-03-25 alex * $Id: irc-mode.c,v 1.4 2002/03/25 17:11:45 alex Exp $
13 c23199d9 2002-02-27 alex *
14 c23199d9 2002-02-27 alex * irc-mode.c: IRC-Befehle zur Mode-Aenderung (MODE, AWAY, ...)
15 c23199d9 2002-02-27 alex */
16 c23199d9 2002-02-27 alex
17 c23199d9 2002-02-27 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 c23199d9 2002-02-27 alex
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 c23199d9 2002-02-27 alex #include <assert.h>
22 c23199d9 2002-02-27 alex #include <string.h>
23 c23199d9 2002-02-27 alex
24 c23199d9 2002-02-27 alex #include "channel.h"
25 ca33cbda 2002-03-12 alex #include "defines.h"
26 c23199d9 2002-02-27 alex #include "irc-write.h"
27 c23199d9 2002-02-27 alex #include "log.h"
28 c23199d9 2002-02-27 alex #include "messages.h"
29 c23199d9 2002-02-27 alex
30 ca33cbda 2002-03-12 alex #include "exp.h"
31 c23199d9 2002-02-27 alex #include "irc-mode.h"
32 c23199d9 2002-02-27 alex
33 c23199d9 2002-02-27 alex
34 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
35 c23199d9 2002-02-27 alex {
36 c23199d9 2002-02-27 alex CHAR *mode_ptr, the_modes[CLIENT_MODE_LEN], x[2];
37 c23199d9 2002-02-27 alex CLIENT *cl, *chan_cl, *prefix;
38 c23199d9 2002-02-27 alex BOOLEAN set, ok;
39 c23199d9 2002-02-27 alex CHANNEL *chan;
40 c23199d9 2002-02-27 alex
41 c23199d9 2002-02-27 alex assert( Client != NULL );
42 c23199d9 2002-02-27 alex assert( Req != NULL );
43 c23199d9 2002-02-27 alex
44 c23199d9 2002-02-27 alex cl = chan_cl = prefix = NULL;
45 c23199d9 2002-02-27 alex chan = NULL;
46 c23199d9 2002-02-27 alex
47 c23199d9 2002-02-27 alex /* Valider Client? */
48 c23199d9 2002-02-27 alex if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
49 c23199d9 2002-02-27 alex
50 c23199d9 2002-02-27 alex /* Keine Parameter? */
51 c23199d9 2002-02-27 alex if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
52 c23199d9 2002-02-27 alex
53 c23199d9 2002-02-27 alex /* Ziel suchen: Client bzw. Channel */
54 c23199d9 2002-02-27 alex if( Client_IsValidNick( Req->argv[0] )) cl = Client_Search( Req->argv[0] );
55 c23199d9 2002-02-27 alex if( Channel_IsValidName( Req->argv[0] )) chan = Channel_Search( Req->argv[0] );
56 c23199d9 2002-02-27 alex
57 c23199d9 2002-02-27 alex /* Kein Ziel gefunden? */
58 c23199d9 2002-02-27 alex if(( ! cl ) && ( ! chan )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
59 c23199d9 2002-02-27 alex
60 c23199d9 2002-02-27 alex assert(( cl && chan ) != TRUE );
61 c23199d9 2002-02-27 alex
62 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
63 c23199d9 2002-02-27 alex if(( cl ) && ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
64 c23199d9 2002-02-27 alex if(( chan ) && ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
65 c23199d9 2002-02-27 alex
66 c23199d9 2002-02-27 alex /* Client ermitteln, wenn bei Channel-Modes mit 3 Parametern */
67 c23199d9 2002-02-27 alex if(( chan ) && (Req->argc == 3 ))
68 c23199d9 2002-02-27 alex {
69 c23199d9 2002-02-27 alex chan_cl = Client_Search( Req->argv[2] );
70 c23199d9 2002-02-27 alex if( ! chan_cl ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
71 c23199d9 2002-02-27 alex }
72 c23199d9 2002-02-27 alex
73 c23199d9 2002-02-27 alex /* Wenn Anfragender ein User ist: Zugriff erlaubt? */
74 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_USER )
75 c23199d9 2002-02-27 alex {
76 c23199d9 2002-02-27 alex if( cl )
77 c23199d9 2002-02-27 alex {
78 c23199d9 2002-02-27 alex /* MODE ist nur fuer sich selber zulaessig! */
79 c23199d9 2002-02-27 alex if( cl != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
80 c23199d9 2002-02-27 alex }
81 c23199d9 2002-02-27 alex if( chan )
82 c23199d9 2002-02-27 alex {
83 c23199d9 2002-02-27 alex /* Darf der User die Channel-Modes ermitteln? */
84 c23199d9 2002-02-27 alex }
85 c23199d9 2002-02-27 alex }
86 c23199d9 2002-02-27 alex
87 c23199d9 2002-02-27 alex /* Werden die Modes "nur" erfragt? */
88 c23199d9 2002-02-27 alex if(( cl ) && ( Req->argc == 1 )) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( cl ));
89 c23199d9 2002-02-27 alex if(( chan ) && ( Req->argc == 1 )) return IRC_WriteStrClient( Client, RPL_CHANNELMODEIS_MSG, Client_ID( Client ), Channel_Name( chan ), Channel_Modes( chan ));
90 c23199d9 2002-02-27 alex
91 c23199d9 2002-02-27 alex mode_ptr = Req->argv[1];
92 c23199d9 2002-02-27 alex
93 c23199d9 2002-02-27 alex /* Sollen Modes gesetzt oder geloescht werden? */
94 c23199d9 2002-02-27 alex if( cl )
95 c23199d9 2002-02-27 alex {
96 c23199d9 2002-02-27 alex if( *mode_ptr == '+' ) set = TRUE;
97 c23199d9 2002-02-27 alex else if( *mode_ptr == '-' ) set = FALSE;
98 c23199d9 2002-02-27 alex else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
99 c23199d9 2002-02-27 alex mode_ptr++;
100 c23199d9 2002-02-27 alex }
101 c23199d9 2002-02-27 alex else
102 c23199d9 2002-02-27 alex {
103 c23199d9 2002-02-27 alex if( *mode_ptr == '-' ) set = FALSE;
104 c23199d9 2002-02-27 alex else set = TRUE;
105 c23199d9 2002-02-27 alex if(( *mode_ptr == '-' ) || ( *mode_ptr == '+' )) mode_ptr++;
106 c23199d9 2002-02-27 alex }
107 c23199d9 2002-02-27 alex
108 c23199d9 2002-02-27 alex /* Prefix fuer Antworten etc. ermitteln */
109 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
110 c23199d9 2002-02-27 alex {
111 d4fca86a 2002-03-25 alex prefix = Client_Search( Req->prefix );
112 c23199d9 2002-02-27 alex if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
113 c23199d9 2002-02-27 alex }
114 c23199d9 2002-02-27 alex else prefix = Client;
115 c23199d9 2002-02-27 alex
116 c23199d9 2002-02-27 alex /* Reply-String mit Aenderungen vorbereiten */
117 c23199d9 2002-02-27 alex if( set ) strcpy( the_modes, "+" );
118 c23199d9 2002-02-27 alex else strcpy( the_modes, "-" );
119 c23199d9 2002-02-27 alex
120 c23199d9 2002-02-27 alex ok = TRUE;
121 c23199d9 2002-02-27 alex x[1] = '\0';
122 c23199d9 2002-02-27 alex while( *mode_ptr )
123 c23199d9 2002-02-27 alex {
124 c23199d9 2002-02-27 alex x[0] = '\0';
125 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
126 c23199d9 2002-02-27 alex {
127 c23199d9 2002-02-27 alex /* Befehl kommt von einem Server, daher
128 c23199d9 2002-02-27 alex * trauen wir ihm "unbesehen" ... */
129 c23199d9 2002-02-27 alex x[0] = *mode_ptr;
130 c23199d9 2002-02-27 alex }
131 c23199d9 2002-02-27 alex else
132 c23199d9 2002-02-27 alex {
133 c23199d9 2002-02-27 alex /* Modes validieren */
134 c23199d9 2002-02-27 alex if( cl )
135 c23199d9 2002-02-27 alex {
136 c23199d9 2002-02-27 alex /* User-Modes */
137 c23199d9 2002-02-27 alex switch( *mode_ptr )
138 c23199d9 2002-02-27 alex {
139 c23199d9 2002-02-27 alex case 'i':
140 c23199d9 2002-02-27 alex /* invisible */
141 c23199d9 2002-02-27 alex x[0] = 'i';
142 c23199d9 2002-02-27 alex break;
143 c23199d9 2002-02-27 alex case 'r':
144 c23199d9 2002-02-27 alex /* restricted (kann nur gesetzt werden) */
145 c23199d9 2002-02-27 alex if( set ) x[0] = 'r';
146 c23199d9 2002-02-27 alex else ok = IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
147 c23199d9 2002-02-27 alex break;
148 c23199d9 2002-02-27 alex case 'o':
149 c23199d9 2002-02-27 alex /* operator (kann nur geloescht werden) */
150 c23199d9 2002-02-27 alex if( ! set )
151 c23199d9 2002-02-27 alex {
152 c23199d9 2002-02-27 alex Client_SetOperByMe( Client, FALSE );
153 c23199d9 2002-02-27 alex x[0] = 'o';
154 c23199d9 2002-02-27 alex }
155 c23199d9 2002-02-27 alex else ok = IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
156 c23199d9 2002-02-27 alex break;
157 d4fca86a 2002-03-25 alex case 's':
158 d4fca86a 2002-03-25 alex /* server messages */
159 d4fca86a 2002-03-25 alex x[0] = 's';
160 d4fca86a 2002-03-25 alex break;
161 c23199d9 2002-02-27 alex default:
162 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Unknown mode \"%c%c\" from \"%s\"!?", set ? '+' : '-', *mode_ptr, Client_ID( Client ));
163 c23199d9 2002-02-27 alex ok = IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Client ), set ? '+' : '-', *mode_ptr );
164 c23199d9 2002-02-27 alex x[0] = '\0';
165 c23199d9 2002-02-27 alex }
166 c23199d9 2002-02-27 alex }
167 c23199d9 2002-02-27 alex if( chan )
168 c23199d9 2002-02-27 alex {
169 c23199d9 2002-02-27 alex /* Ist der User ein Channel Operator? */
170 c23199d9 2002-02-27 alex if( ! strchr( Channel_UserModes( chan, Client ), 'o' ))
171 c23199d9 2002-02-27 alex {
172 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Can't change modes: \"%s\" is not operator on %s!", Client_ID( Client ), Channel_Name( chan ));
173 c23199d9 2002-02-27 alex ok = IRC_WriteStrClient( Client, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( Client ), Channel_Name( chan ));
174 c23199d9 2002-02-27 alex break;
175 c23199d9 2002-02-27 alex }
176 c23199d9 2002-02-27 alex
177 c23199d9 2002-02-27 alex /* Channel-Modes oder Channel-User-Modes */
178 c23199d9 2002-02-27 alex if( chan_cl )
179 c23199d9 2002-02-27 alex {
180 c23199d9 2002-02-27 alex /* Channel-User-Modes */
181 c23199d9 2002-02-27 alex switch( *mode_ptr )
182 c23199d9 2002-02-27 alex {
183 c23199d9 2002-02-27 alex case 'o':
184 c23199d9 2002-02-27 alex /* Channel Operator */
185 c23199d9 2002-02-27 alex x[0] = 'o';
186 c23199d9 2002-02-27 alex break;
187 c23199d9 2002-02-27 alex case 'v':
188 c23199d9 2002-02-27 alex /* Voice */
189 c23199d9 2002-02-27 alex x[0] = 'v';
190 c23199d9 2002-02-27 alex break;
191 c23199d9 2002-02-27 alex default:
192 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Unknown channel-user-mode \"%c%c\" from \"%s\" on \"%s\" at %s!?", set ? '+' : '-', *mode_ptr, Client_ID( Client ), Client_ID( chan_cl ), Channel_Name( chan ));
193 c23199d9 2002-02-27 alex ok = IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Client ), set ? '+' : '-', *mode_ptr );
194 c23199d9 2002-02-27 alex x[0] = '\0';
195 c23199d9 2002-02-27 alex }
196 c23199d9 2002-02-27 alex }
197 c23199d9 2002-02-27 alex else
198 c23199d9 2002-02-27 alex {
199 c23199d9 2002-02-27 alex /* Channel-Modes */
200 c23199d9 2002-02-27 alex switch( *mode_ptr )
201 c23199d9 2002-02-27 alex {
202 c23199d9 2002-02-27 alex case 'a':
203 c23199d9 2002-02-27 alex /* Anonymous */
204 c23199d9 2002-02-27 alex x[0] = 'a';
205 c23199d9 2002-02-27 alex break;
206 c23199d9 2002-02-27 alex case 'm':
207 c23199d9 2002-02-27 alex /* Moderated */
208 c23199d9 2002-02-27 alex x[0] = 'm';
209 c23199d9 2002-02-27 alex break;
210 c23199d9 2002-02-27 alex case 'n':
211 c23199d9 2002-02-27 alex /* kein Schreiben in den Channel von aussen */
212 c23199d9 2002-02-27 alex x[0] = 'n';
213 c23199d9 2002-02-27 alex break;
214 c23199d9 2002-02-27 alex case 'p':
215 c23199d9 2002-02-27 alex /* Private */
216 c23199d9 2002-02-27 alex x[0] = 'p';
217 c23199d9 2002-02-27 alex break;
218 c23199d9 2002-02-27 alex case 'q':
219 c23199d9 2002-02-27 alex /* Quiet */
220 c23199d9 2002-02-27 alex x[0] = 'q';
221 c23199d9 2002-02-27 alex break;
222 c23199d9 2002-02-27 alex case 's':
223 c23199d9 2002-02-27 alex /* Secret */
224 c23199d9 2002-02-27 alex x[0] = 's';
225 c23199d9 2002-02-27 alex break;
226 c23199d9 2002-02-27 alex case 't':
227 c23199d9 2002-02-27 alex /* Topic Lock */
228 c23199d9 2002-02-27 alex x[0] = 't';
229 c23199d9 2002-02-27 alex break;
230 c23199d9 2002-02-27 alex default:
231 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Unknown channel-mode \"%c%c\" from \"%s\" at %s!?", set ? '+' : '-', *mode_ptr, Client_ID( Client ), Channel_Name( chan ));
232 c23199d9 2002-02-27 alex ok = IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG2_MSG, Client_ID( Client ), set ? '+' : '-', *mode_ptr );
233 c23199d9 2002-02-27 alex x[0] = '\0';
234 c23199d9 2002-02-27 alex }
235 c23199d9 2002-02-27 alex }
236 c23199d9 2002-02-27 alex }
237 c23199d9 2002-02-27 alex }
238 c23199d9 2002-02-27 alex if( ! ok ) break;
239 c23199d9 2002-02-27 alex
240 c23199d9 2002-02-27 alex mode_ptr++;
241 c23199d9 2002-02-27 alex if( ! x[0] ) continue;
242 c23199d9 2002-02-27 alex
243 c23199d9 2002-02-27 alex /* Okay, gueltigen Mode gefunden */
244 c23199d9 2002-02-27 alex if( cl )
245 c23199d9 2002-02-27 alex {
246 c23199d9 2002-02-27 alex /* Es geht um User-Modes */
247 c23199d9 2002-02-27 alex if( set )
248 c23199d9 2002-02-27 alex {
249 c23199d9 2002-02-27 alex /* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
250 c23199d9 2002-02-27 alex if( Client_ModeAdd( cl, x[0] )) strcat( the_modes, x );
251 802a17b1 2002-03-04 alex
252 c23199d9 2002-02-27 alex }
253 c23199d9 2002-02-27 alex else
254 c23199d9 2002-02-27 alex {
255 c23199d9 2002-02-27 alex /* Modes geloescht. Wenn der Client ihn hatte: merken */
256 c23199d9 2002-02-27 alex if( Client_ModeDel( cl, x[0] )) strcat( the_modes, x );
257 c23199d9 2002-02-27 alex }
258 802a17b1 2002-03-04 alex
259 802a17b1 2002-03-04 alex /* "nachbearbeiten" */
260 802a17b1 2002-03-04 alex if( x[0] == 'a' )
261 802a17b1 2002-03-04 alex {
262 802a17b1 2002-03-04 alex /* away */
263 802a17b1 2002-03-04 alex if( set ) Client_SetAway( cl, DEFAULT_AWAY_MSG );
264 802a17b1 2002-03-04 alex else Client_SetAway( cl, NULL );
265 802a17b1 2002-03-04 alex }
266 c23199d9 2002-02-27 alex }
267 c23199d9 2002-02-27 alex if( chan )
268 c23199d9 2002-02-27 alex {
269 c23199d9 2002-02-27 alex /* Es geht um Channel-Modes oder Channel-User-Modes */
270 c23199d9 2002-02-27 alex if( chan_cl )
271 c23199d9 2002-02-27 alex {
272 c23199d9 2002-02-27 alex /* Channel-User-Modes */
273 c23199d9 2002-02-27 alex if( set )
274 c23199d9 2002-02-27 alex {
275 c23199d9 2002-02-27 alex /* Mode setzen. Wenn der Channel ihn noch nicht hatte: merken */
276 c23199d9 2002-02-27 alex if( Channel_UserModeAdd( chan, chan_cl, x[0] )) strcat( the_modes, x );
277 c23199d9 2002-02-27 alex }
278 c23199d9 2002-02-27 alex else
279 c23199d9 2002-02-27 alex {
280 c23199d9 2002-02-27 alex /* Mode setzen. Wenn der Channel ihn noch nicht hatte: merken */
281 c23199d9 2002-02-27 alex if( Channel_UserModeDel( chan, chan_cl, x[0] )) strcat( the_modes, x );
282 c23199d9 2002-02-27 alex }
283 c23199d9 2002-02-27 alex }
284 c23199d9 2002-02-27 alex else
285 c23199d9 2002-02-27 alex {
286 c23199d9 2002-02-27 alex /* Channel-Mode */
287 c23199d9 2002-02-27 alex if( set )
288 c23199d9 2002-02-27 alex {
289 c23199d9 2002-02-27 alex /* Mode setzen. Wenn der Channel ihn noch nicht hatte: merken */
290 c23199d9 2002-02-27 alex if( Channel_ModeAdd( chan, x[0] )) strcat( the_modes, x );
291 c23199d9 2002-02-27 alex }
292 c23199d9 2002-02-27 alex else
293 c23199d9 2002-02-27 alex {
294 c23199d9 2002-02-27 alex /* Mode setzen. Wenn der Channel ihn noch nicht hatte: merken */
295 c23199d9 2002-02-27 alex if( Channel_ModeDel( chan, x[0] )) strcat( the_modes, x );
296 c23199d9 2002-02-27 alex }
297 c23199d9 2002-02-27 alex }
298 c23199d9 2002-02-27 alex }
299 c23199d9 2002-02-27 alex }
300 c23199d9 2002-02-27 alex
301 c23199d9 2002-02-27 alex /* Wurden Modes geaendert? */
302 c23199d9 2002-02-27 alex if( the_modes[1] )
303 c23199d9 2002-02-27 alex {
304 c23199d9 2002-02-27 alex if( cl )
305 c23199d9 2002-02-27 alex {
306 c23199d9 2002-02-27 alex /* Client-Mode */
307 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
308 c23199d9 2002-02-27 alex {
309 c23199d9 2002-02-27 alex /* Modes an andere Server forwarden */
310 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, prefix, "MODE %s :%s", Client_ID( cl ), the_modes );
311 c23199d9 2002-02-27 alex }
312 c23199d9 2002-02-27 alex else
313 c23199d9 2002-02-27 alex {
314 c23199d9 2002-02-27 alex /* Bestaetigung an Client schicken & andere Server informieren */
315 c23199d9 2002-02-27 alex ok = IRC_WriteStrClientPrefix( Client, prefix, "MODE %s %s", Client_ID( cl ), the_modes );
316 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, prefix, "MODE %s :%s", Client_ID( cl ), the_modes );
317 c23199d9 2002-02-27 alex }
318 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( cl ), Client_Modes( cl ));
319 c23199d9 2002-02-27 alex }
320 c23199d9 2002-02-27 alex if( chan )
321 c23199d9 2002-02-27 alex {
322 c23199d9 2002-02-27 alex /* Channel-Modes oder Channel-User-Mode */
323 c23199d9 2002-02-27 alex if( chan_cl )
324 c23199d9 2002-02-27 alex {
325 c23199d9 2002-02-27 alex /* Channel-User-Mode */
326 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
327 c23199d9 2002-02-27 alex {
328 c23199d9 2002-02-27 alex /* Modes an andere Server und Channel-User forwarden */
329 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, prefix, "MODE %s %s :%s", Channel_Name( chan ), the_modes, Client_ID( chan_cl));
330 c23199d9 2002-02-27 alex IRC_WriteStrChannelPrefix( Client, chan, prefix, FALSE, "MODE %s %s %s", Channel_Name( chan ), the_modes, Client_ID( chan_cl));
331 c23199d9 2002-02-27 alex }
332 c23199d9 2002-02-27 alex else
333 c23199d9 2002-02-27 alex {
334 c23199d9 2002-02-27 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
335 c23199d9 2002-02-27 alex ok = IRC_WriteStrClientPrefix( Client, prefix, "MODE %s %s %s", Channel_Name( chan ), the_modes, Client_ID( chan_cl));
336 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, prefix, "MODE %s %s :%s", Channel_Name( chan ), the_modes, Client_ID( chan_cl));
337 c23199d9 2002-02-27 alex IRC_WriteStrChannelPrefix( Client, chan, prefix, FALSE, "MODE %s %s %s", Channel_Name( chan ), the_modes, Client_ID( chan_cl));
338 c23199d9 2002-02-27 alex }
339 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "User \"%s\" on %s: Mode change, now \"%s\".", Client_Mask( chan_cl), Channel_Name( chan ), Channel_UserModes( chan, chan_cl ));
340 c23199d9 2002-02-27 alex }
341 c23199d9 2002-02-27 alex else
342 c23199d9 2002-02-27 alex {
343 c23199d9 2002-02-27 alex /* Channel-Mode */
344 c23199d9 2002-02-27 alex if( Client_Type( Client ) == CLIENT_SERVER )
345 c23199d9 2002-02-27 alex {
346 c23199d9 2002-02-27 alex /* Modes an andere Server und Channel-User forwarden */
347 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, prefix, "MODE %s :%s", Channel_Name( chan ), the_modes );
348 c23199d9 2002-02-27 alex IRC_WriteStrChannelPrefix( Client, chan, prefix, FALSE, "MODE %s %s", Channel_Name( chan ), the_modes );
349 c23199d9 2002-02-27 alex }
350 c23199d9 2002-02-27 alex else
351 c23199d9 2002-02-27 alex {
352 c23199d9 2002-02-27 alex /* Bestaetigung an Client schicken & andere Server sowie Channel-User informieren */
353 c23199d9 2002-02-27 alex ok = IRC_WriteStrClientPrefix( Client, prefix, "MODE %s %s", Channel_Name( chan ), the_modes );
354 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, prefix, "MODE %s :%s", Channel_Name( chan ), the_modes );
355 c23199d9 2002-02-27 alex IRC_WriteStrChannelPrefix( Client, chan, prefix, FALSE, "MODE %s %s", Channel_Name( chan ), the_modes );
356 c23199d9 2002-02-27 alex }
357 c23199d9 2002-02-27 alex Log( LOG_DEBUG, "Channel \"%s\": Mode change, now \"%s\".", Channel_Name( chan ), Channel_Modes( chan ));
358 c23199d9 2002-02-27 alex }
359 c23199d9 2002-02-27 alex }
360 c23199d9 2002-02-27 alex }
361 c23199d9 2002-02-27 alex
362 c23199d9 2002-02-27 alex return ok;
363 c23199d9 2002-02-27 alex } /* IRC_MODE */
364 c23199d9 2002-02-27 alex
365 c23199d9 2002-02-27 alex
366 c23199d9 2002-02-27 alex GLOBAL BOOLEAN IRC_AWAY( CLIENT *Client, REQUEST *Req )
367 c23199d9 2002-02-27 alex {
368 c23199d9 2002-02-27 alex assert( Client != NULL );
369 c23199d9 2002-02-27 alex assert( Req != NULL );
370 c23199d9 2002-02-27 alex
371 c23199d9 2002-02-27 alex if( Client_Type( Client ) != CLIENT_USER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
372 c23199d9 2002-02-27 alex
373 c23199d9 2002-02-27 alex /* Falsche Anzahl Parameter? */
374 c23199d9 2002-02-27 alex if( Req->argc > 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
375 c23199d9 2002-02-27 alex
376 c23199d9 2002-02-27 alex if(( Req->argc == 1 ) && (Req->argv[0][0] ))
377 c23199d9 2002-02-27 alex {
378 c23199d9 2002-02-27 alex /* AWAY setzen */
379 c23199d9 2002-02-27 alex Client_SetAway( Client, Req->argv[0] );
380 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :+a", Client_ID( Client ));
381 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_NOWAWAY_MSG, Client_ID( Client ));
382 c23199d9 2002-02-27 alex }
383 c23199d9 2002-02-27 alex else
384 c23199d9 2002-02-27 alex {
385 c23199d9 2002-02-27 alex /* AWAY loeschen */
386 c23199d9 2002-02-27 alex Client_SetAway( Client, NULL );
387 c23199d9 2002-02-27 alex IRC_WriteStrServersPrefix( Client, Client, "MODE %s :-a", Client_ID( Client ));
388 c23199d9 2002-02-27 alex return IRC_WriteStrClient( Client, RPL_UNAWAY_MSG, Client_ID( Client ));
389 c23199d9 2002-02-27 alex }
390 c23199d9 2002-02-27 alex } /* IRC_AWAY */
391 c23199d9 2002-02-27 alex
392 c23199d9 2002-02-27 alex
393 c23199d9 2002-02-27 alex /* -eof- */