]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/client.c
{Add|Del}_Ban_Invite > {Add_To|Del_From}_List(): more generic
[ngircd-alex.git] / src / ngircd / client.c
index 7a6b275da5918ea0030a12f4aa97804d980cd6ee..d1f751d4adff0d3c52e7fa269a82df70479af02c 100644 (file)
@@ -9,10 +9,8 @@
  * Please read the file COPYING, README and AUTHORS for more information.
  */
 
-
 #define __client_c__
 
-
 #include "portab.h"
 
 /**
 
 #include <exp.h>
 
-
 #define GETID_LEN (CLIENT_NICK_LEN-1) + 1 + (CLIENT_USER_LEN-1) + 1 + (CLIENT_HOST_LEN-1) + 1
 
-
 static CLIENT *This_Server, *My_Clients;
 
 static WHOWAS My_Whowas[MAX_WHOWAS];
@@ -323,7 +319,11 @@ Client_SetHostname( CLIENT *Client, const char *Hostname )
        assert( Client != NULL );
        assert( Hostname != NULL );
 
-       strlcpy( Client->host, Hostname, sizeof( Client->host ));
+       if (strlen(Conf_CloakHost)) {
+               strlcpy( Client->host, Conf_CloakHost, sizeof( Client->host ));
+       } else {
+               strlcpy( Client->host, Hostname, sizeof( Client->host ));
+       }
 } /* Client_SetHostname */
 
 
@@ -335,6 +335,11 @@ Client_SetID( CLIENT *Client, const char *ID )
        
        strlcpy( Client->id, ID, sizeof( Client->id ));
 
+       if (Conf_CloakUserToNick) {
+               strlcpy( Client->user, ID, sizeof( Client->user ));
+               strlcpy( Client->info, ID, sizeof( Client->info ));
+       }
+
        /* Hash */
        Client->hash = Hash( Client->id );
 } /* Client_SetID */
@@ -348,7 +353,9 @@ Client_SetUser( CLIENT *Client, const char *User, bool Idented )
        assert( Client != NULL );
        assert( User != NULL );
 
-       if (Idented) {
+       if (Conf_CloakUserToNick) {
+               strlcpy(Client->user, Client->id, sizeof(Client->user));
+       } else if (Idented) {
                strlcpy(Client->user, User, sizeof(Client->user));
        } else {
                Client->user[0] = '~';
@@ -385,7 +392,10 @@ Client_SetInfo( CLIENT *Client, const char *Info )
        assert( Client != NULL );
        assert( Info != NULL );
 
-       strlcpy(Client->info, Info, sizeof(Client->info));
+       if (Conf_CloakUserToNick)
+               strlcpy(Client->info, Client->id, sizeof(Client->info));
+       else
+               strlcpy(Client->info, Info, sizeof(Client->info));
 } /* Client_SetInfo */
 
 
@@ -758,7 +768,7 @@ Client_NextHop( CLIENT *Client )
  * Return ID of a client: "client!user@host"
  * This client ID is used for IRC prefixes, for example.
  * Please note that this function uses a global static buffer, so you can't
- * nest invocations without overwriting erlier results!
+ * nest invocations without overwriting earlier results!
  * @param Client Pointer to client structure
  * @return Pointer to global buffer containing the client ID
  */
@@ -783,7 +793,7 @@ Client_Mask( CLIENT *Client )
  * Return ID of a client with cloaked hostname: "client!user@server-name"
  * This client ID is used for IRC prefixes, for example.
  * Please note that this function uses a global static buffer, so you can't
- * nest invocations without overwriting erlier results!
+ * nest invocations without overwriting earlier results!
  * If the client has not enabled cloaking, the real hostname is used.
  * @param Client Pointer to client structure
  * @return Pointer to global buffer containing the client ID
@@ -837,23 +847,37 @@ 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 );
-
-       if (! Client_IsValidNick( Nick ))
-       {
-               IRC_WriteStrClient( Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID( Client ), Nick );
+       assert(Client != NULL);
+       assert(Nick != NULL);
+
+       if (!Client_IsValidNick(Nick)) {
+               if (strlen(Nick ) >= Conf_MaxNickLength)
+                       IRC_WriteStrClient(Client, ERR_NICKNAMETOOLONG_MSG,
+                                          Client_ID(Client), Nick,
+                                          Conf_MaxNickLength - 1);
+               else
+                       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;
        }
 
@@ -1009,23 +1033,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++;
        }
 
@@ -1182,6 +1214,10 @@ Client_RegisterWhowas( CLIENT *Client )
 
        assert( Client != NULL );
 
+       /* Don't register WHOWAS information when "MorePrivacy" is enabled. */
+       if (Conf_MorePrivacy)
+               return;
+
        now = time(NULL);
        /* Don't register clients that were connected less than 30 seconds. */
        if( now - Client->starttime < 30 )