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 commands for server links
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 fa80012e 2003-01-08 alex static char UNUSED id[] = "$Id: irc-server.c,v 1.31 2003/01/08 22:04:43 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 2ee05c9a 2002-03-03 alex #include <stdio.h>
22 2ee05c9a 2002-03-03 alex #include <stdlib.h>
23 2ee05c9a 2002-03-03 alex #include <string.h>
24 2ee05c9a 2002-03-03 alex
25 c2f60abe 2002-05-27 alex #include "resolve.h"
26 c2f60abe 2002-05-27 alex #include "conn.h"
27 437f2c33 2002-12-30 alex #include "conn-zip.h"
28 a2544e49 2002-12-30 alex #include "conf.h"
29 c2f60abe 2002-05-27 alex #include "client.h"
30 c2f60abe 2002-05-27 alex #include "channel.h"
31 2ee05c9a 2002-03-03 alex #include "irc-write.h"
32 2ee05c9a 2002-03-03 alex #include "log.h"
33 2ee05c9a 2002-03-03 alex #include "messages.h"
34 c2f60abe 2002-05-27 alex #include "parse.h"
35 d58431a0 2002-09-02 alex #include "ngircd.h"
36 2ee05c9a 2002-03-03 alex
37 ca33cbda 2002-03-12 alex #include "exp.h"
38 2ee05c9a 2002-03-03 alex #include "irc-server.h"
39 2ee05c9a 2002-03-03 alex
40 2ee05c9a 2002-03-03 alex
41 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
42 c2f60abe 2002-05-27 alex IRC_SERVER( CLIENT *Client, REQUEST *Req )
43 2ee05c9a 2002-03-03 alex {
44 fa80012e 2003-01-08 alex CHAR str[LINE_LEN], *ptr, *modes, *topic;
45 2ee05c9a 2002-03-03 alex CLIENT *from, *c, *cl;
46 2ee05c9a 2002-03-03 alex CL2CHAN *cl2chan;
47 2ee05c9a 2002-03-03 alex INT max_hops, i;
48 2ee05c9a 2002-03-03 alex CHANNEL *chan;
49 2ee05c9a 2002-03-03 alex BOOLEAN ok;
50 65f3adca 2002-11-26 alex CONN_ID con;
51 2ee05c9a 2002-03-03 alex
52 2ee05c9a 2002-03-03 alex assert( Client != NULL );
53 2ee05c9a 2002-03-03 alex assert( Req != NULL );
54 2ee05c9a 2002-03-03 alex
55 2ee05c9a 2002-03-03 alex /* Fehler liefern, wenn kein lokaler Client */
56 2ee05c9a 2002-03-03 alex if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
57 2ee05c9a 2002-03-03 alex
58 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) == CLIENT_GOTPASSSERVER )
59 2ee05c9a 2002-03-03 alex {
60 2ee05c9a 2002-03-03 alex /* Verbindung soll als Server-Server-Verbindung registriert werden */
61 2ee05c9a 2002-03-03 alex Log( LOG_DEBUG, "Connection %d: got SERVER command (new server link) ...", Client_Conn( Client ));
62 2ee05c9a 2002-03-03 alex
63 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
64 2ee05c9a 2002-03-03 alex if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
65 2ee05c9a 2002-03-03 alex
66 2ee05c9a 2002-03-03 alex /* Ist dieser Server bei uns konfiguriert? */
67 a2544e49 2002-12-30 alex for( i = 0; i < MAX_SERVERS; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
68 a2544e49 2002-12-30 alex if( i >= MAX_SERVERS )
69 2ee05c9a 2002-03-03 alex {
70 2ee05c9a 2002-03-03 alex /* Server ist nicht konfiguriert! */
71 2ee05c9a 2002-03-03 alex Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] );
72 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", TRUE );
73 2ee05c9a 2002-03-03 alex return DISCONNECTED;
74 2ee05c9a 2002-03-03 alex }
75 b2615bcc 2002-11-19 alex if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 )
76 2ee05c9a 2002-03-03 alex {
77 2ee05c9a 2002-03-03 alex /* Falsches Passwort */
78 b2615bcc 2002-11-19 alex Log( LOG_ERR, "Connection %d: Got bad password from server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
79 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
80 2ee05c9a 2002-03-03 alex return DISCONNECTED;
81 2ee05c9a 2002-03-03 alex }
82 2ee05c9a 2002-03-03 alex
83 2ee05c9a 2002-03-03 alex /* Ist ein Server mit dieser ID bereits registriert? */
84 2ee05c9a 2002-03-03 alex if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
85 2ee05c9a 2002-03-03 alex
86 2ee05c9a 2002-03-03 alex /* Server-Strukturen fuellen ;-) */
87 2ee05c9a 2002-03-03 alex Client_SetID( Client, Req->argv[0] );
88 2ee05c9a 2002-03-03 alex Client_SetHops( Client, 1 );
89 2ee05c9a 2002-03-03 alex Client_SetInfo( Client, Req->argv[Req->argc - 1] );
90 65f3adca 2002-11-26 alex
91 2310ac2c 2002-04-08 alex /* Meldet sich der Server bei uns an (d.h., bauen nicht wir
92 2310ac2c 2002-04-08 alex * selber die Verbindung zu einem anderen Server auf)? */
93 65f3adca 2002-11-26 alex con = Client_Conn( Client );
94 2310ac2c 2002-04-08 alex if( Client_Token( Client ) != TOKEN_OUTBOUND )
95 2ee05c9a 2002-03-03 alex {
96 2310ac2c 2002-04-08 alex /* Eingehende Verbindung: Unseren SERVER- und PASS-Befehl senden */
97 2ee05c9a 2002-03-03 alex ok = TRUE;
98 b2615bcc 2002-11-19 alex if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd_out, NGIRCd_ProtoID )) ok = FALSE;
99 2ee05c9a 2002-03-03 alex else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
100 2ee05c9a 2002-03-03 alex if( ! ok )
101 2ee05c9a 2002-03-03 alex {
102 65f3adca 2002-11-26 alex Conn_Close( con, "Unexpected server behavior!", NULL, FALSE );
103 2ee05c9a 2002-03-03 alex return DISCONNECTED;
104 2ee05c9a 2002-03-03 alex }
105 2ee05c9a 2002-03-03 alex Client_SetIntroducer( Client, Client );
106 2ee05c9a 2002-03-03 alex Client_SetToken( Client, 1 );
107 2ee05c9a 2002-03-03 alex }
108 2310ac2c 2002-04-08 alex else
109 2310ac2c 2002-04-08 alex {
110 2310ac2c 2002-04-08 alex /* Ausgehende verbindung, SERVER und PASS wurden von uns bereits
111 2310ac2c 2002-04-08 alex * an die Gegenseite uerbermittelt */
112 2310ac2c 2002-04-08 alex Client_SetToken( Client, atoi( Req->argv[1] ));
113 2310ac2c 2002-04-08 alex }
114 2ee05c9a 2002-03-03 alex
115 65f3adca 2002-11-26 alex Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), con );
116 2ee05c9a 2002-03-03 alex
117 2ee05c9a 2002-03-03 alex Client_SetType( Client, CLIENT_SERVER );
118 a2544e49 2002-12-30 alex Conf_SetServer( i, con );
119 2ee05c9a 2002-03-03 alex
120 65f3adca 2002-11-26 alex #ifdef USE_ZLIB
121 65f3adca 2002-11-26 alex /* Kompression initialisieren, wenn erforderlich */
122 65f3adca 2002-11-26 alex if( strchr( Client_Flags( Client ), 'Z' ))
123 65f3adca 2002-11-26 alex {
124 437f2c33 2002-12-30 alex if( ! Zip_InitConn( con ))
125 65f3adca 2002-11-26 alex {
126 65f3adca 2002-11-26 alex /* Fehler! */
127 65f3adca 2002-11-26 alex Conn_Close( con, "Can't inizialize compression (zlib)!", NULL, FALSE );
128 65f3adca 2002-11-26 alex return DISCONNECTED;
129 65f3adca 2002-11-26 alex }
130 65f3adca 2002-11-26 alex }
131 65f3adca 2002-11-26 alex #endif
132 65f3adca 2002-11-26 alex
133 2ee05c9a 2002-03-03 alex /* maximalen Hop Count ermitteln */
134 2ee05c9a 2002-03-03 alex max_hops = 0;
135 2ee05c9a 2002-03-03 alex c = Client_First( );
136 2ee05c9a 2002-03-03 alex while( c )
137 2ee05c9a 2002-03-03 alex {
138 2ee05c9a 2002-03-03 alex if( Client_Hops( c ) > max_hops ) max_hops = Client_Hops( c );
139 2ee05c9a 2002-03-03 alex c = Client_Next( c );
140 2ee05c9a 2002-03-03 alex }
141 2ee05c9a 2002-03-03 alex
142 2ee05c9a 2002-03-03 alex /* Alle bisherigen Server dem neuen Server bekannt machen,
143 2ee05c9a 2002-03-03 alex * die bisherigen Server ueber den neuen informierenn */
144 2ee05c9a 2002-03-03 alex for( i = 0; i < ( max_hops + 1 ); i++ )
145 2ee05c9a 2002-03-03 alex {
146 2ee05c9a 2002-03-03 alex c = Client_First( );
147 2ee05c9a 2002-03-03 alex while( c )
148 2ee05c9a 2002-03-03 alex {
149 2ee05c9a 2002-03-03 alex if(( Client_Type( c ) == CLIENT_SERVER ) && ( c != Client ) && ( c != Client_ThisServer( )) && ( Client_Hops( c ) == i ))
150 2ee05c9a 2002-03-03 alex {
151 2ee05c9a 2002-03-03 alex if( Client_Conn( c ) > NONE )
152 2ee05c9a 2002-03-03 alex {
153 2ee05c9a 2002-03-03 alex /* Dem gefundenen Server gleich den neuen
154 2ee05c9a 2002-03-03 alex * Server bekannt machen */
155 2ee05c9a 2002-03-03 alex if( ! IRC_WriteStrClient( c, "SERVER %s %d %d :%s", Client_ID( Client ), Client_Hops( Client ) + 1, Client_MyToken( Client ), Client_Info( Client ))) return DISCONNECTED;
156 2ee05c9a 2002-03-03 alex }
157 2ee05c9a 2002-03-03 alex
158 2ee05c9a 2002-03-03 alex /* Den neuen Server ueber den alten informieren */
159 2ee05c9a 2002-03-03 alex if( ! IRC_WriteStrClientPrefix( Client, Client_Hops( c ) == 1 ? Client_ThisServer( ) : Client_Introducer( c ), "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c ))) return DISCONNECTED;
160 2ee05c9a 2002-03-03 alex }
161 2ee05c9a 2002-03-03 alex c = Client_Next( c );
162 2ee05c9a 2002-03-03 alex }
163 2ee05c9a 2002-03-03 alex }
164 2ee05c9a 2002-03-03 alex
165 2ee05c9a 2002-03-03 alex /* alle User dem neuen Server bekannt machen */
166 2ee05c9a 2002-03-03 alex c = Client_First( );
167 2ee05c9a 2002-03-03 alex while( c )
168 2ee05c9a 2002-03-03 alex {
169 2ee05c9a 2002-03-03 alex if( Client_Type( c ) == CLIENT_USER )
170 2ee05c9a 2002-03-03 alex {
171 2ee05c9a 2002-03-03 alex /* User an neuen Server melden */
172 2ee05c9a 2002-03-03 alex if( ! IRC_WriteStrClient( Client, "NICK %s %d %s %s %d +%s :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_User( c ), Client_Hostname( c ), Client_MyToken( Client_Introducer( c )), Client_Modes( c ), Client_Info( c ))) return DISCONNECTED;
173 2ee05c9a 2002-03-03 alex }
174 2ee05c9a 2002-03-03 alex c = Client_Next( c );
175 2ee05c9a 2002-03-03 alex }
176 2ee05c9a 2002-03-03 alex
177 2ee05c9a 2002-03-03 alex /* Channels dem neuen Server bekannt machen */
178 2ee05c9a 2002-03-03 alex chan = Channel_First( );
179 2ee05c9a 2002-03-03 alex while( chan )
180 2ee05c9a 2002-03-03 alex {
181 3dc16212 2002-09-07 alex #ifdef IRCPLUS
182 fa80012e 2003-01-08 alex /* Send CHANINFO if the peer supports it */
183 938abb02 2002-09-03 alex if( strchr( Client_Flags( Client ), 'C' ))
184 938abb02 2002-09-03 alex {
185 fa80012e 2003-01-08 alex modes = Channel_Modes( chan );
186 fa80012e 2003-01-08 alex topic = Channel_Topic( chan );
187 fa80012e 2003-01-08 alex
188 fa80012e 2003-01-08 alex if( *modes || *topic )
189 fa80012e 2003-01-08 alex {
190 fa80012e 2003-01-08 alex /* send CHANINFO */
191 fa80012e 2003-01-08 alex if(( ! strchr( Channel_Modes( chan ), 'k' )) && ( ! strchr( Channel_Modes( chan ), 'l' )) && ( ! *topic ))
192 fa80012e 2003-01-08 alex {
193 fa80012e 2003-01-08 alex /* "CHANINFO <chan> +<modes>" */
194 fa80012e 2003-01-08 alex if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s", Channel_Name( chan ), modes )) return DISCONNECTED;
195 fa80012e 2003-01-08 alex }
196 fa80012e 2003-01-08 alex else if(( ! strchr( Channel_Modes( chan ), 'k' )) && ( ! strchr( Channel_Modes( chan ), 'l' )))
197 fa80012e 2003-01-08 alex {
198 fa80012e 2003-01-08 alex /* "CHANINFO <chan> +<modes> :<topic>" */
199 fa80012e 2003-01-08 alex if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s :%s", Channel_Name( chan ), modes, topic )) return DISCONNECTED;
200 fa80012e 2003-01-08 alex }
201 fa80012e 2003-01-08 alex else
202 fa80012e 2003-01-08 alex {
203 fa80012e 2003-01-08 alex /* "CHANINFO <chan> +<modes> <key> <limit> :<topic>" */
204 fa80012e 2003-01-08 alex if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s %s %ld :%s", Channel_Name( chan ), modes, strchr( Channel_Modes( chan ), 'k' ) ? Channel_Key( chan ) : "*", strchr( Channel_Modes( chan ), 'l' ) ? Channel_MaxUsers( chan ) : 0L, topic )) return DISCONNECTED;
205 fa80012e 2003-01-08 alex }
206 fa80012e 2003-01-08 alex }
207 938abb02 2002-09-03 alex }
208 3dc16212 2002-09-07 alex #endif
209 3dc16212 2002-09-07 alex
210 2ee05c9a 2002-03-03 alex /* alle Member suchen */
211 2ee05c9a 2002-03-03 alex cl2chan = Channel_FirstMember( chan );
212 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), "NJOIN %s :", Channel_Name( chan ));
213 2ee05c9a 2002-03-03 alex while( cl2chan )
214 2ee05c9a 2002-03-03 alex {
215 2ee05c9a 2002-03-03 alex cl = Channel_GetClient( cl2chan );
216 2ee05c9a 2002-03-03 alex assert( cl != NULL );
217 2ee05c9a 2002-03-03 alex
218 2ee05c9a 2002-03-03 alex /* Nick, ggf. mit Modes, anhaengen */
219 6626395c 2002-12-26 alex if( str[strlen( str ) - 1] != ':' ) strlcat( str, ",", sizeof( str ));
220 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( chan, cl ), 'v' )) strlcat( str, "+", sizeof( str ));
221 6626395c 2002-12-26 alex if( strchr( Channel_UserModes( chan, cl ), 'o' )) strlcat( str, "@", sizeof( str ));
222 6626395c 2002-12-26 alex strlcat( str, Client_ID( cl ), sizeof( str ));
223 2ee05c9a 2002-03-03 alex
224 0e092b3f 2002-03-06 alex if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 8 ))
225 2ee05c9a 2002-03-03 alex {
226 2ee05c9a 2002-03-03 alex /* Zeile senden */
227 ec474a4b 2002-10-04 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
228 b316c380 2002-12-26 alex snprintf( str, sizeof( str ), "NJOIN %s :", Channel_Name( chan ));
229 2ee05c9a 2002-03-03 alex }
230 2ee05c9a 2002-03-03 alex
231 2ee05c9a 2002-03-03 alex cl2chan = Channel_NextMember( chan, cl2chan );
232 2ee05c9a 2002-03-03 alex }
233 2ee05c9a 2002-03-03 alex
234 2ee05c9a 2002-03-03 alex /* noch Daten da? */
235 2ee05c9a 2002-03-03 alex if( str[strlen( str ) - 1] != ':')
236 2ee05c9a 2002-03-03 alex {
237 2ee05c9a 2002-03-03 alex /* Ja; Also senden ... */
238 ec474a4b 2002-10-04 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
239 2ee05c9a 2002-03-03 alex }
240 2ee05c9a 2002-03-03 alex
241 2ee05c9a 2002-03-03 alex /* naechsten Channel suchen */
242 2ee05c9a 2002-03-03 alex chan = Channel_Next( chan );
243 2ee05c9a 2002-03-03 alex }
244 2ee05c9a 2002-03-03 alex
245 2ee05c9a 2002-03-03 alex return CONNECTED;
246 2ee05c9a 2002-03-03 alex }
247 2ee05c9a 2002-03-03 alex else if( Client_Type( Client ) == CLIENT_SERVER )
248 2ee05c9a 2002-03-03 alex {
249 2ee05c9a 2002-03-03 alex /* Neuer Server wird im Netz angekuendigt */
250 2ee05c9a 2002-03-03 alex
251 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
252 2ee05c9a 2002-03-03 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
253 2ee05c9a 2002-03-03 alex
254 2ee05c9a 2002-03-03 alex /* Ist ein Server mit dieser ID bereits registriert? */
255 2ee05c9a 2002-03-03 alex if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
256 2ee05c9a 2002-03-03 alex
257 2ee05c9a 2002-03-03 alex /* Ueberfluessige Hostnamen aus Info-Text entfernen */
258 2ee05c9a 2002-03-03 alex ptr = strchr( Req->argv[3] + 2, '[' );
259 2ee05c9a 2002-03-03 alex if( ! ptr ) ptr = Req->argv[3];
260 2ee05c9a 2002-03-03 alex
261 bc4ed226 2002-03-25 alex from = Client_Search( Req->prefix );
262 2ee05c9a 2002-03-03 alex if( ! from )
263 2ee05c9a 2002-03-03 alex {
264 2ee05c9a 2002-03-03 alex /* Hm, Server, der diesen einfuehrt, ist nicht bekannt!? */
265 2ee05c9a 2002-03-03 alex Log( LOG_ALERT, "Unknown ID in prefix of SERVER: \"%s\"! (on connection %d)", Req->prefix, Client_Conn( Client ));
266 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Unknown ID in prefix of SERVER", TRUE );
267 2ee05c9a 2002-03-03 alex return DISCONNECTED;
268 2ee05c9a 2002-03-03 alex }
269 2ee05c9a 2002-03-03 alex
270 2ee05c9a 2002-03-03 alex /* Neue Client-Struktur anlegen */
271 2ee05c9a 2002-03-03 alex c = Client_NewRemoteServer( Client, Req->argv[0], from, atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, TRUE );
272 2ee05c9a 2002-03-03 alex if( ! c )
273 2ee05c9a 2002-03-03 alex {
274 2ee05c9a 2002-03-03 alex /* Neue Client-Struktur konnte nicht angelegt werden */
275 2ee05c9a 2002-03-03 alex Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client ));
276 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", TRUE );
277 2ee05c9a 2002-03-03 alex return DISCONNECTED;
278 2ee05c9a 2002-03-03 alex }
279 2ee05c9a 2002-03-03 alex
280 2ee05c9a 2002-03-03 alex /* Log-Meldung zusammenbauen und ausgeben */
281 b316c380 2002-12-26 alex if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) snprintf( str, sizeof( str ), "connected to %s, ", Client_ID( from ));
282 2ee05c9a 2002-03-03 alex else strcpy( str, "" );
283 6b58ab84 2002-03-27 alex Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (via %s, %s%d hop%s).", Client_ID( c ), Client_ID( Client ), str, Client_Hops( c ), Client_Hops( c ) > 1 ? "s": "" );
284 2ee05c9a 2002-03-03 alex
285 2ee05c9a 2002-03-03 alex /* Andere Server informieren */
286 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, from, "SERVER %s %d %d :%s", Client_ID( c ), Client_Hops( c ) + 1, Client_MyToken( c ), Client_Info( c ));
287 2ee05c9a 2002-03-03 alex
288 2ee05c9a 2002-03-03 alex return CONNECTED;
289 2ee05c9a 2002-03-03 alex }
290 2ee05c9a 2002-03-03 alex else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
291 2ee05c9a 2002-03-03 alex } /* IRC_SERVER */
292 2ee05c9a 2002-03-03 alex
293 2ee05c9a 2002-03-03 alex
294 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
295 c2f60abe 2002-05-27 alex IRC_NJOIN( CLIENT *Client, REQUEST *Req )
296 2ee05c9a 2002-03-03 alex {
297 e07fab17 2002-07-25 alex CHAR str[COMMAND_LEN], *channame, *ptr, modes[8];
298 2ee05c9a 2002-03-03 alex BOOLEAN is_op, is_voiced;
299 2ee05c9a 2002-03-03 alex CHANNEL *chan;
300 2ee05c9a 2002-03-03 alex CLIENT *c;
301 2ee05c9a 2002-03-03 alex
302 2ee05c9a 2002-03-03 alex assert( Client != NULL );
303 2ee05c9a 2002-03-03 alex assert( Req != NULL );
304 2ee05c9a 2002-03-03 alex
305 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
306 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
307 2ee05c9a 2002-03-03 alex
308 0ced4181 2002-12-26 alex strlcpy( str, Req->argv[1], sizeof( str ));
309 e07fab17 2002-07-25 alex
310 2ee05c9a 2002-03-03 alex channame = Req->argv[0];
311 e07fab17 2002-07-25 alex ptr = strtok( str, "," );
312 2ee05c9a 2002-03-03 alex while( ptr )
313 2ee05c9a 2002-03-03 alex {
314 2ee05c9a 2002-03-03 alex is_op = is_voiced = FALSE;
315 2ee05c9a 2002-03-03 alex
316 2ee05c9a 2002-03-03 alex /* Prefixe abschneiden */
317 2ee05c9a 2002-03-03 alex while(( *ptr == '@' ) || ( *ptr == '+' ))
318 2ee05c9a 2002-03-03 alex {
319 2ee05c9a 2002-03-03 alex if( *ptr == '@' ) is_op = TRUE;
320 2ee05c9a 2002-03-03 alex if( *ptr == '+' ) is_voiced = TRUE;
321 2ee05c9a 2002-03-03 alex ptr++;
322 2ee05c9a 2002-03-03 alex }
323 2ee05c9a 2002-03-03 alex
324 bc4ed226 2002-03-25 alex c = Client_Search( ptr );
325 2ee05c9a 2002-03-03 alex if( c )
326 2ee05c9a 2002-03-03 alex {
327 2ee05c9a 2002-03-03 alex Channel_Join( c, channame );
328 2ee05c9a 2002-03-03 alex chan = Channel_Search( channame );
329 2ee05c9a 2002-03-03 alex assert( chan != NULL );
330 2ee05c9a 2002-03-03 alex
331 2ee05c9a 2002-03-03 alex if( is_op ) Channel_UserModeAdd( chan, c, 'o' );
332 2ee05c9a 2002-03-03 alex if( is_voiced ) Channel_UserModeAdd( chan, c, 'v' );
333 2ee05c9a 2002-03-03 alex
334 2ee05c9a 2002-03-03 alex /* im Channel bekannt machen */
335 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, c, FALSE, "JOIN :%s", channame );
336 2ee05c9a 2002-03-03 alex
337 2ee05c9a 2002-03-03 alex /* Channel-User-Modes setzen */
338 695631b2 2002-12-26 alex strlcpy( modes, Channel_UserModes( chan, c ), sizeof( modes ));
339 2ee05c9a 2002-03-03 alex if( modes[0] )
340 2ee05c9a 2002-03-03 alex {
341 2ee05c9a 2002-03-03 alex /* Modes im Channel bekannt machen */
342 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, Client, FALSE, "MODE %s +%s %s", channame, modes, Client_ID( c ));
343 2ee05c9a 2002-03-03 alex }
344 2ee05c9a 2002-03-03 alex }
345 7d30c8ce 2002-08-26 alex else Log( LOG_ERR, "Got NJOIN for unknown nick \"%s\" for channel \"%s\"!", ptr, channame );
346 2ee05c9a 2002-03-03 alex
347 2ee05c9a 2002-03-03 alex /* naechsten Nick suchen */
348 2ee05c9a 2002-03-03 alex ptr = strtok( NULL, "," );
349 2ee05c9a 2002-03-03 alex }
350 2ee05c9a 2002-03-03 alex
351 2ee05c9a 2002-03-03 alex /* an andere Server weiterleiten */
352 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], Req->argv[1] );
353 2ee05c9a 2002-03-03 alex
354 2ee05c9a 2002-03-03 alex return CONNECTED;
355 2ee05c9a 2002-03-03 alex } /* IRC_NJOIN */
356 2ee05c9a 2002-03-03 alex
357 2ee05c9a 2002-03-03 alex
358 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
359 c2f60abe 2002-05-27 alex IRC_SQUIT( CLIENT *Client, REQUEST *Req )
360 2ee05c9a 2002-03-03 alex {
361 2ee05c9a 2002-03-03 alex CLIENT *target;
362 2ee05c9a 2002-03-03 alex CHAR msg[LINE_LEN + 64];
363 2ee05c9a 2002-03-03 alex
364 2ee05c9a 2002-03-03 alex assert( Client != NULL );
365 2ee05c9a 2002-03-03 alex assert( Req != NULL );
366 2ee05c9a 2002-03-03 alex
367 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
368 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
369 2ee05c9a 2002-03-03 alex
370 2ee05c9a 2002-03-03 alex Log( LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...", Client_ID( Client ), Req->argv[0], Req->argv[1] );
371 2ee05c9a 2002-03-03 alex
372 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[0] );
373 2ee05c9a 2002-03-03 alex if( ! target )
374 2ee05c9a 2002-03-03 alex {
375 9fc7e66f 2002-03-11 alex /* Den Server kennen wir nicht (mehr), also nichts zu tun. */
376 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] );
377 2ee05c9a 2002-03-03 alex return CONNECTED;
378 2ee05c9a 2002-03-03 alex }
379 2ee05c9a 2002-03-03 alex
380 2ee05c9a 2002-03-03 alex if( Req->argv[1][0] )
381 2ee05c9a 2002-03-03 alex {
382 2ee05c9a 2002-03-03 alex if( strlen( Req->argv[1] ) > LINE_LEN ) Req->argv[1][LINE_LEN] = '\0';
383 b316c380 2002-12-26 alex snprintf( msg, sizeof( msg ), "%s (SQUIT from %s).", Req->argv[1], Client_ID( Client ));
384 2ee05c9a 2002-03-03 alex }
385 b316c380 2002-12-26 alex else snprintf( msg, sizeof( msg ), "Got SQUIT from %s.", Client_ID( Client ));
386 2ee05c9a 2002-03-03 alex
387 2ee05c9a 2002-03-03 alex if( Client_Conn( target ) > NONE )
388 2ee05c9a 2002-03-03 alex {
389 2ee05c9a 2002-03-03 alex /* dieser Server hat die Connection */
390 2ee05c9a 2002-03-03 alex if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], TRUE );
391 2ee05c9a 2002-03-03 alex else Conn_Close( Client_Conn( target ), msg, NULL, TRUE );
392 2ee05c9a 2002-03-03 alex return DISCONNECTED;
393 2ee05c9a 2002-03-03 alex }
394 2ee05c9a 2002-03-03 alex else
395 2ee05c9a 2002-03-03 alex {
396 2ee05c9a 2002-03-03 alex /* Verbindung hielt anderer Server */
397 50ec7a56 2002-03-11 alex Client_Destroy( target, msg, Req->argv[1], FALSE );
398 2ee05c9a 2002-03-03 alex return CONNECTED;
399 2ee05c9a 2002-03-03 alex }
400 2ee05c9a 2002-03-03 alex } /* IRC_SQUIT */
401 2ee05c9a 2002-03-03 alex
402 2ee05c9a 2002-03-03 alex
403 2ee05c9a 2002-03-03 alex /* -eof- */