2 2ee05c9a 2002-03-03 alex * ngIRCd -- The Next Generation IRC Daemon
3 2ee05c9a 2002-03-03 alex * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
5 490f28ff 2002-12-12 alex * This program is free software; you can redistribute it and/or modify
6 490f28ff 2002-12-12 alex * it under the terms of the GNU General Public License as published by
7 490f28ff 2002-12-12 alex * the Free Software Foundation; either version 2 of the License, or
8 490f28ff 2002-12-12 alex * (at your option) any later version.
9 490f28ff 2002-12-12 alex * Please read the file COPYING, README and AUTHORS for more information.
11 490f28ff 2002-12-12 alex * IRC channel commands
15 ca33cbda 2002-03-12 alex #include "portab.h"
17 43d9a624 2003-01-08 alex static char UNUSED id[] = "$Id: irc-channel.c,v 1.25 2003/01/08 22:04:05 alex Exp $";
19 ca33cbda 2002-03-12 alex #include "imp.h"
20 2ee05c9a 2002-03-03 alex #include <assert.h>
21 43d9a624 2003-01-08 alex #include <stdlib.h>
22 43d9a624 2003-01-08 alex #include <stdio.h>
23 2ee05c9a 2002-03-03 alex #include <string.h>
25 ca33cbda 2002-03-12 alex #include "defines.h"
26 c2f60abe 2002-05-27 alex #include "conn.h"
27 c2f60abe 2002-05-27 alex #include "client.h"
28 c2f60abe 2002-05-27 alex #include "channel.h"
29 c2f60abe 2002-05-27 alex #include "lists.h"
30 2ee05c9a 2002-03-03 alex #include "log.h"
31 39b9f65d 2002-06-26 alex #include "match.h"
32 2ee05c9a 2002-03-03 alex #include "messages.h"
33 c2f60abe 2002-05-27 alex #include "parse.h"
34 0c471b84 2002-11-30 alex #include "irc-info.h"
35 c2f60abe 2002-05-27 alex #include "irc-write.h"
36 5b8b3b83 2002-12-13 alex #include "resolve.h"
37 5b8b3b83 2002-12-13 alex #include "conf.h"
39 ca33cbda 2002-03-12 alex #include "exp.h"
40 2ee05c9a 2002-03-03 alex #include "irc-channel.h"
43 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
44 c2f60abe 2002-05-27 alex IRC_JOIN( CLIENT *Client, REQUEST *Req )
46 69ad0e38 2002-12-16 alex CHAR *channame, *key, *flags, *topic, modes[8];
47 a1ded68a 2002-09-08 alex BOOLEAN is_new_chan, is_invited, is_banned;
48 2ee05c9a 2002-03-03 alex CLIENT *target;
49 2ee05c9a 2002-03-03 alex CHANNEL *chan;
51 2ee05c9a 2002-03-03 alex assert( Client != NULL );
52 2ee05c9a 2002-03-03 alex assert( Req != NULL );
54 69ad0e38 2002-12-16 alex /* Bad number of arguments? */
55 69ad0e38 2002-12-16 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
57 69ad0e38 2002-12-16 alex /* Who is the sender? */
58 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
59 2ee05c9a 2002-03-03 alex else target = Client;
60 2ee05c9a 2002-03-03 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
62 69ad0e38 2002-12-16 alex /* Are channel keys given? */
63 69ad0e38 2002-12-16 alex if( Req->argc > 1 ) key = Req->argv[1];
64 69ad0e38 2002-12-16 alex else key = NULL;
66 2ee05c9a 2002-03-03 alex /* Channel-Namen durchgehen */
67 c2f60abe 2002-05-27 alex chan = NULL;
68 2ee05c9a 2002-03-03 alex channame = strtok( Req->argv[0], "," );
69 2ee05c9a 2002-03-03 alex while( channame )
71 f7567db0 2002-06-02 alex chan = flags = NULL;
73 f7567db0 2002-06-02 alex /* wird der Channel neu angelegt? */
74 2ee05c9a 2002-03-03 alex if( Channel_Search( channame )) is_new_chan = FALSE;
75 2ee05c9a 2002-03-03 alex else is_new_chan = TRUE;
77 2ee05c9a 2002-03-03 alex /* Hat ein Server Channel-User-Modes uebergeben? */
78 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) == CLIENT_SERVER )
80 2ee05c9a 2002-03-03 alex /* Channel-Flags extrahieren */
81 2ee05c9a 2002-03-03 alex flags = strchr( channame, 0x7 );
84 e876e210 2002-06-10 alex *flags = '\0';
89 c2f60abe 2002-05-27 alex /* Lokaler Client? */
90 c2f60abe 2002-05-27 alex if( Client_Type( Client ) == CLIENT_USER )
92 00e75ccd 2002-12-14 alex /* Test if the user has reached his maximum channel count */
93 00e75ccd 2002-12-14 alex if( Client_Type( Client ) == CLIENT_USER )
95 00e75ccd 2002-12-14 alex if(( Conf_MaxJoins > 0 ) && ( Channel_CountForUser( Client ) >= Conf_MaxJoins ))
97 00e75ccd 2002-12-14 alex IRC_WriteStrClient( Client, ERR_TOOMANYCHANNELS_MSG, Client_ID( Client ), channame );
98 00e75ccd 2002-12-14 alex return CONNECTED;
102 c2f60abe 2002-05-27 alex /* Existiert der Channel bereits, oder wird er im Moment neu erzeugt? */
103 c2f60abe 2002-05-27 alex if( is_new_chan )
105 c2f60abe 2002-05-27 alex /* Erster User im Channel: Operator-Flag setzen */
106 c2f60abe 2002-05-27 alex flags = "o";
110 c2f60abe 2002-05-27 alex /* Existierenden Channel suchen */
111 c2f60abe 2002-05-27 alex chan = Channel_Search( channame );
112 c2f60abe 2002-05-27 alex assert( chan != NULL );
114 a1ded68a 2002-09-08 alex is_banned = Lists_CheckBanned( target, chan );
115 a1ded68a 2002-09-08 alex is_invited = Lists_CheckInvited( target, chan );
117 c2f60abe 2002-05-27 alex /* Testen, ob Client gebanned ist */
118 a1ded68a 2002-09-08 alex if(( is_banned == TRUE ) && ( is_invited == FALSE ))
120 a1ded68a 2002-09-08 alex /* Client ist gebanned (und nicht invited): */
121 f7567db0 2002-06-02 alex IRC_WriteStrClient( Client, ERR_BANNEDFROMCHAN_MSG, Client_ID( Client ), channame );
123 69ad0e38 2002-12-16 alex /* Try next name, if any */
124 f7567db0 2002-06-02 alex channame = strtok( NULL, "," );
128 c2f60abe 2002-05-27 alex /* Ist der Channel "invite-only"? */
129 69ad0e38 2002-12-16 alex if(( strchr( Channel_Modes( chan ), 'i' )) && ( is_invited == FALSE ))
131 a1ded68a 2002-09-08 alex /* Channel ist "invite-only" und Client wurde nicht invited: */
132 a1ded68a 2002-09-08 alex IRC_WriteStrClient( Client, ERR_INVITEONLYCHAN_MSG, Client_ID( Client ), channame );
134 69ad0e38 2002-12-16 alex /* Try next name, if any */
135 69ad0e38 2002-12-16 alex channame = strtok( NULL, "," );
139 69ad0e38 2002-12-16 alex /* Is the channel protected by a key? */
140 69ad0e38 2002-12-16 alex if(( strchr( Channel_Modes( chan ), 'k' )) && ( strcmp( Channel_Key( chan ), key ? key : "" ) != 0 ))
142 69ad0e38 2002-12-16 alex /* Bad channel key! */
143 69ad0e38 2002-12-16 alex IRC_WriteStrClient( Client, ERR_BADCHANNELKEY_MSG, Client_ID( Client ), channame );
145 69ad0e38 2002-12-16 alex /* Try next name, if any */
146 69ad0e38 2002-12-16 alex channame = strtok( NULL, "," );
150 69ad0e38 2002-12-16 alex /* Are there already too many members? */
151 69ad0e38 2002-12-16 alex if(( strchr( Channel_Modes( chan ), 'l' )) && ( Channel_MaxUsers( chan ) <= Channel_MemberCount( chan )))
153 69ad0e38 2002-12-16 alex /* Bad channel key! */
154 69ad0e38 2002-12-16 alex IRC_WriteStrClient( Client, ERR_CHANNELISFULL_MSG, Client_ID( Client ), channame );
156 69ad0e38 2002-12-16 alex /* Try next name, if any */
157 a1ded68a 2002-09-08 alex channame = strtok( NULL, "," );
163 2ee05c9a 2002-03-03 alex /* Channel joinen (und ggf. anlegen) */
164 2ee05c9a 2002-03-03 alex if( ! Channel_Join( target, channame ))
166 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
167 2ee05c9a 2002-03-03 alex channame = strtok( NULL, "," );
170 c2f60abe 2002-05-27 alex if( ! chan ) chan = Channel_Search( channame );
171 2ee05c9a 2002-03-03 alex assert( chan != NULL );
173 2ee05c9a 2002-03-03 alex /* Modes setzen (wenn vorhanden) */
174 2ee05c9a 2002-03-03 alex while( flags && *flags )
176 2ee05c9a 2002-03-03 alex Channel_UserModeAdd( chan, target, *flags );
180 040f5422 2002-05-21 alex /* Wenn persistenter Channel und IRC-Operator: zum Channel-OP machen */
181 040f5422 2002-05-21 alex if(( strchr( Channel_Modes( chan ), 'P' )) && ( strchr( Client_Modes( target ), 'o' ))) Channel_UserModeAdd( chan, target, 'o' );
183 2ee05c9a 2002-03-03 alex /* Muessen Modes an andere Server gemeldet werden? */
184 695631b2 2002-12-26 alex strlcpy( &modes[1], Channel_UserModes( chan, target ), sizeof( modes ) - 1 );
185 2ee05c9a 2002-03-03 alex if( modes[1] ) modes[0] = 0x7;
186 2ee05c9a 2002-03-03 alex else modes[0] = '\0';
188 2ee05c9a 2002-03-03 alex /* An andere Server weiterleiten */
189 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, target, "JOIN :%s%s", channame, modes );
191 2ee05c9a 2002-03-03 alex /* im Channel bekannt machen */
192 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "JOIN :%s", channame );
193 2ee05c9a 2002-03-03 alex if( modes[1] )
195 2ee05c9a 2002-03-03 alex /* Modes im Channel bekannt machen */
196 f673fb96 2002-08-27 alex IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "MODE %s +%s %s", channame, &modes[1], Client_ID( target ));
199 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) == CLIENT_USER )
201 2ee05c9a 2002-03-03 alex /* an Client bestaetigen */
202 2ee05c9a 2002-03-03 alex IRC_WriteStrClientPrefix( Client, target, "JOIN :%s", channame );
204 2ee05c9a 2002-03-03 alex /* Topic an Client schicken */
205 2ee05c9a 2002-03-03 alex topic = Channel_Topic( chan );
206 2ee05c9a 2002-03-03 alex if( *topic ) IRC_WriteStrClient( Client, RPL_TOPIC_MSG, Client_ID( Client ), channame, topic );
208 2ee05c9a 2002-03-03 alex /* Mitglieder an Client Melden */
209 2ee05c9a 2002-03-03 alex IRC_Send_NAMES( Client, chan );
210 2ee05c9a 2002-03-03 alex IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), Channel_Name( chan ));
213 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
214 2ee05c9a 2002-03-03 alex channame = strtok( NULL, "," );
216 2ee05c9a 2002-03-03 alex return CONNECTED;
217 2ee05c9a 2002-03-03 alex } /* IRC_JOIN */
220 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
221 c2f60abe 2002-05-27 alex IRC_PART( CLIENT *Client, REQUEST *Req )
223 2ee05c9a 2002-03-03 alex CLIENT *target;
224 2ee05c9a 2002-03-03 alex CHAR *chan;
226 2ee05c9a 2002-03-03 alex assert( Client != NULL );
227 2ee05c9a 2002-03-03 alex assert( Req != NULL );
229 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
230 2ee05c9a 2002-03-03 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
232 2ee05c9a 2002-03-03 alex /* Wer ist der Absender? */
233 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
234 2ee05c9a 2002-03-03 alex else target = Client;
235 2ee05c9a 2002-03-03 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
237 2ee05c9a 2002-03-03 alex /* Channel-Namen durchgehen */
238 2ee05c9a 2002-03-03 alex chan = strtok( Req->argv[0], "," );
239 2ee05c9a 2002-03-03 alex while( chan )
241 2ee05c9a 2002-03-03 alex if( ! Channel_Part( target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID( target )))
243 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
244 2ee05c9a 2002-03-03 alex chan = strtok( NULL, "," );
248 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
249 2ee05c9a 2002-03-03 alex chan = strtok( NULL, "," );
251 2ee05c9a 2002-03-03 alex return CONNECTED;
252 2ee05c9a 2002-03-03 alex } /* IRC_PART */
255 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
256 c2f60abe 2002-05-27 alex IRC_TOPIC( CLIENT *Client, REQUEST *Req )
258 2ee05c9a 2002-03-03 alex CHANNEL *chan;
259 2ee05c9a 2002-03-03 alex CLIENT *from;
260 2ee05c9a 2002-03-03 alex CHAR *topic;
262 2ee05c9a 2002-03-03 alex assert( Client != NULL );
263 2ee05c9a 2002-03-03 alex assert( Req != NULL );
265 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
266 2ee05c9a 2002-03-03 alex if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
268 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
269 2ee05c9a 2002-03-03 alex else from = Client;
270 2ee05c9a 2002-03-03 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
272 2ee05c9a 2002-03-03 alex /* Welcher Channel? */
273 2ee05c9a 2002-03-03 alex chan = Channel_Search( Req->argv[0] );
274 a2119a66 2002-06-01 alex if( ! chan ) return IRC_WriteStrClient( from, ERR_NOSUCHCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
276 2ee05c9a 2002-03-03 alex /* Ist der User Mitglied in dem Channel? */
277 2ee05c9a 2002-03-03 alex if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
279 2ee05c9a 2002-03-03 alex if( Req->argc == 1 )
281 2ee05c9a 2002-03-03 alex /* Topic erfragen */
282 2ee05c9a 2002-03-03 alex topic = Channel_Topic( chan );
283 2ee05c9a 2002-03-03 alex if( *topic ) return IRC_WriteStrClient( from, RPL_TOPIC_MSG, Client_ID( from ), Channel_Name( chan ), topic );
284 2ee05c9a 2002-03-03 alex else return IRC_WriteStrClient( from, RPL_NOTOPIC_MSG, Client_ID( from ), Channel_Name( chan ));
287 2ee05c9a 2002-03-03 alex if( strchr( Channel_Modes( chan ), 't' ))
289 2ee05c9a 2002-03-03 alex /* Topic Lock. Ist der User ein Channel Operator? */
290 2ee05c9a 2002-03-03 alex if( ! strchr( Channel_UserModes( chan, from ), 'o' )) return IRC_WriteStrClient( from, ERR_CHANOPRIVSNEEDED_MSG, Client_ID( from ), Channel_Name( chan ));
293 2ee05c9a 2002-03-03 alex /* Topic setzen */
294 2ee05c9a 2002-03-03 alex Channel_SetTopic( chan, Req->argv[1] );
295 2ee05c9a 2002-03-03 alex Log( LOG_DEBUG, "User \"%s\" set topic on \"%s\": %s", Client_Mask( from ), Channel_Name( chan ), Req->argv[1][0] ? Req->argv[1] : "<none>" );
297 2ee05c9a 2002-03-03 alex /* im Channel bekannt machen und an Server weiterleiten */
298 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, from, "TOPIC %s :%s", Req->argv[0], Req->argv[1] );
299 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "TOPIC %s :%s", Req->argv[0], Req->argv[1] );
301 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) == CLIENT_USER ) return IRC_WriteStrClientPrefix( Client, Client, "TOPIC %s :%s", Req->argv[0], Req->argv[1] );
302 2ee05c9a 2002-03-03 alex else return CONNECTED;
303 2ee05c9a 2002-03-03 alex } /* IRC_TOPIC */
306 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
307 c2f60abe 2002-05-27 alex IRC_LIST( CLIENT *Client, REQUEST *Req )
309 3c0c3c3c 2002-04-23 alex CHAR *pattern;
310 3c0c3c3c 2002-04-23 alex CHANNEL *chan;
311 005391ca 2002-09-16 alex CLIENT *from, *target;
313 3c0c3c3c 2002-04-23 alex assert( Client != NULL );
314 3c0c3c3c 2002-04-23 alex assert( Req != NULL );
316 3c0c3c3c 2002-04-23 alex /* Falsche Anzahl Parameter? */
317 005391ca 2002-09-16 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
319 3c0c3c3c 2002-04-23 alex if( Req->argc > 0 ) pattern = strtok( Req->argv[0], "," );
320 3c0c3c3c 2002-04-23 alex else pattern = "*";
322 005391ca 2002-09-16 alex /* From aus Prefix ermitteln */
323 005391ca 2002-09-16 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
324 005391ca 2002-09-16 alex else from = Client;
325 005391ca 2002-09-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
327 005391ca 2002-09-16 alex if( Req->argc == 2 )
329 005391ca 2002-09-16 alex /* an anderen Server forwarden */
330 005391ca 2002-09-16 alex target = Client_Search( Req->argv[1] );
331 ae6a7e7c 2003-01-01 alex if(( ! target ) || ( Client_Type( target ) != CLIENT_SERVER )) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
333 005391ca 2002-09-16 alex if( target != Client_ThisServer( ))
335 005391ca 2002-09-16 alex /* Ok, anderer Server ist das Ziel: forwarden */
336 005391ca 2002-09-16 alex return IRC_WriteStrClientPrefix( target, from, "LIST %s :%s", from, Req->argv[1] );
340 3c0c3c3c 2002-04-23 alex while( pattern )
342 3c0c3c3c 2002-04-23 alex /* alle Channel durchgehen */
343 3c0c3c3c 2002-04-23 alex chan = Channel_First( );
344 3c0c3c3c 2002-04-23 alex while( chan )
346 39b9f65d 2002-06-26 alex /* Passt die Suchmaske auf diesen Channel? */
347 39b9f65d 2002-06-26 alex if( Match( pattern, Channel_Name( chan )))
349 3c0c3c3c 2002-04-23 alex /* Treffer! */
350 005391ca 2002-09-16 alex if( ! IRC_WriteStrClient( from, RPL_LIST_MSG, from, Channel_Name( chan ), Channel_MemberCount( chan ), Channel_Topic( chan ))) return DISCONNECTED;
352 3c0c3c3c 2002-04-23 alex chan = Channel_Next( chan );
355 3c0c3c3c 2002-04-23 alex /* naechsten Namen ermitteln */
356 3c0c3c3c 2002-04-23 alex if( Req->argc > 0 ) pattern = strtok( NULL, "," );
357 3c0c3c3c 2002-04-23 alex else pattern = NULL;
360 005391ca 2002-09-16 alex return IRC_WriteStrClient( from, RPL_LISTEND_MSG, from );
361 3c0c3c3c 2002-04-23 alex } /* IRC_LIST */
364 1f9ba7b3 2002-09-03 alex GLOBAL BOOLEAN
365 1f9ba7b3 2002-09-03 alex IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
367 43d9a624 2003-01-08 alex CHAR modes_add[COMMAND_LEN], l[16], *ptr;
368 1f9ba7b3 2002-09-03 alex CLIENT *from;
369 1f9ba7b3 2002-09-03 alex CHANNEL *chan;
370 43d9a624 2003-01-08 alex INT arg_topic;
372 1f9ba7b3 2002-09-03 alex assert( Client != NULL );
373 1f9ba7b3 2002-09-03 alex assert( Req != NULL );
375 43d9a624 2003-01-08 alex /* Bad number of parameters? */
376 43d9a624 2003-01-08 alex if(( Req->argc < 2 ) || ( Req->argc == 4 ) || ( Req->argc > 5 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
378 43d9a624 2003-01-08 alex /* Compatibility kludge */
379 43d9a624 2003-01-08 alex if( Req->argc == 5 ) arg_topic = 4;
380 43d9a624 2003-01-08 alex else if( Req->argc == 3 ) arg_topic = 2;
381 43d9a624 2003-01-08 alex else arg_topic = -1;
383 43d9a624 2003-01-08 alex /* Search origin */
384 1f9ba7b3 2002-09-03 alex from = Client_Search( Req->prefix );
385 1f9ba7b3 2002-09-03 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
387 43d9a624 2003-01-08 alex /* Search or create channel */
388 1f9ba7b3 2002-09-03 alex chan = Channel_Search( Req->argv[0] );
389 1f9ba7b3 2002-09-03 alex if( ! chan ) chan = Channel_Create( Req->argv[0] );
390 1f9ba7b3 2002-09-03 alex if( ! chan ) return CONNECTED;
392 1f9ba7b3 2002-09-03 alex if( Req->argv[1][0] == '+' )
394 1f9ba7b3 2002-09-03 alex ptr = Channel_Modes( chan );
395 1f9ba7b3 2002-09-03 alex if( ! *ptr )
397 bb94d181 2003-01-08 alex /* OK, this channel doesn't have modes jet, set the received ones: */
398 1f9ba7b3 2002-09-03 alex Channel_SetModes( chan, &Req->argv[1][1] );
400 43d9a624 2003-01-08 alex if( Req->argc == 5 )
402 43d9a624 2003-01-08 alex if( strchr( Channel_Modes( chan ), 'k' )) Channel_SetKey( chan, Req->argv[2] );
403 43d9a624 2003-01-08 alex if( strchr( Channel_Modes( chan ), 'l' )) Channel_SetMaxUsers( chan, atol( Req->argv[3] ));
407 43d9a624 2003-01-08 alex /* Delete modes which we never want to inherit */
408 43d9a624 2003-01-08 alex Channel_ModeDel( chan, 'l' );
409 43d9a624 2003-01-08 alex Channel_ModeDel( chan, 'k' );
412 43d9a624 2003-01-08 alex strcpy( modes_add, "" );
413 43d9a624 2003-01-08 alex ptr = Channel_Modes( chan );
414 43d9a624 2003-01-08 alex while( *ptr )
416 43d9a624 2003-01-08 alex if( *ptr == 'l' )
418 43d9a624 2003-01-08 alex snprintf( l, sizeof( l ), " %ld", Channel_MaxUsers( chan ));
419 43d9a624 2003-01-08 alex strlcat( modes_add, l, sizeof( modes_add ));
421 43d9a624 2003-01-08 alex if( *ptr == 'k' )
423 43d9a624 2003-01-08 alex strlcat( modes_add, " ", sizeof( modes_add ));
424 43d9a624 2003-01-08 alex strlcat( modes_add, Channel_Key( chan ), sizeof( modes_add ));
429 43d9a624 2003-01-08 alex /* Inform members of this channel */
430 43d9a624 2003-01-08 alex IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "MODE %s +%s%s", Req->argv[0], Channel_Modes( chan ), modes_add );
433 43d9a624 2003-01-08 alex else Log( LOG_WARNING, "CHANINFO: invalid MODE format ignored!" );
435 43d9a624 2003-01-08 alex if( arg_topic > 0 )
437 43d9a624 2003-01-08 alex /* We got a topic */
438 1f9ba7b3 2002-09-03 alex ptr = Channel_Topic( chan );
439 43d9a624 2003-01-08 alex if(( ! *ptr ) && ( Req->argv[arg_topic][0] ))
441 43d9a624 2003-01-08 alex /* OK, there is no topic jet */
442 43d9a624 2003-01-08 alex Channel_SetTopic( chan, Req->argv[arg_topic] );
443 43d9a624 2003-01-08 alex IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "TOPIC %s :%s", Req->argv[0], Channel_Topic( chan ));
447 43d9a624 2003-01-08 alex /* Forward CHANINFO to other serevrs */
448 43d9a624 2003-01-08 alex if( Req->argc == 5 ) IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s %s %s :%s", Req->argv[0], Req->argv[1], Req->argv[2], Req->argv[3], Req->argv[4] );
449 43d9a624 2003-01-08 alex else if( Req->argc == 3 ) IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s :%s", Req->argv[0], Req->argv[1], Req->argv[2] );
450 43d9a624 2003-01-08 alex else IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s", Req->argv[0], Req->argv[1] );
452 1f9ba7b3 2002-09-03 alex return CONNECTED;
453 1f9ba7b3 2002-09-03 alex } /* IRC_CHANINFO */
456 2ee05c9a 2002-03-03 alex /* -eof- */