]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd.cpp
Tidied up zline stuff
[user/henk/code/inspircd.git] / src / inspircd.cpp
index e2adcce16f9193e1dfcf6336d61755bcce0340a7..c42306a30302408c7a979556ff8b7db550da59c1 100644 (file)
@@ -850,6 +850,12 @@ void WriteCommon(userrec *u, char* text, ...)
                         }
                 }
         }
+       // if the user was not in any channels, no users will receive the text. Make sure the user
+       // receives their OWN message for WriteCommon
+       if (!already_sent.size())
+       {
+               WriteFrom(u->fd,u,"%s",textbuffer);
+       }
 }
 
 /* write a formatted string to all users who share at least one common
@@ -2678,18 +2684,45 @@ void ConnectUser(userrec *user)
        }
 }
 
-void handle_version(char **parameters, int pcnt, userrec *user)
+std::string GetVersionString()
 {
-       char Revision[] = "$Revision$";
+        char Revision[] = "$Revision$";
+       char versiondata[MAXBUF];
+        char *s1 = Revision;
+        char *savept;
+        char *v2 = strtok_r(s1," ",&savept);
+        s1 = savept;
+        v2 = strtok_r(s1," ",&savept);
+        s1 = savept;
+       snprintf(versiondata,MAXBUF,"%s Rev. %s %s :%s (O=%lu)",VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION);
+       return versiondata;
+}
 
-       char *s1 = Revision;
-       char *savept;
-       char *v2 = strtok_r(s1," ",&savept);
-       s1 = savept;
-       v2 = strtok_r(s1," ",&savept);
-       s1 = savept;
-       
-       WriteServ(user->fd,"351 %s :%s Rev. %s %s :%s (O=%lu)",user->nick,VERSION,v2,ServerName,SYSTEM,(unsigned long)OPTIMISATION);
+void handle_version(char **parameters, int pcnt, userrec *user)
+{
+       if (!pcnt)
+       {
+               WriteServ(user->fd,"351 %s :%s",user->nick,GetVersionString().c_str());
+       }
+       else
+       {
+                for (int j = 0; j < 32; j++)
+                {
+                        if (me[j] != NULL)
+                        {
+                                for (int x = 0; x < me[j]->connectors.size(); x++)
+                                {
+                                        if (match(me[j]->connectors[x].GetServerName().c_str(),parameters[0]))
+                                        {
+                                               WriteServ(user->fd,"351 %s :%s",user->nick,me[j]->connectors[x].GetVersionString().c_str());
+                                               return;
+                                       }
+                               }
+                       }
+               }
+               WriteServ(user->fd,"402 %s %s :No such server",user->nick,parameters[0]);
+       }
+       return;
 }
 
 
@@ -3308,6 +3341,7 @@ void DoSync(serverrec* serv, char* tcp_host)
 
        NetSendMyRoutingTable();
 
+       // send all routing table and uline voodoo. The ordering of these commands is IMPORTANT!
         for (int j = 0; j < 32; j++)
         {
                 if (me[j] != NULL)
@@ -3323,6 +3357,11 @@ void DoSync(serverrec* serv, char* tcp_host)
                 }
         }
 
+       // send our version for the remote side to cache
+       snprintf(data,MAXBUF,"v %s %s",ServerName,GetVersionString().c_str());
+       serv->SendPacket(data,tcp_host);
+
+       // sync the users and channels, give the modules a look-in.
        for (user_hash::iterator u = clientlist.begin(); u != clientlist.end(); u++)
        {
                snprintf(data,MAXBUF,"N %lu %s %s %s %s +%s %s %s :%s",(unsigned long)u->second->age,u->second->nick,u->second->host,u->second->dhost,u->second->ident,u->second->modes,u->second->ip,u->second->server,u->second->fullname);
@@ -3824,7 +3863,7 @@ int InspIRCd(void)
         tvs.tv_sec = 0;
        tv.tv_sec = 0;
        tv.tv_usec = 10000L;
-        char data[10240];
+        char data[65535];
        timeval tval;
        fd_set sfd;
         tval.tv_usec = 10000L;
@@ -4026,9 +4065,7 @@ int InspIRCd(void)
                                result = EAGAIN;
                                if ((count2a->second->fd != FD_MAGIC_NUMBER) && (count2a->second->fd != -1) && (FD_ISSET (count2a->second->fd, &sfd)))
                                {
-                                       memset(data, 0, 10240);
-                                       result = read(count2a->second->fd, data, 10240);
-                                       
+                                       result = read(count2a->second->fd, data, 65535);
                                        if (result)
                                        {
                                                // perform a check on the raw buffer as an array (not a string!) to remove
@@ -4039,40 +4076,55 @@ int InspIRCd(void)
                                                        if ((data[checker] == 0) || (data[checker] == 7))
                                                                data[checker] = ' ';
                                                }
+                                               if (result > 0)
+                                                       data[result] = '\0';
                                                userrec* current = count2a->second;
                                                int currfd = current->fd;
-                                               char* l = strtok(data,"\n");
                                                int floodlines = 0;
-                                               while (l)
+                                               current->AddBuffer(data);
+                                               if (current->recvq.length() > NetBufferSize)
                                                {
-                                                       floodlines++;
-                                                       if ((floodlines > current->flood) && (current->flood != 0))
+                                                       if (current->registered == 7)
                                                        {
-                                                               log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
-                                                               WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
-                                                               kill_link(current,"Excess flood");
-                                                               goto label;
+                                                               kill_link(current,"RecvQ exceeded");
                                                        }
-                                                       char sanitized[NetBufferSize];
-                                                       memset(sanitized, 0, NetBufferSize);
-                                                       int ptt = 0;
-                                                       for (int pt = 0; pt < strlen(l); pt++)
+                                                       else
                                                        {
-                                                               if (l[pt] != '\r')
+                                                               WriteOpers("*** Excess flood from %s",current->ip);
+                                                               log(DEFAULT,"Excess flood from: %s",current->ip);
+                                                               add_zline(120,ServerName,"Flood from unregistered connection",current->ip);
+                                                               apply_lines();
+                                                       }
+                                                       goto label;
+                                               }
+                                               // while there are complete lines to process...
+                                               while (current->BufferIsReady())
+                                               {
+                                                       floodlines++;
+                                                       if ((floodlines > current->flood) && (current->flood != 0))
+                                                       {
+                                                               if (current->registered == 7)
                                                                {
-                                                                       sanitized[ptt++] = l[pt];
+                                                                       log(DEFAULT,"Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+                                                                       WriteOpers("*** Excess flood from: %s!%s@%s",current->nick,current->ident,current->host);
+                                                                       kill_link(current,"Excess flood");
                                                                }
+                                                               else
+                                                               {
+                                                                       add_zline(120,ServerName,"Flood from unregistered connection",current->ip);
+                                                                       apply_lines();
+                                                               }
+                                                               goto label;
                                                        }
-                                                       sanitized[ptt] = '\0';
+                                                       char sanitized[MAXBUF];
+                                                       // use GetBuffer to copy single lines into the sanitized string
+                                                       strlcpy(sanitized,current->GetBuffer().c_str(),MAXBUF);
                                                        if (*sanitized)
                                                        {
-
-
                                                                // we're gonna re-scan to check if the nick is gone, after every
                                                                // command - if it has, we're gonna bail
                                                                bool find_again = false;
                                                                process_buffer(sanitized,current);
-       
                                                                // look for the user's record in case it's changed
                                                                for (user_hash::iterator c2 = clientlist.begin(); c2 != clientlist.end(); c2++)
                                                                {
@@ -4088,7 +4140,6 @@ int InspIRCd(void)
                                                                        goto label;
 
                                                        }
-                                                       l = strtok(NULL,"\n");
                                                }
                                                goto label;
                                        }