X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=3b02e82b9b0e324625999803c200420f5ee37e30;hb=b83765d756c2568d15b87654963b5237d0482367;hp=43d09554d561b82cd421013343a8630955d46b72;hpb=b6641a519f2c3664fa44c2fa86fef6426d3324a5;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index 43d09554d..3b02e82b9 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -138,12 +138,12 @@ UserResolver::UserResolver(InspIRCd* Instance, userrec* user, std::string to_res Resolver(Instance, to_resolve, forward ? DNS_QUERY_FORWARD : DNS_QUERY_REVERSE), bound_user(user) { this->fwd = forward; - this->bound_fd = user->fd; + this->bound_fd = user->GetFd(); } void UserResolver::OnLookupComplete(const std::string &result) { - if ((!this->fwd) && (ServerInstance->fd_ref_table[this->bound_fd] == this->bound_user)) + if ((!this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)) { ServerInstance->Log(DEBUG,"Commencing forward lookup"); this->bound_user->stored_host = result; @@ -161,7 +161,7 @@ void UserResolver::OnLookupComplete(const std::string &result) ServerInstance->Log(DEBUG,"Error in resolver: %s",e.GetReason()); } } - else if ((this->fwd) && (ServerInstance->fd_ref_table[this->bound_fd] == this->bound_user)) + else if ((this->fwd) && (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user)) { /* Both lookups completed */ if (this->bound_user->GetIPString() == result) @@ -196,7 +196,7 @@ void UserResolver::OnLookupComplete(const std::string &result) void UserResolver::OnError(ResolverError e, const std::string &errormessage) { - if (ServerInstance->fd_ref_table[this->bound_fd] == this->bound_user) + if (ServerInstance->SE->GetRef(this->bound_fd) == this->bound_user) { /* Error message here */ this->bound_user->WriteServ("NOTICE Auth :*** Could not resolve your hostname, using your IP address (%s) instead.", this->bound_user->GetIPString()); @@ -262,9 +262,10 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance) *password = *nick = *ident = *host = *dhost = *fullname = *awaymsg = *oper = 0; server = (char*)Instance->FindServerNamePtr(Instance->Config->ServerName); reset_due = ServerInstance->Time(); - lines_in = fd = lastping = signon = idle_lastmsg = nping = registered = 0; + lines_in = lastping = signon = idle_lastmsg = nping = registered = 0; timeout = flood = bytes_in = bytes_out = cmds_in = cmds_out = 0; haspassed = dns_done = false; + fd = -1; recvq = ""; sendq = ""; WriteError = ""; @@ -477,22 +478,24 @@ bool userrec::HasPermission(const std::string &command) return false; } - -bool userrec::AddBuffer(const std::string &a) +/** NOTE: We cannot pass a const reference to this method. + * The string is changed by the workings of the method, + * so that if we pass const ref, we end up copying it to + * something we can change anyway. Makes sense to just let + * the compiler do that copy for us. + */ +bool userrec::AddBuffer(std::string a) { - std::string b = ""; + std::string::size_type i = a.rfind('\r'); - /* NB: std::string is arsey about \r and \n and tries to translate them - * somehow, so we CANNOT use std::string::find() here :( - */ - for (std::string::const_iterator i = a.begin(); i != a.end(); i++) + while (i != std::string::npos) { - if (*i != '\r') - b += *i; + a.erase(i, 1); + i = a.rfind('\r'); } - if (b.length()) - recvq.append(b); + if (a.length()) + recvq.append(a); if (recvq.length() > (unsigned)this->recvqmax) { @@ -688,7 +691,7 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quit } } - Instance->SE->DelFd(user->fd); + Instance->SE->DelFd(user); user->CloseSocket(); } @@ -712,7 +715,6 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quit Instance->Log(DEBUG,"deleting user hash value %lx",(unsigned long)user); if (IS_LOCAL(user)) { - Instance->fd_ref_table[user->fd] = NULL; if (find(Instance->local_users.begin(),Instance->local_users.end(),user) != Instance->local_users.end()) Instance->local_users.erase(find(Instance->local_users.begin(),Instance->local_users.end(),user)); } @@ -872,7 +874,6 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, _new->sendqmax = class_sqmax; _new->recvqmax = class_rqmax; - Instance->fd_ref_table[socket] = _new; Instance->local_users.push_back(_new); if (Instance->local_users.size() > Instance->Config->SoftLimit) @@ -917,7 +918,7 @@ void userrec::AddClient(InspIRCd* Instance, int socket, int port, bool iscached, if (socket > -1) { - if (!Instance->SE->AddFd(socket,true,X_ESTAB_CLIENT)) + if (!Instance->SE->AddFd(_new)) { userrec::QuitUser(Instance, _new, "Internal error handling connection"); return; @@ -1272,20 +1273,24 @@ const char* userrec::GetIPString(char* buf) return ""; } - -void userrec::Write(const std::string &text) +/** NOTE: We cannot pass a const reference to this method. + * The string is changed by the workings of the method, + * so that if we pass const ref, we end up copying it to + * something we can change anyway. Makes sense to just let + * the compiler do that copy for us. + */ +void userrec::Write(std::string text) { if ((this->fd < 0) || (this->fd > MAX_DESCRIPTORS)) return; - std::string crlf = text; - crlf.append("\r\n"); + text.append("\r\n"); if (ServerInstance->Config->GetIOHook(this->GetPort())) { try { - ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, crlf.data(), crlf.length()); + ServerInstance->Config->GetIOHook(this->GetPort())->OnRawSocketWrite(this->fd, text.data(), text.length()); } catch (ModuleException& modexcept) { @@ -1294,9 +1299,9 @@ void userrec::Write(const std::string &text) } else { - this->AddWriteBuf(crlf); + this->AddWriteBuf(text); } - ServerInstance->stats->statsSent += crlf.length(); + ServerInstance->stats->statsSent += text.length(); } /** Write() @@ -1739,6 +1744,7 @@ void userrec::PurgeEmptyChannels() ucrec* uc = *f; if (uc->channel) { + uc->channel->RemoveAllPrefixes(this); if (uc->channel->DelUser(this) == 0) { /* No users left in here, mark it for deletion */ @@ -1793,3 +1799,9 @@ void userrec::ShowRULES() this->WriteServ("NOTICE %s :End of %s rules.",this->nick,ServerInstance->Config->ServerName); } +void userrec::HandleEvent(EventType et) +{ + /* WARNING: May delete this user! */ + ServerInstance->ProcessUser(this); +} +