]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/configreader.cpp
Whoops, make /stats s work
[user/henk/code/inspircd.git] / src / configreader.cpp
index e983bbc9029f2ef8af6e32b1fad74585d2e1704e..b8719fcd85b1e149ff6ade231a3f66d1ec57c396 100644 (file)
  * ---------------------------------------------------
  */
 
-#include "inspircd_config.h"
 #include "configreader.h"
-#include <string>
 #include <sstream>
-#include <iostream>
 #include <fstream>
 #include "inspircd.h"
-#include "inspstring.h"
-#include "helperfuncs.h"
-#include "userprocess.h"
 #include "xline.h"
 
 std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
@@ -34,10 +28,10 @@ ServerConfig::ServerConfig(InspIRCd* Instance) : ServerInstance(Instance)
        *TempDir = *ServerName = *Network = *ServerDesc = *AdminName = '\0';
        *HideWhoisServer = *AdminEmail = *AdminNick = *diepass = *restartpass = '\0';
        *CustomVersion = *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
-       *OperOnlyStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
+       *UserStats = *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
        log_file = NULL;
        NoUserDns = forcedebug = OperSpyWhois = nofork = HideBans = HideSplits = false;
-       writelog = AllowHalfop = true;
+       CycleHosts = writelog = AllowHalfop = true;
        dns_timeout = DieDelay = 5;
        MaxTargets = 20;
        NetBufferSize = 10240;
@@ -524,7 +518,7 @@ void ServerConfig::Read(bool bail, userrec* user)
        std::ostringstream errstr;      /* String stream containing the error output */
 
        /* These tags MUST occur and must ONLY occur once in the config file */
-       static char* Once[] = { "server", "admin", "files", "power", "options", "pid", NULL };
+       static char* Once[] = { "server", "admin", "files", "power", "options", NULL };
 
        /* These tags can occur ONCE or not at all */
        static InitialConfig Values[] = {
@@ -539,7 +533,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"files",               "motd",                         &this->motd,                    DT_CHARPTR, ValidateMotd},
                {"files",               "rules",                        &this->rules,                   DT_CHARPTR, ValidateRules},
                {"power",               "diepass",                      &this->diepass,                 DT_CHARPTR, NoValidation},      
-               {"power",               "pauseval",                     &this->DieDelay,                DT_INTEGER, NoValidation},
+               {"power",               "pause",                        &this->DieDelay,                DT_INTEGER, NoValidation},
                {"power",               "restartpass",                  &this->restartpass,             DT_CHARPTR, NoValidation},
                {"options",             "prefixquit",                   &this->PrefixQuit,              DT_CHARPTR, NoValidation},
                {"die",                 "value",                        &this->DieValue,                DT_CHARPTR, NoValidation},
@@ -551,7 +545,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"dns",                 "timeout",                      &this->dns_timeout,             DT_INTEGER, ValidateDnsTimeout},
                {"options",             "moduledir",                    &this->ModPath,                 DT_CHARPTR, ValidateModPath},
                {"disabled",            "commands",                     &this->DisabledCommands,        DT_CHARPTR, NoValidation},
-               {"options",             "operonlystats",                &this->OperOnlyStats,           DT_CHARPTR, NoValidation},
+               {"options",             "userstats",            &this->UserStats,               DT_CHARPTR, NoValidation},
                {"options",             "customversion",                &this->CustomVersion,           DT_CHARPTR, NoValidation},
                {"options",             "hidesplits",                   &this->HideSplits,              DT_BOOLEAN, NoValidation},
                {"options",             "hidebans",                     &this->HideBans,                DT_BOOLEAN, NoValidation},
@@ -560,6 +554,7 @@ void ServerConfig::Read(bool bail, userrec* user)
                {"options",             "tempdir",                      &this->TempDir,                 DT_CHARPTR, ValidateTempDir},
                {"options",             "nouserdns",                    &this->NoUserDns,               DT_BOOLEAN, NoValidation},
                {"options",             "syntaxhints",                  &this->SyntaxHints,             DT_BOOLEAN, NoValidation},
+               {"options",             "cyclehosts",                   &this->CycleHosts,              DT_BOOLEAN, NoValidation},
                {"pid",                 "file",                         &this->PID,                     DT_CHARPTR, NoValidation},
                {NULL}
        };
@@ -634,24 +629,8 @@ void ServerConfig::Read(bool bail, userrec* user)
        if (this->LoadConf(newconfig, CONFIG_FILE, errstr))
        {
                /* If we succeeded, set the ircd config to the new one */
-               this->config_data = newconfig;
-               
-/*             int c = 1;
-               std::string last;
-               
-               for(ConfigDataHash::const_iterator i = this->config_data.begin(); i != this->config_data.end(); i++)
-               {
-                       c = (i->first != last) ? 1 : c+1;
-                       last = i->first;
-                       
-                       std::cout << "[" << i->first << " " << c << "/" << this->config_data.count(i->first) << "]" << std::endl;
-                       
-                       for(KeyValList::const_iterator j = i->second.begin(); j != i->second.end(); j++)
-                               std::cout << "\t" << j->first << " = " << j->second << std::endl;
-                       
-                       std::cout << "[/" << i->first << " " << c << "/" << this->config_data.count(i->first) << "]" << std::endl;
-               }
- */    }
+               this->config_data = newconfig;  
+       }
        else
        {
                ServerInstance->Log(DEFAULT, "There were errors in your configuration:\n%s", errstr.str().c_str());
@@ -792,7 +771,8 @@ void ServerConfig::Read(bool bail, userrec* user)
         */
        if (!bail)
        {
-               ServerInstance->stats->BoundPortCount = ServerInstance->BindPorts(false);
+               int found_ports;
+               ServerInstance->stats->BoundPortCount = ServerInstance->BindPorts(false, found_ports);
 
                if (!removed_modules.empty())
                        for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
@@ -925,6 +905,8 @@ bool ServerConfig::LoadConf(ConfigDataHash &target, const char* filename, std::o
                        if (conf.get(real_character))
                        {
                                ServerInstance->Log(DEBUG,"Escaping %c", real_character);
+                               if (real_character == 'n')
+                                       real_character = '\n';
                                line += real_character;
                                continue;
                        }
@@ -1089,7 +1071,10 @@ bool ServerConfig::ParseLine(ConfigDataHash &target, std::string &line, long lin
                                if ((*c == '\\') && (in_quote))
                                {
                                        c++;
-                                       current_value += *c;
+                                       if (*c == 'n')
+                                               current_value += '\n';
+                                       else
+                                               current_value += *c;
                                        continue;
                                }
                                if (*c == '"')
@@ -1287,23 +1272,32 @@ bool ServerConfig::ReadFile(file_cache &F, const char* fname)
        char linebuf[MAXBUF];
 
        F.clear();
-       file =  fopen(fname,"r");
+       
+       if (*fname != '/')
+       {
+               std::string::size_type pos;
+               std::string confpath = CONFIG_FILE;
+               if((pos = confpath.find("/inspircd.conf")) != std::string::npos)
+               {
+                       /* Leaves us with just the path */
+                       std::string newfile = confpath.substr(0, pos) + std::string("/") + fname;
+                       file =  fopen(newfile.c_str(), "r");
+                       
+               }
+       }
+       else
+               file =  fopen(fname, "r");
 
        if (file)
        {
                while (!feof(file))
                {
-                       fgets(linebuf,sizeof(linebuf),file);
-                       linebuf[strlen(linebuf)-1]='\0';
-
-                       if (!*linebuf)
-                       {
-                               strcpy(linebuf," ");
-                       }
+                       fgets(linebuf, sizeof(linebuf), file);
+                       linebuf[strlen(linebuf)-1] = 0;
 
                        if (!feof(file))
                        {
-                               F.push_back(linebuf);
+                               F.push_back(*linebuf ? linebuf : " ");
                        }
                }