]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/inspircd_io.cpp
Made <disabled> non-manditory, added check for when singular tags arent defined at all
[user/henk/code/inspircd.git] / src / inspircd_io.cpp
index d685faf4eb08a4ce6380ba826749abb79d3d3c4d..3716057aff3bb559a1088c65891f421e7f33fef9 100644 (file)
@@ -2,7 +2,7 @@
  *       | Inspire Internet Relay Chat Daemon |
  *       +------------------------------------+
  *
- *  Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
+ *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
  *                       E-mail:
  *                <brain@chatspike.net>
  *               <Craig@chatspike.net>
@@ -29,6 +29,7 @@ using namespace std;
 #include "inspircd_io.h"
 #include "inspstring.h"
 #include "helperfuncs.h"
+#include "userprocess.h"
 #include "xline.h"
 
 extern ServerConfig *Config;
@@ -36,13 +37,16 @@ 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()
 {
        this->ClearStack();
        *ServerName = *Network = *ServerDesc = *AdminName = '\0';
        *AdminEmail = *AdminNick = *diepass = *restartpass = '\0';
-       *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
+       *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
        *OperOnlyStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
        log_file = NULL;
        nofork = false;
@@ -90,6 +94,56 @@ 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.",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];
@@ -132,6 +186,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);
@@ -158,6 +221,7 @@ void ServerConfig::Read(bool bail, userrec* user)
         ConfValue("options","somaxconn",0,MCON,&Config->config_f);
         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);
 
         Config->SoftLimit = atoi(SLIMT);
         if ((Config->SoftLimit < 1) || (Config->SoftLimit > MAXCLIENTS))
@@ -371,10 +435,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(""));
 }