]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Some more class stuff, blah. Now possible to move a user to a different class via...
authorw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 23 Oct 2007 23:25:49 +0000 (23:25 +0000)
committerw00t <w00t@e03df62e-2008-0410-955e-edbf42e46eb7>
Tue, 23 Oct 2007 23:25:49 +0000 (23:25 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8337 e03df62e-2008-0410-955e-edbf42e46eb7

include/users.h
src/commands/cmd_oper.cpp
src/users.cpp

index 211ae8c0402258f0c9f369fed8e2cc2fad7e6c54..148c673f4b22cbc4ac8d1a652458eeb700563c36 100644 (file)
@@ -925,7 +925,7 @@ class CoreExport User : public connection
 
        /** Call this method to find the matching <connect> for a user, and to check them against it.
         */
-       void CheckClass(const std::string &explicit_class = "");
+       void CheckClass();
 
        /** Use this method to fully connect a user.
         * This will send the message of the day, check G/K/E lines, etc.
@@ -1135,11 +1135,16 @@ class CoreExport User : public connection
         */
        void PurgeEmptyChannels();
 
-       /** Get the connect class which matches this user's host or IP address
-        * @param explicit_name Set this string to tie the user to a specific class name
-        * @return A reference to this user's connect class
+       /** Get the connect class which this user belongs to.
+        * @return A pointer to this user's connect class
         */
-       ConnectClass* GetClass(const std::string &explicit_name = "");
+       ConnectClass *GetClass();
+
+       /** Set the connect class to which this user belongs to.
+        * @param explicit_name Set this string to tie the user to a specific class name. Otherwise, the class is fitted by checking <connect> tags from the configuration file.
+        * @return A reference to this user's current connect class.
+        */
+       ConnectClass *SetClass(const std::string &explicit_name = "");
 
        /** Show the message of the day to this user
         */
index 70376c89429e845121479415cd6ff76adf9114e1..55277b1ba5ad3c57742a3e672d247a2f14ee729c 100644 (file)
@@ -89,7 +89,10 @@ CmdResult CommandOper::Handle (const char** parameters, int, User *user)
                                        if (*HostName)
                                                user->ChangeDisplayedHost(HostName);
                                        if (*ClassName)
-                                               user->CheckClass(ClassName);
+                                       {
+                                               user->SetClass(ClassName);
+                                               user->CheckClass();
+                                       }
                                        found = true;
                                        type_invalid = false;
                                        break;
index 49d807ac1aa7eaead56322be71fcb1e7c221cc92..74c64e730008540d7a0a58358fe897482d0d6767 100644 (file)
@@ -789,7 +789,7 @@ void User::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, in
         * First class check. We do this again in FullConnect after DNS is done, and NICK/USER is recieved.
         * See my note down there for why this is required. DO NOT REMOVE. :) -- w00t
         */
-       ConnectClass* i = New->GetClass();
+       ConnectClass* i = New->SetClass();
 
        if (!i)
        {
@@ -890,9 +890,9 @@ unsigned long User::LocalCloneCount()
 /*
  * Check class restrictions
  */
-void User::CheckClass(const std::string &explicit_class)
+void User::CheckClass()
 {
-       ConnectClass* a = this->GetClass(explicit_class);
+       ConnectClass* a = this->MyClass;
 
        if ((!a) || (a->GetType() == CC_DENY))
        {
@@ -933,12 +933,12 @@ void User::FullConnect()
         * may put the user into a totally seperate class with different restrictions! so we *must* check again.
         * Don't remove this! -- w00t
         */
-       this->CheckClass();
+       this->SetClass();
        
        /* Check the password, if one is required by the user's connect class.
         * This CANNOT be in CheckClass(), because that is called prior to PASS as well!
         */
-       if ((!this->GetClass()->GetPass().empty()) && (!this->haspassed))
+       if ((!this->MyClass->GetPass().empty()) && (!this->haspassed))
        {
                User::QuitUser(ServerInstance, this, "Invalid password");
                return;
@@ -1711,35 +1711,34 @@ unsigned int User::GetMaxChans()
        return this->MaxChans;
 }
 
-/* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
+
+/*
+ * Sets a user's connection class.
+ * If the class name is provided, it will be used. Otherwise, the class will be guessed using host/ip/ident/etc.
  * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
  * then their ip will be taken as 'priority' anyway, so for example,
  * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
- *
- * NOTE: This will CACHE (i.e. once a user is in a class, subsequent calls will return the
- * same class value.
- * NOTE 2: As of 1.2, explicit_name is DEPRECATED, as we now tie users to classes :)
  */
-ConnectClass* User::GetClass(const std::string &explicit_name)
+ConnectClass* User::SetClass(const std::string &explicit_name)
 {
+       if (this->MyClass)
+       {
+               ServerInstance->Log(DEBUG, "Untying user from connect class -- refcount: %u", this->MyClass->RefCount);
+               this->MyClass->RefCount--;
+       }
+
        if (!explicit_name.empty())
        {
                for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
                {
                        if (explicit_name == i->GetName())
                        {
-                               return &(*i);
+                               this->MyClass = &(*i);
                        }
                }
        }
        else
        {
-               if (this->MyClass)
-                       return this->MyClass;
-
-               if (!IS_LOCAL(this))
-                       return NULL;
-
                for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++)
                {
                        if (((match(this->GetIPString(),i->GetHost().c_str(),true)) || (match(this->host,i->GetHost().c_str()))))
@@ -1749,9 +1748,6 @@ ConnectClass* User::GetClass(const std::string &explicit_name)
                                        if (this->GetPort() == i->GetPort())
                                        {
                                                this->MyClass = &(*i);
-                                               this->MyClass->RefCount++;
-                                               ServerInstance->Log(DEBUG, "User tied to class -- connect refcount now: %u", this->MyClass->RefCount);
-                                               return &(*i);
                                        }
                                        else
                                                continue;
@@ -1759,16 +1755,25 @@ ConnectClass* User::GetClass(const std::string &explicit_name)
                                else
                                {
                                        this->MyClass = &(*i);
-                                       this->MyClass->RefCount++;
-                                       ServerInstance->Log(DEBUG, "User tied to class -- connect refcount now: %u", this->MyClass->RefCount);
-                                       return &(*i);
                                }
                        }
                }
        }
 
+       this->MyClass->RefCount++;
+       ServerInstance->Log(DEBUG, "User tied to class -- connect refcount now: %u", this->MyClass->RefCount);
        /* will only happen for remote users. */
-       return NULL;
+       return this->MyClass;
+}
+
+/* looks up a users password for their connection class (<ALLOW>/<DENY> tags)
+ * NOTE: If the <ALLOW> or <DENY> tag specifies an ip, and this user resolves,
+ * then their ip will be taken as 'priority' anyway, so for example,
+ * <connect allow="127.0.0.1"> will match joe!bloggs@localhost
+ */
+ConnectClass* User::GetClass()
+{
+       return this->MyClass;
 }
 
 void User::PurgeEmptyChannels()