]> 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 e5bc33d2f379462fd1b7e04d1aee72204902f013..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
@@ -60,8 +62,8 @@
 using namespace std;
 
 extern int MODCOUNT;
-extern vector<Module*> modules;
-extern vector<ircd_module*> factory;
+extern std::vector<Module*> modules;
+extern std::vector<ircd_module*> factory;
 
 extern int LogLevel;
 extern char ServerName[MAXBUF];
@@ -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);
@@ -843,6 +852,7 @@ void handle_quit(char **parameters, int pcnt, userrec *user)
 void handle_who(char **parameters, int pcnt, userrec *user)
 {
        chanrec* Ptr = NULL;
+       char tmp[10];
        
        /* theres more to do here, but for now just close the socket */
        if (pcnt == 1)
@@ -858,7 +868,15 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                                        // suggested by phidjit and FCS
                                        if ((!common_channels(user,i->second)) && (isnick(i->second->nick)))
                                        {
-                                               WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
+                                               // Bug Fix #29
+                                               strcpy(tmp, "");
+                                               if (strcmp(i->second->awaymsg, "")) {
+                                                       strncat(tmp, "G", 9);
+                                               } else {
+                                                       strncat(tmp, "H", 9);
+                                               }
+                                               if (strchr(i->second->modes,'o')) { strncat(tmp, "*", 9); }
+                                               WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, Ptr ? Ptr->name : "*", i->second->ident, i->second->dhost, i->second->server, i->second->nick, tmp, i->second->fullname);
                                                n_list++;
                                                if (n_list > MaxWhoResults)
                                                        break;
@@ -867,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;
                }
@@ -884,10 +902,19 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                                {
                                        if ((has_channel(i->second,Ptr)) && (isnick(i->second->nick)))
                                        {
-                                               WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, Ptr->name, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
+                                               // Fix Bug #29 - Part 2..
+                                               strcpy(tmp, "");
+                                               if (strcmp(i->second->awaymsg, "")) {
+                                                       strncat(tmp, "G", 9);
+                                               } else {
+                                                       strncat(tmp, "H", 9);
+                                               }
+                                               if (strchr(i->second->modes,'o')) { strncat(tmp, "*", 9); }
+                                               strcat(tmp, cmode(i->second, Ptr));
+                                               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
                        {
@@ -899,7 +926,15 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                        userrec* u = Find(parameters[0]);
                        if (u)
                        {
-                               WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, u->nick, u->ident, u->dhost, u->server, u->nick, u->fullname);
+                               // Bug Fix #29 -- Part 29..
+                               strcpy(tmp, "");
+                               if (strcmp(u->awaymsg, "")) {
+                                       strncat(tmp, "G" ,9);
+                               } else {
+                                       strncat(tmp, "H" ,9);
+                               }
+                               if (strchr(u->modes,'o')) { strncat(tmp, "*" ,9); }
+                               WriteServ(user->fd,"352 %s %s %s %s %s %s %s :0 %s",user->nick, u->nick, u->ident, u->dhost, u->server, u->nick, tmp, u->fullname);
                        }
                        WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
                }
@@ -914,11 +949,20 @@ void handle_who(char **parameters, int pcnt, userrec *user)
                                 {
                                         if (strchr(i->second->modes,'o'))
                                         {
-                                                WriteServ(user->fd,"352 %s %s %s %s %s %s Hr@ :0 %s",user->nick, user->nick, i->second->ident, i->second->dhost, i->second->server, i->second->nick, i->second->fullname);
+                                               // If i were a rich man.. I wouldn't need to me making these bugfixes..
+                                               // But i'm a poor bastard with nothing better to do.
+                                               strcpy(tmp, "");
+                                               if (strcmp(i->second->awaymsg, "")) {
+                                                       strncat(tmp, "G" ,9);
+                                               } else {
+                                                       strncat(tmp, "H" ,9);
+                                               }
+
+                                                WriteServ(user->fd,"352 %s %s %s %s %s %s %s* :0 %s",user->nick, user->nick, 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, user->nick);
+                        WriteServ(user->fd,"315 %s %s :End of /WHO list.",user->nick, parameters[0]);
                         return;
                 }
        }
@@ -948,7 +992,7 @@ void handle_list(char **parameters, int pcnt, userrec *user)
 void handle_rehash(char **parameters, int pcnt, userrec *user)
 {
        WriteServ(user->fd,"382 %s %s :Rehashing",user->nick,CleanFilename(CONFIG_FILE));
-       ReadConfig();
+       ReadConfig(false,user);
        FOREACH_MOD OnRehash();
        WriteOpers("%s is rehashing config file %s",user->nick,CleanFilename(CONFIG_FILE));
 }
@@ -1444,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 */
@@ -1470,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)
@@ -1573,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 */
@@ -2520,6 +2593,10 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
                        snprintf(buffer,MAXBUF,"+ %s %s %d %d",tcp_host,ipaddr,port,authcookie);
                        NetSendToAllExcept(tcp_host,buffer);
                break;
+               case '/':
+                       WriteOpers("Server %s is IRCServices-based server (assumes-SVSMODE) - Nickname Services: %s",tcp_host,params);
+                       strlcpy(source->nickserv,params,NICKMAX);
+               break;
                // F <TS>
                // end netburst with no mesh creation
                case 'f':
@@ -2618,14 +2695,14 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                }
                if (!strcmp(command,"SVSMODE"))
                {
-                       snprintf(udp_msg,MAXBUF,"M %s",data);
+                       snprintf(udp_msg,MAXBUF,"m %s %s",source,data);
                        log(DEBUG,"Rewrote SVSMODE from services to: '%s'",udp_msg);
                        token = udp_msg[0];
                }
                if (!strcmp(command,"SVS2MODE"))
                {
-                       snprintf(udp_msg,MAXBUF,"M %s",data);
-                       log(DEBUG,"Rewrote SVSMODE from services to: '%s'",udp_msg);
+                       snprintf(udp_msg,MAXBUF,"m %s %s",source,data);
+                       log(DEBUG,"Rewrote SVS2MODE from services to: '%s'",udp_msg);
                        token = udp_msg[0];
                }
                // todo: this wont work without u:lines
@@ -2778,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...
@@ -2902,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