+
+ if (user->registered == REG_ALL)
+ {
+ FOREACH_MOD_I(ServerInstance,I_OnUserQuit,OnUserQuit(user, reason, oper_reason));
+ user->PurgeEmptyChannels();
+ user->WriteCommonQuit(reason, oper_reason);
+ }
+
+ FOREACH_MOD_I(ServerInstance,I_OnUserDisconnect,OnUserDisconnect(user));
+
+ if (user->registered != REG_ALL)
+ if (ServerInstance->Users->unregistered_count)
+ ServerInstance->Users->unregistered_count--;
+
+ if (IS_LOCAL(user))
+ {
+ user->DoWrite();
+ if (user->GetIOHook())
+ {
+ try
+ {
+ user->GetIOHook()->OnStreamSocketClose(user);
+ }
+ catch (CoreException& modexcept)
+ {
+ ServerInstance->Logs->Log("USERS",DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
+ }
+ }
+
+ ServerInstance->SE->DelFd(user);
+ user->Close();
+ // user->Close() will set fd to -1; this breaks IS_LOCAL. Fix
+ user->SetFd(INT_MAX);
+ }
+
+ /*
+ * this must come before the ServerInstance->SNO->WriteToSnoMaskso that it doesnt try to fill their buffer with anything
+ * if they were an oper with +sn +qQ.
+ */
+ if (user->registered == REG_ALL)
+ {
+ if (IS_LOCAL(user))
+ {
+ if (!user->quietquit)
+ {
+ ServerInstance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",
+ user->nick.c_str(), user->ident.c_str(), user->host.c_str(), oper_reason.c_str());
+ }
+ }
+ else
+ {
+ if ((!ServerInstance->SilentULine(user->server)) && (!user->quietquit))
+ {
+ ServerInstance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",
+ user->server, user->nick.c_str(), user->ident.c_str(), user->host.c_str(), oper_reason.c_str());
+ }
+ }
+ user->AddToWhoWas();
+ }
+
+ user_hash::iterator iter = this->clientlist->find(user->nick);
+
+ if (iter != this->clientlist->end())
+ this->clientlist->erase(iter);
+ else
+ ServerInstance->Logs->Log("USERS", DEBUG, "iter == clientlist->end, can't remove them from hash... problematic..");