-GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
-{
- CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr;
- BOOLEAN set, ok;
- CLIENT *target;
-
- 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 ) || ( Req->argc < 1 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
-
- /* "Ziel-Client" suchen */
- target = Client_Search( Req->argv[0] );
-
- /* Wer ist der Anfragende? */
- if( Client_Type( Client ) == CLIENT_USER )
- {
- /* User: MODE ist nur fuer sich selber zulaessig */
- if( target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
- }
- else
- {
- /* Server: gibt es den Client ueberhaupt? */
- if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
- }
-
- /* Werden die Modes erfragt? */
- if( Req->argc == 1 ) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( Client ));
-
- ptr = Req->argv[1];
-
- /* Sollen Modes gesetzt oder geloescht werden? */
- if( *ptr == '+' ) set = TRUE;
- else if( *ptr == '-' ) set = FALSE;
- else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
-
- /* Reply-String mit Aenderungen vorbereiten */
- if( set ) strcpy( new_modes, "+" );
- else strcpy( new_modes, "-" );
-
- ptr++;
- ok = TRUE;
- x[1] = '\0';
- while( *ptr )
- {
- x[0] = '\0';
- if( Client_Type( Client ) == CLIENT_SERVER )
- {
- x[0] = *ptr;
- ok = TRUE;
- }
- else
- {
- switch( *ptr )
- {
- case 'i':
- /* invisible */
- x[0] = 'i';
- break;
- case 'r':
- /* restricted (kann nur gesetzt werden) */
- if( set ) x[0] = 'r';
- else ok = IRC_WriteStrClient( target, ERR_RESTRICTED_MSG, Client_ID( target ));
- break;
- case 'o':
- /* operator (kann nur geloescht werden) */
- if( ! set )
- {
- Client_SetOperByMe( target, FALSE );
- x[0] = 'o';
- }
- else ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
- break;
- default:
- ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
- x[0] = '\0';
- }
- }
- if( ! ok ) break;
-
- ptr++;
- if( ! x[0] ) continue;
-
- /* Okay, gueltigen Mode gefunden */
- if( set )
- {
- /* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
- if( Client_ModeAdd( target, x[0] )) strcat( new_modes, x );
- }
- else
- {
- /* Modes geloescht. Wenn der Client ihn hatte: merken */
- if( Client_ModeDel( target, x[0] )) strcat( new_modes, x );
- }
- }
-
- /* Geanderte Modes? */
- if( new_modes[1] )
- {
- if( Client_Type( Client ) == CLIENT_SERVER )
- {
- /* Modes an andere Server forwarden */
- IRC_WriteStrServersPrefix( Client, Client, "MODE %s :%s", Client_ID( target ), new_modes );
- }
- else
- {
- /* Bestaetigung an Client schicken & andere Server informieren */
- ok = IRC_WriteStrRelated( Client, "MODE %s :%s", Client_ID( target ), new_modes );
- IRC_WriteStrServers( Client, "MODE %s :%s", Client_ID( target ), new_modes );
- }
- Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( target ), Client_Modes( target ));
- }
- return ok;
-} /* IRC_MODE */
-
-
-GLOBAL BOOLEAN IRC_OPER( CLIENT *Client, REQUEST *Req )
-{
- INT 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 != 2 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
-
- /* Operator suchen */
- for( i = 0; i < Conf_Oper_Count; i++)
- {
- if( Conf_Oper[i].name[0] && Conf_Oper[i].pwd[0] && ( strcmp( Conf_Oper[i].name, Req->argv[0] ) == 0 )) break;
- }
- if( i >= Conf_Oper_Count )
- {
- Log( LOG_WARNING, "Got invalid OPER from \"%s\": Name \"%s\" not configured!", Client_Mask( Client ), Req->argv[0] );
- return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
- }
-
- /* Stimmt das Passwort? */
- if( strcmp( Conf_Oper[i].pwd, Req->argv[1] ) != 0 )
- {
- Log( LOG_WARNING, "Got invalid OPER from \"%s\": Bad password for \"%s\"!", Client_Mask( Client ), Conf_Oper[i].name );
- return IRC_WriteStrClient( Client, ERR_PASSWDMISMATCH_MSG, Client_ID( Client ));
- }
-
- if( ! Client_HasMode( Client, 'o' ))
- {
- /* noch kein o-Mode gesetzt */
- Client_ModeAdd( Client, 'o' );
- if( ! IRC_WriteStrRelated( Client, "MODE %s :+o", Client_ID( Client ))) return DISCONNECTED;
- }
-
- if( ! Client_OperByMe( Client )) Log( LOG_NOTICE, "Got valid OPER from \"%s\", user is an IRC operator now.", Client_Mask( Client ));
-
- Client_SetOperByMe( Client, TRUE );
- return IRC_WriteStrClient( Client, RPL_YOUREOPER_MSG, Client_ID( Client ));
-} /* IRC_OPER */
-
-
-GLOBAL BOOLEAN IRC_DIE( CLIENT *Client, REQUEST *Req )
-{
- 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 != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
-
- if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
-
- Log( LOG_NOTICE, "Got DIE command from \"%s\", going down!", Client_Mask( Client ));
- NGIRCd_Quit = TRUE;
- return CONNECTED;
-} /* IRC_DIE */
-
-
-GLOBAL BOOLEAN IRC_RESTART( CLIENT *Client, REQUEST *Req )
-{
- 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 != 0 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
-
- if(( ! Client_HasMode( Client, 'o' )) || ( ! Client_OperByMe( Client ))) return IRC_WriteStrClient( Client, ERR_NOPRIVILEGES_MSG, Client_ID( Client ));
-
- Log( LOG_NOTICE, "Got RESTART command from \"%s\", going down!", Client_Mask( Client ));
- NGIRCd_Restart = TRUE;
- return CONNECTED;
-} /* IRC_RESTART */
-
-
-GLOBAL BOOLEAN IRC_NAMES( CLIENT *Client, REQUEST *Req )