1
0
mirror of https://github.com/osmarks/ngircd.git synced 2024-12-12 18:00:28 +00:00

Client_CheckNick(), Client_IsValidNick(): code cleanup

This commit is contained in:
Alexander Barton 2011-08-19 10:44:26 +02:00
parent 7795b07c53
commit 1189200d4a

View File

@ -847,23 +847,32 @@ Client_Away( CLIENT *Client )
} /* Client_Away */ } /* Client_Away */
/**
* Make sure that a given nickname is valid.
*
* If the nickname is not valid for the given client, this function sends back
* the appropriate error messages.
*
* @param Client Client that wants to change the nickname.
* @param Nick New nick name.
* @returns true if nickname is valid, false otherwise.
*/
GLOBAL bool GLOBAL bool
Client_CheckNick( CLIENT *Client, char *Nick ) Client_CheckNick(CLIENT *Client, char *Nick)
{ {
assert( Client != NULL ); assert(Client != NULL);
assert( Nick != NULL ); assert(Nick != NULL);
if (! Client_IsValidNick( Nick )) if (!Client_IsValidNick(Nick)) {
{ IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick ); Client_ID(Client), Nick);
return false; return false;
} }
/* Nick bereits vergeben? */ /* Nickname already registered? */
if( Client_Search( Nick )) if (Client_Search(Nick)) {
{ IRC_WriteStrClient(Client, ERR_NICKNAMEINUSE_MSG,
/* den Nick gibt es bereits */ Client_ID(Client), Nick);
IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
return false; return false;
} }
@ -1019,23 +1028,31 @@ Client_MyMaxUserCount( void )
} /* Client_MyMaxUserCount */ } /* Client_MyMaxUserCount */
/**
* Check that a given nickname is valid.
*
* @param Nick the nickname to check.
* @returns true if nickname is valid, false otherwise.
*/
GLOBAL bool GLOBAL bool
Client_IsValidNick( const char *Nick ) Client_IsValidNick(const char *Nick)
{ {
const char *ptr; const char *ptr;
static const char goodchars[] = ";0123456789-"; static const char goodchars[] = ";0123456789-";
assert( Nick != NULL ); assert (Nick != NULL);
if( Nick[0] == '#' ) return false; if (strchr(goodchars, Nick[0]))
if( strchr( goodchars, Nick[0] )) return false; return false;
if( strlen( Nick ) >= Conf_MaxNickLength) return false; if (strlen(Nick ) >= Conf_MaxNickLength)
return false;
ptr = Nick; ptr = Nick;
while( *ptr ) while (*ptr) {
{ if (*ptr < 'A' && !strchr(goodchars, *ptr ))
if (( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false; return false;
if ( *ptr > '}' ) return false; if (*ptr > '}')
return false;
ptr++; ptr++;
} }