mirror of
https://github.com/osmarks/ngircd.git
synced 2025-01-28 16:24:44 +00:00
- neue Funktion zur MODE-Behandlung, fuer Channel-Modes vorbereitet.
This commit is contained in:
parent
175b20bbb5
commit
f29ae5ae0e
188
src/ngircd/irc.c
188
src/ngircd/irc.c
@ -9,11 +9,14 @@
|
|||||||
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
* Naehere Informationen entnehmen Sie bitter der Datei COPYING. Eine Liste
|
||||||
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
|
* der an ngIRCd beteiligten Autoren finden Sie in der Datei AUTHORS.
|
||||||
*
|
*
|
||||||
* $Id: irc.c,v 1.48 2002/01/29 00:13:45 alex Exp $
|
* $Id: irc.c,v 1.49 2002/02/06 16:51:22 alex Exp $
|
||||||
*
|
*
|
||||||
* irc.c: IRC-Befehle
|
* irc.c: IRC-Befehle
|
||||||
*
|
*
|
||||||
* $Log: irc.c,v $
|
* $Log: irc.c,v $
|
||||||
|
* Revision 1.49 2002/02/06 16:51:22 alex
|
||||||
|
* - neue Funktion zur MODE-Behandlung, fuer Channel-Modes vorbereitet.
|
||||||
|
*
|
||||||
* Revision 1.48 2002/01/29 00:13:45 alex
|
* Revision 1.48 2002/01/29 00:13:45 alex
|
||||||
* - WHOIS zeigt nun auch die Channels an, in denen der jeweilige User Mitglied ist.
|
* - WHOIS zeigt nun auch die Channels an, in denen der jeweilige User Mitglied ist.
|
||||||
* - zu jedem Server wird nun der "Top-Server" gespeichert, somit funktioniert
|
* - zu jedem Server wird nun der "Top-Server" gespeichert, somit funktioniert
|
||||||
@ -1011,136 +1014,161 @@ GLOBAL BOOLEAN IRC_NOTICE( CLIENT *Client, REQUEST *Req )
|
|||||||
|
|
||||||
GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
|
GLOBAL BOOLEAN IRC_MODE( CLIENT *Client, REQUEST *Req )
|
||||||
{
|
{
|
||||||
CHAR x[2], new_modes[CLIENT_MODE_LEN], *ptr;
|
CHAR *mode_ptr, the_modes[CLIENT_MODE_LEN], x[2];
|
||||||
BOOLEAN set, ok;
|
BOOLEAN set, ok;
|
||||||
CLIENT *target;
|
|
||||||
CHANNEL *chan;
|
CHANNEL *chan;
|
||||||
|
CLIENT *cl;
|
||||||
|
|
||||||
assert( Client != NULL );
|
assert( Client != NULL );
|
||||||
assert( Req != NULL );
|
assert( Req != NULL );
|
||||||
|
|
||||||
|
cl = NULL;
|
||||||
|
chan = NULL;
|
||||||
|
|
||||||
|
/* Valider Client? */
|
||||||
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
if(( Client_Type( Client ) != CLIENT_USER ) && ( Client_Type( Client ) != CLIENT_SERVER )) return IRC_WriteStrClient( Client, ERR_NOTREGISTERED_MSG, Client_ID( Client ));
|
||||||
|
|
||||||
/* Falsche Anzahl Parameter? */
|
/* Keine Parameter? */
|
||||||
if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
if( Req->argc < 1 ) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
||||||
|
|
||||||
/* "Ziel-Client" bzw. Channel suchen */
|
/* Ziel suchen: Client bzw. Channel */
|
||||||
chan = NULL;
|
if( Client_IsValidNick( Req->argv[0] )) cl = Client_Search( Req->argv[0] );
|
||||||
target = Client_Search( Req->argv[0] );
|
if( Channel_IsValidName( Req->argv[0] )) chan = Channel_Search( Req->argv[0] );
|
||||||
if( ! target )
|
|
||||||
{
|
/* Kein Ziel gefunden? */
|
||||||
chan = Channel_Search( Req->argv[0] );
|
if(( ! cl ) && ( ! chan )) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
|
||||||
}
|
|
||||||
|
|
||||||
/* Falsche Anzahl Parameter? */
|
/* Falsche Anzahl Parameter? */
|
||||||
if( target && ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
if(( cl ) && ( Req->argc > 2 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
||||||
if( chan && ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
if(( chan ) && ( Req->argc > 3 )) return IRC_WriteStrClient( Client, ERR_NEEDMOREPARAMS_MSG, Client_ID( Client ), Req->command );
|
||||||
|
|
||||||
if( chan )
|
|
||||||
{
|
|
||||||
/* Channel Modes kennen wir noch nicht ... */
|
|
||||||
Log( LOG_DEBUG, "MODE for channel \"%s\" ignored ...", Channel_Name( chan ));
|
|
||||||
return CONNECTED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Wer ist der Anfragende? */
|
/* Wenn Anfragender ein User ist: Zugriff erlaubt? */
|
||||||
if( Client_Type( Client ) == CLIENT_USER )
|
if( Client_Type( Client ) == CLIENT_USER )
|
||||||
{
|
{
|
||||||
/* User: MODE ist nur fuer sich selber zulaessig */
|
if( cl )
|
||||||
if( target != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
|
{
|
||||||
}
|
/* MODE ist nur fuer sich selber zulaessig! */
|
||||||
else
|
if( cl != Client ) return IRC_WriteStrClient( Client, ERR_USERSDONTMATCH_MSG, Client_ID( Client ));
|
||||||
{
|
}
|
||||||
/* Server: gibt es den Client ueberhaupt? */
|
if( chan )
|
||||||
if( ! target ) return IRC_WriteStrClient( Client, ERR_NOSUCHNICK_MSG, Client_ID( Client ), Req->argv[0] );
|
{
|
||||||
|
/* Darf der User die Channel-Modes ermitteln? */
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Werden die Modes erfragt? */
|
/* Werden die Modes "nur" erfragt? */
|
||||||
if( Req->argc == 1 ) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( Client ));
|
if(( cl ) && ( Req->argc == 1 )) return IRC_WriteStrClient( Client, RPL_UMODEIS_MSG, Client_ID( Client ), Client_Modes( cl ));
|
||||||
|
if(( chan ) && ( Req->argc == 1 )) return IRC_WriteStrClient( Client, RPL_UMODEISCHAN_MSG, Client_ID( Client ), Channel_Name( chan ), Channel_Modes( chan ));
|
||||||
|
|
||||||
ptr = Req->argv[1];
|
mode_ptr = Req->argv[1];
|
||||||
|
|
||||||
/* Sollen Modes gesetzt oder geloescht werden? */
|
/* Sollen Modes gesetzt oder geloescht werden? */
|
||||||
if( *ptr == '+' ) set = TRUE;
|
if( *mode_ptr == '+' ) set = TRUE;
|
||||||
else if( *ptr == '-' ) set = FALSE;
|
else if( *mode_ptr == '-' ) set = FALSE;
|
||||||
else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
|
else return IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
|
||||||
|
|
||||||
/* Reply-String mit Aenderungen vorbereiten */
|
/* Reply-String mit Aenderungen vorbereiten */
|
||||||
if( set ) strcpy( new_modes, "+" );
|
if( set ) strcpy( the_modes, "+" );
|
||||||
else strcpy( new_modes, "-" );
|
else strcpy( the_modes, "-" );
|
||||||
|
|
||||||
ptr++;
|
mode_ptr++;
|
||||||
ok = TRUE;
|
ok = TRUE;
|
||||||
x[1] = '\0';
|
x[1] = '\0';
|
||||||
while( *ptr )
|
while( *mode_ptr )
|
||||||
{
|
{
|
||||||
x[0] = '\0';
|
x[0] = '\0';
|
||||||
if( Client_Type( Client ) == CLIENT_SERVER )
|
if( Client_Type( Client ) == CLIENT_SERVER )
|
||||||
{
|
{
|
||||||
x[0] = *ptr;
|
/* Befehl kommt von einem Server, daher
|
||||||
ok = TRUE;
|
* trauen wir ihm "unbesehen" ... */
|
||||||
|
x[0] = *mode_ptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch( *ptr )
|
/* Modes validieren */
|
||||||
|
if( cl )
|
||||||
{
|
{
|
||||||
case 'i':
|
/* User-Modes */
|
||||||
/* invisible */
|
switch( *mode_ptr )
|
||||||
x[0] = 'i';
|
{
|
||||||
break;
|
case 'i':
|
||||||
case 'r':
|
/* invisible */
|
||||||
/* restricted (kann nur gesetzt werden) */
|
x[0] = 'i';
|
||||||
if( set ) x[0] = 'r';
|
break;
|
||||||
else ok = IRC_WriteStrClient( target, ERR_RESTRICTED_MSG, Client_ID( target ));
|
case 'r':
|
||||||
break;
|
/* restricted (kann nur gesetzt werden) */
|
||||||
case 'o':
|
if( set ) x[0] = 'r';
|
||||||
/* operator (kann nur geloescht werden) */
|
else ok = IRC_WriteStrClient( Client, ERR_RESTRICTED_MSG, Client_ID( Client ));
|
||||||
if( ! set )
|
break;
|
||||||
{
|
case 'o':
|
||||||
Client_SetOperByMe( target, FALSE );
|
/* operator (kann nur geloescht werden) */
|
||||||
x[0] = 'o';
|
if( ! set )
|
||||||
}
|
{
|
||||||
else ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
|
Client_SetOperByMe( Client, FALSE );
|
||||||
break;
|
x[0] = 'o';
|
||||||
default:
|
}
|
||||||
ok = IRC_WriteStrClient( target, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( target ));
|
else ok = IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
|
||||||
x[0] = '\0';
|
break;
|
||||||
|
default:
|
||||||
|
ok = IRC_WriteStrClient( Client, ERR_UMODEUNKNOWNFLAG_MSG, Client_ID( Client ));
|
||||||
|
x[0] = '\0';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if( chan )
|
||||||
|
{
|
||||||
|
/* Channel-Modes */
|
||||||
|
Log( LOG_DEBUG, "Channel-Mode '%c' not supported ...", *mode_ptr );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( ! ok ) break;
|
if( ! ok ) break;
|
||||||
|
|
||||||
ptr++;
|
mode_ptr++;
|
||||||
if( ! x[0] ) continue;
|
if( ! x[0] ) continue;
|
||||||
|
|
||||||
/* Okay, gueltigen Mode gefunden */
|
/* Okay, gueltigen Mode gefunden */
|
||||||
if( set )
|
if( cl )
|
||||||
{
|
{
|
||||||
/* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
|
/* Es geht um User-Modes */
|
||||||
if( Client_ModeAdd( target, x[0] )) strcat( new_modes, x );
|
if( set )
|
||||||
|
{
|
||||||
|
/* Mode setzen. Wenn der Client ihn noch nicht hatte: merken */
|
||||||
|
if( Client_ModeAdd( Client, x[0] )) strcat( the_modes, x );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Modes geloescht. Wenn der Client ihn hatte: merken */
|
||||||
|
if( Client_ModeDel( Client, x[0] )) strcat( the_modes, x );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
if( chan )
|
||||||
{
|
{
|
||||||
/* Modes geloescht. Wenn der Client ihn hatte: merken */
|
/* Es geht um Channel-Modes */
|
||||||
if( Client_ModeDel( target, x[0] )) strcat( new_modes, x );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Geanderte Modes? */
|
/* Wurden Modes geaendert? */
|
||||||
if( new_modes[1] )
|
if( the_modes[1] )
|
||||||
{
|
{
|
||||||
if( Client_Type( Client ) == CLIENT_SERVER )
|
if( cl )
|
||||||
{
|
{
|
||||||
/* Modes an andere Server forwarden */
|
if( Client_Type( Client ) == CLIENT_SERVER )
|
||||||
IRC_WriteStrServersPrefix( Client, Client, "MODE %s :%s", Client_ID( target ), new_modes );
|
{
|
||||||
|
/* Modes an andere Server forwarden */
|
||||||
|
IRC_WriteStrServersPrefix( Client, Client, "MODE %s :%s", Client_ID( cl ), the_modes );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Bestaetigung an Client schicken & andere Server informieren */
|
||||||
|
ok = IRC_WriteStrClient( Client, "MODE %s :%s", Client_ID( cl ), the_modes );
|
||||||
|
IRC_WriteStrServers( Client, "MODE %s :%s", Client_ID( cl ), the_modes );
|
||||||
|
}
|
||||||
|
Log( LOG_DEBUG, "User \"%s\": Mode change, now \"%s\".", Client_Mask( cl ), Client_Modes( cl ));
|
||||||
}
|
}
|
||||||
else
|
if( chan )
|
||||||
{
|
{
|
||||||
/* Bestaetigung an Client schicken & andere Server informieren */
|
|
||||||
ok = IRC_WriteStrClient( 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;
|
return ok;
|
||||||
} /* IRC_MODE */
|
} /* IRC_MODE */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user