]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Cut out some code duplication by using the existing exception framework in here,...
authorbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 25 Jan 2007 01:26:21 +0000 (01:26 +0000)
committerbrain <brain@e03df62e-2008-0410-955e-edbf42e46eb7>
Thu, 25 Jan 2007 01:26:21 +0000 (01:26 +0000)
(this is currently the only value we dont allow changing at runtime, maybe there are more to be found which are obviously unsafe to change)

git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@6439 e03df62e-2008-0410-955e-edbf42e46eb7

src/configreader.cpp

index f767eae72efe886d62f8f27d2c8f808de8f0845d..0bb22e43a679aa2e9212cde11e07dc421d7bf929 100644 (file)
@@ -151,46 +151,12 @@ bool ServerConfig::CheckOnce(char* tag, bool bail, userrec* user)
        
        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);
-                       InspIRCd::Exit(EXIT_STATUS_CONFIG);
-               }
-               else
-               {
-                       if (user)
-                       {
-                               user->WriteServ("There were errors in your configuration:");
-                               user->WriteServ("You have more than one <%s> tag, this is not permitted.\n",tag);
-                       }
-                       else
-                       {
-                               ServerInstance->WriteOpers("There were errors in the configuration file:");
-                               ServerInstance->WriteOpers("You have more than one <%s> tag, this is not permitted.\n",tag);
-                       }
-               }
+               throw CoreException("You have more than one <"+std::string(tag)+"> tag, this is not permitted.");
                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);
-                       InspIRCd::Exit(EXIT_STATUS_CONFIG);
-               }
-               else
-               {
-                       if (user)
-                       {
-                               user->WriteServ("There were errors in your configuration:");
-                               user->WriteServ("You have not defined a <%s> tag, this is required.",tag);
-                       }
-                       else
-                       {
-                               ServerInstance->WriteOpers("There were errors in the configuration file:");
-                               ServerInstance->WriteOpers("You have not defined a <%s> tag, this is required.",tag);
-                       }
-               }
+               throw CoreException("You have not defined a <"+std::string(tag)+"> tag, this is required.");
                return false;
        }
        return true;
@@ -289,6 +255,13 @@ bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, V
 
 bool ValidateServerName(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
 {
+       /* If we already have a servername, and they changed it, we should throw an exception. */
+       if ((strcasecmp(conf->ServerName, data.GetString())) && (*conf->ServerName)) 
+       {
+               throw CoreException("Configuration error: You cannot change your servername at runtime! Please restart your server for this change to be applied.");
+               /* XXX: We don't actually reach this return of course... */
+               return false;
+       }
        if (!strchr(data.GetString(),'.'))
        {
                conf->GetInstance()->Log(DEFAULT,"WARNING: <server:name> '%s' is not a fully-qualified domain name. Changed to '%s%c'",data.GetString(),data.GetString(),'.');
@@ -733,7 +706,8 @@ void ServerConfig::Read(bool bail, userrec* user)
                        ConfValue(this->config_data, Values[Index].tag, Values[Index].value, Values[Index].default_value, 0, item, MAXBUF, allow_newlines);
                        ValueItem vi(item);
 
-                       Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi);
+                       if (!Values[Index].validation_function(this, Values[Index].tag, Values[Index].value, vi))
+                               throw CoreException("One or more values in your configuration file failed to validate. Please see your ircd.log for more information.");
 
                        switch (Values[Index].datatype)
                        {