]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands.cpp
Fixed remote squit
[user/henk/code/inspircd.git] / src / commands.cpp
index 8b024544e4512e671971095947c42e06ac6ab5ee..bd30e5573417bc1414fc79a81a6558943b061daf 100644 (file)
@@ -233,7 +233,7 @@ void handle_kick(char **parameters, int pcnt, userrec *user)
 
        if ((!u) || (!Ptr))
        {
-               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
                return;
        }
        
@@ -385,12 +385,13 @@ void handle_kill(char **parameters, int pcnt, userrec *user)
                        if (iter != clientlist.end())
                        {
                                log(DEBUG,"deleting user hash value %d",iter->second);
-                               if ((iter->second) && (user->registered == 7)) {
-                                       delete iter->second;
-                               }
                                clientlist.erase(iter);
                        }
-                       purge_empty_chans();
+                       if (u->registered == 7)
+                       {
+                               purge_empty_chans(u);
+                       }
+                       delete u;
                }
                else
                {
@@ -404,7 +405,7 @@ void handle_kill(char **parameters, int pcnt, userrec *user)
        }
        else
        {
-               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
        }
 }
 
@@ -518,7 +519,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user)
                        }
                        else
                        {
-                               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+                               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
                        }
                }
                return;
@@ -568,7 +569,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user)
                        }
                        else
                        {
-                               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+                               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
                        }
                }
        }
@@ -599,7 +600,7 @@ void handle_names(char **parameters, int pcnt, userrec *user)
        }
        else
        {
-               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
        }
 }
 
@@ -647,7 +648,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
                else
                {
                        /* no such nick/channel */
-                       WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+                       WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
                }
                return;
        }
@@ -687,7 +688,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
        else
        {
                /* no such nick/channel */
-               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
        }
 }
 
@@ -735,7 +736,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
                else
                {
                        /* no such nick/channel */
-                       WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+                       WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
                }
                return;
        }
@@ -767,7 +768,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
        else
        {
                /* no such nick/channel */
-               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
        }
 }
 
@@ -869,13 +870,13 @@ void handle_whois(char **parameters, int pcnt, userrec *user)
                }
                else
                {
-                       WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+                       WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
                }
        }
        else
        {
                /* no such nick/channel */
-               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
        }
 }
 
@@ -934,15 +935,12 @@ void handle_quit(char **parameters, int pcnt, userrec *user)
        if (iter != clientlist.end())
        {
                clientlist.erase(iter);
-               log(DEBUG,"deleting user hash value %d",iter->second);
-               //if ((user) && (user->registered == 7)) {
-                       //delete user;
-               //}
        }
 
        if (user->registered == 7) {
-               purge_empty_chans();
+               purge_empty_chans(user);
        }
+       delete user;
 }
 
 void handle_who(char **parameters, int pcnt, userrec *user)
@@ -1014,7 +1012,7 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                        }
                        else
                        {
-                               WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+                               WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
                        }
                }
                else
@@ -1282,7 +1280,7 @@ void handle_modules(char **parameters, int pcnt, userrec *user)
                        strlcat(flagstate,", common",MAXBUF);
                if (V.Flags & VF_SERVICEPROVIDER)
                        strlcat(flagstate,", service provider",MAXBUF);
-               if (!strlen(flagstate))
+               if (!flagstate[0])
                        strcpy(flagstate,"  <no flags>");
                strlcpy(modulename,module_names[i].c_str(),256);
                if (strchr(user->modes,'o'))
@@ -1312,7 +1310,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
 
        FOREACH_MOD OnStats(*parameters[0]);
 
-       if (!strcasecmp(parameters[0],"c"))
+       if (*parameters[0] == 'c')
        {
                for (int i = 0; i < ConfValueEnum("link",&config_f); i++)
                {
@@ -1324,7 +1322,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
                }
        }
        
-       if (!strcasecmp(parameters[0],"i"))
+       if (*parameters[0] == 'i')
        {
                int idx = 0;
                for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
@@ -1334,7 +1332,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
                }
        }
        
-       if (!strcasecmp(parameters[0],"y"))
+       if (*parameters[0] == 'y')
        {
                int idx = 0;
                for (ClassVector::iterator i = Classes.begin(); i != Classes.end(); i++)
@@ -1344,7 +1342,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
                }
        }
 
-       if (!strcmp(parameters[0],"U"))
+       if (*parameters[0] == 'U')
        {
                for (int i = 0; i < ConfValueEnum("uline",&config_f); i++)
                {
@@ -1353,7 +1351,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
                }
        }
        
-       if (!strcmp(parameters[0],"P"))
+       if (*parameters[0] == 'P')
        {
                int idx = 0;
                for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
@@ -1368,33 +1366,33 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
        //249 [Brain] :bwoadway-monitor (~wgmon@204.152.186.58) Idle: 18
        }
        
-       if (!strcmp(parameters[0],"k"))
+       if (*parameters[0] == 'k')
        {
                stats_k(user);
        }
 
-       if (!strcmp(parameters[0],"g"))
+       if (*parameters[0] == 'g')
        {
                stats_g(user);
        }
 
-       if (!strcmp(parameters[0],"q"))
+       if (*parameters[0] == 'q')
        {
                stats_q(user);
        }
 
-       if (!strcmp(parameters[0],"Z"))
+       if (*parameters[0] == 'Z')
        {
                stats_z(user);
        }
 
-       if (!strcmp(parameters[0],"e"))
+       if (*parameters[0] == 'e')
        {
                stats_e(user);
        }
 
        /* stats m (list number of times each command has been used, plus bytecount) */
-       if (!strcmp(parameters[0],"m"))
+       if (*parameters[0] == 'm')
        {
                for (int i = 0; i < cmdlist.size(); i++)
                {
@@ -1411,7 +1409,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
        }
 
        /* stats z (debug and memory info) */
-       if (!strcmp(parameters[0],"z"))
+       if (*parameters[0] == 'z')
        {
                WriteServ(user->fd,"249 %s :Users(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,clientlist.size(),clientlist.size()*sizeof(userrec),clientlist.bucket_count());
                WriteServ(user->fd,"249 %s :Channels(HASH_MAP) %d (%d bytes, %d buckets)",user->nick,chanlist.size(),chanlist.size()*sizeof(chanrec),chanlist.bucket_count());
@@ -1424,7 +1422,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
        }
        
        /* stats o */
-       if (!strcmp(parameters[0],"o"))
+       if (*parameters[0] == 'o')
        {
                for (int i = 0; i < ConfValueEnum("oper",&config_f); i++)
                {
@@ -1439,7 +1437,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
        }
        
        /* stats l (show user I/O stats) */
-       if (!strcmp(parameters[0],"l"))
+       if (*parameters[0] == 'l')
        {
                WriteServ(user->fd,"211 %s :server:port nick bytes_in cmds_in bytes_out cmds_out",user->nick);
                for (user_hash::iterator i = clientlist.begin(); i != clientlist.end(); i++)
@@ -1457,7 +1455,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
        }
        
        /* stats u (show server uptime) */
-       if (!strcmp(parameters[0],"u"))
+       if (*parameters[0] == 'u')
        {
                time_t current_time = 0;
                current_time = TIME;
@@ -1540,7 +1538,40 @@ void handle_squit(char **parameters, int pcnt, userrec *user)
        }
        else
        {
-               WriteServ(user->fd,"NOTICE :*** Remote SQUIT not supported yet.");
+               if (!strcasecmp(ServerName,parameters[0]))
+               {
+                       WriteServ(user->fd,"NOTICE %s :*** To take the local server out of the mesh, just use /SQUIT with no parameters instead.",user->nick);
+                       return;
+               }
+               bool have_this_server = false;
+                for (int j = 0; j < 32; j++)
+                {
+                        if (me[j] != NULL)
+                        {
+                                for (int x = 0; x < me[j]->connectors.size(); x++)
+                                {
+                                        if (!strcasecmp(me[j]->connectors[x].GetServerName().c_str(),parameters[0]))
+                                        {
+                                                // found a valid ircd_connector.
+                                               have_this_server = true;
+                                               break;
+                                        }
+                                }
+                        }
+                }
+               if (have_this_server)
+               {
+                       WriteOpers("SQUIT command issued by %s to remove %s from the mesh",user->nick,parameters[0]);
+                       WriteServ(user->fd,"NOTICE %s :*** Removing remote server %s.",user->nick,parameters[0]);
+                       char buffer[MAXBUF];
+                       snprintf(buffer,MAXBUF,"& %s",parameters[0]);
+                       NetSendToAll(buffer);
+                       DoSplit(parameters[0]);
+               }
+               else
+               {
+                       WriteServ(user->fd,"NOTICE %s :*** No such server exists in the mesh.",user->nick);
+               }
        }
 }
 
@@ -1600,10 +1631,12 @@ int operstrcmp(char* data,char* input)
 {
        int MOD_RESULT = 0;
        FOREACH_RESULT(OnOperCompare(data,input))
+       log(DEBUG,"operstrcmp: %d",MOD_RESULT);
        if (MOD_RESULT == 1)
                return 0;
        if (MOD_RESULT == -1)
                return 1;
+       log(DEBUG,"strcmp fallback: '%s' '%s' %d",data,input,strcmp(data,input));
        return strcmp(data,input);
 }
 
@@ -1665,6 +1698,7 @@ void handle_oper(char **parameters, int pcnt, userrec *user)
                         NetSendToAll(global);
                        FOREACH_MOD OnOper(user);
                        log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
+                       AddOper(user);
                }
        }
        else
@@ -1697,7 +1731,7 @@ void handle_nick(char **parameters, int pcnt, userrec *user)
                log(DEBUG,"invalid parameter passed to handle_nick");
                return;
        }
-       if (!strlen(parameters[0]))
+       if (!parameters[0][0])
        {
                log(DEBUG,"zero length new nick passed to handle_nick");
                return;
@@ -1755,7 +1789,7 @@ void handle_nick(char **parameters, int pcnt, userrec *user)
 
                WriteCommon(user,"NICK %s",parameters[0]);
                
-               // Q token must go to ALL servers!!!
+               // N token must go to ALL servers!!!
                char buffer[MAXBUF];
                snprintf(buffer,MAXBUF,"n %s %s",user->nick,parameters[0]);
                NetSendToAll(buffer);
@@ -2048,13 +2082,14 @@ void handle_Q(char token,char* params,serverrec* source,serverrec* reply, char*
                if (iter != clientlist.end())
                {
                        log(DEBUG,"deleting user hash value %d",iter->second);
-                       if ((iter->second) && (user->registered == 7)) {
-                               delete iter->second;
-                       }
                        clientlist.erase(iter);
                }
 
-               purge_empty_chans();
+               if (user->registered == 7)
+               {
+                       purge_empty_chans(user);
+               }
+               delete user;
        }
 }
 
@@ -2064,10 +2099,9 @@ void handle_n(char token,char* params,serverrec* source,serverrec* reply, char*
        char* newnick = strtok(NULL," ");
        
        userrec* user = Find(oldnick);
-       
+
        if (user)
        {
-               WriteCommon(user,"NICK %s",newnick);
                if (is_uline(tcp_host))
                {
                        int MOD_RESULT = 0;
@@ -2086,8 +2120,9 @@ void handle_n(char token,char* params,serverrec* source,serverrec* reply, char*
                        // broadcast this because its a services thingy
                        char buffer[MAXBUF];
                        snprintf(buffer,MAXBUF,"n %s %s",user->nick,newnick);
-                       NetSendToAll(buffer);
+                       NetSendToAllExcept(tcp_host,buffer);
                }
+               WriteCommon(user,"NICK %s",newnick);
                user = ReHashNick(user->nick, newnick);
                if (!user) return;
                if (!user->nick) return;
@@ -3140,8 +3175,6 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                                                        }
                                                }
                                        }
-                                       WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right noe! Possible intrusion attempt!",tcp_host);
-                                       return;
                                }
                        }
                        else {
@@ -3172,7 +3205,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                char Link_SendPass[1024];
                int LinkPort = 0;
 
-               log(DEBUG,"U-token linked server detected.");
+               log(DEBUG,"U-token linked server detected.\n\nservername='%s' password='%s'\n\n",servername,password);
 
                
                 for (int j = 0; j < 32; j++)
@@ -3218,6 +3251,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                                                        if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),tcp_host))
                                                        {
                                                                char buffer[MAXBUF];
+                                                               log(DEBUG,"Found matching link block");
                                                                me[j]->connectors[k].SetDescription(serverdesc);
                                                                me[j]->connectors[k].SetServerName(servername);
                                                                me[j]->connectors[k].SetState(STATE_SERVICES);
@@ -3235,14 +3269,13 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                                                        }
                                                }
                                        }
-                                       WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right noe! Possible intrusion attempt!",tcp_host);
-                                       return;
                                }
                        }
                        else {
                                log(DEBUG,"Server names '%s' and '%s' don't match",Link_ServerName,servername);
                        }
                }
+               log(DEBUG,"No matching link block found");
                char buffer[MAXBUF];
                sprintf(buffer,"E :Access is denied (no matching link block)");
                serv->SendPacket(buffer,tcp_host);