]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/users.cpp
Fix for correct display when removing snomask
[user/henk/code/inspircd.git] / src / users.cpp
index 84f762640d0bee014725444234267c03cdc0cbaf..b919ae759937bcc6e72ba0e7ed499cd2a2767700 100644 (file)
@@ -92,31 +92,47 @@ bool DoneClassesAndTypes(ServerConfig* conf, const char* tag)
        return true;
 }
 
-bool userrec::ProcessNoticeMasks(const char *sm)
+std::string userrec::ProcessNoticeMasks(const char *sm)
 {
-       bool adding = true;
+       bool adding = true, oldadding = false;
        const char *c = sm;
+       std::string output = "";
+
+       ServerInstance->Log(DEBUG,"Process notice masks");
 
        while (c && *c)
        {
+               ServerInstance->Log(DEBUG,"Process notice mask %c",*c);
+               
                switch (*c)
                {
                        case '+':
                                adding = true;
-                               break;
+                       break;
                        case '-':
                                adding = false;
-                               break;
+                       break;
                        default:
-                               if ((*c >= 'A') && (*c <= 'z'))
-                                       this->SetNoticeMask(*c, adding);
-                               break;
+                               if ((*c >= 'A') && (*c <= 'z') && (ServerInstance->SNO->IsEnabled(*c)))
+                               {
+                                       if ((!IsNoticeMaskSet(*c) && adding) || (IsNoticeMaskSet(*c) && !adding))
+                                       {
+                                               if ((oldadding != adding) || (sm == (c+1)))
+                                                       output += (adding ? '+' : '-');
+
+                                               this->SetNoticeMask(*c, adding);
+
+                                               output += *c;
+                                       }
+                               }
+                               oldadding = adding;
+                       break;
                }
 
                *c++;
        }
 
-       return true;
+       return output;
 }
 
 void userrec::StartDNSLookup()
@@ -138,12 +154,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 +177,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 +212,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 +278,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 = "";
@@ -274,6 +291,7 @@ userrec::userrec(InspIRCd* Instance) : ServerInstance(Instance)
        invites.clear();
        chans.resize(MAXCHANS);
        memset(modes,0,sizeof(modes));
+       memset(snomasks,0,sizeof(snomasks));
        
        for (unsigned int n = 0; n < MAXCHANS; n++)
        {
@@ -477,22 +495,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,22 +708,20 @@ void userrec::QuitUser(InspIRCd* Instance, userrec *user,const std::string &quit
                        }
                }
                
-               Instance->SE->DelFd(user->fd);
+               Instance->SE->DelFd(user);
                user->CloseSocket();
        }
 
        /*
-        * this must come before the ServerInstance->WriteOpers so that it doesnt try to fill their buffer with anything
-        * if they were an oper with +s.
-        *
-        * XXX -
-        * In the current implementation, we only show local quits, as we only show local connects. With 
-        * the proposed implmentation of snomasks however, this will likely change in the (near?) future.
+        * 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->WriteOpers("*** Client exiting: %s!%s@%s [%s]",user->nick,user->ident,user->host,reason.c_str());
+                       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();
        }
 
@@ -712,7 +730,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 +889,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 +933,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;
@@ -1059,9 +1075,9 @@ void userrec::FullConnect(CullList* Goners)
         * changes dont go out onto the network and produce 'fake direction'.
         */
        FOREACH_MOD(I_OnUserConnect,OnUserConnect(this));
-       FOREACH_MOD(I_OnGlobalConnect,OnGlobalConnect(this));
+       FOREACH_MOD(I_OnPostConnect,OnPostConnect(this));
        this->registered = REG_ALL;
-       ServerInstance->WriteOpers("*** Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
+       ServerInstance->SNO->WriteToSnoMask('c',"Client connecting on port %d: %s!%s@%s [%s]", this->GetPort(), this->nick, this->ident, this->host, this->GetIPString());
 }
 
 /** userrec::UpdateNick()
@@ -1192,7 +1208,6 @@ int userrec::GetProtocolFamily()
 const char* userrec::GetIPString()
 {
        static char buf[1024];
-       static char temp[1024];
 
        if (this->ip == NULL)
                return "";
@@ -1202,6 +1217,8 @@ const char* userrec::GetIPString()
 #ifdef SUPPORT_IP6LINKS
                case AF_INET6:
                {
+                       static char temp[1024];
+               
                        sockaddr_in6* sin = (sockaddr_in6*)this->ip;
                        inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
                        /* IP addresses starting with a : on irc are a Bad Thing (tm) */
@@ -1231,8 +1248,6 @@ const char* userrec::GetIPString()
 
 const char* userrec::GetIPString(char* buf)
 {
-       static char temp[1024];
-
        if (this->ip == NULL)
        {
                *buf = 0;
@@ -1244,6 +1259,8 @@ const char* userrec::GetIPString(char* buf)
 #ifdef SUPPORT_IP6LINKS
                case AF_INET6:
                {
+                       static char temp[1024];
+               
                        sockaddr_in6* sin = (sockaddr_in6*)this->ip;
                        inet_ntop(sin->sin6_family, &sin->sin6_addr, buf, sizeof(buf));
                        /* IP addresses starting with a : on irc are a Bad Thing (tm) */
@@ -1272,20 +1289,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 +1315,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()
@@ -1454,7 +1475,7 @@ void userrec::WriteCommonExcept(const char* text, ...)
 
 void userrec::WriteCommonExcept(const std::string &text)
 {
-       bool quit_munge = true;
+       bool quit_munge = false;
        char oper_quit[MAXBUF];
        char textbuffer[MAXBUF];
 
@@ -1626,14 +1647,55 @@ bool userrec::ChangeDisplayedHost(const char* host)
                        return false;
                FOREACH_MOD(I_OnChangeHost,OnChangeHost(this,host));
        }
+       if (this->ServerInstance->Config->CycleHosts)
+               this->WriteCommonExcept("%s","QUIT :Changing hosts");
+
        strlcpy(this->dhost,host,63);
 
+       if (this->ServerInstance->Config->CycleHosts)
+       {
+               for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+               {
+                       if ((*i)->channel)
+                       {
+                               (*i)->channel->WriteAllExceptSender(this, 0, "JOIN %s", (*i)->channel->name);
+                               std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
+                               if (n.length())
+                                       (*i)->channel->WriteChannelWithServ(this->ServerInstance->Config->ServerName, "MODE %s +%s", (*i)->channel->name, n.c_str());
+                       }
+               }
+       }
+
        if (IS_LOCAL(this))
                this->WriteServ("396 %s %s :is now your hidden host",this->nick,this->dhost);
 
        return true;
 }
 
+bool userrec::ChangeIdent(const char* newident)
+{
+       if (this->ServerInstance->Config->CycleHosts)
+               this->WriteCommonExcept("%s","QUIT :Changing ident");
+
+       strlcpy(this->ident, newident, IDENTMAX+2);
+
+       if (this->ServerInstance->Config->CycleHosts)
+       {
+               for (std::vector<ucrec*>::const_iterator i = this->chans.begin(); i != this->chans.end(); i++)
+               {
+                       if ((*i)->channel)
+                       {
+                               (*i)->channel->WriteAllExceptSender(this, 0, "JOIN %s", (*i)->channel->name);
+                               std::string n = this->ServerInstance->Modes->ModeString(this, (*i)->channel);
+                               if (n.length())
+                                       (*i)->channel->WriteChannelWithServ(this->ServerInstance->Config->ServerName, "MODE %s +%s", (*i)->channel->name, n.c_str());
+                       }
+               }
+       }
+
+       return true;
+}
+
 void userrec::NoticeAll(char* text, ...)
 {
        char textbuffer[MAXBUF];
@@ -1669,7 +1731,7 @@ std::string userrec::ChannelList(userrec* source)
                         */
                        if ((source == this) || (*source->oper && ServerInstance->Config->OperSpyWhois) || (((!rec->channel->modes[CM_PRIVATE]) && (!rec->channel->modes[CM_SECRET])) || (rec->channel->HasUser(source))))
                        {
-                               list.append(rec->channel->GetStatusChar(this)).append(rec->channel->name).append(" ");
+                               list.append(rec->channel->GetPrefixChar(this)).append(rec->channel->name).append(" ");
                        }
                }
        }
@@ -1697,12 +1759,12 @@ void userrec::SplitChanList(userrec* dest, const std::string &cl)
 
                if(pos == std::string::npos)
                {
-                       line += cl.substr(start, length - start);
+                       line.append(cl.substr(start, length - start));
                        break;
                }
                else
                {
-                       line += cl.substr(start, length - start + 1);
+                       line.append(cl.substr(start, length - start + 1));
                }
        }
 
@@ -1739,6 +1801,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 +1856,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);
+}
+