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 2ee05c9a 2002-03-03 alex * Dieses Programm ist freie Software. Sie koennen es unter den Bedingungen
6 2ee05c9a 2002-03-03 alex * der GNU General Public License (GPL), wie von der Free Software Foundation
7 2ee05c9a 2002-03-03 alex * herausgegeben, weitergeben und/oder modifizieren, entweder unter Version 2
8 2ee05c9a 2002-03-03 alex * der Lizenz oder (wenn Sie es wuenschen) jeder spaeteren Version.
9 2ee05c9a 2002-03-03 alex * Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
10 2ee05c9a 2002-03-03 alex * der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
11 2ee05c9a 2002-03-03 alex *
12 b2615bcc 2002-11-19 alex * $Id: irc-server.c,v 1.20 2002/11/19 12:50:20 alex Exp $
13 2ee05c9a 2002-03-03 alex *
14 2ee05c9a 2002-03-03 alex * irc-server.c: IRC-Befehle fuer Server-Links
15 2ee05c9a 2002-03-03 alex */
16 2ee05c9a 2002-03-03 alex
17 2ee05c9a 2002-03-03 alex
18 ca33cbda 2002-03-12 alex #include "portab.h"
19 2ee05c9a 2002-03-03 alex
20 ca33cbda 2002-03-12 alex #include "imp.h"
21 2ee05c9a 2002-03-03 alex #include <assert.h>
22 2ee05c9a 2002-03-03 alex #include <stdio.h>
23 2ee05c9a 2002-03-03 alex #include <stdlib.h>
24 2ee05c9a 2002-03-03 alex #include <string.h>
25 2ee05c9a 2002-03-03 alex
26 c2f60abe 2002-05-27 alex #include "resolve.h"
27 2ee05c9a 2002-03-03 alex #include "conf.h"
28 c2f60abe 2002-05-27 alex #include "conn.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 2ee05c9a 2002-03-03 alex CHAR str[LINE_LEN], *ptr;
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 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 2ee05c9a 2002-03-03 alex /* Fehler liefern, wenn kein lokaler Client */
55 2ee05c9a 2002-03-03 alex if( Client_Conn( Client ) <= NONE ) return IRC_WriteStrClient( Client, ERR_UNKNOWNCOMMAND_MSG, Client_ID( Client ), Req->command );
56 2ee05c9a 2002-03-03 alex
57 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) == CLIENT_GOTPASSSERVER )
58 2ee05c9a 2002-03-03 alex {
59 2ee05c9a 2002-03-03 alex /* Verbindung soll als Server-Server-Verbindung registriert werden */
60 2ee05c9a 2002-03-03 alex Log( LOG_DEBUG, "Connection %d: got SERVER command (new server link) ...", Client_Conn( Client ));
61 2ee05c9a 2002-03-03 alex
62 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
63 2ee05c9a 2002-03-03 alex if(( Req->argc != 2 ) && ( Req->argc != 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
64 2ee05c9a 2002-03-03 alex
65 2ee05c9a 2002-03-03 alex /* Ist dieser Server bei uns konfiguriert? */
66 2ee05c9a 2002-03-03 alex for( i = 0; i < Conf_Server_Count; i++ ) if( strcasecmp( Req->argv[0], Conf_Server[i].name ) == 0 ) break;
67 2ee05c9a 2002-03-03 alex if( i >= Conf_Server_Count )
68 2ee05c9a 2002-03-03 alex {
69 2ee05c9a 2002-03-03 alex /* Server ist nicht konfiguriert! */
70 2ee05c9a 2002-03-03 alex Log( LOG_ERR, "Connection %d: Server \"%s\" not configured here!", Client_Conn( Client ), Req->argv[0] );
71 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Server not configured here", TRUE );
72 2ee05c9a 2002-03-03 alex return DISCONNECTED;
73 2ee05c9a 2002-03-03 alex }
74 b2615bcc 2002-11-19 alex if( strcmp( Client_Password( Client ), Conf_Server[i].pwd_in ) != 0 )
75 2ee05c9a 2002-03-03 alex {
76 2ee05c9a 2002-03-03 alex /* Falsches Passwort */
77 b2615bcc 2002-11-19 alex Log( LOG_ERR, "Connection %d: Got bad password from server \"%s\"!", Client_Conn( Client ), Req->argv[0] );
78 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
79 2ee05c9a 2002-03-03 alex return DISCONNECTED;
80 2ee05c9a 2002-03-03 alex }
81 2ee05c9a 2002-03-03 alex
82 2ee05c9a 2002-03-03 alex /* Ist ein Server mit dieser ID bereits registriert? */
83 2ee05c9a 2002-03-03 alex if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
84 2ee05c9a 2002-03-03 alex
85 2ee05c9a 2002-03-03 alex /* Server-Strukturen fuellen ;-) */
86 2ee05c9a 2002-03-03 alex Client_SetID( Client, Req->argv[0] );
87 2ee05c9a 2002-03-03 alex Client_SetHops( Client, 1 );
88 2ee05c9a 2002-03-03 alex Client_SetInfo( Client, Req->argv[Req->argc - 1] );
89 2ee05c9a 2002-03-03 alex
90 2310ac2c 2002-04-08 alex /* Meldet sich der Server bei uns an (d.h., bauen nicht wir
91 2310ac2c 2002-04-08 alex * selber die Verbindung zu einem anderen Server auf)? */
92 2310ac2c 2002-04-08 alex if( Client_Token( Client ) != TOKEN_OUTBOUND )
93 2ee05c9a 2002-03-03 alex {
94 2310ac2c 2002-04-08 alex /* Eingehende Verbindung: Unseren SERVER- und PASS-Befehl senden */
95 2ee05c9a 2002-03-03 alex ok = TRUE;
96 b2615bcc 2002-11-19 alex if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd_out, NGIRCd_ProtoID )) ok = FALSE;
97 2ee05c9a 2002-03-03 alex else ok = IRC_WriteStrClient( Client, "SERVER %s 1 :%s", Conf_ServerName, Conf_ServerInfo );
98 2ee05c9a 2002-03-03 alex if( ! ok )
99 2ee05c9a 2002-03-03 alex {
100 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), "Unexpected server behavior!", NULL, FALSE );
101 2ee05c9a 2002-03-03 alex return DISCONNECTED;
102 2ee05c9a 2002-03-03 alex }
103 2ee05c9a 2002-03-03 alex Client_SetIntroducer( Client, Client );
104 2ee05c9a 2002-03-03 alex Client_SetToken( Client, 1 );
105 2ee05c9a 2002-03-03 alex }
106 2310ac2c 2002-04-08 alex else
107 2310ac2c 2002-04-08 alex {
108 2310ac2c 2002-04-08 alex /* Ausgehende verbindung, SERVER und PASS wurden von uns bereits
109 2310ac2c 2002-04-08 alex * an die Gegenseite uerbermittelt */
110 2310ac2c 2002-04-08 alex Client_SetToken( Client, atoi( Req->argv[1] ));
111 2310ac2c 2002-04-08 alex }
112 2ee05c9a 2002-03-03 alex
113 6b58ab84 2002-03-27 alex Log( LOG_NOTICE|LOG_snotice, "Server \"%s\" registered (connection %d, 1 hop - direct link).", Client_ID( Client ), Client_Conn( Client ));
114 2ee05c9a 2002-03-03 alex
115 2ee05c9a 2002-03-03 alex Client_SetType( Client, CLIENT_SERVER );
116 9523e281 2002-11-05 alex Conn_SetServer( Client_Conn( Client ), i );
117 2ee05c9a 2002-03-03 alex
118 2ee05c9a 2002-03-03 alex /* maximalen Hop Count ermitteln */
119 2ee05c9a 2002-03-03 alex max_hops = 0;
120 2ee05c9a 2002-03-03 alex c = Client_First( );
121 2ee05c9a 2002-03-03 alex while( c )
122 2ee05c9a 2002-03-03 alex {
123 2ee05c9a 2002-03-03 alex if( Client_Hops( c ) > max_hops ) max_hops = Client_Hops( c );
124 2ee05c9a 2002-03-03 alex c = Client_Next( c );
125 2ee05c9a 2002-03-03 alex }
126 2ee05c9a 2002-03-03 alex
127 2ee05c9a 2002-03-03 alex /* Alle bisherigen Server dem neuen Server bekannt machen,
128 2ee05c9a 2002-03-03 alex * die bisherigen Server ueber den neuen informierenn */
129 2ee05c9a 2002-03-03 alex for( i = 0; i < ( max_hops + 1 ); i++ )
130 2ee05c9a 2002-03-03 alex {
131 2ee05c9a 2002-03-03 alex c = Client_First( );
132 2ee05c9a 2002-03-03 alex while( c )
133 2ee05c9a 2002-03-03 alex {
134 2ee05c9a 2002-03-03 alex if(( Client_Type( c ) == CLIENT_SERVER ) && ( c != Client ) && ( c != Client_ThisServer( )) && ( Client_Hops( c ) == i ))
135 2ee05c9a 2002-03-03 alex {
136 2ee05c9a 2002-03-03 alex if( Client_Conn( c ) > NONE )
137 2ee05c9a 2002-03-03 alex {
138 2ee05c9a 2002-03-03 alex /* Dem gefundenen Server gleich den neuen
139 2ee05c9a 2002-03-03 alex * Server bekannt machen */
140 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;
141 2ee05c9a 2002-03-03 alex }
142 2ee05c9a 2002-03-03 alex
143 2ee05c9a 2002-03-03 alex /* Den neuen Server ueber den alten informieren */
144 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;
145 2ee05c9a 2002-03-03 alex }
146 2ee05c9a 2002-03-03 alex c = Client_Next( c );
147 2ee05c9a 2002-03-03 alex }
148 2ee05c9a 2002-03-03 alex }
149 2ee05c9a 2002-03-03 alex
150 2ee05c9a 2002-03-03 alex /* alle User dem neuen Server bekannt machen */
151 2ee05c9a 2002-03-03 alex c = Client_First( );
152 2ee05c9a 2002-03-03 alex while( c )
153 2ee05c9a 2002-03-03 alex {
154 2ee05c9a 2002-03-03 alex if( Client_Type( c ) == CLIENT_USER )
155 2ee05c9a 2002-03-03 alex {
156 2ee05c9a 2002-03-03 alex /* User an neuen Server melden */
157 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;
158 2ee05c9a 2002-03-03 alex }
159 2ee05c9a 2002-03-03 alex c = Client_Next( c );
160 2ee05c9a 2002-03-03 alex }
161 2ee05c9a 2002-03-03 alex
162 2ee05c9a 2002-03-03 alex /* Channels dem neuen Server bekannt machen */
163 2ee05c9a 2002-03-03 alex chan = Channel_First( );
164 2ee05c9a 2002-03-03 alex while( chan )
165 2ee05c9a 2002-03-03 alex {
166 3dc16212 2002-09-07 alex #ifdef IRCPLUS
167 938abb02 2002-09-03 alex /* Wenn unterstuetzt, CHANINFO senden */
168 938abb02 2002-09-03 alex if( strchr( Client_Flags( Client ), 'C' ))
169 938abb02 2002-09-03 alex {
170 938abb02 2002-09-03 alex /* CHANINFO senden */
171 938abb02 2002-09-03 alex if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s :%s", Channel_Name( chan ), Channel_Modes( chan ), Channel_Topic( chan ))) return DISCONNECTED;
172 938abb02 2002-09-03 alex }
173 3dc16212 2002-09-07 alex #endif
174 3dc16212 2002-09-07 alex
175 2ee05c9a 2002-03-03 alex /* alle Member suchen */
176 2ee05c9a 2002-03-03 alex cl2chan = Channel_FirstMember( chan );
177 0e092b3f 2002-03-06 alex sprintf( str, "NJOIN %s :", Channel_Name( chan ));
178 2ee05c9a 2002-03-03 alex while( cl2chan )
179 2ee05c9a 2002-03-03 alex {
180 2ee05c9a 2002-03-03 alex cl = Channel_GetClient( cl2chan );
181 2ee05c9a 2002-03-03 alex assert( cl != NULL );
182 2ee05c9a 2002-03-03 alex
183 2ee05c9a 2002-03-03 alex /* Nick, ggf. mit Modes, anhaengen */
184 2ee05c9a 2002-03-03 alex if( str[strlen( str ) - 1] != ':' ) strcat( str, "," );
185 2ee05c9a 2002-03-03 alex if( strchr( Channel_UserModes( chan, cl ), 'v' )) strcat( str, "+" );
186 2ee05c9a 2002-03-03 alex if( strchr( Channel_UserModes( chan, cl ), 'o' )) strcat( str, "@" );
187 2ee05c9a 2002-03-03 alex strcat( str, Client_ID( cl ));
188 2ee05c9a 2002-03-03 alex
189 0e092b3f 2002-03-06 alex if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 8 ))
190 2ee05c9a 2002-03-03 alex {
191 2ee05c9a 2002-03-03 alex /* Zeile senden */
192 ec474a4b 2002-10-04 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
193 2ee05c9a 2002-03-03 alex sprintf( str, "NJOIN %s :", Channel_Name( chan ));
194 2ee05c9a 2002-03-03 alex }
195 2ee05c9a 2002-03-03 alex
196 2ee05c9a 2002-03-03 alex cl2chan = Channel_NextMember( chan, cl2chan );
197 2ee05c9a 2002-03-03 alex }
198 2ee05c9a 2002-03-03 alex
199 2ee05c9a 2002-03-03 alex /* noch Daten da? */
200 2ee05c9a 2002-03-03 alex if( str[strlen( str ) - 1] != ':')
201 2ee05c9a 2002-03-03 alex {
202 2ee05c9a 2002-03-03 alex /* Ja; Also senden ... */
203 ec474a4b 2002-10-04 alex if( ! IRC_WriteStrClient( Client, "%s", str )) return DISCONNECTED;
204 2ee05c9a 2002-03-03 alex }
205 2ee05c9a 2002-03-03 alex
206 2ee05c9a 2002-03-03 alex /* naechsten Channel suchen */
207 2ee05c9a 2002-03-03 alex chan = Channel_Next( chan );
208 2ee05c9a 2002-03-03 alex }
209 2ee05c9a 2002-03-03 alex
210 2ee05c9a 2002-03-03 alex return CONNECTED;
211 2ee05c9a 2002-03-03 alex }
212 2ee05c9a 2002-03-03 alex else if( Client_Type( Client ) == CLIENT_SERVER )
213 2ee05c9a 2002-03-03 alex {
214 2ee05c9a 2002-03-03 alex /* Neuer Server wird im Netz angekuendigt */
215 2ee05c9a 2002-03-03 alex
216 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
217 2ee05c9a 2002-03-03 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
218 2ee05c9a 2002-03-03 alex
219 2ee05c9a 2002-03-03 alex /* Ist ein Server mit dieser ID bereits registriert? */
220 2ee05c9a 2002-03-03 alex if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
221 2ee05c9a 2002-03-03 alex
222 2ee05c9a 2002-03-03 alex /* Ueberfluessige Hostnamen aus Info-Text entfernen */
223 2ee05c9a 2002-03-03 alex ptr = strchr( Req->argv[3] + 2, '[' );
224 2ee05c9a 2002-03-03 alex if( ! ptr ) ptr = Req->argv[3];
225 2ee05c9a 2002-03-03 alex
226 bc4ed226 2002-03-25 alex from = Client_Search( Req->prefix );
227 2ee05c9a 2002-03-03 alex if( ! from )
228 2ee05c9a 2002-03-03 alex {
229 2ee05c9a 2002-03-03 alex /* Hm, Server, der diesen einfuehrt, ist nicht bekannt!? */
230 2ee05c9a 2002-03-03 alex Log( LOG_ALERT, "Unknown ID in prefix of SERVER: \"%s\"! (on connection %d)", Req->prefix, Client_Conn( Client ));
231 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Unknown ID in prefix of SERVER", TRUE );
232 2ee05c9a 2002-03-03 alex return DISCONNECTED;
233 2ee05c9a 2002-03-03 alex }
234 2ee05c9a 2002-03-03 alex
235 2ee05c9a 2002-03-03 alex /* Neue Client-Struktur anlegen */
236 2ee05c9a 2002-03-03 alex c = Client_NewRemoteServer( Client, Req->argv[0], from, atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, TRUE );
237 2ee05c9a 2002-03-03 alex if( ! c )
238 2ee05c9a 2002-03-03 alex {
239 2ee05c9a 2002-03-03 alex /* Neue Client-Struktur konnte nicht angelegt werden */
240 2ee05c9a 2002-03-03 alex Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client ));
241 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", TRUE );
242 2ee05c9a 2002-03-03 alex return DISCONNECTED;
243 2ee05c9a 2002-03-03 alex }
244 2ee05c9a 2002-03-03 alex
245 2ee05c9a 2002-03-03 alex /* Log-Meldung zusammenbauen und ausgeben */
246 2ee05c9a 2002-03-03 alex if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) sprintf( str, "connected to %s, ", Client_ID( from ));
247 2ee05c9a 2002-03-03 alex else strcpy( str, "" );
248 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": "" );
249 2ee05c9a 2002-03-03 alex
250 2ee05c9a 2002-03-03 alex /* Andere Server informieren */
251 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 ));
252 2ee05c9a 2002-03-03 alex
253 2ee05c9a 2002-03-03 alex return CONNECTED;
254 2ee05c9a 2002-03-03 alex }
255 2ee05c9a 2002-03-03 alex else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
256 2ee05c9a 2002-03-03 alex } /* IRC_SERVER */
257 2ee05c9a 2002-03-03 alex
258 2ee05c9a 2002-03-03 alex
259 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
260 c2f60abe 2002-05-27 alex IRC_NJOIN( CLIENT *Client, REQUEST *Req )
261 2ee05c9a 2002-03-03 alex {
262 e07fab17 2002-07-25 alex CHAR str[COMMAND_LEN], *channame, *ptr, modes[8];
263 2ee05c9a 2002-03-03 alex BOOLEAN is_op, is_voiced;
264 2ee05c9a 2002-03-03 alex CHANNEL *chan;
265 2ee05c9a 2002-03-03 alex CLIENT *c;
266 2ee05c9a 2002-03-03 alex
267 2ee05c9a 2002-03-03 alex assert( Client != NULL );
268 2ee05c9a 2002-03-03 alex assert( Req != NULL );
269 2ee05c9a 2002-03-03 alex
270 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTEREDSERVER_MSG, Client_ID( Client ));
271 2ee05c9a 2002-03-03 alex
272 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
273 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
274 2ee05c9a 2002-03-03 alex
275 e07fab17 2002-07-25 alex strncpy( str, Req->argv[1], COMMAND_LEN - 1 );
276 e07fab17 2002-07-25 alex str[COMMAND_LEN - 1] = '\0';
277 e07fab17 2002-07-25 alex
278 2ee05c9a 2002-03-03 alex channame = Req->argv[0];
279 e07fab17 2002-07-25 alex ptr = strtok( str, "," );
280 2ee05c9a 2002-03-03 alex while( ptr )
281 2ee05c9a 2002-03-03 alex {
282 2ee05c9a 2002-03-03 alex is_op = is_voiced = FALSE;
283 2ee05c9a 2002-03-03 alex
284 2ee05c9a 2002-03-03 alex /* Prefixe abschneiden */
285 2ee05c9a 2002-03-03 alex while(( *ptr == '@' ) || ( *ptr == '+' ))
286 2ee05c9a 2002-03-03 alex {
287 2ee05c9a 2002-03-03 alex if( *ptr == '@' ) is_op = TRUE;
288 2ee05c9a 2002-03-03 alex if( *ptr == '+' ) is_voiced = TRUE;
289 2ee05c9a 2002-03-03 alex ptr++;
290 2ee05c9a 2002-03-03 alex }
291 2ee05c9a 2002-03-03 alex
292 bc4ed226 2002-03-25 alex c = Client_Search( ptr );
293 2ee05c9a 2002-03-03 alex if( c )
294 2ee05c9a 2002-03-03 alex {
295 2ee05c9a 2002-03-03 alex Channel_Join( c, channame );
296 2ee05c9a 2002-03-03 alex chan = Channel_Search( channame );
297 2ee05c9a 2002-03-03 alex assert( chan != NULL );
298 2ee05c9a 2002-03-03 alex
299 2ee05c9a 2002-03-03 alex if( is_op ) Channel_UserModeAdd( chan, c, 'o' );
300 2ee05c9a 2002-03-03 alex if( is_voiced ) Channel_UserModeAdd( chan, c, 'v' );
301 2ee05c9a 2002-03-03 alex
302 2ee05c9a 2002-03-03 alex /* im Channel bekannt machen */
303 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, c, FALSE, "JOIN :%s", channame );
304 2ee05c9a 2002-03-03 alex
305 2ee05c9a 2002-03-03 alex /* Channel-User-Modes setzen */
306 2ee05c9a 2002-03-03 alex strcpy( modes, Channel_UserModes( chan, c ));
307 2ee05c9a 2002-03-03 alex if( modes[0] )
308 2ee05c9a 2002-03-03 alex {
309 2ee05c9a 2002-03-03 alex /* Modes im Channel bekannt machen */
310 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, Client, FALSE, "MODE %s +%s %s", channame, modes, Client_ID( c ));
311 2ee05c9a 2002-03-03 alex }
312 2ee05c9a 2002-03-03 alex }
313 7d30c8ce 2002-08-26 alex else Log( LOG_ERR, "Got NJOIN for unknown nick \"%s\" for channel \"%s\"!", ptr, channame );
314 2ee05c9a 2002-03-03 alex
315 2ee05c9a 2002-03-03 alex /* naechsten Nick suchen */
316 2ee05c9a 2002-03-03 alex ptr = strtok( NULL, "," );
317 2ee05c9a 2002-03-03 alex }
318 2ee05c9a 2002-03-03 alex
319 2ee05c9a 2002-03-03 alex /* an andere Server weiterleiten */
320 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], Req->argv[1] );
321 2ee05c9a 2002-03-03 alex
322 2ee05c9a 2002-03-03 alex return CONNECTED;
323 2ee05c9a 2002-03-03 alex } /* IRC_NJOIN */
324 2ee05c9a 2002-03-03 alex
325 2ee05c9a 2002-03-03 alex
326 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
327 c2f60abe 2002-05-27 alex IRC_SQUIT( CLIENT *Client, REQUEST *Req )
328 2ee05c9a 2002-03-03 alex {
329 2ee05c9a 2002-03-03 alex CLIENT *target;
330 2ee05c9a 2002-03-03 alex CHAR msg[LINE_LEN + 64];
331 2ee05c9a 2002-03-03 alex
332 2ee05c9a 2002-03-03 alex assert( Client != NULL );
333 2ee05c9a 2002-03-03 alex assert( Req != NULL );
334 2ee05c9a 2002-03-03 alex
335 2ee05c9a 2002-03-03 alex /* SQUIT ist nur fuer Server erlaubt */
336 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
337 2ee05c9a 2002-03-03 alex
338 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
339 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
340 2ee05c9a 2002-03-03 alex
341 2ee05c9a 2002-03-03 alex Log( LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...", Client_ID( Client ), Req->argv[0], Req->argv[1] );
342 2ee05c9a 2002-03-03 alex
343 2ee05c9a 2002-03-03 alex /* SQUIT an alle Server weiterleiten */
344 2ee05c9a 2002-03-03 alex IRC_WriteStrServers( Client, "SQUIT %s :%s", Req->argv[0], Req->argv[1] );
345 2ee05c9a 2002-03-03 alex
346 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[0] );
347 2ee05c9a 2002-03-03 alex if( ! target )
348 2ee05c9a 2002-03-03 alex {
349 9fc7e66f 2002-03-11 alex /* Den Server kennen wir nicht (mehr), also nichts zu tun. */
350 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] );
351 2ee05c9a 2002-03-03 alex return CONNECTED;
352 2ee05c9a 2002-03-03 alex }
353 2ee05c9a 2002-03-03 alex
354 2ee05c9a 2002-03-03 alex if( Req->argv[1][0] )
355 2ee05c9a 2002-03-03 alex {
356 2ee05c9a 2002-03-03 alex if( strlen( Req->argv[1] ) > LINE_LEN ) Req->argv[1][LINE_LEN] = '\0';
357 2ee05c9a 2002-03-03 alex sprintf( msg, "%s (SQUIT from %s).", Req->argv[1], Client_ID( Client ));
358 2ee05c9a 2002-03-03 alex }
359 2ee05c9a 2002-03-03 alex else sprintf( msg, "Got SQUIT from %s.", Client_ID( Client ));
360 2ee05c9a 2002-03-03 alex
361 2ee05c9a 2002-03-03 alex if( Client_Conn( target ) > NONE )
362 2ee05c9a 2002-03-03 alex {
363 2ee05c9a 2002-03-03 alex /* dieser Server hat die Connection */
364 2ee05c9a 2002-03-03 alex if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], TRUE );
365 2ee05c9a 2002-03-03 alex else Conn_Close( Client_Conn( target ), msg, NULL, TRUE );
366 2ee05c9a 2002-03-03 alex return DISCONNECTED;
367 2ee05c9a 2002-03-03 alex }
368 2ee05c9a 2002-03-03 alex else
369 2ee05c9a 2002-03-03 alex {
370 2ee05c9a 2002-03-03 alex /* Verbindung hielt anderer Server */
371 50ec7a56 2002-03-11 alex Client_Destroy( target, msg, Req->argv[1], FALSE );
372 2ee05c9a 2002-03-03 alex return CONNECTED;
373 2ee05c9a 2002-03-03 alex }
374 2ee05c9a 2002-03-03 alex } /* IRC_SQUIT */
375 2ee05c9a 2002-03-03 alex
376 2ee05c9a 2002-03-03 alex
377 2ee05c9a 2002-03-03 alex /* -eof- */