Blame


1 2ee05c9a 2002-03-03 alex /*
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)
4 2ee05c9a 2002-03-03 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 2ee05c9a 2002-03-03 alex *
11 490f28ff 2002-12-12 alex * IRC channel commands
12 2ee05c9a 2002-03-03 alex */
13 2ee05c9a 2002-03-03 alex
14 2ee05c9a 2002-03-03 alex
15 ca33cbda 2002-03-12 alex #include "portab.h"
16 490f28ff 2002-12-12 alex
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 $";
18 2ee05c9a 2002-03-03 alex
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>
24 2ee05c9a 2002-03-03 alex
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"
38 2ee05c9a 2002-03-03 alex
39 ca33cbda 2002-03-12 alex #include "exp.h"
40 2ee05c9a 2002-03-03 alex #include "irc-channel.h"
41 2ee05c9a 2002-03-03 alex
42 2ee05c9a 2002-03-03 alex
43 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
44 c2f60abe 2002-05-27 alex IRC_JOIN( CLIENT *Client, REQUEST *Req )
45 2ee05c9a 2002-03-03 alex {
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;
50 2ee05c9a 2002-03-03 alex
51 2ee05c9a 2002-03-03 alex assert( Client != NULL );
52 2ee05c9a 2002-03-03 alex assert( Req != NULL );
53 2ee05c9a 2002-03-03 alex
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 );
56 2ee05c9a 2002-03-03 alex
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 );
61 2ee05c9a 2002-03-03 alex
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;
65 69ad0e38 2002-12-16 alex
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 )
70 2ee05c9a 2002-03-03 alex {
71 f7567db0 2002-06-02 alex chan = flags = NULL;
72 2ee05c9a 2002-03-03 alex
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;
76 2ee05c9a 2002-03-03 alex
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 )
79 2ee05c9a 2002-03-03 alex {
80 2ee05c9a 2002-03-03 alex /* Channel-Flags extrahieren */
81 2ee05c9a 2002-03-03 alex flags = strchr( channame, 0x7 );
82 e876e210 2002-06-10 alex if( flags )
83 e876e210 2002-06-10 alex {
84 e876e210 2002-06-10 alex *flags = '\0';
85 e876e210 2002-06-10 alex flags++;
86 e876e210 2002-06-10 alex }
87 2ee05c9a 2002-03-03 alex }
88 2ee05c9a 2002-03-03 alex
89 c2f60abe 2002-05-27 alex /* Lokaler Client? */
90 c2f60abe 2002-05-27 alex if( Client_Type( Client ) == CLIENT_USER )
91 2ee05c9a 2002-03-03 alex {
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 )
94 00e75ccd 2002-12-14 alex {
95 00e75ccd 2002-12-14 alex if(( Conf_MaxJoins > 0 ) && ( Channel_CountForUser( Client ) >= Conf_MaxJoins ))
96 00e75ccd 2002-12-14 alex {
97 00e75ccd 2002-12-14 alex IRC_WriteStrClient( Client, ERR_TOOMANYCHANNELS_MSG, Client_ID( Client ), channame );
98 00e75ccd 2002-12-14 alex return CONNECTED;
99 00e75ccd 2002-12-14 alex }
100 00e75ccd 2002-12-14 alex }
101 00e75ccd 2002-12-14 alex
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 )
104 c2f60abe 2002-05-27 alex {
105 c2f60abe 2002-05-27 alex /* Erster User im Channel: Operator-Flag setzen */
106 c2f60abe 2002-05-27 alex flags = "o";
107 c2f60abe 2002-05-27 alex }
108 c2f60abe 2002-05-27 alex else
109 c2f60abe 2002-05-27 alex {
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 );
113 c2f60abe 2002-05-27 alex
114 a1ded68a 2002-09-08 alex is_banned = Lists_CheckBanned( target, chan );
115 a1ded68a 2002-09-08 alex is_invited = Lists_CheckInvited( target, chan );
116 a1ded68a 2002-09-08 alex
117 c2f60abe 2002-05-27 alex /* Testen, ob Client gebanned ist */
118 a1ded68a 2002-09-08 alex if(( is_banned == TRUE ) && ( is_invited == FALSE ))
119 c2f60abe 2002-05-27 alex {
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 );
122 f7567db0 2002-06-02 alex
123 69ad0e38 2002-12-16 alex /* Try next name, if any */
124 f7567db0 2002-06-02 alex channame = strtok( NULL, "," );
125 f7567db0 2002-06-02 alex continue;
126 c2f60abe 2002-05-27 alex }
127 c2f60abe 2002-05-27 alex
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 ))
130 c2f60abe 2002-05-27 alex {
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 );
133 f7567db0 2002-06-02 alex
134 69ad0e38 2002-12-16 alex /* Try next name, if any */
135 69ad0e38 2002-12-16 alex channame = strtok( NULL, "," );
136 69ad0e38 2002-12-16 alex continue;
137 69ad0e38 2002-12-16 alex }
138 69ad0e38 2002-12-16 alex
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 ))
141 69ad0e38 2002-12-16 alex {
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 );
144 69ad0e38 2002-12-16 alex
145 69ad0e38 2002-12-16 alex /* Try next name, if any */
146 69ad0e38 2002-12-16 alex channame = strtok( NULL, "," );
147 69ad0e38 2002-12-16 alex continue;
148 69ad0e38 2002-12-16 alex }
149 69ad0e38 2002-12-16 alex
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 )))
152 69ad0e38 2002-12-16 alex {
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 );
155 69ad0e38 2002-12-16 alex
156 69ad0e38 2002-12-16 alex /* Try next name, if any */
157 a1ded68a 2002-09-08 alex channame = strtok( NULL, "," );
158 a1ded68a 2002-09-08 alex continue;
159 c2f60abe 2002-05-27 alex }
160 c2f60abe 2002-05-27 alex }
161 2ee05c9a 2002-03-03 alex }
162 2ee05c9a 2002-03-03 alex
163 2ee05c9a 2002-03-03 alex /* Channel joinen (und ggf. anlegen) */
164 2ee05c9a 2002-03-03 alex if( ! Channel_Join( target, channame ))
165 2ee05c9a 2002-03-03 alex {
166 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
167 2ee05c9a 2002-03-03 alex channame = strtok( NULL, "," );
168 2ee05c9a 2002-03-03 alex continue;
169 2ee05c9a 2002-03-03 alex }
170 c2f60abe 2002-05-27 alex if( ! chan ) chan = Channel_Search( channame );
171 2ee05c9a 2002-03-03 alex assert( chan != NULL );
172 2ee05c9a 2002-03-03 alex
173 2ee05c9a 2002-03-03 alex /* Modes setzen (wenn vorhanden) */
174 2ee05c9a 2002-03-03 alex while( flags && *flags )
175 2ee05c9a 2002-03-03 alex {
176 2ee05c9a 2002-03-03 alex Channel_UserModeAdd( chan, target, *flags );
177 2ee05c9a 2002-03-03 alex flags++;
178 2ee05c9a 2002-03-03 alex }
179 2ee05c9a 2002-03-03 alex
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' );
182 040f5422 2002-05-21 alex
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';
187 2ee05c9a 2002-03-03 alex
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 );
190 2ee05c9a 2002-03-03 alex
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] )
194 2ee05c9a 2002-03-03 alex {
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 ));
197 2ee05c9a 2002-03-03 alex }
198 2ee05c9a 2002-03-03 alex
199 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) == CLIENT_USER )
200 2ee05c9a 2002-03-03 alex {
201 2ee05c9a 2002-03-03 alex /* an Client bestaetigen */
202 2ee05c9a 2002-03-03 alex IRC_WriteStrClientPrefix( Client, target, "JOIN :%s", channame );
203 2ee05c9a 2002-03-03 alex
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 );
207 2ee05c9a 2002-03-03 alex
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 ));
211 2ee05c9a 2002-03-03 alex }
212 2ee05c9a 2002-03-03 alex
213 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
214 2ee05c9a 2002-03-03 alex channame = strtok( NULL, "," );
215 2ee05c9a 2002-03-03 alex }
216 2ee05c9a 2002-03-03 alex return CONNECTED;
217 2ee05c9a 2002-03-03 alex } /* IRC_JOIN */
218 2ee05c9a 2002-03-03 alex
219 2ee05c9a 2002-03-03 alex
220 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
221 c2f60abe 2002-05-27 alex IRC_PART( CLIENT *Client, REQUEST *Req )
222 2ee05c9a 2002-03-03 alex {
223 2ee05c9a 2002-03-03 alex CLIENT *target;
224 2ee05c9a 2002-03-03 alex CHAR *chan;
225 2ee05c9a 2002-03-03 alex
226 2ee05c9a 2002-03-03 alex assert( Client != NULL );
227 2ee05c9a 2002-03-03 alex assert( Req != NULL );
228 2ee05c9a 2002-03-03 alex
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 );
231 2ee05c9a 2002-03-03 alex
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 );
236 2ee05c9a 2002-03-03 alex
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 )
240 2ee05c9a 2002-03-03 alex {
241 2ee05c9a 2002-03-03 alex if( ! Channel_Part( target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID( target )))
242 2ee05c9a 2002-03-03 alex {
243 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
244 2ee05c9a 2002-03-03 alex chan = strtok( NULL, "," );
245 2ee05c9a 2002-03-03 alex continue;
246 2ee05c9a 2002-03-03 alex }
247 2ee05c9a 2002-03-03 alex
248 2ee05c9a 2002-03-03 alex /* naechsten Namen ermitteln */
249 2ee05c9a 2002-03-03 alex chan = strtok( NULL, "," );
250 2ee05c9a 2002-03-03 alex }
251 2ee05c9a 2002-03-03 alex return CONNECTED;
252 2ee05c9a 2002-03-03 alex } /* IRC_PART */
253 2ee05c9a 2002-03-03 alex
254 2ee05c9a 2002-03-03 alex
255 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
256 c2f60abe 2002-05-27 alex IRC_TOPIC( CLIENT *Client, REQUEST *Req )
257 2ee05c9a 2002-03-03 alex {
258 2ee05c9a 2002-03-03 alex CHANNEL *chan;
259 2ee05c9a 2002-03-03 alex CLIENT *from;
260 2ee05c9a 2002-03-03 alex CHAR *topic;
261 2ee05c9a 2002-03-03 alex
262 2ee05c9a 2002-03-03 alex assert( Client != NULL );
263 2ee05c9a 2002-03-03 alex assert( Req != NULL );
264 2ee05c9a 2002-03-03 alex
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 );
267 2ee05c9a 2002-03-03 alex
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 );
271 2ee05c9a 2002-03-03 alex
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] );
275 2ee05c9a 2002-03-03 alex
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] );
278 2ee05c9a 2002-03-03 alex
279 2ee05c9a 2002-03-03 alex if( Req->argc == 1 )
280 2ee05c9a 2002-03-03 alex {
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 ));
285 2ee05c9a 2002-03-03 alex }
286 2ee05c9a 2002-03-03 alex
287 2ee05c9a 2002-03-03 alex if( strchr( Channel_Modes( chan ), 't' ))
288 2ee05c9a 2002-03-03 alex {
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 ));
291 2ee05c9a 2002-03-03 alex }
292 2ee05c9a 2002-03-03 alex
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>" );
296 2ee05c9a 2002-03-03 alex
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] );
300 2ee05c9a 2002-03-03 alex
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 */
304 2ee05c9a 2002-03-03 alex
305 2ee05c9a 2002-03-03 alex
306 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
307 c2f60abe 2002-05-27 alex IRC_LIST( CLIENT *Client, REQUEST *Req )
308 3c0c3c3c 2002-04-23 alex {
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;
312 3c0c3c3c 2002-04-23 alex
313 3c0c3c3c 2002-04-23 alex assert( Client != NULL );
314 3c0c3c3c 2002-04-23 alex assert( Req != NULL );
315 3c0c3c3c 2002-04-23 alex
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 );
318 3c0c3c3c 2002-04-23 alex
319 3c0c3c3c 2002-04-23 alex if( Req->argc > 0 ) pattern = strtok( Req->argv[0], "," );
320 3c0c3c3c 2002-04-23 alex else pattern = "*";
321 005391ca 2002-09-16 alex
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 );
326 005391ca 2002-09-16 alex
327 005391ca 2002-09-16 alex if( Req->argc == 2 )
328 005391ca 2002-09-16 alex {
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] );
332 005391ca 2002-09-16 alex
333 005391ca 2002-09-16 alex if( target != Client_ThisServer( ))
334 005391ca 2002-09-16 alex {
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] );
337 005391ca 2002-09-16 alex }
338 005391ca 2002-09-16 alex }
339 3c0c3c3c 2002-04-23 alex
340 3c0c3c3c 2002-04-23 alex while( pattern )
341 3c0c3c3c 2002-04-23 alex {
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 )
345 3c0c3c3c 2002-04-23 alex {
346 39b9f65d 2002-06-26 alex /* Passt die Suchmaske auf diesen Channel? */
347 39b9f65d 2002-06-26 alex if( Match( pattern, Channel_Name( chan )))
348 3c0c3c3c 2002-04-23 alex {
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;
351 3c0c3c3c 2002-04-23 alex }
352 3c0c3c3c 2002-04-23 alex chan = Channel_Next( chan );
353 3c0c3c3c 2002-04-23 alex }
354 3c0c3c3c 2002-04-23 alex
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;
358 3c0c3c3c 2002-04-23 alex }
359 3c0c3c3c 2002-04-23 alex
360 005391ca 2002-09-16 alex return IRC_WriteStrClient( from, RPL_LISTEND_MSG, from );
361 3c0c3c3c 2002-04-23 alex } /* IRC_LIST */
362 1f9ba7b3 2002-09-03 alex
363 1f9ba7b3 2002-09-03 alex
364 1f9ba7b3 2002-09-03 alex GLOBAL BOOLEAN
365 1f9ba7b3 2002-09-03 alex IRC_CHANINFO( CLIENT *Client, REQUEST *Req )
366 1f9ba7b3 2002-09-03 alex {
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;
371 1f9ba7b3 2002-09-03 alex
372 1f9ba7b3 2002-09-03 alex assert( Client != NULL );
373 1f9ba7b3 2002-09-03 alex assert( Req != NULL );
374 1f9ba7b3 2002-09-03 alex
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 );
377 43d9a624 2003-01-08 alex
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;
382 1f9ba7b3 2002-09-03 alex
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 );
386 1f9ba7b3 2002-09-03 alex
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;
391 1f9ba7b3 2002-09-03 alex
392 1f9ba7b3 2002-09-03 alex if( Req->argv[1][0] == '+' )
393 1f9ba7b3 2002-09-03 alex {
394 1f9ba7b3 2002-09-03 alex ptr = Channel_Modes( chan );
395 1f9ba7b3 2002-09-03 alex if( ! *ptr )
396 1f9ba7b3 2002-09-03 alex {
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] );
399 bb94d181 2003-01-08 alex
400 43d9a624 2003-01-08 alex if( Req->argc == 5 )
401 43d9a624 2003-01-08 alex {
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] ));
404 43d9a624 2003-01-08 alex }
405 43d9a624 2003-01-08 alex else
406 43d9a624 2003-01-08 alex {
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' );
410 43d9a624 2003-01-08 alex }
411 3c0c3c3c 2002-04-23 alex
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 )
415 43d9a624 2003-01-08 alex {
416 43d9a624 2003-01-08 alex if( *ptr == 'l' )
417 43d9a624 2003-01-08 alex {
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 ));
420 43d9a624 2003-01-08 alex }
421 43d9a624 2003-01-08 alex if( *ptr == 'k' )
422 43d9a624 2003-01-08 alex {
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 ));
425 43d9a624 2003-01-08 alex }
426 43d9a624 2003-01-08 alex ptr++;
427 43d9a624 2003-01-08 alex }
428 43d9a624 2003-01-08 alex
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 );
431 43d9a624 2003-01-08 alex }
432 43d9a624 2003-01-08 alex }
433 43d9a624 2003-01-08 alex else Log( LOG_WARNING, "CHANINFO: invalid MODE format ignored!" );
434 43d9a624 2003-01-08 alex
435 43d9a624 2003-01-08 alex if( arg_topic > 0 )
436 43d9a624 2003-01-08 alex {
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] ))
440 1f9ba7b3 2002-09-03 alex {
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 ));
444 1f9ba7b3 2002-09-03 alex }
445 1f9ba7b3 2002-09-03 alex }
446 3c0c3c3c 2002-04-23 alex
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] );
451 43d9a624 2003-01-08 alex
452 1f9ba7b3 2002-09-03 alex return CONNECTED;
453 1f9ba7b3 2002-09-03 alex } /* IRC_CHANINFO */
454 1f9ba7b3 2002-09-03 alex
455 1f9ba7b3 2002-09-03 alex
456 2ee05c9a 2002-03-03 alex /* -eof- */