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