]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd_io.cpp
And the programming god looked down upon his deciples and said: VERILY, THOU SHALT...
[user/henk/code/inspircd.git] / src / inspircd_io.cpp
index 2b380becfaae8f394dd23082903d7938f94d6f86..a52c5933b0a13a4f2698943a5ccc3bea2561490a 100644 (file)
@@ -37,6 +37,9 @@ extern InspIRCd* ServerInstance;
 extern int openSockfd[MAXSOCKS];
 extern time_t TIME;
 
+extern int MODCOUNT;
+extern std::vector<Module*> modules;
+extern std::vector<ircd_module*> factory;
 
 ServerConfig::ServerConfig()
 {
@@ -50,6 +53,7 @@ ServerConfig::ServerConfig()
        unlimitcore = false;
        AllowHalfop = true;
        dns_timeout = 5;
+       MaxTargets = 20;
        NetBufferSize = 10240;
        SoftLimit = MAXCLIENTS;
        MaxConn = SOMAXCONN;
@@ -91,9 +95,59 @@ bool ServerConfig::DelIOHook(int port)
        return false;
 }
 
+bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
+{
+       int count = ConfValueEnum(tag,&Config->config_f);
+       if (count > 1)
+       {
+               if (bail)
+               {
+                       printf("There were errors in your configuration:\nYou have more than one <%s> tag, this is not permitted.\n",tag);
+                       Exit(0);
+               }
+               else
+               {
+                       if (user)
+                       {
+                               WriteServ(user->fd,"There were errors in your configuration:");
+                               WriteServ(user->fd,"You have more than one <%s> tag, this is not permitted.\n",tag);
+                       }
+                       else
+                       {
+                               WriteOpers("There were errors in the configuration file:");
+                               WriteOpers("You have more than one <%s> tag, this is not permitted.\n",tag);
+                       }
+               }
+               return false;
+       }
+       if (count < 1)
+       {
+               if (bail)
+               {
+                       printf("There were errors in your configuration:\nYou have not defined a <%s> tag, this is required.\n",tag);
+                       Exit(0);
+               }
+               else
+               {
+                       if (user)
+                       {
+                               WriteServ(user->fd,"There were errors in your configuration:");
+                               WriteServ(user->fd,"You have not defined a <%s> tag, this is required.",tag);
+                       }
+                       else
+                       {
+                               WriteOpers("There were errors in the configuration file:");
+                               WriteOpers("You have not defined a <%s> tag, this is required.",tag);
+                       }
+               }
+               return false;
+       }
+       return true;
+}
+
 void ServerConfig::Read(bool bail, userrec* user)
 {
-        char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF];
+        char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF],MT[MAXBUF];
         char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF],SLIMT[MAXBUF];
         ConnectClass c;
         std::stringstream errstr;
@@ -133,6 +187,15 @@ void ServerConfig::Read(bool bail, userrec* user)
                 }
         }
 
+       /* Check we dont have more than one of singular tags
+        */
+       if (!CheckOnce("server",bail,user) || !CheckOnce("admin",bail,user) || !CheckOnce("files",bail,user)
+               || !CheckOnce("power",bail,user) || !CheckOnce("options",bail,user)
+               || !CheckOnce("dns",bail,user) || !CheckOnce("pid",bail,user))
+       {
+               return;
+       }
+
         ConfValue("server","name",0,Config->ServerName,&Config->config_f);
         ConfValue("server","description",0,Config->ServerDesc,&Config->config_f);
         ConfValue("server","network",0,Config->Network,&Config->config_f);
@@ -160,8 +223,16 @@ void ServerConfig::Read(bool bail, userrec* user)
         ConfValue("options","softlimit",0,SLIMT,&Config->config_f);
        ConfValue("options","operonlystats",0,Config->OperOnlyStats,&Config->config_f);
        ConfValue("options","customversion",0,Config->CustomVersion,&Config->config_f);
+       ConfValue("options","maxtargets",0,MT,&Config->config_f);
 
         Config->SoftLimit = atoi(SLIMT);
+       if (*MT)
+               Config->MaxTargets = atoi(MT);
+       if ((Config->MaxTargets < 0) || (Config->MaxTargets > 31))
+       {
+               log(DEFAULT,"WARNING: <options:maxtargets> value is greater than 31 or less than 0, set to 20.");
+               Config->MaxTargets = 20;
+       }
         if ((Config->SoftLimit < 1) || (Config->SoftLimit > MAXCLIENTS))
         {
                 log(DEFAULT,"WARNING: <options:softlimit> value is greater than %d or less than 0, set to %d.",MAXCLIENTS,MAXCLIENTS);
@@ -373,12 +444,21 @@ void Killed(int status)
        exit(status);
 }
 
+char* CleanFilename(char* name)
+{
+       char* p = name + strlen(name);
+       while ((p != name) && (*p != '/')) p--;
+       return (p != name ? ++p : p);
+}
+
+
 void Rehash(int status)
 {
-       WriteOpers("Rehashing config file %s due to SIGHUP",CONFIG_FILE);
+       WriteOpers("Rehashing config file %s due to SIGHUP",CleanFilename(CONFIG_FILE));
        fclose(Config->log_file);
        OpenLog(NULL,0);
        Config->Read(false,NULL);
+       FOREACH_MOD(I_OnRehash,OnRehash(""));
 }
 
 
@@ -1067,7 +1147,7 @@ int BindPorts()
                 Config->ConfValue("bind","port",count,configToken,&Config->config_f);
                 Config->ConfValue("bind","address",count,Addr,&Config->config_f);
                 Config->ConfValue("bind","type",count,Type,&Config->config_f);
-                if (strcmp(Type,"servers"))
+                if ((!*Type) || (!strcmp(Type,"clients")))
                 {
                         // modules handle server bind types now,
                         // its not a typo in the strcmp.