+ return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
+} /* IRC_ISON */
+
+
+GLOBAL BOOLEAN IRC_WHOIS( CLIENT *Client, REQUEST *Req )
+{
+ CLIENT *from, *target, *c;
+ CHAR *ptr = NULL;
+
+ 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 ) || ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
+
+ /* Client suchen */
+ c = Client_GetFromID( Req->argv[Req->argc - 1] );
+ if(( ! c ) || ( Client_Type( c ) != CLIENT_USER )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[Req->argc - 1] );
+
+ /* Empfaenger des WHOIS suchen */
+ 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 );
+
+ /* Forwarden an anderen Server? */
+ if( Req->argc > 1 )
+ {
+ /* angegebenen Ziel-Server suchen */
+ target = Client_GetFromID( Req->argv[1] );
+ if( ! target ) return IRC_WriteStrClient( from, ERR_NOSUCHSERVER_MSG, Client_ID( from ), Req->argv[1] );
+ ptr = Req->argv[1];
+ }
+#ifndef STRICT_RFC
+ else if( Client_Conn( c ) == NONE )
+ {
+ /* Client ist nicht von uns. Ziel-Server suchen */
+ target = c;
+ ptr = Req->argv[0];
+ }
+#endif
+ else target = NULL;
+
+ if( target && ( Client_NextHop( target ) != Client_ThisServer( )) && ( Client_Type( Client_NextHop( target )) == CLIENT_SERVER )) return IRC_WriteStrClientPrefix( target, from, "WHOIS %s :%s", Req->argv[0], ptr );
+
+ /* Nick, User und Name */
+ if( ! IRC_WriteStrClient( from, RPL_WHOISUSER_MSG, Client_ID( from ), Client_ID( c ), Client_User( c ), Client_Hostname( c ), Client_Info( c ))) return DISCONNECTED;
+
+ /* Server */
+ if( ! IRC_WriteStrClient( from, RPL_WHOISSERVER_MSG, Client_ID( from ), Client_ID( c ), Client_ID( Client_Introducer( c )), Client_Info( Client_Introducer( c )))) return DISCONNECTED;
+
+ /* IRC-Operator? */
+ if( Client_HasMode( c, 'o' ))
+ {
+ if( ! IRC_WriteStrClient( from, RPL_WHOISOPERATOR_MSG, Client_ID( from ), Client_ID( c ))) return DISCONNECTED;
+ }
+
+ /* Idle (nur lokale Clients) */
+ if( Client_Conn( c ) > NONE )
+ {
+ if( ! IRC_WriteStrClient( from, RPL_WHOISIDLE_MSG, Client_ID( from ), Client_ID( c ), Conn_GetIdle( Client_Conn ( c )))) return DISCONNECTED;
+ }
+
+ /* End of Whois */
+ return IRC_WriteStrClient( from, RPL_ENDOFWHOIS_MSG, Client_ID( from ), Client_ID( c ));
+} /* IRC_WHOIS */
+
+
+GLOBAL BOOLEAN IRC_USERHOST( CLIENT *Client, REQUEST *Req )
+{
+ CHAR rpl[COMMAND_LEN];
+ CLIENT *c;
+ INT max, i;
+
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ if( Client_Type( Client ) != CLIENT_USER ) 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 );
+
+ if( Req->argc > 5 ) max = 5;
+ else max = Req->argc;
+
+ strcpy( rpl, RPL_USERHOST_MSG );
+ for( i = 0; i < max; i++ )
+ {
+ c = Client_GetFromID( Req->argv[i] );
+ if( c && ( Client_Type( c ) == CLIENT_USER ))
+ {
+ /* Dieser Nick ist "online" */
+ strcat( rpl, Client_ID( c ));
+ if( Client_HasMode( c, 'o' )) strcat( rpl, "*" );
+ strcat( rpl, "=" );
+ if( Client_HasMode( c, 'a' )) strcat( rpl, "-" );
+ else strcat( rpl, "+" );
+ strcat( rpl, Client_User( c ));
+ strcat( rpl, "@" );
+ strcat( rpl, Client_Hostname( c ));
+ strcat( rpl, " " );
+ }
+ }
+ if( rpl[strlen( rpl ) - 1] == ' ' ) rpl[strlen( rpl ) - 1] = '\0';
+
+ return IRC_WriteStrClient( Client, rpl, Client_ID( Client ) );
+} /* IRC_USERHOST */
+
+
+GLOBAL BOOLEAN IRC_ERROR( CLIENT *Client, REQUEST *Req )
+{
+ assert( Client != NULL );
+ assert( Req != NULL );
+
+ if( Req->argc < 1 ) Log( LOG_NOTICE, "Got ERROR from \"%s\"!", Client_Mask( Client ));
+ else Log( LOG_NOTICE, "Got ERROR from \"%s\": %s!", Client_Mask( Client ), Req->argv[0] );
+
+ return CONNECTED;
+} /* IRC_ERROR */
+
+
+GLOBAL BOOLEAN IRC_LUSERS( CLIENT *Client, REQUEST *Req )
+{
+ CLIENT *target, *from;
+ INT cnt;
+
+ 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 );
+
+ /* Users, Services und Serevr im Netz */
+ if( ! IRC_WriteStrClient( target, RPL_LUSERCLIENT_MSG, Client_ID( target ), Client_UserCount( ), Client_ServiceCount( ), Client_ServerCount( ))) return DISCONNECTED;
+
+ /* IRC-Operatoren im Netz */
+ cnt = Client_OperCount( );
+ if( cnt > 0 )
+ {
+ if( ! IRC_WriteStrClient( target, RPL_LUSEROP_MSG, Client_ID( target ), cnt )) return DISCONNECTED;
+ }
+
+ /* Unbekannt Verbindungen */
+ cnt = Client_UnknownCount( );
+ if( cnt > 0 )
+ {
+ if( ! IRC_WriteStrClient( target, RPL_LUSERUNKNOWN_MSG, Client_ID( target ), cnt )) return DISCONNECTED;
+ }
+
+ /* Channels im Netz */
+ if( ! IRC_WriteStrClient( target, RPL_LUSERCHANNELS_MSG, Client_ID( target ), Channel_Count( ))) return DISCONNECTED;
+
+ /* Channels im Netz */
+ if( ! IRC_WriteStrClient( target, RPL_LUSERME_MSG, Client_ID( target ), Client_MyUserCount( ), Client_MyServiceCount( ), Client_MyServerCount( ))) return DISCONNECTED;
+
+ 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_Introducer( c )), 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 )
+{
+ CLIENT *target;
+ CHAR *chan, *flags;
+
+ 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 */
+ chan = strtok( Req->argv[0], "," );
+ while( chan )
+ {
+ if( Client_Type( Client ) == CLIENT_SERVER )
+ {
+ /* Channel-Flags extrahieren */
+ flags = strchr( chan, 0x7 );
+ if( flags ) *flags++ = '\0';
+ }
+ else flags = NULL;
+
+ if( ! Channel_Join( target, chan ))
+ {
+ /* naechsten Namen ermitteln */
+ chan = strtok( NULL, "," );
+ continue;
+ }
+
+ /* An andere Server weiterleiten */
+ IRC_WriteStrServersPrefix( Client, target, "JOIN :%s", chan );
+ IRC_WriteStrChannelPrefix( Client, Channel_Search( chan ), target, FALSE, "JOIN :%s", chan );
+
+ if( Client_Type( Client ) == CLIENT_USER )
+ {
+ /* an Client bestaetigen */
+ IRC_WriteStrClientPrefix( Client, target, "JOIN :%s", chan );
+ /* Topic an Client schicken */
+ IRC_WriteStrClient( Client, RPL_TOPIC_MSG, Client_ID( Client ), chan, "What a wonderful channel!" );
+ }
+
+ /* naechsten Namen ermitteln */
+ chan = 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 */
+
+
+LOCAL BOOLEAN Hello_User( CLIENT *Client )
+{
+ assert( Client != NULL );
+
+ /* Passwort ueberpruefen */
+ if( strcmp( Client_Password( Client ), Conf_ServerPwd ) != 0 )
+ {
+ /* Falsches Passwort */
+ Log( LOG_ERR, "User \"%s\" rejected (connection %d): Bad password!", Client_Mask( Client ), Client_Conn( Client ));
+ Conn_Close( Client_Conn( Client ), NULL, "Bad password", TRUE );
+ return DISCONNECTED;
+ }
+
+ Log( LOG_NOTICE, "User \"%s\" registered (connection %d).", Client_Mask( Client ), Client_Conn( Client ));
+
+ /* Andere Server informieren */
+ IRC_WriteStrServers( NULL, "NICK %s 1 %s %s 1 +%s :%s", Client_ID( Client ), Client_User( Client ), Client_Hostname( Client ), Client_Modes( Client ), Client_Info( Client ));
+
+ if( ! IRC_WriteStrClient( Client, RPL_WELCOME_MSG, Client_ID( Client ), Client_Mask( Client ))) return FALSE;
+ if( ! IRC_WriteStrClient( Client, RPL_YOURHOST_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
+ if( ! IRC_WriteStrClient( Client, RPL_CREATED_MSG, Client_ID( Client ), NGIRCd_StartStr )) return FALSE;
+ if( ! IRC_WriteStrClient( Client, RPL_MYINFO_MSG, Client_ID( Client ), Client_ID( Client_ThisServer( )))) return FALSE;
+
+ Client_SetType( Client, CLIENT_USER );