]> arthur.barton.de Git - ngircd-alex.git/blobdiff - src/ngircd/client.c
Implement account login support
[ngircd-alex.git] / src / ngircd / client.c
index a6ada37d7635376c1bdb7296125dfdca55775b0f..32690288529499097c0b6d88c1127774202f51bd 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2012 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2013 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -124,6 +124,8 @@ Client_Exit( void )
        {
                cnt++;
                next = (CLIENT *)c->next;
+               if (c->account_name)
+                       free(c->account_name);
                free( c );
                c = next;
        }
@@ -318,6 +320,8 @@ Client_Destroy( CLIENT *Client, const char *LogMsg, const char *FwdMsg, bool Sen
                                }
                        }
 
+                       if (c->account_name)
+                               free(c->account_name);
                        if (c->cloaked)
                                free(c->cloaked);
                        free( c );
@@ -454,6 +458,21 @@ Client_SetFlags( CLIENT *Client, const char *Flags )
 } /* Client_SetFlags */
 
 
+GLOBAL void
+Client_SetAccountName(CLIENT *Client, const char *AccountName)
+{
+       assert(Client != NULL);
+
+       if (Client->account_name)
+               free(Client->account_name);
+
+       if (*AccountName)
+               Client->account_name = strdup(AccountName);
+       else
+               Client->account_name = NULL;
+}
+
+
 GLOBAL void
 Client_SetAway( CLIENT *Client, const char *Txt )
 {
@@ -973,6 +992,14 @@ Client_Away( CLIENT *Client )
 } /* Client_Away */
 
 
+GLOBAL char *
+Client_AccountName(CLIENT *Client)
+{
+       assert(Client != NULL);
+       return Client->account_name;
+}
+
+
 /**
  * Make sure that a given nickname is valid.
  *
@@ -991,11 +1018,11 @@ Client_CheckNick(CLIENT *Client, char *Nick)
 
        if (!Client_IsValidNick(Nick)) {
                if (strlen(Nick ) >= Conf_MaxNickLength)
-                       IRC_WriteStrClient(Client, ERR_NICKNAMETOOLONG_MSG,
+                       IRC_WriteErrClient(Client, ERR_NICKNAMETOOLONG_MSG,
                                           Client_ID(Client), Nick,
                                           Conf_MaxNickLength - 1);
                else
-                       IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
+                       IRC_WriteErrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
                                           Client_ID(Client), Nick);
                return false;
        }
@@ -1004,7 +1031,7 @@ Client_CheckNick(CLIENT *Client, char *Nick)
            && Client_Type(Client) != CLIENT_SERVICE) {
                /* Make sure that this isn't a restricted/forbidden nickname */
                if (Conf_NickIsBlocked(Nick)) {
-                       IRC_WriteStrClient(Client, ERR_FORBIDDENNICKNAME_MSG,
+                       IRC_WriteErrClient(Client, ERR_FORBIDDENNICKNAME_MSG,
                                           Client_ID(Client), Nick);
                        return false;
                }
@@ -1012,7 +1039,7 @@ Client_CheckNick(CLIENT *Client, char *Nick)
 
        /* Nickname already registered? */
        if (Client_Search(Nick)) {
-               IRC_WriteStrClient(Client, ERR_NICKNAMEINUSE_MSG,
+               IRC_WriteErrClient(Client, ERR_NICKNAMEINUSE_MSG,
                        Client_ID(Client), Nick);
                return false;
        }
@@ -1033,7 +1060,8 @@ Client_CheckID( CLIENT *Client, char *ID )
 
        /* ID too long? */
        if (strlen(ID) > CLIENT_ID_LEN) {
-               IRC_WriteStrClient(Client, ERR_ERRONEUSNICKNAME_MSG, Client_ID(Client), ID);
+               IRC_WriteErrClient(Client, ERR_ERRONEUSNICKNAME_MSG,
+                                  Client_ID(Client), ID);
                return false;
        }
 
@@ -1610,6 +1638,14 @@ Client_Announce(CLIENT * Client, CLIENT * Prefix, CLIENT * User)
                                return DISCONNECTED;
                }
 
+               if (Client_AccountName(User)) {
+                       if (!IRC_WriteStrClientPrefix(Client, Prefix,
+                                       "METADATA %s accountname :%s",
+                                       Client_ID(User),
+                                       Client_AccountName(User)))
+                               return DISCONNECTED;
+               }
+
                if (Conn_GetCertFp(Client_Conn(User))) {
                        if (!IRC_WriteStrClientPrefix(Client, Prefix,
                                        "METADATA %s certfp :%s",