The InspIRCd Project
Home | Developers | Wiki | Forums | Bug Tracker | SVN | Download
Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

cull_list.cpp

Go to the documentation of this file.
00001 /*       +------------------------------------+
00002  *       | Inspire Internet Relay Chat Daemon |
00003  *       +------------------------------------+
00004  *
00005  *  InspIRCd: (C) 2002-2008 InspIRCd Development Team
00006  * See: http://www.inspircd.org/wiki/index.php/Credits
00007  *
00008  * This program is free but copyrighted software; see
00009  *            the file COPYING for details.
00010  *
00011  * ---------------------------------------------------
00012  */
00013 
00014 /* $Core */
00015 
00016 #include "inspircd.h"
00017 #include "cull_list.h"
00018 
00019 CullList::CullList(InspIRCd* Instance) : ServerInstance(Instance)
00020 {
00021         list.clear();
00022 }
00023 
00024 void CullList::AddItem(User* user)
00025 {
00026         list.push_back(user);
00027 }
00028 
00029 void CullList::MakeSilent(User* user)
00030 {
00031         user->quietquit = true;
00032         return;
00033 }
00034 
00035 int CullList::Apply()
00036 {
00037         int n = list.size();
00038         int i = 0;
00039 
00040         while (list.size() && i++ != 100)
00041         {
00042                 std::vector<User *>::iterator a = list.begin();
00043 
00044                 User *u = (*a);
00045                 user_hash::iterator iter = ServerInstance->Users->clientlist->find(u->nick);
00046                 const std::string& preset_reason = u->GetOperQuit();
00047                 std::string reason;
00048                 std::string oper_reason;
00049 
00050                 reason.assign(u->quitmsg, 0, ServerInstance->Config->Limits.MaxQuit);
00051                 oper_reason.assign(preset_reason.empty() ? preset_reason : u->operquitmsg, 0, ServerInstance->Config->Limits.MaxQuit);
00052 
00053                 if (u->registered != REG_ALL)
00054                         if (ServerInstance->Users->unregistered_count)
00055                                 ServerInstance->Users->unregistered_count--;
00056 
00057                 if (IS_LOCAL(u))
00058                 {
00059                         if (!u->sendq.empty())
00060                                 u->FlushWriteBuf();
00061                 }
00062 
00063                 if (u->registered == REG_ALL)
00064                 {
00065                         FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(u, reason, oper_reason));
00066                         u->PurgeEmptyChannels();
00067                         u->WriteCommonQuit(reason, oper_reason);
00068                 }
00069 
00070                 FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(u));
00071 
00072                 if (IS_LOCAL(u))
00073                 {
00074                         if (u->GetIOHook())
00075                         {
00076                                 try
00077                                 {
00078                                         u->GetIOHook()->OnRawSocketClose(u->GetFd());
00079                                 }
00080                                 catch (CoreException& modexcept)
00081                                 {
00082                                         ServerInstance->Logs->Log("CULLLIST",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
00083                                 }
00084                         }
00085 
00086                         ServerInstance->SE->DelFd(u);
00087                         u->CloseSocket();
00088                 }
00089 
00090                 /*
00091                  * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
00092                  * if they were an oper with +sn +qQ.
00093                  */
00094                 if (u->registered == REG_ALL)
00095                 {
00096                         if (IS_LOCAL(u))
00097                         {
00098                                 if (!u->quietquit)
00099                                 {
00100                                         ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]", u->nick.c_str(), u->ident.c_str(), u->host.c_str(), oper_reason.c_str());
00101                                 }
00102                         }
00103                         else
00104                         {
00105                                 if ((!ServerInstance->SilentULine(u->server)) && (!u->quietquit))
00106                                 {
00107                                         ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]", u->server, u->nick.c_str(), u->ident.c_str(), u->host.c_str(), oper_reason.c_str());
00108                                 }
00109                         }
00110                         u->AddToWhoWas();
00111                 }
00112 
00113                 if (iter != ServerInstance->Users->clientlist->end())
00114                 {
00115                         ServerInstance->Users->clientlist->erase(iter);
00116                 }
00117                 else
00118                 {
00119                         ServerInstance->Logs->Log("CULLLIST", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic..");
00120                 }
00121 
00122                 if (IS_LOCAL(u))
00123                 {
00124                         std::vector<User*>::iterator x = find(ServerInstance->Users->local_users.begin(),ServerInstance->Users->local_users.end(),u);
00125                         if (x != ServerInstance->Users->local_users.end())
00126                                 ServerInstance->Users->local_users.erase(x);
00127                         else
00128                         {
00129                                 ServerInstance->Logs->Log("CULLLIST", DEBUG, "Failed to remove user from vector..");
00130                         }
00131                 }
00132 
00133                 delete u;
00134                 list.erase(list.begin());
00135         }
00136 
00137         return n;
00138 }
00139