]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands.cpp
Fixed cosmetic bug in /who
[user/henk/code/inspircd.git] / src / commands.cpp
index b149da7e8fb8984538a710fac7871587aa4b33c4..4ff6edc31ea4bc291b4164af84b879c7457d203a 100644 (file)
@@ -50,6 +50,8 @@
 #include "message.h"
 #include "mode.h"
 #include "xline.h"
+#include "inspstring.h"
+#include "dnsqueue.h"
 
 #ifdef GCC3
 #define nspace __gnu_cxx
@@ -116,28 +118,35 @@ const long duration_y = duration_w * 52;
 
 namespace nspace
 {
-       template<> struct nspace::hash<in_addr>
-       {
-               size_t operator()(const struct in_addr &a) const
-               {
-                       size_t q;
-                       memcpy(&q,&a,sizeof(size_t));
-                       return q;
-               }
-       };
-
-       template<> struct nspace::hash<string>
-       {
-               size_t operator()(const string &s) const
-               {
-                       char a[MAXBUF];
-                       static struct hash<const char *> strhash;
-                       strlcpy(a,s.c_str(),MAXBUF);
-                       strlower(a);
-                       return strhash(a);
-               }
-       };
-}      
+#ifdef GCC34
+        template<> struct hash<in_addr>
+#else
+        template<> struct nspace::hash<in_addr>
+#endif
+        {
+                size_t operator()(const struct in_addr &a) const
+                {
+                        size_t q;
+                        memcpy(&q,&a,sizeof(size_t));
+                        return q;
+                }
+        };
+#ifdef GCC34
+        template<> struct hash<string>
+#else
+        template<> struct nspace::hash<string>
+#endif
+        {
+                size_t operator()(const string &s) const
+                {
+                        char a[MAXBUF];
+                        static struct hash<const char *> strhash;
+                        strlcpy(a,s.c_str(),MAXBUF);
+                        strlower(a);
+                        return strhash(a);
+                }
+        };
+}
 
 
 struct StrHashComp
@@ -754,7 +763,7 @@ void handle_whois(char **parameters, int pcnt, userrec *user)
                        {
                                WriteServ(user->fd,"301 %s %s :%s",user->nick, dest->nick, dest->awaymsg);
                        }
-                       if (strchr(dest->modes,'o'))
+                       if ((strchr(dest->modes,'o')) && (strcmp(dest->oper,"")))
                        {
                                WriteServ(user->fd,"313 %s %s :is %s %s on %s",user->nick, dest->nick,
                                (strchr("aeiou",dest->oper[0]) ? "an" : "a"),dest->oper, Network);
@@ -876,11 +885,11 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                        }
                        if (Ptr)
                        {
-                               WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, Ptr->name);
+                               WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick , parameters[0]);
                        }
                        else
                        {
-                               WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, user->nick);
+                               WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
                        }
                        return;
                }
@@ -905,7 +914,7 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                                                WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
                                        }
                                }
-                               WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, Ptr->name);
+                               WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
                        }
                        else
                        {
@@ -953,7 +962,7 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                                         }
                                 }
                         }
-                        WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, user->nick);
+                        WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
                         return;
                 }
        }
@@ -1479,24 +1488,22 @@ void handle_oper(char **parameters, int pcnt, userrec *user)
        char TypeName[MAXBUF];
        char Hostname[MAXBUF];
        int i,j;
+       bool found = false;
+       bool fail2 = false;
+       char global[MAXBUF];
 
        for (int i = 0; i < ConfValueEnum("oper",&config_f); i++)
        {
                ConfValue("oper","name",i,LoginName,&config_f);
                ConfValue("oper","password",i,Password,&config_f);
+               ConfValue("oper","type",i,OperType,&config_f);
                if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1])))
                {
-                       /* correct oper credentials */
-                       ConfValue("oper","type",i,OperType,&config_f);
-                       WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
-                       WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
-                       WriteServ(user->fd,"MODE %s :+o",user->nick);
-                       char global[MAXBUF];
-                       snprintf(global,MAXBUF,"M %s +o",user->nick);
-                       NetSendToAll(global);
+                       fail2 = true;
                        for (j =0; j < ConfValueEnum("type",&config_f); j++)
                        {
                                ConfValue("type","name",j,TypeName,&config_f);
+
                                if (!strcmp(TypeName,OperType))
                                {
                                        /* found this oper's opertype */
@@ -1505,19 +1512,43 @@ void handle_oper(char **parameters, int pcnt, userrec *user)
                                        ConfValue("type","host",j,Hostname,&config_f);
                                        ChangeDisplayedHost(user,Hostname);
                                        strlcpy(user->oper,TypeName,NICKMAX);
+                                       found = true;
+                                       fail2 = false;
+                                       break;
                                }
                        }
-                       if (!strchr(user->modes,'o'))
-                       {
-                               strcat(user->modes,"o");
-                       }
+               }
+               if (found)
+                       break;
+       }
+       if (found)
+       {
+                /* correct oper credentials */
+                WriteOpers("*** %s (%s@%s) is now an IRC operator of type %s",user->nick,user->ident,user->host,OperType);
+                WriteServ(user->fd,"381 %s :You are now an IRC operator of type %s",user->nick,OperType);
+               if (!strchr(user->modes,'o'))
+               {
+                       strcat(user->modes,"o");
+                       WriteServ(user->fd,"MODE %s :+o",user->nick);
+                        snprintf(global,MAXBUF,"M %s +o",user->nick);
+                        NetSendToAll(global);
                        FOREACH_MOD OnOper(user);
-                       return;
                }
        }
-       /* no such oper */
-       WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
-       WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
+       else
+       {
+               if (!fail2)
+               {
+                       WriteServ(user->fd,"491 %s :Invalid oper credentials",user->nick);
+                       WriteOpers("*** WARNING! Failed oper attempt by %s!%s@%s!",user->nick,user->ident,user->host);
+               }
+               else
+               {
+                       WriteServ(user->fd,"491 %s :Your oper block does not have a valid opertype associated with it",user->nick);
+                       WriteOpers("*** CONFIGURATION ERROR! Oper block mismatch for OperType %s",OperType);
+               }
+       }
+       return;
 }
 
 void handle_nick(char **parameters, int pcnt, userrec *user)
@@ -1608,7 +1639,14 @@ void handle_nick(char **parameters, int pcnt, userrec *user)
        log(DEBUG,"new nick set: %s",user->nick);
        
        if (user->registered < 3)
+       {
                user->registered = (user->registered | 2);
+               // dont attempt to look up the dns until they pick a nick... because otherwise their pointer WILL change
+               // and unless we're lucky we'll get a duff one later on.
+               user->dns_done = (!lookup_dns(user->nick));
+               if (user->dns_done)
+                       log(DEBUG,"Aborting dns lookup of %s because dns server experienced a failure.",user->nick);
+       }
        if (user->registered == 3)
        {
                /* user is registered now, bit 0 = USER command, bit 1 = sent a NICK command */
@@ -2817,7 +2855,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                        ConfValue("link","sendpass",i,Link_SendPass,&config_f);
                        log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
                        LinkPort = atoi(Link_Port);
-                       if (!strcasecmp(Link_ServerName,servername))
+                       if ((!strcasecmp(Link_ServerName,servername)) && (!strcmp(Link_Pass,password)))
                        {
                                // we have a matching link line -
                                // send a 'diminutive' server message back...
@@ -2941,7 +2979,7 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                        ConfValue("link","sendpass",i,Link_SendPass,&config_f);
                        log(DEBUG,"(%d) Comparing against name='%s', ipaddr='%s', port='%s', recvpass='%s'",i,Link_ServerName,Link_IPAddr,Link_Port,Link_Pass);
                        LinkPort = atoi(Link_Port);
-                       if (!strcasecmp(Link_ServerName,servername))
+                       if ((!strcasecmp(Link_ServerName,servername)) && (!strcmp(Link_Pass,password)))
                        {
                                // matching link at this end too, we're all done!
                                // at this point we must begin key exchange and insert this