]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/commands.cpp
Changed to non-conflicting numeric 948 for invalid idle time
[user/henk/code/inspircd.git] / src / commands.cpp
index ef95d1f3fb384c12c688332d4492d4275bb7ebda..dc757c80328d8e8acf3bb2fa590a0d582dcb585a 100644 (file)
@@ -91,6 +91,8 @@ extern time_t nb_start;
 
 extern bool nofork;
 
+extern time_t TIME;
+
 extern std::vector<int> fd_reap;
 extern std::vector<std::string> module_names;
 
@@ -262,12 +264,36 @@ void handle_kick(char **parameters, int pcnt, userrec *user)
        }
        
        // this must be propogated so that channel membership is kept in step network-wide
-       
        char buffer[MAXBUF];
        snprintf(buffer,MAXBUF,"k %s %s %s :%s",user->nick,u->nick,Ptr->name,reason);
        NetSendToAll(buffer);
 }
 
+void handle_loadmodule(char **parameters, int pcnt, userrec *user)
+{
+       if (LoadModule(parameters[0]))
+       {
+               WriteOpers("*** NEW MODULE: %s",parameters[0]);
+               WriteServ(user->fd,"975 %s %s :Module successfully loaded.",user->nick, parameters[0]);
+       }
+       else
+       {
+               WriteServ(user->fd,"974 %s %s :Failed to load module: %s",user->nick, parameters[0],ModuleError());
+       }
+}
+
+void handle_unloadmodule(char **parameters, int pcnt, userrec *user)
+{
+        if (UnloadModule(parameters[0]))
+        {
+                WriteOpers("*** MODULE UNLOADED: %s",parameters[0]);
+                WriteServ(user->fd,"973 %s %s :Module successfully unloaded.",user->nick, parameters[0]);
+        }
+        else
+        {
+                WriteServ(user->fd,"972 %s %s :Failed to unload module: %s",user->nick, parameters[0],ModuleError());
+        }
+}
 
 void handle_die(char **parameters, int pcnt, userrec *user)
 {
@@ -339,9 +365,11 @@ void handle_kill(char **parameters, int pcnt, userrec *user)
         log(DEBUG,"kill: %s %s",parameters[0],parameters[1]);
        if (u)
        {
+               log(DEBUG,"into kill mechanism");
                int MOD_RESULT = 0;
                 FOREACH_RESULT(OnKill(user,u,parameters[1]));
                 if (MOD_RESULT) {
+                       log(DEBUG,"A module prevented the kill with result %d",MOD_RESULT);
                         return;
                 }
 
@@ -362,14 +390,15 @@ void handle_kill(char **parameters, int pcnt, userrec *user)
                                log(DEBUG,"deleting user hash value %d",iter->second);
                                if ((iter->second) && (user->registered == 7)) {
                                        delete iter->second;
-                                       }
-                       clientlist.erase(iter);
+                               }
+                               clientlist.erase(iter);
                        }
                        purge_empty_chans();
                }
                else
                {
                        // local kill
+                       log(DEFAULT,"LOCAL KILL: %s :%s!%s!%s (%s)", u->nick, ServerName,user->dhost,user->nick,parameters[1]);
                        WriteTo(user, u, "KILL %s :%s!%s!%s (%s)", u->nick, ServerName,user->dhost,user->nick,parameters[1]);
                        WriteOpers("*** Local Kill by %s: %s!%s@%s (%s)",user->nick,u->nick,u->ident,u->host,parameters[1]);
                        snprintf(killreason,MAXBUF,"Killed (%s (%s))",user->nick,parameters[1]);
@@ -523,7 +552,7 @@ void handle_topic(char **parameters, int pcnt, userrec *user)
                                        
                                strlcpy(Ptr->topic,topic,MAXBUF);
                                strlcpy(Ptr->setby,user->nick,NICKMAX);
-                               Ptr->topicset = time(NULL);
+                               Ptr->topicset = TIME;
                                WriteChannel(Ptr,user,"TOPIC %s :%s",Ptr->name, Ptr->topic);
 
                                // t token must go to ALL servers!!!
@@ -543,6 +572,12 @@ void handle_names(char **parameters, int pcnt, userrec *user)
 {
        chanrec* c;
 
+       if (!pcnt)
+       {
+               WriteServ(user->fd,"366 %s * :End of /NAMES list.",user->nick);
+               return;
+       }
+
        if (loop_call(handle_names,parameters,pcnt,user,0,pcnt-1,0))
                return;
        c = FindChan(parameters[0]);
@@ -567,7 +602,7 @@ void handle_privmsg(char **parameters, int pcnt, userrec *user)
        userrec *dest;
        chanrec *chan;
 
-       user->idle_lastmsg = time(NULL);
+       user->idle_lastmsg = TIME;
        
        if (loop_call(handle_privmsg,parameters,pcnt,user,0,pcnt-2,0))
                return;
@@ -655,7 +690,7 @@ void handle_notice(char **parameters, int pcnt, userrec *user)
        userrec *dest;
        chanrec *chan;
 
-       user->idle_lastmsg = time(NULL);
+       user->idle_lastmsg = TIME;
        
        if (loop_call(handle_notice,parameters,pcnt,user,0,pcnt-2,0))
                return;
@@ -792,7 +827,7 @@ void handle_whois(char **parameters, int pcnt, userrec *user)
                        if (!strcasecmp(user->server,dest->server))
                        {
                                // idle time and signon line can only be sent if youre on the same server (according to RFC)
-                               WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-time(NULL)), dest->signon);
+                               WriteServ(user->fd,"317 %s %s %d %d :seconds idle, signon time",user->nick, dest->nick, abs((dest->idle_lastmsg)-TIME), dest->signon);
                        }
                        
                        WriteServ(user->fd,"318 %s %s :End of /WHOIS list.",user->nick, dest->nick);
@@ -1196,10 +1231,29 @@ void handle_modules(char **parameters, int pcnt, userrec *user)
 {
        for (int i = 0; i < module_names.size(); i++)
        {
-                       Version V = modules[i]->GetVersion();
-                       char modulename[MAXBUF];
-                       strlcpy(modulename,module_names[i].c_str(),256);
-                       WriteServ(user->fd,"900 %s :0x%08lx %d.%d.%d.%d %s",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename));
+               Version V = modules[i]->GetVersion();
+               char modulename[MAXBUF];
+               char flagstate[MAXBUF];
+               strcpy(flagstate,"");
+               if (V.Flags & VF_STATIC)
+                       strlcat(flagstate,", static",MAXBUF);
+               if (V.Flags & VF_VENDOR)
+                       strlcat(flagstate,", vendor",MAXBUF);
+               if (V.Flags & VF_COMMON)
+                       strlcat(flagstate,", common",MAXBUF);
+               if (V.Flags & VF_SERVICEPROVIDER)
+                       strlcat(flagstate,", service provider",MAXBUF);
+               if (!strlen(flagstate))
+                       strcpy(flagstate,"  <no flags>");
+               strlcpy(modulename,module_names[i].c_str(),256);
+               if (strchr(user->modes,'o'))
+               {
+                       WriteServ(user->fd,"900 %s :0x%08lx %d.%d.%d.%d %s (%s)",user->nick,modules[i],V.Major,V.Minor,V.Revision,V.Build,CleanFilename(modulename),flagstate+2);
+               }
+               else
+               {
+                       WriteServ(user->fd,"900 %s :%s",user->nick,CleanFilename(modulename));
+               }
        }
 }
 
@@ -1265,7 +1319,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
                {
                        if (strchr(i->second->modes,'o'))
                        {
-                               WriteServ(user->fd,"249 %s :%s (%s@%s) Idle: %d",user->nick,i->second->nick,i->second->ident,i->second->dhost,(time(NULL) - i->second->idle_lastmsg));
+                               WriteServ(user->fd,"249 %s :%s (%s@%s) Idle: %d",user->nick,i->second->nick,i->second->ident,i->second->dhost,(TIME - i->second->idle_lastmsg));
                                idx++;
                        }
                }
@@ -1365,7 +1419,7 @@ void handle_stats(char **parameters, int pcnt, userrec *user)
        if (!strcmp(parameters[0],"u"))
        {
                time_t current_time = 0;
-               current_time = time(NULL);
+               current_time = TIME;
                time_t server_uptime = current_time - startup_time;
                struct tm* stime;
                stime = gmtime(&server_uptime);
@@ -1471,7 +1525,7 @@ void handle_map(char **parameters, int pcnt, userrec *user)
        snprintf(line,MAXBUF,"006 %s :%s",user->nick,ServerName);
        while (strlen(line) < 50)
                strcat(line," ");
-       WriteServ(user->fd,"%s%d (%.2f%%)",line,local_count(),(float)(((float)local_count()/(float)usercnt())*100));
+       WriteServ(user->fd,"%s%d (%.2f%%)",line,local_count(),(float)(((float)local_count()/(float)registered_usercount())*100));
        for (int j = 0; j < 32; j++)
        {
                if (me[j] != NULL)
@@ -1481,7 +1535,7 @@ void handle_map(char **parameters, int pcnt, userrec *user)
                                snprintf(line,MAXBUF,"006 %s :%c-%s",user->nick,islast(me[j]->connectors[k].GetServerName().c_str()),me[j]->connectors[k].GetServerName().c_str());
                                while (strlen(line) < 50)
                                        strcat(line," ");
-                               WriteServ(user->fd,"%s%d (%.2f%%)",line,map_count(me[j]->connectors[k].GetServerName().c_str()),(float)(((float)map_count(me[j]->connectors[k].GetServerName().c_str())/(float)usercnt())*100));
+                               WriteServ(user->fd,"%s%d (%.2f%%)",line,map_count(me[j]->connectors[k].GetServerName().c_str()),(float)(((float)map_count(me[j]->connectors[k].GetServerName().c_str())/(float)registered_usercount())*100));
                        }
                }
        }
@@ -1511,18 +1565,22 @@ void handle_oper(char **parameters, int pcnt, userrec *user)
        char Password[MAXBUF];
        char OperType[MAXBUF];
        char TypeName[MAXBUF];
-       char Hostname[MAXBUF];
+       char HostName[MAXBUF];
+       char TheHost[MAXBUF];
        int i,j;
        bool found = false;
        bool fail2 = false;
        char global[MAXBUF];
 
+       snprintf(TheHost,MAXBUF,"%s@%s",user->ident,user->host);
+
        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])))
+               ConfValue("oper","host",i,HostName,&config_f);
+               if ((!strcmp(LoginName,parameters[0])) && (!strcmp(Password,parameters[1])) && (match(TheHost,HostName)))
                {
                        fail2 = true;
                        for (j =0; j < ConfValueEnum("type",&config_f); j++)
@@ -1534,8 +1592,8 @@ void handle_oper(char **parameters, int pcnt, userrec *user)
                                        /* found this oper's opertype */
                                        snprintf(global,MAXBUF,"| %s %s",user->nick,TypeName);
                                        NetSendToAll(global);
-                                       ConfValue("type","host",j,Hostname,&config_f);
-                                       ChangeDisplayedHost(user,Hostname);
+                                       ConfValue("type","host",j,HostName,&config_f);
+                                       ChangeDisplayedHost(user,HostName);
                                        strlcpy(user->oper,TypeName,NICKMAX);
                                        found = true;
                                        fail2 = false;
@@ -1558,6 +1616,7 @@ void handle_oper(char **parameters, int pcnt, userrec *user)
                         snprintf(global,MAXBUF,"M %s +o",user->nick);
                         NetSendToAll(global);
                        FOREACH_MOD OnOper(user);
+                       log(DEFAULT,"OPER: %s!%s@%s opered as type: %s",user->nick,user->ident,user->host,OperType);
                }
        }
        else
@@ -1566,11 +1625,13 @@ void handle_oper(char **parameters, int pcnt, userrec *user)
                {
                        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);
+                       log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: user, host or password did not match.",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);
+                        log(DEFAULT,"OPER: Failed oper attempt by %s!%s@%s: credentials valid, but oper type nonexistent.",user->nick,user->ident,user->host);
                }
        }
        return;
@@ -1772,7 +1833,7 @@ void handle_t(char token,char* params,serverrec* source,serverrec* reply, char*
                WriteChannelLocal(c,u,"TOPIC %s :%s",c->name,topic);
                strlcpy(c->topic,topic,MAXTOPIC);
                strlcpy(c->setby,u->nick,NICKMAX);
-               c->topicset = time(NULL);
+               c->topicset = TIME;
        }       
 }
        
@@ -2076,7 +2137,7 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char*
        clientlist[nick]->lastping = 1;
        clientlist[nick]->port = 0; // so is this...
        clientlist[nick]->registered = 7; // this however we need to set for them to receive messages and appear online
-       clientlist[nick]->idle_lastmsg = time(NULL); // this is unrealiable and wont actually be used locally
+       clientlist[nick]->idle_lastmsg = TIME; // this is unrealiable and wont actually be used locally
        for (int i = 0; i < MAXCHANS; i++)
        {
                clientlist[nick]->chans[i].channel = NULL;
@@ -2086,7 +2147,7 @@ void handle_N(char token,char* params,serverrec* source,serverrec* reply, char*
 
 void handle_F(char token,char* params,serverrec* source,serverrec* reply, char* tcp_host)
 {
-       long tdiff = time(NULL) - atoi(params);
+       long tdiff = TIME - atoi(params);
        if (tdiff)
                WriteOpers("TS split for %s -> %s: %d",source->name,reply->name,tdiff);
 }
@@ -2301,7 +2362,7 @@ void handle_hash(char token,char* params,serverrec* source,serverrec* reply, cha
        char* create_time = strtok(NULL," ");
        char* duration = strtok(NULL," :");
        char* reason = strtok(NULL,"\r\n");
-       add_gline(atoi(duration),who,reason,mask);
+       add_gline(atoi(duration),(const char*)who,(const char*)reason,(const char*)mask);
        // we must update the creation time on this gline
        // now that we've added it, or it wont expire at the right time.
        gline_set_creation_time(mask,atoi(create_time));
@@ -2323,7 +2384,7 @@ void handle_dot(char token,char* params,serverrec* source,serverrec* reply, char
        char* who = strtok(NULL," ");
        if (mask)
        {
-               if (del_gline(mask))
+               if (del_gline((const char*)mask))
                {
                        if (who)
                        {
@@ -2342,7 +2403,7 @@ void handle_add_sqline(char token,char* params,serverrec* source,serverrec* repl
        char* create_time = strtok(NULL," ");
        char* duration = strtok(NULL," :");
        char* reason = strtok(NULL,"\r\n");
-       add_qline(atoi(duration),who,reason,mask);
+       add_qline(atoi(duration),(const char*)who,(const char*)reason,(const char*)mask);
        // we must update the creation time on this gline
        // now that we've added it, or it wont expire at the right time.
        qline_set_creation_time(mask,atoi(create_time));
@@ -2365,7 +2426,7 @@ void handle_del_sqline(char token,char* params,serverrec* source,serverrec* repl
        char* who = strtok(NULL," ");
        if (mask)
        {
-               if (del_qline(mask))
+               if (del_qline((const char*)mask))
                {
                        if (who)
                        {
@@ -2384,7 +2445,7 @@ void handle_add_szline(char token,char* params,serverrec* source,serverrec* repl
        char* create_time = strtok(NULL," ");
        char* duration = strtok(NULL," :");
        char* reason = strtok(NULL,"\r\n");
-       add_zline(atoi(duration),who,reason,mask);
+       add_zline(atoi(duration),(const char*)who,(const char*)reason,(const char*)mask);
        // we must update the creation time on this gline
        // now that we've added it, or it wont expire at the right time.
        zline_set_creation_time(mask,atoi(create_time));
@@ -2407,7 +2468,7 @@ void handle_del_szline(char token,char* params,serverrec* source,serverrec* repl
        char* who = strtok(NULL," ");
        if (mask)
        {
-               if (del_zline(mask))
+               if (del_zline((const char*)mask))
                {
                        if (who)
                        {
@@ -2438,7 +2499,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
                // Y <TS>
                // start netburst
                case 'Y':
-                       nb_start = time(NULL);
+                       nb_start = TIME;
                        WriteOpers("Server %s is starting netburst.",tcp_host);
                        // now broadcast this new servers address out to all servers that are linked to us,
                        // except the newcomer. They'll all attempt to connect back to it.
@@ -2616,7 +2677,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
                // F <TS>
                // end netburst
                case 'F':
-                       WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,time(NULL)-nb_start);
+                       WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start);
                        handle_F(token,params,source,reply,tcp_host);
                        nb_start = 0;
                        // tell all the other servers to use this authcookie to connect back again
@@ -2631,7 +2692,7 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
                // F <TS>
                // end netburst with no mesh creation
                case 'f':
-                       WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,time(NULL)-nb_start);
+                       WriteOpers("Server %s has completed netburst. (%d secs)",tcp_host,TIME-nb_start);
                        handle_F(token,params,source,reply,tcp_host);
                        nb_start = 0;
                        // tell everyone else about the new server name so they just add it in the disconnected
@@ -2698,6 +2759,10 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                {
                        token = '*';
                }
+               if (!strcmp(command,"PING"))
+               {
+                       token = '*';
+               }
                if (!strcmp(command,"NOTICE"))
                {
                        snprintf(udp_msg,MAXBUF,"V %s %s",source,data);
@@ -2999,6 +3064,8 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
                char Link_Pass[1024];
                char Link_SendPass[1024];
                int LinkPort = 0;
+
+               log(DEBUG,"U-token linked server detected.");
                
                // search for a corresponding <link> block in the config files
                for (int i = 0; i < ConfValueEnum("link",&config_f); i++)
@@ -3089,14 +3156,14 @@ void handle_link_packet(char* udp_msg, char* tcp_host, serverrec *serv)
        }
 }
 
-long duration(char* str)
+long duration(const char* str)
 {
        char n_field[MAXBUF];
        long total = 0;
-       char* str_end = str + strlen(str);
+       const char* str_end = str + strlen(str);
        n_field[0] = 0;
        
-       for (char* i = str; i < str_end; i++)
+       for (char* i = (char*)str; i < str_end; i++)
        {
                // if we have digits, build up a string for the value in n_field,
                // up to 10 digits in size.
@@ -3206,7 +3273,7 @@ void handle_gline(char **parameters, int pcnt, userrec *user)
        {
                add_gline(duration(parameters[1]),user->nick,parameters[2],parameters[0]);
                // # <mask> <who-set-it> <time-set> <duration> :<reason>
-               snprintf(netdata,MAXBUF,"# %s %s %ld %ld :%s",parameters[0],user->nick,time(NULL),duration(parameters[1]),parameters[2]);
+               snprintf(netdata,MAXBUF,"# %s %s %ld %ld :%s",parameters[0],user->nick,TIME,duration(parameters[1]),parameters[2]);
                NetSendToAll(netdata);
                if (!duration(parameters[1]))
                {