+GLOBAL BOOLEAN IRC_LUSERS( CLIENT *Client, REQUEST *Req )
+{
+ CLIENT *target, *from;
+
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
+
+ /* Falsche Anzahl Parameter? */
+ if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+ /* Absender ermitteln */
+ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
+ else from = Client;
+ if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+
+ /* An anderen Server forwarden? */
+ if( Req->argc == 2 )
+ {
+ target = Client_GetFromID( Req->argv[1] );
+ if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[1] );
+ else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LUSERS %s %s", Req->argv[0], Req->argv[1] );
+ }
+
+ /* Wer ist der Absender? */
+ if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
+ else target = Client;
+ if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+
+ Send_LUSERS( target );
+
+ return CONNECTED;
+} /* IRC_LUSERS */
+
+
+GLOBAL BOOLEAN IRC_LINKS( CLIENT *Client, REQUEST *Req )
+{
+ CLIENT *target, *from, *c;
+ CHAR *mask;
+
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
+
+ /* Falsche Anzahl Parameter? */
+ if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+ /* Server-Mask ermitteln */
+ if( Req->argc > 0 ) mask = Req->argv[Req->argc - 1];
+ else mask = "*";
+
+ /* Absender ermitteln */
+ if( Client_Type( Client ) == CLIENT_SERVER ) from = Client_GetFromID( Req->prefix );
+ else from = Client;
+ if( ! from ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+
+ /* An anderen Server forwarden? */
+ if( Req->argc == 2 )
+ {
+ target = Client_GetFromID( Req->argv[0] );
+ if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
+ else if( target != Client_ThisServer( )) return IRC_WriteStrClientPrefix( target, from, "LINKS %s %s", Req->argv[0], Req->argv[1] );
+ }
+
+ /* Wer ist der Absender? */
+ if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
+ else target = Client;
+ if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+
+ c = Client_First( );
+ while( c )
+ {
+ if( Client_Type( c ) == CLIENT_SERVER )
+ {
+ if( ! IRC_WriteStrClient( target, RPL_LINKS_MSG, Client_ID( target ), Client_ID( c ), Client_ID( Client_TopServer( c ) ? Client_TopServer( c ) : Client_ThisServer( )), Client_Hops( c ), Client_Info( c ))) return DISCONNECTED;
+ }
+ c = Client_Next( c );
+ }
+
+ return IRC_WriteStrClient( target, RPL_ENDOFLINKS_MSG, Client_ID( target ), mask );
+} /* IRC_LINKS */
+
+
+GLOBAL BOOLEAN IRC_JOIN( CLIENT *Client, REQUEST *Req )
+{
+ CHAR *channame, *flags, modes[8];
+ BOOLEAN is_new_chan;
+ CLIENT *target;
+ CHANNEL *chan;
+
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
+
+ /* Falsche Anzahl Parameter? */
+ if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+ /* Wer ist der Absender? */
+ if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
+ else target = Client;
+ if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+
+ /* Channel-Namen durchgehen */
+ channame = strtok( Req->argv[0], "," );
+ while( channame )
+ {
+ /* wird der Channel neu angelegt? */
+ flags = NULL;
+
+ if( Channel_Search( channame )) is_new_chan = FALSE;
+ else is_new_chan = TRUE;
+
+ /* Hat ein Server Channel-User-Modes uebergeben? */
+ if( Client_Type( Client ) == CLIENT_SERVER )
+ {
+ /* Channel-Flags extrahieren */
+ flags = strchr( channame, 0x7 );
+ if( flags ) *flags++ = '\0';
+ }
+
+ /* neuer Channel udn lokaler Client? */
+ if( is_new_chan && ( Client_Type( Client ) == CLIENT_USER ))
+ {
+ /* Dann soll der Client Channel-Operator werden! */
+ flags = "o";
+ }
+
+ /* Channel joinen (und ggf. anlegen) */
+ if( ! Channel_Join( target, channame ))
+ {
+ /* naechsten Namen ermitteln */
+ channame = strtok( NULL, "," );
+ continue;
+ }
+ chan = Channel_Search( channame );
+ assert( chan != NULL );
+
+ /* Modes setzen (wenn vorhanden) */
+ while( flags && *flags )
+ {
+ Channel_UserModeAdd( chan, target, *flags );
+ flags++;
+ }
+
+ /* Muessen Modes an andere Server gemeldet werden? */
+ strcpy( &modes[1], Channel_UserModes( chan, target ));
+ if( modes[1] ) modes[0] = 0x7;
+ else modes[0] = '\0';
+
+ /* An andere Server weiterleiten */
+ IRC_WriteStrServersPrefix( Client, target, "JOIN :%s%s", channame, modes );
+
+ /* im Channel bekannt machen */
+ IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "JOIN :%s", channame );
+ if( modes[1] )
+ {
+ /* Modes im Channel bekannt machen */
+ IRC_WriteStrChannelPrefix( Client, chan, target, FALSE, "MODE %s %s :%s", channame, modes, Client_ID( target ));
+ }
+
+ if( Client_Type( Client ) == CLIENT_USER )
+ {
+ /* an Client bestaetigen */
+ IRC_WriteStrClientPrefix( Client, target, "JOIN :%s", channame );
+
+ /* Topic an Client schicken */
+ IRC_WriteStrClient( Client, RPL_TOPIC_MSG, Client_ID( Client ), channame, "What a wonderful channel!" );
+
+ /* Mitglieder an Client Melden */
+ Send_NAMES( Client, chan );
+ IRC_WriteStrClient( Client, RPL_ENDOFNAMES_MSG, Client_ID( Client ), Channel_Name( chan ));
+ }
+
+ /* naechsten Namen ermitteln */
+ channame = strtok( NULL, "," );
+ }
+ return CONNECTED;
+} /* IRC_JOIN */
+
+
+GLOBAL BOOLEAN IRC_PART( CLIENT *Client, REQUEST *Req )
+{
+ CLIENT *target;
+ CHAR *chan;
+
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
+
+ /* Falsche Anzahl Parameter? */
+ if(( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+ /* Wer ist der Absender? */
+ if( Client_Type( Client ) == CLIENT_SERVER ) target = Client_GetFromID( Req->prefix );
+ else target = Client;
+ if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->prefix );
+
+ /* Channel-Namen durchgehen */
+ chan = strtok( Req->argv[0], "," );
+ while( chan )
+ {
+ if( ! Channel_Part( target, Client, chan, Req->argc > 1 ? Req->argv[1] : Client_ID( target )))
+ {
+ /* naechsten Namen ermitteln */
+ chan = strtok( NULL, "," );
+ continue;
+ }
+
+ /* naechsten Namen ermitteln */
+ chan = strtok( NULL, "," );
+ }
+ return CONNECTED;
+} /* IRC_PART */
+
+
+GLOBAL BOOLEAN IRC_VERSION( CLIENT *Client, REQUEST *Req )
+{
+ CLIENT *target, *prefix;
+
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ /* Falsche Anzahl Parameter? */
+ if(( Req->argc > 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+ /* Ziel suchen */
+ if( Req->argc == 1 ) target = Client_GetFromID( Req->argv[0] );
+ else target = Client_ThisServer( );
+
+ /* Prefix ermitteln */
+ if( Client_Type( Client ) == CLIENT_SERVER ) prefix = Client_GetFromID( Req->prefix );
+ else prefix = Client;
+ if( ! prefix ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->prefix );
+
+ /* An anderen Server weiterleiten? */
+ if( target != Client_ThisServer( ))
+ {
+ if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHSERVER_MSG, Client_ID( Client ), Req->argv[0] );
+
+ /* forwarden */
+ IRC_WriteStrClientPrefix( target, prefix, "VERSION %s", Req->argv[0] );
+ return CONNECTED;
+ }
+
+ /* mit Versionsinfo antworten */
+ return IRC_WriteStrClient( Client, RPL_VERSION_MSG, Client_ID( prefix ), NGIRCd_DebugLevel, Conf_ServerName, NGIRCd_VersionAddition( ));
+} /* IRC_VERSION */
+
+
+GLOBAL BOOLEAN IRC_KILL( CLIENT *Client, REQUEST *Req )
+{
+ CLIENT *prefix, *c;
+
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ if( Client_Type( Client ) != CLIENT_SERVER ) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
+
+ /* Falsche Anzahl Parameter? */
+ if(( Req->argc != 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+ prefix = Client_GetFromID( Req->prefix );
+ if( ! prefix )
+ {
+ Log( LOG_WARNING, "Got KILL with invalid prefix: \"%s\"!", Req->prefix );
+ prefix = Client_ThisServer( );
+ }
+
+ Log( LOG_NOTICE, "Got KILL command from \"%s\" for \"%s\": %s", Client_Mask( prefix ), Req->argv[0], Req->argv[1] );
+
+ /* andere Server benachrichtigen */
+ IRC_WriteStrServersPrefix( Client, prefix, "KILL %s :%s", Req->argv[0], Req->argv[1] );
+
+ /* haben wir selber einen solchen Client? */
+ c = Client_GetFromID( Req->argv[0] );
+ if( c && ( Client_Conn( c ) != NONE )) Conn_Close( Client_Conn( c ), NULL, Req->argv[1], TRUE );
+
+ return CONNECTED;
+} /* IRC_KILL */
+
+