]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Made SANICK not collide the user (theres no need to in the new 1.1 now we have return...
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index a6c4f1f5e6f3d17d3c3f64b2d202d5c2ad5ce9e0..4afe7afeba1fcdfcdd4774666c3261609b3d795a 100644 (file)
  */
 
 #include <stdarg.h>
-#include "inspircd_config.h"
 #include "configreader.h"
-#include <unistd.h>
-#include <fcntl.h>
-#include <sys/errno.h>
-#include <signal.h>
-#include <time.h>
-#include <string>
-#include <sstream>
-#ifdef HAS_EXECINFO
-#include <execinfo.h>
-#endif
-#include "connection.h"
 #include "users.h"
-#include "ctables.h"
-#include "globals.h"
 #include "modules.h"
-#include "dynamic.h"
 #include "wildcard.h"
 #include "mode.h"
 #include "xline.h"
-#include "commands.h"
-#include "inspstring.h"
-#include "helperfuncs.h"
-#include "hashcomp.h"
-#include "typedefs.h"
 #include "inspircd.h"
 
-extern int MODCOUNT;
-extern ModuleList modules;
-
-extern time_t TIME;
-extern char lowermap[255];
-extern std::vector<userrec*> all_opers;
-
-char LOG_FILE[MAXBUF];
-
 static char TIMESTR[26];
 static time_t LAST = 0;
 
@@ -68,36 +39,35 @@ void InspIRCd::Log(int level, const char* text, ...)
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
 
-       InspIRCd::Log(level, std::string(textbuffer));
+       this->Log(level, std::string(textbuffer));
 }
 
 void InspIRCd::Log(int level, const std::string &text)
 {
-       extern InspIRCd* ServerInstance;
-
-       if (!ServerInstance || !ServerInstance->Config)
+       if (!this->Config)
                return;
 
        /* If we were given -debug we output all messages, regardless of configured loglevel */
-       if ((level < ServerInstance->Config->LogLevel) && !ServerInstance->Config->forcedebug)
+       if ((level < Config->LogLevel) && !Config->forcedebug)
                return;
 
-       if (TIME != LAST)
+       if (Time() != LAST)
        {
-               struct tm *timeinfo = localtime(&TIME);
+               time_t local = Time();
+               struct tm *timeinfo = localtime(&local);
 
                strlcpy(TIMESTR,asctime(timeinfo),26);
                TIMESTR[24] = ':';
-               LAST = TIME;
+               LAST = Time();
        }
 
-       if (ServerInstance->Config->log_file && ServerInstance->Config->writelog)
+       if (Config->log_file && Config->writelog)
        {
-               fprintf(ServerInstance->Config->log_file,"%s %s\n",TIMESTR,text.c_str());
-               fflush(ServerInstance->Config->log_file);
+               std::string out = std::string(TIMESTR) + " " + text.c_str() + "\n";
+               this->Logger->WriteLogLine(out);
        }
 
-       if (ServerInstance->Config->nofork)
+       if (Config->nofork)
        {
                printf("%s %s\n", TIMESTR, text.c_str());
        }
@@ -141,7 +111,7 @@ void InspIRCd::WriteOpers(const char* text, ...)
 
 void InspIRCd::WriteOpers(const std::string &text)
 {
-       for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
+       for (std::vector<userrec*>::iterator i = this->all_opers.begin(); i != this->all_opers.end(); i++)
        {
                userrec* a = *i;
                if (IS_LOCAL(a) && a->modes[UM_SERVERNOTICE])
@@ -202,7 +172,7 @@ void InspIRCd::WriteMode(const char* modes, int flags, const char* text, ...)
 
        if ((!text) || (!modes) || (!flags))
        {
-               log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
+               this->Log(DEFAULT,"*** BUG *** WriteMode was given an invalid parameter");
                return;
        }
 
@@ -329,47 +299,14 @@ void InspIRCd::SendError(const char *s)
        }
 }
 
-void InspIRCd::Error(int status)
-{
-       void *array[300];
-       size_t size;
-       char **strings;
-
-       signal(SIGALRM, SIG_IGN);
-       signal(SIGPIPE, SIG_IGN);
-       signal(SIGTERM, SIG_IGN);
-       signal(SIGABRT, SIG_IGN);
-       signal(SIGSEGV, SIG_IGN);
-       signal(SIGURG, SIG_IGN);
-       signal(SIGKILL, SIG_IGN);
-       log(DEFAULT,"*** fell down a pothole in the road to perfection ***");
-#ifdef HAS_EXECINFO
-       log(DEFAULT,"Please report the backtrace lines shown below with any bugreport to the bugtracker at http://www.inspircd.org/bugtrack/");
-       size = backtrace(array, 30);
-       strings = backtrace_symbols(array, size);
-       for (size_t i = 0; i < size; i++) {
-               log(DEFAULT,"[%d] %s", i, strings[i]);
-       }
-       free(strings);
-#else
-       log(DEFAULT,"You do not have execinfo.h so i could not backtrace -- on FreeBSD, please install the libexecinfo port.");
-#endif
-       signal(SIGSEGV, SIG_DFL);
-       if (raise(SIGSEGV) == -1)
-       {
-               log(DEFAULT,"What the hell, i couldnt re-raise SIGSEGV! Error: %s",strerror(errno));
-       }
-       Exit(status);
-}
-
 // this function counts all users connected, wether they are registered or NOT.
-int InspIRCd::usercnt()
+int InspIRCd::UserCount()
 {
        return clientlist.size();
 }
 
 // this counts only registered users, so that the percentages in /MAP don't mess up when users are sitting in an unregistered state
-int InspIRCd::registered_usercount()
+int InspIRCd::RegisteredUserCount()
 {
        int c = 0;
 
@@ -381,7 +318,7 @@ int InspIRCd::registered_usercount()
        return c;
 }
 
-int InspIRCd::usercount_invisible()
+int InspIRCd::InvisibleUserCount()
 {
        int c = 0;
 
@@ -393,7 +330,7 @@ int InspIRCd::usercount_invisible()
        return c;
 }
 
-int InspIRCd::usercount_opers()
+int InspIRCd::OperCount()
 {
        int c = 0;
 
@@ -405,7 +342,7 @@ int InspIRCd::usercount_opers()
        return c;
 }
 
-int InspIRCd::usercount_unknown()
+int InspIRCd::UnregisteredUserCount()
 {
        int c = 0;
 
@@ -419,12 +356,12 @@ int InspIRCd::usercount_unknown()
        return c;
 }
 
-long InspIRCd::chancount()
+long InspIRCd::ChannelCount()
 {
        return chanlist.size();
 }
 
-long InspIRCd::local_count()
+long InspIRCd::LocalUserCount()
 {
        int c = 0;
 
@@ -473,7 +410,7 @@ bool InspIRCd::IsChannel(const char *chname)
 
 void InspIRCd::OpenLog(char** argv, int argc)
 {
-       if (!*LOG_FILE)
+       if (!*this->LogFileName)
        {
                if (Config->logpath == "")
                {
@@ -482,13 +419,15 @@ void InspIRCd::OpenLog(char** argv, int argc)
        }
        else
        {
-               Config->log_file = fopen(LOG_FILE,"a+");
+               Config->log_file = fopen(this->LogFileName,"a+");
 
                if (!Config->log_file)
                {
                        printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str());
                        Exit(ERROR);
                }
+
+               this->Logger = new FileLogger(this, Config->log_file);
                return;
        }
 
@@ -499,6 +438,8 @@ void InspIRCd::OpenLog(char** argv, int argc)
                printf("ERROR: Could not write to logfile %s, bailing!\n\n",Config->logpath.c_str());
                Exit(ERROR);
        }
+
+       this->Logger = new FileLogger(this, Config->log_file);
 }
 
 void InspIRCd::CheckRoot()
@@ -506,7 +447,7 @@ void InspIRCd::CheckRoot()
        if (geteuid() == 0)
        {
                printf("WARNING!!! You are running an irc server as ROOT!!! DO NOT DO THIS!!!\n\n");
-               log(DEFAULT,"InspIRCd: startup: not starting with UID 0!");
+               this->Log(DEFAULT,"Cant start as root");
                Exit(ERROR);
        }
 }
@@ -516,7 +457,7 @@ void InspIRCd::CheckDie()
        if (*Config->DieValue)
        {
                printf("WARNING: %s\n\n",Config->DieValue);
-               log(DEFAULT,"Uh-Oh, somebody didn't read their config file: '%s'",Config->DieValue);
+               this->Log(DEFAULT,"Died because of <die> tag: %s",Config->DieValue);
                Exit(ERROR);
        }
 }
@@ -526,7 +467,7 @@ void InspIRCd::LoadAllModules()
 {
        char configToken[MAXBUF];
        Config->module_names.clear();
-       MODCOUNT = -1;
+       this->ModCount = -1;
 
        for (int count = 0; count < Config->ConfValueEnum(Config->config_data, "module"); count++)
        {
@@ -535,11 +476,12 @@ void InspIRCd::LoadAllModules()
                
                if (!this->LoadModule(configToken))             
                {
-                       log(DEFAULT,"Exiting due to a module loader error.");
+                       this->Log(DEFAULT,"There was an error loading a module: %s", this->ModuleError());
                        printf("\nThere was an error loading a module: %s\n\n",this->ModuleError());
                        Exit(ERROR);
                }
        }
-       log(DEFAULT,"Total loaded modules: %lu",(unsigned long)MODCOUNT+1);
+       printf("\nA total of \033[1;32m%d\033[0m module%s been loaded.\n", this->ModCount+1, this->ModCount+1 == 1 ? " has" : "s have");
+       this->Log(DEFAULT,"Total loaded modules: %d", this->ModCount+1);
 }