about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2011-08-19 10:44:26 +0200
committerAlexander Barton <alex@barton.de>2011-08-19 10:44:26 +0200
commit1189200d4a1df4cf338c7d5979c2a54fc7edfc8d (patch)
tree5483de5f352859b650626044e82f459330078221 /src
parent7795b07c53f29bfdcfb2e4ebb5a9d18e283773c0 (diff)
downloadngircd-1189200d4a1df4cf338c7d5979c2a54fc7edfc8d.tar.gz
ngircd-1189200d4a1df4cf338c7d5979c2a54fc7edfc8d.zip
Client_CheckNick(), Client_IsValidNick(): code cleanup
Diffstat (limited to 'src')
-rw-r--r--src/ngircd/client.c57
1 files changed, 37 insertions, 20 deletions
diff --git a/src/ngircd/client.c b/src/ngircd/client.c
index 83c80f84..0f151ac8 100644
--- a/src/ngircd/client.c
+++ b/src/ngircd/client.c
@@ -847,23 +847,32 @@ Client_Away( CLIENT *Client )
 } /* 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
-Client_CheckNick( CLIENT *Client, char *Nick )
+Client_CheckNick(CLIENT *Client, char *Nick)
 {
-	assert( Client != NULL );
-	assert( Nick != NULL );
+	assert(Client != NULL);
+	assert(Nick != NULL);
 
-	if (! Client_IsValidNick( Nick ))
-	{
-		IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
+	if (!Client_IsValidNick(Nick)) {
+		IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
+				   Client_ID(Client), Nick);
 		return false;
 	}
 
-	/* Nick bereits vergeben? */
-	if( Client_Search( Nick ))
-	{
-		/* den Nick gibt es bereits */
-		IRC_WriteStrClient( Client, ERR_NICKNAMEINUSE_MSG, Client_ID( Client ), Nick );
+	/* Nickname already registered? */
+	if (Client_Search(Nick)) {
+		IRC_WriteStrClient(Client, ERR_NICKNAMEINUSE_MSG,
+			Client_ID(Client), Nick);
 		return false;
 	}
 
@@ -1019,23 +1028,31 @@ Client_MyMaxUserCount( void )
 } /* 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
-Client_IsValidNick( const char *Nick )
+Client_IsValidNick(const char *Nick)
 {
 	const char *ptr;
 	static const char goodchars[] = ";0123456789-";
 
-	assert( Nick != NULL );
+	assert (Nick != NULL);
 
-	if( Nick[0] == '#' ) return false;
-	if( strchr( goodchars, Nick[0] )) return false;
-	if( strlen( Nick ) >= Conf_MaxNickLength) return false;
+	if (strchr(goodchars, Nick[0]))
+		return false;
+	if (strlen(Nick ) >= Conf_MaxNickLength)
+		return false;
 
 	ptr = Nick;
-	while( *ptr )
-	{
-		if (( *ptr < 'A' ) && ( ! strchr( goodchars, *ptr ))) return false;
-		if ( *ptr > '}' ) return false;
+	while (*ptr) {
+		if (*ptr < 'A' && !strchr(goodchars, *ptr ))
+			return false;
+		if (*ptr > '}')
+			return false;
 		ptr++;
 	}