]> arthur.barton.de Git - ngircd.git/blobdiff - src/ngircd/irc-login.c
Make real use of the CLIENT_SERVICE client type.
[ngircd.git] / src / ngircd / irc-login.c
index 0f3b83a962a069d47f6035dca15e4deb8269088a..9a04a3f74cf29c3eba66208904f8615fbf520c47 100644 (file)
@@ -180,22 +180,17 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
        assert( Client != NULL );
        assert( Req != NULL );
 
-#ifndef STRICT_RFC
        /* Some IRC clients, for example BitchX, send the NICK and USER
         * commands in the wrong order ... */
-       if( Client_Type( Client ) == CLIENT_UNKNOWN
-           || Client_Type( Client ) == CLIENT_GOTPASS
-           || Client_Type( Client ) == CLIENT_GOTNICK
-           || Client_Type( Client ) == CLIENT_GOTUSER
-           || Client_Type( Client ) == CLIENT_USER
-           || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
-#else
-       if( Client_Type( Client ) == CLIENT_UNKNOWN
-           || Client_Type( Client ) == CLIENT_GOTPASS
-           || Client_Type( Client ) == CLIENT_GOTNICK
-           || Client_Type( Client ) == CLIENT_USER
-           || ( Client_Type( Client ) == CLIENT_SERVER && Req->argc == 1 ))
+       if(Client_Type(Client) == CLIENT_UNKNOWN
+           || Client_Type(Client) == CLIENT_GOTPASS
+           || Client_Type(Client) == CLIENT_GOTNICK
+#ifndef STRICT_RFC
+           || Client_Type(Client) == CLIENT_GOTUSER
 #endif
+           || Client_Type(Client) == CLIENT_USER
+           || Client_Type(Client) == CLIENT_SERVICE
+           || (Client_Type(Client) == CLIENT_SERVER && Req->argc == 1))
        {
                /* User registration or change of nickname */
 
@@ -243,9 +238,9 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
                                return CONNECTED;
                }
 
-               if(( Client_Type( target ) != CLIENT_USER )
-                  && ( Client_Type( target ) != CLIENT_SERVER ))
-               {
+               if (Client_Type(target) != CLIENT_USER &&
+                   Client_Type(target) != CLIENT_SERVICE &&
+                   Client_Type(target) != CLIENT_SERVER) {
                        /* New client */
                        Log( LOG_DEBUG, "Connection %d: got valid NICK command ...", 
                             Client_Conn( Client ));
@@ -259,25 +254,22 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
                                return Hello_User( Client );
                        else
                                Client_SetType( Client, CLIENT_GOTNICK );
-               }
-               else
-               {
+               } else {
                        /* Nickname change */
                        if (Client_Conn(target) > NONE) {
                                /* Local client */
                                Log(LOG_INFO,
-                                   "User \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
-                                   Client_Mask(target), Client_Conn(target),
-                                   Client_ID(target), Req->argv[0]);
+                                   "%s \"%s\" changed nick (connection %d): \"%s\" -> \"%s\".",
+                                   Client_TypeText(target), Client_Mask(target),
+                                   Client_Conn(target), Client_ID(target),
+                                   Req->argv[0]);
                                Conn_UpdateIdle(Client_Conn(target));
-                       }
-                       else
-                       {
+                       } else {
                                /* Remote client */
-                               Log( LOG_DEBUG,
-                                    "User \"%s\" changed nick: \"%s\" -> \"%s\".",
-                                    Client_Mask( target ), Client_ID( target ),
-                                    Req->argv[0] );
+                               LogDebug("%s \"%s\" changed nick: \"%s\" -> \"%s\".",
+                                        Client_TypeText(target),
+                                        Client_Mask(target), Client_ID(target),
+                                        Req->argv[0]);
                        }
 
                        /* Inform all users and servers (which have to know)
@@ -367,18 +359,12 @@ IRC_NICK( CLIENT *Client, REQUEST *Req )
                 * other servers about the new user.
                 * RFC 1459: announce the new client only after receiving the
                 * USER command, first we need more information! */
-               if (Req->argc >= 7) {
-                       modes = Client_Modes(c);
-                       LogDebug("User \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
-                               Client_Mask(c), modes, Client_ID(Client),
-                               Client_ID(intr_c), Client_Hops(c),
-                               Client_Hops(c) > 1 ? "s": "");
-                       Introduce_Client(Client, c);
-               } else {
-                       LogDebug("User \"%s\" is beeing registered (RFC 1459) ...",
+               if (Req->argc < 7) {
+                       LogDebug("Client \"%s\" is beeing registered (RFC 1459) ...",
                                 Client_Mask(c));
                        Client_SetType(c, CLIENT_GOTNICK);
-               }
+               } else
+                       Introduce_Client(Client, c);
 
                return CONNECTED;
        }
@@ -459,15 +445,10 @@ IRC_USER(CLIENT * Client, REQUEST * Req)
                LogDebug("Connection %d: got valid USER command for \"%s\".",
                         Client_Conn(Client), Client_Mask(c));
 
-               /* RFC 1459 style user registration? Inform other servers! */
-               if (Client_Type(c) == CLIENT_GOTNICK) {
-                       LogDebug("User \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
-                                Client_Mask(c), Client_Modes(c), Client_ID(Client),
-                                Client_ID(Client_Introducer(c)), Client_Hops(c),
-                                Client_Hops(c) > 1 ? "s": "");
-                       Client_SetType(c, CLIENT_USER);
+               /* RFC 1459 style user registration?
+                * Introduce client to network: */
+               if (Client_Type(c) == CLIENT_GOTNICK)
                        Introduce_Client(Client, c);
-               }
 
                return CONNECTED;
        } else if (Client_Type(Client) == CLIENT_USER) {
@@ -691,17 +672,12 @@ Hello_User(CLIENT * Client)
        if (strcmp(Client_Password(Client), Conf_ServerPwd) != 0) {
                /* Bad password! */
                Log(LOG_ERR,
-                   "User \"%s\" rejected (connection %d): Bad password!",
+                   "Client \"%s\" rejected (connection %d): Bad password!",
                    Client_Mask(Client), Client_Conn(Client));
                Conn_Close(Client_Conn(Client), NULL, "Bad password", true);
                return DISCONNECTED;
        }
 
-       Client_SetType(Client, CLIENT_USER);
-       Log(LOG_NOTICE, "User \"%s\" registered (connection %d).",
-           Client_Mask(Client), Client_Conn(Client));
-
-       /* Inform other servers */
        Introduce_Client(NULL, Client);
 
        if (!IRC_WriteStrClient
@@ -759,6 +735,25 @@ Kill_Nick( char *Nick, char *Reason )
 static void
 Introduce_Client(CLIENT *From, CLIENT *Client)
 {
+       char *type;
+
+       Client_SetType(Client, CLIENT_USER);
+
+       if (From) {
+               if (Conf_IsService(Conf_GetServer(Client_Conn(From)), Client_ID(Client))) {
+                       type = "Service";
+                       Client_SetType(Client, CLIENT_SERVICE);
+               } else
+                       type = "User";
+               LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
+                        type, Client_Mask(Client), Client_Modes(Client),
+                        Client_ID(From), Client_ID(Client_Introducer(Client)),
+                        Client_Hops(Client), Client_Hops(Client) > 1 ? "s": "");
+       } else
+               Log(LOG_NOTICE, "User \"%s\" registered (connection %d).",
+                   Client_Mask(Client), Client_Conn(Client));
+
+       /* Inform other servers */
        IRC_WriteStrServersPrefixFlag_CB(From,
                                From != NULL ? From : Client_ThisServer(),
                                '\0', cb_introduceClient, (void *)Client);