From bbb7c9eec52bd4176f25004996701d6133f51073 Mon Sep 17 00:00:00 2001 From: w00t Date: Tue, 23 Oct 2007 23:07:24 +0000 Subject: Some initial work towards tying classes to user accounts. This will (in the longer term) allow for things like limits on how many users can fit in a for 1.2 git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@8336 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/users.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'src/users.cpp') diff --git a/src/users.cpp b/src/users.cpp index fec5694a4..49d807ac1 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -188,6 +188,7 @@ User::User(InspIRCd* Instance, const std::string &uid) : ServerInstance(Instance res_forward = res_reverse = NULL; Visibility = NULL; ip = NULL; + MyClass = NULL; chans.clear(); invites.clear(); memset(modes,0,sizeof(modes)); @@ -234,6 +235,13 @@ void User::RemoveCloneCounts() User::~User() { + /* NULL for remote users :) */ + if (this->MyClass) + { + this->MyClass->RefCount--; + ServerInstance->Log(DEBUG, "User destructor -- connect refcount now: %u", this->MyClass->RefCount); + } + this->InvalidateCache(); this->DecrementModes(); if (operquit) @@ -1707,6 +1715,10 @@ unsigned int User::GetMaxChans() * NOTE: If the or tag specifies an ip, and this user resolves, * then their ip will be taken as 'priority' anyway, so for example, * 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) { @@ -1715,11 +1727,19 @@ ConnectClass* User::GetClass(const std::string &explicit_name) for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) { if (explicit_name == i->GetName()) + { return &(*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())))) @@ -1727,15 +1747,27 @@ ConnectClass* User::GetClass(const std::string &explicit_name) if (i->GetPort()) { 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; } else + { + this->MyClass = &(*i); + this->MyClass->RefCount++; + ServerInstance->Log(DEBUG, "User tied to class -- connect refcount now: %u", this->MyClass->RefCount); return &(*i); + } } } } + + /* will only happen for remote users. */ return NULL; } -- cgit v1.2.3