- user_hash::iterator iter = Instance->clientlist->find(user->nick);
- std::string reason = quitreason;
-
- if (reason.length() > MAXQUIT - 1)
- reason.resize(MAXQUIT - 1);
-
- if (user->registered != REG_ALL)
- if (Instance->unregistered_count)
- Instance->unregistered_count--;
-
- if (IS_LOCAL(user))
- {
- user->Write("ERROR :Closing link (%s@%s) [%s]",user->ident,user->host,reason.c_str());
- if ((!user->sendq.empty()) && (!(*user->GetWriteError())))
- user->FlushWriteBuf();
- }
-
- if (user->registered == REG_ALL)
- {
- user->PurgeEmptyChannels();
- user->WriteCommonExcept("QUIT :%s",reason.c_str());
- FOREACH_MOD_I(Instance,I_OnUserQuit,OnUserQuit(user,reason));
- }
-
- FOREACH_MOD_I(Instance,I_OnUserDisconnect,OnUserDisconnect(user));
-
- if (IS_LOCAL(user))
- {
- if (Instance->Config->GetIOHook(user->GetPort()))
- {
- try
- {
- Instance->Config->GetIOHook(user->GetPort())->OnRawSocketClose(user->fd);
- }
- catch (CoreException& modexcept)
- {
- Instance->Log(DEBUG, "%s threw an exception: %s", modexcept.GetSource(), modexcept.GetReason());
- }
- }
-
- Instance->SE->DelFd(user);
- user->CloseSocket();
- }
-
- /*
- * 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))
- Instance->SNO->WriteToSnoMask('q',"Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
- else
- Instance->SNO->WriteToSnoMask('Q',"Client exiting on server %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,reason.c_str());
- user->AddToWhoWas();
- }
-
- if (iter != Instance->clientlist->end())
- {
- if (IS_LOCAL(user))
- {
- std::vector<userrec*>::iterator x = find(Instance->local_users.begin(),Instance->local_users.end(),user);
- if (x != Instance->local_users.end())
- Instance->local_users.erase(x);
- }
- Instance->clientlist->erase(iter);
- DELETE(user);
- }