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 3dc16212 2002-09-07 alex * $Id: irc-server.c,v 1.17 2002/09/07 17:57:31 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 2ee05c9a 2002-03-03 alex if( strcmp( Client_Password( Client ), Conf_Server[i].pwd ) != 0 )
75 2ee05c9a 2002-03-03 alex {
76 2ee05c9a 2002-03-03 alex /* Falsches Passwort */
77 2ee05c9a 2002-03-03 alex Log( LOG_ERR, "Connection %d: Bad password for 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 d58431a0 2002-09-02 alex if( ! IRC_WriteStrClient( Client, "PASS %s %s", Conf_Server[i].pwd, 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 2ee05c9a 2002-03-03 alex
117 2ee05c9a 2002-03-03 alex /* maximalen Hop Count ermitteln */
118 2ee05c9a 2002-03-03 alex max_hops = 0;
119 2ee05c9a 2002-03-03 alex c = Client_First( );
120 2ee05c9a 2002-03-03 alex while( c )
121 2ee05c9a 2002-03-03 alex {
122 2ee05c9a 2002-03-03 alex if( Client_Hops( c ) > max_hops ) max_hops = Client_Hops( c );
123 2ee05c9a 2002-03-03 alex c = Client_Next( c );
124 2ee05c9a 2002-03-03 alex }
125 2ee05c9a 2002-03-03 alex
126 2ee05c9a 2002-03-03 alex /* Alle bisherigen Server dem neuen Server bekannt machen,
127 2ee05c9a 2002-03-03 alex * die bisherigen Server ueber den neuen informierenn */
128 2ee05c9a 2002-03-03 alex for( i = 0; i < ( max_hops + 1 ); i++ )
129 2ee05c9a 2002-03-03 alex {
130 2ee05c9a 2002-03-03 alex c = Client_First( );
131 2ee05c9a 2002-03-03 alex while( c )
132 2ee05c9a 2002-03-03 alex {
133 2ee05c9a 2002-03-03 alex if(( Client_Type( c ) == CLIENT_SERVER ) && ( c != Client ) && ( c != Client_ThisServer( )) && ( Client_Hops( c ) == i ))
134 2ee05c9a 2002-03-03 alex {
135 2ee05c9a 2002-03-03 alex if( Client_Conn( c ) > NONE )
136 2ee05c9a 2002-03-03 alex {
137 2ee05c9a 2002-03-03 alex /* Dem gefundenen Server gleich den neuen
138 2ee05c9a 2002-03-03 alex * Server bekannt machen */
139 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;
140 2ee05c9a 2002-03-03 alex }
141 2ee05c9a 2002-03-03 alex
142 2ee05c9a 2002-03-03 alex /* Den neuen Server ueber den alten informieren */
143 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;
144 2ee05c9a 2002-03-03 alex }
145 2ee05c9a 2002-03-03 alex c = Client_Next( c );
146 2ee05c9a 2002-03-03 alex }
147 2ee05c9a 2002-03-03 alex }
148 2ee05c9a 2002-03-03 alex
149 2ee05c9a 2002-03-03 alex /* alle User dem neuen Server bekannt machen */
150 2ee05c9a 2002-03-03 alex c = Client_First( );
151 2ee05c9a 2002-03-03 alex while( c )
152 2ee05c9a 2002-03-03 alex {
153 2ee05c9a 2002-03-03 alex if( Client_Type( c ) == CLIENT_USER )
154 2ee05c9a 2002-03-03 alex {
155 2ee05c9a 2002-03-03 alex /* User an neuen Server melden */
156 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;
157 2ee05c9a 2002-03-03 alex }
158 2ee05c9a 2002-03-03 alex c = Client_Next( c );
159 2ee05c9a 2002-03-03 alex }
160 2ee05c9a 2002-03-03 alex
161 2ee05c9a 2002-03-03 alex /* Channels dem neuen Server bekannt machen */
162 2ee05c9a 2002-03-03 alex chan = Channel_First( );
163 2ee05c9a 2002-03-03 alex while( chan )
164 2ee05c9a 2002-03-03 alex {
165 3dc16212 2002-09-07 alex #ifdef IRCPLUS
166 938abb02 2002-09-03 alex /* Wenn unterstuetzt, CHANINFO senden */
167 938abb02 2002-09-03 alex if( strchr( Client_Flags( Client ), 'C' ))
168 938abb02 2002-09-03 alex {
169 938abb02 2002-09-03 alex /* CHANINFO senden */
170 938abb02 2002-09-03 alex if( ! IRC_WriteStrClient( Client, "CHANINFO %s +%s :%s", Channel_Name( chan ), Channel_Modes( chan ), Channel_Topic( chan ))) return DISCONNECTED;
171 938abb02 2002-09-03 alex }
172 3dc16212 2002-09-07 alex #endif
173 3dc16212 2002-09-07 alex
174 2ee05c9a 2002-03-03 alex /* alle Member suchen */
175 2ee05c9a 2002-03-03 alex cl2chan = Channel_FirstMember( chan );
176 0e092b3f 2002-03-06 alex sprintf( str, "NJOIN %s :", Channel_Name( chan ));
177 2ee05c9a 2002-03-03 alex while( cl2chan )
178 2ee05c9a 2002-03-03 alex {
179 2ee05c9a 2002-03-03 alex cl = Channel_GetClient( cl2chan );
180 2ee05c9a 2002-03-03 alex assert( cl != NULL );
181 2ee05c9a 2002-03-03 alex
182 2ee05c9a 2002-03-03 alex /* Nick, ggf. mit Modes, anhaengen */
183 2ee05c9a 2002-03-03 alex if( str[strlen( str ) - 1] != ':' ) strcat( str, "," );
184 2ee05c9a 2002-03-03 alex if( strchr( Channel_UserModes( chan, cl ), 'v' )) strcat( str, "+" );
185 2ee05c9a 2002-03-03 alex if( strchr( Channel_UserModes( chan, cl ), 'o' )) strcat( str, "@" );
186 2ee05c9a 2002-03-03 alex strcat( str, Client_ID( cl ));
187 2ee05c9a 2002-03-03 alex
188 0e092b3f 2002-03-06 alex if( strlen( str ) > ( LINE_LEN - CLIENT_NICK_LEN - 8 ))
189 2ee05c9a 2002-03-03 alex {
190 2ee05c9a 2002-03-03 alex /* Zeile senden */
191 2ee05c9a 2002-03-03 alex if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
192 2ee05c9a 2002-03-03 alex sprintf( str, "NJOIN %s :", Channel_Name( chan ));
193 2ee05c9a 2002-03-03 alex }
194 2ee05c9a 2002-03-03 alex
195 2ee05c9a 2002-03-03 alex cl2chan = Channel_NextMember( chan, cl2chan );
196 2ee05c9a 2002-03-03 alex }
197 2ee05c9a 2002-03-03 alex
198 2ee05c9a 2002-03-03 alex /* noch Daten da? */
199 2ee05c9a 2002-03-03 alex if( str[strlen( str ) - 1] != ':')
200 2ee05c9a 2002-03-03 alex {
201 2ee05c9a 2002-03-03 alex /* Ja; Also senden ... */
202 2ee05c9a 2002-03-03 alex if( ! IRC_WriteStrClient( Client, str )) return DISCONNECTED;
203 2ee05c9a 2002-03-03 alex }
204 2ee05c9a 2002-03-03 alex
205 2ee05c9a 2002-03-03 alex /* naechsten Channel suchen */
206 2ee05c9a 2002-03-03 alex chan = Channel_Next( chan );
207 2ee05c9a 2002-03-03 alex }
208 2ee05c9a 2002-03-03 alex
209 2ee05c9a 2002-03-03 alex return CONNECTED;
210 2ee05c9a 2002-03-03 alex }
211 2ee05c9a 2002-03-03 alex else if( Client_Type( Client ) == CLIENT_SERVER )
212 2ee05c9a 2002-03-03 alex {
213 2ee05c9a 2002-03-03 alex /* Neuer Server wird im Netz angekuendigt */
214 2ee05c9a 2002-03-03 alex
215 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
216 2ee05c9a 2002-03-03 alex if( Req->argc != 4 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
217 2ee05c9a 2002-03-03 alex
218 2ee05c9a 2002-03-03 alex /* Ist ein Server mit dieser ID bereits registriert? */
219 2ee05c9a 2002-03-03 alex if( ! Client_CheckID( Client, Req->argv[0] )) return DISCONNECTED;
220 2ee05c9a 2002-03-03 alex
221 2ee05c9a 2002-03-03 alex /* Ueberfluessige Hostnamen aus Info-Text entfernen */
222 2ee05c9a 2002-03-03 alex ptr = strchr( Req->argv[3] + 2, '[' );
223 2ee05c9a 2002-03-03 alex if( ! ptr ) ptr = Req->argv[3];
224 2ee05c9a 2002-03-03 alex
225 bc4ed226 2002-03-25 alex from = Client_Search( Req->prefix );
226 2ee05c9a 2002-03-03 alex if( ! from )
227 2ee05c9a 2002-03-03 alex {
228 2ee05c9a 2002-03-03 alex /* Hm, Server, der diesen einfuehrt, ist nicht bekannt!? */
229 2ee05c9a 2002-03-03 alex Log( LOG_ALERT, "Unknown ID in prefix of SERVER: \"%s\"! (on connection %d)", Req->prefix, Client_Conn( Client ));
230 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Unknown ID in prefix of SERVER", TRUE );
231 2ee05c9a 2002-03-03 alex return DISCONNECTED;
232 2ee05c9a 2002-03-03 alex }
233 2ee05c9a 2002-03-03 alex
234 2ee05c9a 2002-03-03 alex /* Neue Client-Struktur anlegen */
235 2ee05c9a 2002-03-03 alex c = Client_NewRemoteServer( Client, Req->argv[0], from, atoi( Req->argv[1] ), atoi( Req->argv[2] ), ptr, TRUE );
236 2ee05c9a 2002-03-03 alex if( ! c )
237 2ee05c9a 2002-03-03 alex {
238 2ee05c9a 2002-03-03 alex /* Neue Client-Struktur konnte nicht angelegt werden */
239 2ee05c9a 2002-03-03 alex Log( LOG_ALERT, "Can't create client structure for server! (on connection %d)", Client_Conn( Client ));
240 2ee05c9a 2002-03-03 alex Conn_Close( Client_Conn( Client ), NULL, "Can't allocate client structure for remote server", TRUE );
241 2ee05c9a 2002-03-03 alex return DISCONNECTED;
242 2ee05c9a 2002-03-03 alex }
243 2ee05c9a 2002-03-03 alex
244 2ee05c9a 2002-03-03 alex /* Log-Meldung zusammenbauen und ausgeben */
245 2ee05c9a 2002-03-03 alex if(( Client_Hops( c ) > 1 ) && ( Req->prefix[0] )) sprintf( str, "connected to %s, ", Client_ID( from ));
246 2ee05c9a 2002-03-03 alex else strcpy( str, "" );
247 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": "" );
248 2ee05c9a 2002-03-03 alex
249 2ee05c9a 2002-03-03 alex /* Andere Server informieren */
250 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 ));
251 2ee05c9a 2002-03-03 alex
252 2ee05c9a 2002-03-03 alex return CONNECTED;
253 2ee05c9a 2002-03-03 alex }
254 2ee05c9a 2002-03-03 alex else return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
255 2ee05c9a 2002-03-03 alex } /* IRC_SERVER */
256 2ee05c9a 2002-03-03 alex
257 2ee05c9a 2002-03-03 alex
258 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
259 c2f60abe 2002-05-27 alex IRC_NJOIN( CLIENT *Client, REQUEST *Req )
260 2ee05c9a 2002-03-03 alex {
261 e07fab17 2002-07-25 alex CHAR str[COMMAND_LEN], *channame, *ptr, modes[8];
262 2ee05c9a 2002-03-03 alex BOOLEAN is_op, is_voiced;
263 2ee05c9a 2002-03-03 alex CHANNEL *chan;
264 2ee05c9a 2002-03-03 alex CLIENT *c;
265 2ee05c9a 2002-03-03 alex
266 2ee05c9a 2002-03-03 alex assert( Client != NULL );
267 2ee05c9a 2002-03-03 alex assert( Req != NULL );
268 2ee05c9a 2002-03-03 alex
269 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTEREDSERVER_MSG, Client_ID( Client ));
270 2ee05c9a 2002-03-03 alex
271 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
272 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
273 2ee05c9a 2002-03-03 alex
274 e07fab17 2002-07-25 alex strncpy( str, Req->argv[1], COMMAND_LEN - 1 );
275 e07fab17 2002-07-25 alex str[COMMAND_LEN - 1] = '\0';
276 e07fab17 2002-07-25 alex
277 2ee05c9a 2002-03-03 alex channame = Req->argv[0];
278 e07fab17 2002-07-25 alex ptr = strtok( str, "," );
279 2ee05c9a 2002-03-03 alex while( ptr )
280 2ee05c9a 2002-03-03 alex {
281 2ee05c9a 2002-03-03 alex is_op = is_voiced = FALSE;
282 2ee05c9a 2002-03-03 alex
283 2ee05c9a 2002-03-03 alex /* Prefixe abschneiden */
284 2ee05c9a 2002-03-03 alex while(( *ptr == '@' ) || ( *ptr == '+' ))
285 2ee05c9a 2002-03-03 alex {
286 2ee05c9a 2002-03-03 alex if( *ptr == '@' ) is_op = TRUE;
287 2ee05c9a 2002-03-03 alex if( *ptr == '+' ) is_voiced = TRUE;
288 2ee05c9a 2002-03-03 alex ptr++;
289 2ee05c9a 2002-03-03 alex }
290 2ee05c9a 2002-03-03 alex
291 bc4ed226 2002-03-25 alex c = Client_Search( ptr );
292 2ee05c9a 2002-03-03 alex if( c )
293 2ee05c9a 2002-03-03 alex {
294 2ee05c9a 2002-03-03 alex Channel_Join( c, channame );
295 2ee05c9a 2002-03-03 alex chan = Channel_Search( channame );
296 2ee05c9a 2002-03-03 alex assert( chan != NULL );
297 2ee05c9a 2002-03-03 alex
298 2ee05c9a 2002-03-03 alex if( is_op ) Channel_UserModeAdd( chan, c, 'o' );
299 2ee05c9a 2002-03-03 alex if( is_voiced ) Channel_UserModeAdd( chan, c, 'v' );
300 2ee05c9a 2002-03-03 alex
301 2ee05c9a 2002-03-03 alex /* im Channel bekannt machen */
302 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, c, FALSE, "JOIN :%s", channame );
303 2ee05c9a 2002-03-03 alex
304 2ee05c9a 2002-03-03 alex /* Channel-User-Modes setzen */
305 2ee05c9a 2002-03-03 alex strcpy( modes, Channel_UserModes( chan, c ));
306 2ee05c9a 2002-03-03 alex if( modes[0] )
307 2ee05c9a 2002-03-03 alex {
308 2ee05c9a 2002-03-03 alex /* Modes im Channel bekannt machen */
309 2ee05c9a 2002-03-03 alex IRC_WriteStrChannelPrefix( Client, chan, Client, FALSE, "MODE %s +%s %s", channame, modes, Client_ID( c ));
310 2ee05c9a 2002-03-03 alex }
311 2ee05c9a 2002-03-03 alex }
312 7d30c8ce 2002-08-26 alex else Log( LOG_ERR, "Got NJOIN for unknown nick \"%s\" for channel \"%s\"!", ptr, channame );
313 2ee05c9a 2002-03-03 alex
314 2ee05c9a 2002-03-03 alex /* naechsten Nick suchen */
315 2ee05c9a 2002-03-03 alex ptr = strtok( NULL, "," );
316 2ee05c9a 2002-03-03 alex }
317 2ee05c9a 2002-03-03 alex
318 2ee05c9a 2002-03-03 alex /* an andere Server weiterleiten */
319 2ee05c9a 2002-03-03 alex IRC_WriteStrServersPrefix( Client, Client_ThisServer( ), "NJOIN %s :%s", Req->argv[0], Req->argv[1] );
320 2ee05c9a 2002-03-03 alex
321 2ee05c9a 2002-03-03 alex return CONNECTED;
322 2ee05c9a 2002-03-03 alex } /* IRC_NJOIN */
323 2ee05c9a 2002-03-03 alex
324 2ee05c9a 2002-03-03 alex
325 c2f60abe 2002-05-27 alex GLOBAL BOOLEAN
326 c2f60abe 2002-05-27 alex IRC_SQUIT( CLIENT *Client, REQUEST *Req )
327 2ee05c9a 2002-03-03 alex {
328 2ee05c9a 2002-03-03 alex CLIENT *target;
329 2ee05c9a 2002-03-03 alex CHAR msg[LINE_LEN + 64];
330 2ee05c9a 2002-03-03 alex
331 2ee05c9a 2002-03-03 alex assert( Client != NULL );
332 2ee05c9a 2002-03-03 alex assert( Req != NULL );
333 2ee05c9a 2002-03-03 alex
334 2ee05c9a 2002-03-03 alex /* SQUIT ist nur fuer Server erlaubt */
335 2ee05c9a 2002-03-03 alex if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
336 2ee05c9a 2002-03-03 alex
337 2ee05c9a 2002-03-03 alex /* Falsche Anzahl Parameter? */
338 2ee05c9a 2002-03-03 alex if( Req->argc != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
339 2ee05c9a 2002-03-03 alex
340 2ee05c9a 2002-03-03 alex Log( LOG_DEBUG, "Got SQUIT from %s for \"%s\": \"%s\" ...", Client_ID( Client ), Req->argv[0], Req->argv[1] );
341 2ee05c9a 2002-03-03 alex
342 2ee05c9a 2002-03-03 alex /* SQUIT an alle Server weiterleiten */
343 2ee05c9a 2002-03-03 alex IRC_WriteStrServers( Client, "SQUIT %s :%s", Req->argv[0], Req->argv[1] );
344 2ee05c9a 2002-03-03 alex
345 bc4ed226 2002-03-25 alex target = Client_Search( Req->argv[0] );
346 2ee05c9a 2002-03-03 alex if( ! target )
347 2ee05c9a 2002-03-03 alex {
348 9fc7e66f 2002-03-11 alex /* Den Server kennen wir nicht (mehr), also nichts zu tun. */
349 f7a0ff1f 2002-03-11 alex Log( LOG_WARNING, "Got SQUIT from %s for unknown server \"%s\"!?", Client_ID( Client ), Req->argv[0] );
350 2ee05c9a 2002-03-03 alex return CONNECTED;
351 2ee05c9a 2002-03-03 alex }
352 2ee05c9a 2002-03-03 alex
353 2ee05c9a 2002-03-03 alex if( Req->argv[1][0] )
354 2ee05c9a 2002-03-03 alex {
355 2ee05c9a 2002-03-03 alex if( strlen( Req->argv[1] ) > LINE_LEN ) Req->argv[1][LINE_LEN] = '\0';
356 2ee05c9a 2002-03-03 alex sprintf( msg, "%s (SQUIT from %s).", Req->argv[1], Client_ID( Client ));
357 2ee05c9a 2002-03-03 alex }
358 2ee05c9a 2002-03-03 alex else sprintf( msg, "Got SQUIT from %s.", Client_ID( Client ));
359 2ee05c9a 2002-03-03 alex
360 2ee05c9a 2002-03-03 alex if( Client_Conn( target ) > NONE )
361 2ee05c9a 2002-03-03 alex {
362 2ee05c9a 2002-03-03 alex /* dieser Server hat die Connection */
363 2ee05c9a 2002-03-03 alex if( Req->argv[1][0] ) Conn_Close( Client_Conn( target ), msg, Req->argv[1], TRUE );
364 2ee05c9a 2002-03-03 alex else Conn_Close( Client_Conn( target ), msg, NULL, TRUE );
365 2ee05c9a 2002-03-03 alex return DISCONNECTED;
366 2ee05c9a 2002-03-03 alex }
367 2ee05c9a 2002-03-03 alex else
368 2ee05c9a 2002-03-03 alex {
369 2ee05c9a 2002-03-03 alex /* Verbindung hielt anderer Server */
370 50ec7a56 2002-03-11 alex Client_Destroy( target, msg, Req->argv[1], FALSE );
371 2ee05c9a 2002-03-03 alex return CONNECTED;
372 2ee05c9a 2002-03-03 alex }
373 2ee05c9a 2002-03-03 alex } /* IRC_SQUIT */
374 2ee05c9a 2002-03-03 alex
375 2ee05c9a 2002-03-03 alex
376 2ee05c9a 2002-03-03 alex /* -eof- */