- try
- {
- if ((this->fd == FD_MAGIC_NUMBER) || (*this->GetWriteError()))
- {
- sendq = "";
- }
- if ((sendq.length()) && (this->fd != FD_MAGIC_NUMBER))
- {
- int old_sendq_length = sendq.length();
- const char* tb = this->sendq.c_str();
- int n_sent = write(this->fd,tb,this->sendq.length());
- if (n_sent == -1)
- {
- if (errno == EAGAIN)
- {
- ServerInstance->Log(DEBUG,"EAGAIN, want write");
- this->ServerInstance->SE->WantWrite(this);
- }
- else
- {
- this->QuitUser(ServerInstance, this, strerror(errno));
- return;
- }
- }
- else
- {
- /*ServerInstance->Log(DEBUG,"Wrote: %d of %d: %s", n_sent, old_sendq_length, sendq.substr(0, n_sent).c_str());*/
- // advance the queue
- tb += n_sent;
- this->sendq = tb;
- // update the user's stats counters
- this->bytes_out += n_sent;
- this->cmds_out++;
- if (n_sent != old_sendq_length)
- {
- ServerInstance->Log(DEBUG,"Not all written, want write");
- this->ServerInstance->SE->WantWrite(this);
- }
- }
- }
- }
-
- catch (...)
- {
- ServerInstance->Log(DEBUG,"Exception in userrec::FlushWriteBuf()");
- }
-}
-
-void userrec::SetWriteError(const std::string &error)
-{
- try
- {
- ServerInstance->Log(DEBUG,"SetWriteError: %s",error.c_str());
- // don't try to set the error twice, its already set take the first string.
- if (!this->WriteError.length())
- {
- ServerInstance->Log(DEBUG,"Setting error string for %s to '%s'",this->nick,error.c_str());
- this->WriteError = error;
- }
- }
-
- catch (...)
- {
- ServerInstance->Log(DEBUG,"Exception in userrec::SetWriteError()");
- }
-}
-
-const char* userrec::GetWriteError()
-{
- return this->WriteError.c_str();
-}
-
-void userrec::Oper(const std::string &opertype)
-{
- try
- {
- this->modes[UM_OPERATOR] = 1;
- this->WriteServ("MODE %s :+o", this->nick);
- FOREACH_MOD(I_OnOper, OnOper(this, opertype));
- ServerInstance->Log(DEFAULT,"OPER: %s!%s@%s opered as type: %s", this->nick, this->ident, this->host, opertype.c_str());
- strlcpy(this->oper, opertype.c_str(), NICKMAX - 1);
- ServerInstance->all_opers.push_back(this);
- FOREACH_MOD(I_OnPostOper,OnPostOper(this, opertype));
- }
-
- catch (...)
- {
- ServerInstance->Log(DEBUG,"Exception in userrec::Oper()");
- }
-}
-
-void userrec::UnOper()
-{
- try
- {
- if (*this->oper)
- {
- *this->oper = 0;
- this->modes[UM_OPERATOR] = 0;
- for (std::vector<userrec*>::iterator a = ServerInstance->all_opers.begin(); a < ServerInstance->all_opers.end(); a++)
- {
- if (*a == this)
- {
- ServerInstance->Log(DEBUG,"Oper removed from optimization list");
- ServerInstance->all_opers.erase(a);
- return;
- }
- }
- }
- }
-
- catch (...)
- {
- ServerInstance->Log(DEBUG,"Exception in userrec::UnOper()");
- }
-}
-
-void userrec::QuitUser(InspIRCd* Instance, userrec *user, const std::string &quitreason)
-{
- user_hash::iterator iter = Instance->clientlist.find(user->nick);
- std::string reason = quitreason;