]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Grrr
[user/henk/code/inspircd.git] / src / configreader.cpp
index 6e9b75c4303aae433300c8ad72d30d0cfa01b78c..d4291692ff72385585f84090f5b38c3b9a80b022 100644 (file)
@@ -37,7 +37,7 @@ ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
        NetBufferSize = 10240;
        SoftLimit = MAXCLIENTS;
        MaxConn = SOMAXCONN;
-       MaxWhoResults = 100;
+       MaxWhoResults = 0;
        debugging = 0;
        MaxChans = 20;
        OperMaxChans = 30;
@@ -129,7 +129,7 @@ void ServerConfig::Update005()
                        char buf[MAXBUF];
                        snprintf(buf, MAXBUF, "%s:are supported by this server", line5.c_str());
                        isupport.push_back(buf);
-                       line5 = "";
+                       line5.clear();
                        token_counter = 0;
                }
        }
@@ -225,6 +225,11 @@ bool ValidateDnsServer(ServerConfig* conf, const char* tag, const char* value, V
 #ifdef WINDOWS
                conf->GetInstance()->Log(DEFAULT,"WARNING: <dns:server> not defined, attempting to find working server in the registry...");
                nameserver = FindNameServerWin();
+               /* Windows stacks multiple nameservers in one registry key, seperated by commas.
+                * Spotted by Cataclysm.
+                */
+               if (nameserver.find(',') != std::string::npos)
+                       nameserver = nameserver.substr(0, nameserver.find(','));
                data.Set(nameserver.c_str());
                conf->GetInstance()->Log(DEFAULT,"<dns:server> set to '%s' as first active resolver in registry.", nameserver.c_str());
 #else
@@ -292,9 +297,9 @@ bool ValidateNetBufferSize(ServerConfig* conf, const char* tag, const char* valu
 
 bool ValidateMaxWho(ServerConfig* conf, const char* tag, const char* value, ValueItem &data)
 {
-       if ((!data.GetInteger()) || (data.GetInteger() > 65535) || (data.GetInteger() < 1))
+       if ((data.GetInteger() > 65535) || (data.GetInteger() < 1))
        {
-               conf->GetInstance()->Log(DEFAULT,"No MaxWhoResults specified or size out of range, setting to default of 128.");
+               conf->GetInstance()->Log(DEFAULT,"<options:maxwhoresults> size out of range, setting to default of 128.");
                data.Set(128);
        }
        return true;
@@ -593,6 +598,7 @@ void ServerConfig::Read(bool bail, userrec* user)
        InitialConfig Values[] = {
                {"options",     "softlimit",    MAXCLIENTS_S,           new ValueContainerUInt (&this->SoftLimit),              DT_INTEGER, ValidateSoftLimit},
                {"options",     "somaxconn",    SOMAXCONN_S,            new ValueContainerInt  (&this->MaxConn),                DT_INTEGER, ValidateMaxConn},
+               {"options",     "moronbanner",  "Youre banned!",        new ValueContainerChar (this->MoronBanner),             DT_CHARPTR, NoValidation},
                {"server",      "name",         "",                     new ValueContainerChar (this->ServerName),              DT_CHARPTR, ValidateServerName},
                {"server",      "description",  "Configure Me",         new ValueContainerChar (this->ServerDesc),              DT_CHARPTR, NoValidation},
                {"server",      "network",      "Network",              new ValueContainerChar (this->Network),                 DT_CHARPTR, NoValidation},
@@ -937,6 +943,7 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
        bool in_tag;
        bool in_quote;
        bool in_comment;
+       int character_count = 0;
 
        linenumber = 1;
        in_tag = false;
@@ -968,6 +975,21 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
        /* Start reading characters... */
        while(conf.get(ch))
        {
+
+               /*
+                * Fix for moronic windows issue spotted by Adremelech.
+                * Some windows editors save text files as utf-16, which is
+                * a total pain in the ass to parse. Users should save in the
+                * right config format! If we ever see a file where the first
+                * byte is 0xFF or 0xFE, or the second is 0xFF or 0xFE, then
+                * this is most likely a utf-16 file. Bail out and insult user.
+                */
+               if ((character_count++ < 2) && (ch == '\xFF' || ch == '\xFE'))
+               {
+                       errorstream << "File " << filename << " cannot be read, as it is encoded in braindead UTF-16. Save your file as plain ASCII!" << std::endl;
+                       return false;
+               }
+
                /*
                 * Here we try and get individual tags on separate lines,
                 * this would be so easy if we just made people format
@@ -980,12 +1002,6 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                if((ch == '#') && !in_quote)
                        in_comment = true;
 
-               /*if(((ch == '\n') || (ch == '\r')) && in_quote)
-               {
-                       errorstream << "Got a newline within a quoted section, this is probably a typo: " << filename << ":" << linenumber << std::endl;
-                       return false;
-               }*/
-
                switch(ch)
                {
                        case '\n':
@@ -1473,19 +1489,20 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
 
        F.clear();
 
-       if (*fname != '/')
+       if ((*fname != '/') && (*fname != '\\'))
        {
                std::string::size_type pos;
                std::string confpath = ServerInstance->ConfigFileName;
-               if((pos = confpath.rfind("/")) != std::string::npos)
-               {
-                       /* Leaves us with just the path */
-                       std::string newfile = confpath.substr(0, pos) + std::string("/") + fname;
-                       if (!FileExists(newfile.c_str()))
-                               return false;
-                       file =  fopen(newfile.c_str(), "r");
+               std::string newfile = fname;
 
-               }
+               if ((pos = confpath.rfind("/")) != std::string::npos)
+                       newfile = confpath.substr(0, pos) + std::string("/") + fname;
+               else if ((pos = confpath.rfind("\\")) != std::string::npos)
+                       newfile = confpath.substr(0, pos) + std::string("\\") + fname;
+
+               if (!FileExists(newfile.c_str()))
+                       return false;
+               file =  fopen(newfile.c_str(), "r");
        }
        else
        {
@@ -1539,7 +1556,7 @@ bool ServerConfig::FileExists(const char* file)
 char* ServerConfig::CleanFilename(char* name)
 {
        char* p = name + strlen(name);
-       while ((p != name) && (*p != '/')) p--;
+       while ((p != name) && (*p != '/') && (*p != '\\')) p--;
        return (p != name ? ++p : p);
 }
 
@@ -1604,7 +1621,18 @@ bool ServerConfig::DirValid(const char* dirandfile)
 std::string ServerConfig::GetFullProgDir()
 {
        char buffer[PATH_MAX+1];
-
+#ifdef WINDOWS
+       /* Windows has specific api calls to get the exe path that never fail.
+        * For once, windows has something of use, compared to the POSIX code
+        * for this, this is positively neato.
+        */
+       if (GetModuleFileName(NULL, buffer, MAX_PATH))
+       {
+               std::string fullpath = buffer;
+               std::string::size_type n = fullpath.rfind("\\inspircd.exe");
+               return std::string(fullpath, 0, n);
+       }
+#else
        // Get the current working directory
        if (getcwd(buffer, PATH_MAX))
        {
@@ -1621,7 +1649,7 @@ std::string ServerConfig::GetFullProgDir()
                std::string::size_type n = fullpath.rfind("/inspircd");
                return std::string(fullpath, 0, n);
        }
-
+#endif
        return "/";
 }