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 233210b9 2004-04-09 alex static char UNUSED id[] = "$Id: irc-channel.c,v 1.27 2004/04/09 20:46:48 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 cb76d96e 2004-03-11 alex chan = NULL; 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 233210b9 2004-04-09 alex /* Local 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, "," );
164 233210b9 2004-04-09 alex /* Remote server: we don't need to know whether the
165 233210b9 2004-04-09 alex * client is invited or not, but we have to make sure
166 233210b9 2004-04-09 alex * that the "one shot" entries (generated by INVITE
167 233210b9 2004-04-09 alex * commands) in this list become deleted when a user
168 233210b9 2004-04-09 alex * joins a channel this way. */
169 233210b9 2004-04-09 alex chan = Channel_Search( channame );
170 233210b9 2004-04-09 alex if( chan != NULL ) (VOID)Lists_CheckInvited( target, chan );
173 2ee05c9a 2002-03-03 alex /* Channel joinen (und ggf. anlegen) */
174 2ee05c9a 2002-03-03 alex if( ! Channel_Join( target, channame ))
176 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
177 2ee05c9a 2002-03-03 alex channame = strtok( NULL, "," );
180 c2f60abe 2002-05-27 alex if( ! chan ) chan = Channel_Search( channame );
181 2ee05c9a 2002-03-03 alex assert( chan != NULL );
183 2ee05c9a 2002-03-03 alex /* Modes setzen (wenn vorhanden) */
184 2ee05c9a 2002-03-03 alex while( flags && *flags )
186 2ee05c9a 2002-03-03 alex Channel_UserModeAdd( chan, target, *flags );
190 040f5422 2002-05-21 alex /* Wenn persistenter Channel und IRC-Operator: zum Channel-OP machen */
191 040f5422 2002-05-21 alex if(( strchr( Channel_Modes( chan ), 'P' )) && ( strchr( Client_Modes( target ), 'o' ))) Channel_UserModeAdd( chan, target, 'o' );
193 2ee05c9a 2002-03-03 alex /* Muessen Modes an andere Server gemeldet werden? */
194 695631b2 2002-12-26 alex strlcpy( &modes[1], Channel_UserModes( chan, target ), sizeof( modes ) - 1 );
195 2ee05c9a 2002-03-03 alex if( modes[1] ) modes[0] = 0x7;
196 2ee05c9a 2002-03-03 alex else modes[0] = '\0';
198 2ee05c9a 2002-03-03 alex /* An andere Server weiterleiten */
199 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, target, "JOIN :%s%s", channame, modes );
201 2ee05c9a 2002-03-03 alex /* im Channel bekannt machen */
202 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "JOIN :%s", channame );
203 2ee05c9a 2002-03-03 alex if( modes[1] )
205 2ee05c9a 2002-03-03 alex /* Modes im Channel bekannt machen */
206 f673fb96 2002-08-27 alex IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "MODE %s +%s %s", channame, &modes[1], Client_ID( target ));
209 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) == CLIENT_USER )
211 2ee05c9a 2002-03-03 alex /* an Client bestaetigen */
212 2ee05c9a 2002-03-03 alex IRC_WriteStrClientPrefix( Client, target, "JOIN :%s", channame );
214 2ee05c9a 2002-03-03 alex /* Topic an Client schicken */
215 2ee05c9a 2002-03-03 alex topic = Channel_Topic( chan );
216 2ee05c9a 2002-03-03 alex if( *topic ) IRC_WriteStrClient( Client, RPL_TOPIC_MSG, Client_ID( Client ), channame, topic );
218 2ee05c9a 2002-03-03 alex /* Mitglieder an Client Melden */
219 2ee05c9a 2002-03-03 alex IRC_Send_NAMES( Client, chan );
220 2ee05c9a 2002-03-03 alex IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), Channel_Name( chan ));
223 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
224 2ee05c9a 2002-03-03 alex channame = strtok( NULL, "," );
226 2ee05c9a 2002-03-03 alex return CONNECTED;
227 2ee05c9a 2002-03-03 alex } /* IRC_JOIN */
230 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
231 c2f60abe 2002-05-27 alex IRC_PART( CLIENT *Client, REQUEST *Req )
233 2ee05c9a 2002-03-03 alex CLIENT *target;
234 2ee05c9a 2002-03-03 alex CHAR *chan;
236 2ee05c9a 2002-03-03 alex assert( Client != NULL );
237 2ee05c9a 2002-03-03 alex assert( Req != NULL );
239 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
240 2ee05c9a 2002-03-03 alex if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
242 2ee05c9a 2002-03-03 alex /* Wer ist der Absender? */
243 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_Search( Req->prefix );
244 2ee05c9a 2002-03-03 alex else target = Client;
245 2ee05c9a 2002-03-03 alex if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
247 2ee05c9a 2002-03-03 alex /* Channel-Namen durchgehen */
248 2ee05c9a 2002-03-03 alex chan = strtok( Req->argv[0], "," );
249 2ee05c9a 2002-03-03 alex while( chan )
251 2ee05c9a 2002-03-03 alex if( ! Channel_Part( target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID( target )))
253 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
254 2ee05c9a 2002-03-03 alex chan = strtok( NULL, "," );
258 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
259 2ee05c9a 2002-03-03 alex chan = strtok( NULL, "," );
261 2ee05c9a 2002-03-03 alex return CONNECTED;
262 2ee05c9a 2002-03-03 alex } /* IRC_PART */
265 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
266 c2f60abe 2002-05-27 alex IRC_TOPIC( CLIENT *Client, REQUEST *Req )
268 2ee05c9a 2002-03-03 alex CHANNEL *chan;
269 2ee05c9a 2002-03-03 alex CLIENT *from;
270 2ee05c9a 2002-03-03 alex CHAR *topic;
272 2ee05c9a 2002-03-03 alex assert( Client != NULL );
273 2ee05c9a 2002-03-03 alex assert( Req != NULL );
275 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
276 2ee05c9a 2002-03-03 alex if(( Req->argc < 1 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
278 bc4ed226 2002-03-25 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
279 2ee05c9a 2002-03-03 alex else from = Client;
280 2ee05c9a 2002-03-03 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
282 2ee05c9a 2002-03-03 alex /* Welcher Channel? */
283 2ee05c9a 2002-03-03 alex chan = Channel_Search( Req->argv[0] );
284 a2119a66 2002-06-01 alex if( ! chan ) return IRC_WriteStrClient( from, ERR_NOSUCHCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
286 2ee05c9a 2002-03-03 alex /* Ist der User Mitglied in dem Channel? */
287 2ee05c9a 2002-03-03 alex if( ! Channel_IsMemberOf( chan, from )) return IRC_WriteStrClient( from, ERR_NOTONCHANNEL_MSG, Client_ID( from ), Req->argv[0] );
289 2ee05c9a 2002-03-03 alex if( Req->argc == 1 )
291 2ee05c9a 2002-03-03 alex /* Topic erfragen */
292 2ee05c9a 2002-03-03 alex topic = Channel_Topic( chan );
293 2ee05c9a 2002-03-03 alex if( *topic ) return IRC_WriteStrClient( from, RPL_TOPIC_MSG, Client_ID( from ), Channel_Name( chan ), topic );
294 2ee05c9a 2002-03-03 alex else return IRC_WriteStrClient( from, RPL_NOTOPIC_MSG, Client_ID( from ), Channel_Name( chan ));
297 2ee05c9a 2002-03-03 alex if( strchr( Channel_Modes( chan ), 't' ))
299 2ee05c9a 2002-03-03 alex /* Topic Lock. Ist der User ein Channel Operator? */
300 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 ));
303 2ee05c9a 2002-03-03 alex /* Topic setzen */
304 2ee05c9a 2002-03-03 alex Channel_SetTopic( chan, Req->argv[1] );
305 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>" );
307 2ee05c9a 2002-03-03 alex /* im Channel bekannt machen und an Server weiterleiten */
308 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, from, "TOPIC %s :%s", Req->argv[0], Req->argv[1] );
309 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "TOPIC %s :%s", Req->argv[0], Req->argv[1] );
311 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] );
312 2ee05c9a 2002-03-03 alex else return CONNECTED;
313 2ee05c9a 2002-03-03 alex } /* IRC_TOPIC */
316 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
317 c2f60abe 2002-05-27 alex IRC_LIST( CLIENT *Client, REQUEST *Req )
319 3c0c3c3c 2002-04-23 alex CHAR *pattern;
320 3c0c3c3c 2002-04-23 alex CHANNEL *chan;
321 005391ca 2002-09-16 alex CLIENT *from, *target;
323 3c0c3c3c 2002-04-23 alex assert( Client != NULL );
324 3c0c3c3c 2002-04-23 alex assert( Req != NULL );
326 3c0c3c3c 2002-04-23 alex /* Falsche Anzahl Parameter? */
327 005391ca 2002-09-16 alex if( Req->argc > 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
329 3c0c3c3c 2002-04-23 alex if( Req->argc > 0 ) pattern = strtok( Req->argv[0], "," );
330 3c0c3c3c 2002-04-23 alex else pattern = "*";
332 005391ca 2002-09-16 alex /* From aus Prefix ermitteln */
333 005391ca 2002-09-16 alex if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_Search( Req->prefix );
334 005391ca 2002-09-16 alex else from = Client;
335 005391ca 2002-09-16 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
337 005391ca 2002-09-16 alex if( Req->argc == 2 )
339 005391ca 2002-09-16 alex /* an anderen Server forwarden */
340 005391ca 2002-09-16 alex target = Client_Search( Req->argv[1] );
341 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] );
343 005391ca 2002-09-16 alex if( target != Client_ThisServer( ))
345 005391ca 2002-09-16 alex /* Ok, anderer Server ist das Ziel: forwarden */
346 005391ca 2002-09-16 alex return IRC_WriteStrClientPrefix( target, from, "LIST %s :%s", from, Req->argv[1] );
350 3c0c3c3c 2002-04-23 alex while( pattern )
352 3c0c3c3c 2002-04-23 alex /* alle Channel durchgehen */
353 3c0c3c3c 2002-04-23 alex chan = Channel_First( );
354 3c0c3c3c 2002-04-23 alex while( chan )
356 39b9f65d 2002-06-26 alex /* Passt die Suchmaske auf diesen Channel? */
357 39b9f65d 2002-06-26 alex if( Match( pattern, Channel_Name( chan )))
359 3c0c3c3c 2002-04-23 alex /* Treffer! */
360 005391ca 2002-09-16 alex if( ! IRC_WriteStrClient( from, RPL_LIST_MSG, from, Channel_Name( chan ), Channel_MemberCount( chan ), Channel_Topic( chan ))) return DISCONNECTED;
362 3c0c3c3c 2002-04-23 alex chan = Channel_Next( chan );
365 3c0c3c3c 2002-04-23 alex /* naechsten Namen ermitteln */
366 3c0c3c3c 2002-04-23 alex if( Req->argc > 0 ) pattern = strtok( NULL, "," );
367 3c0c3c3c 2002-04-23 alex else pattern = NULL;
370 005391ca 2002-09-16 alex return IRC_WriteStrClient( from, RPL_LISTEND_MSG, from );
371 3c0c3c3c 2002-04-23 alex } /* IRC_LIST */
374 1f9ba7b3 2002-09-03 alex GLOBAL BOOLEAN
375 1f9ba7b3 2002-09-03 alex IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
377 43d9a624 2003-01-08 alex CHAR modes_add[COMMAND_LEN], l[16], *ptr;
378 1f9ba7b3 2002-09-03 alex CLIENT *from;
379 1f9ba7b3 2002-09-03 alex CHANNEL *chan;
380 43d9a624 2003-01-08 alex INT arg_topic;
382 1f9ba7b3 2002-09-03 alex assert( Client != NULL );
383 1f9ba7b3 2002-09-03 alex assert( Req != NULL );
385 43d9a624 2003-01-08 alex /* Bad number of parameters? */
386 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 );
388 43d9a624 2003-01-08 alex /* Compatibility kludge */
389 43d9a624 2003-01-08 alex if( Req->argc == 5 ) arg_topic = 4;
390 43d9a624 2003-01-08 alex else if( Req->argc == 3 ) arg_topic = 2;
391 43d9a624 2003-01-08 alex else arg_topic = -1;
393 43d9a624 2003-01-08 alex /* Search origin */
394 1f9ba7b3 2002-09-03 alex from = Client_Search( Req->prefix );
395 1f9ba7b3 2002-09-03 alex if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
397 43d9a624 2003-01-08 alex /* Search or create channel */
398 1f9ba7b3 2002-09-03 alex chan = Channel_Search( Req->argv[0] );
399 1f9ba7b3 2002-09-03 alex if( ! chan ) chan = Channel_Create( Req->argv[0] );
400 1f9ba7b3 2002-09-03 alex if( ! chan ) return CONNECTED;
402 1f9ba7b3 2002-09-03 alex if( Req->argv[1][0] == '+' )
404 1f9ba7b3 2002-09-03 alex ptr = Channel_Modes( chan );
405 1f9ba7b3 2002-09-03 alex if( ! *ptr )
407 bb94d181 2003-01-08 alex /* OK, this channel doesn't have modes jet, set the received ones: */
408 1f9ba7b3 2002-09-03 alex Channel_SetModes( chan, &Req->argv[1][1] );
410 43d9a624 2003-01-08 alex if( Req->argc == 5 )
412 43d9a624 2003-01-08 alex if( strchr( Channel_Modes( chan ), 'k' )) Channel_SetKey( chan, Req->argv[2] );
413 43d9a624 2003-01-08 alex if( strchr( Channel_Modes( chan ), 'l' )) Channel_SetMaxUsers( chan, atol( Req->argv[3] ));
417 43d9a624 2003-01-08 alex /* Delete modes which we never want to inherit */
418 43d9a624 2003-01-08 alex Channel_ModeDel( chan, 'l' );
419 43d9a624 2003-01-08 alex Channel_ModeDel( chan, 'k' );
422 43d9a624 2003-01-08 alex strcpy( modes_add, "" );
423 43d9a624 2003-01-08 alex ptr = Channel_Modes( chan );
424 43d9a624 2003-01-08 alex while( *ptr )
426 43d9a624 2003-01-08 alex if( *ptr == 'l' )
428 43d9a624 2003-01-08 alex snprintf( l, sizeof( l ), " %ld", Channel_MaxUsers( chan ));
429 43d9a624 2003-01-08 alex strlcat( modes_add, l, sizeof( modes_add ));
431 43d9a624 2003-01-08 alex if( *ptr == 'k' )
433 43d9a624 2003-01-08 alex strlcat( modes_add, " ", sizeof( modes_add ));
434 43d9a624 2003-01-08 alex strlcat( modes_add, Channel_Key( chan ), sizeof( modes_add ));
439 43d9a624 2003-01-08 alex /* Inform members of this channel */
440 43d9a624 2003-01-08 alex IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "MODE %s +%s%s", Req->argv[0], Channel_Modes( chan ), modes_add );
443 43d9a624 2003-01-08 alex else Log( LOG_WARNING, "CHANINFO: invalid MODE format ignored!" );
445 43d9a624 2003-01-08 alex if( arg_topic > 0 )
447 43d9a624 2003-01-08 alex /* We got a topic */
448 1f9ba7b3 2002-09-03 alex ptr = Channel_Topic( chan );
449 43d9a624 2003-01-08 alex if(( ! *ptr ) && ( Req->argv[arg_topic][0] ))
451 43d9a624 2003-01-08 alex /* OK, there is no topic jet */
452 43d9a624 2003-01-08 alex Channel_SetTopic( chan, Req->argv[arg_topic] );
453 43d9a624 2003-01-08 alex IRC_WriteStrChannelPrefix( Client, chan, from, FALSE, "TOPIC %s :%s", Req->argv[0], Channel_Topic( chan ));
457 43d9a624 2003-01-08 alex /* Forward CHANINFO to other serevrs */
458 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] );
459 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] );
460 43d9a624 2003-01-08 alex else IRC_WriteStrServersPrefixFlag( Client, from, 'C', "CHANINFO %s %s", Req->argv[0], Req->argv[1] );
462 1f9ba7b3 2002-09-03 alex return CONNECTED;
463 1f9ba7b3 2002-09-03 alex } /* IRC_CHANINFO */
466 2ee05c9a 2002-03-03 alex /* -eof- */