From 396c9ef9f7a96934d3227bb7d1d091315e3d4fa8 Mon Sep 17 00:00:00 2001 From: brain Date: Thu, 10 Aug 2006 14:43:29 +0000 Subject: FindNick, FindChan, ChanModes, UserList, CountInvisible, PurgeEmptyChannels, GetClass, WriteOpers, GetServerDescription -> into classes ServerConfig takes InspIRCd pointer in its constructor git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4832 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/users.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 59 insertions(+), 9 deletions(-) (limited to 'src/users.cpp') diff --git a/src/users.cpp b/src/users.cpp index 7fcda61a9..baef05e28 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -497,7 +497,7 @@ bool userrec::AddBuffer(const std::string &a) if (recvq.length() > (unsigned)this->recvqmax) { this->SetWriteError("RecvQ exceeded"); - WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax); + ServerInstance->WriteOpers("*** User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->recvqmax); return false; } @@ -554,7 +554,7 @@ void userrec::AddWriteBuf(const std::string &data) * to repeatedly add the text to the sendq! */ this->SetWriteError("SendQ exceeded"); - WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax); + ServerInstance->WriteOpers("*** User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->sendqmax); return; } @@ -664,7 +664,7 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quit if (user->registered == REG_ALL) { - purge_empty_chans(user); + user->PurgeEmptyChannels(); FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason)); user->WriteCommonExcept("QUIT :%s",reason.c_str()); } @@ -693,7 +693,7 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quit } /* - * this must come before the WriteOpers so that it doesnt try to fill their buffer with anything + * this must come before the ServerInstance->WriteOpers so that it doesnt try to fill their buffer with anything * if they were an oper with +s. * * XXX - @@ -703,7 +703,7 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quit if (user->registered == REG_ALL) { if (IS_LOCAL(user)) - WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str()); + Instance->WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str()); user->AddToWhoWas(); } @@ -970,7 +970,7 @@ void userrec::FullConnect(CullList* Goners) ServerInstance->stats->statsConnects++; this->idle_lastmsg = TIME; - ConnectClass a = GetClass(this); + ConnectClass a = this->GetClass(); if (a.type == CC_DENY) { @@ -987,13 +987,13 @@ void userrec::FullConnect(CullList* Goners) if (this->LocalCloneCount() > a.maxlocal) { Goners->AddItem(this, "No more connections allowed from your host via this connect class (local)"); - WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString()); + ServerInstance->WriteOpers("*** WARNING: maximum LOCAL connections (%ld) exceeded for IP %s", a.maxlocal, this->GetIPString()); return; } else if (this->GlobalCloneCount() > a.maxglobal) { Goners->AddItem(this, "No more connections allowed from your host via this connect class (global)"); - WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString()); + ServerInstance->WriteOpers("*** WARNING: maximum GLOBAL connections (%ld) exceeded for IP %s",a.maxglobal, this->GetIPString()); return; } @@ -1061,7 +1061,7 @@ void userrec::FullConnect(CullList* Goners) FOREACH_MOD(I_OnUserConnect,OnUserConnect(this)); FOREACH_MOD(I_OnGlobalConnect,OnGlobalConnect(this)); this->registered = REG_ALL; - WriteOpers("*** Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString()); + ServerInstance->WriteOpers("*** Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString()); } /** userrec::UpdateNick() @@ -1713,3 +1713,53 @@ void userrec::SplitChanList(userrec* dest, const std::string &cl) } +/* looks up a users password for their connection class (/ tags) + * 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 + */ +ConnectClass& userrec::GetClass() +{ + for (ClassVector::iterator i = ServerInstance->Config->Classes.begin(); i != ServerInstance->Config->Classes.end(); i++) + { + if ((match(this->GetIPString(),i->host.c_str(),true)) || (match(this->host,i->host.c_str()))) + return *i; + } + + return *(ServerInstance->Config->Classes.begin()); +} + +void userrec::PurgeEmptyChannels() +{ + std::vector to_delete; + + // firstly decrement the count on each channel + for (std::vector::iterator f = this->chans.begin(); f != this->chans.end(); f++) + { + ucrec* uc = *f; + if (uc->channel) + { + if (uc->channel->DelUser(this) == 0) + { + /* No users left in here, mark it for deletion */ + to_delete.push_back(uc->channel); + uc->channel = NULL; + } + } + } + + for (std::vector::iterator n = to_delete.begin(); n != to_delete.end(); n++) + { + chanrec* thischan = *n; + chan_hash::iterator i2 = ServerInstance->chanlist.find(thischan->name); + if (i2 != ServerInstance->chanlist.end()) + { + FOREACH_MOD(I_OnChannelDelete,OnChannelDelete(i2->second)); + DELETE(i2->second); + ServerInstance->chanlist.erase(i2); + } + } + + this->UnOper(); +} + -- cgit v1.2.3