diff options
author | frostycoolslug <frostycoolslug@e03df62e-2008-0410-955e-edbf42e46eb7> | 2003-09-27 20:33:15 +0000 |
---|---|---|
committer | frostycoolslug <frostycoolslug@e03df62e-2008-0410-955e-edbf42e46eb7> | 2003-09-27 20:33:15 +0000 |
commit | 1078718b3c90e9653ffb1d92054c7740abf11356 (patch) | |
tree | fa6427a8ac27d173fe251e2e0f338cba5c5f19f3 | |
parent | b1a82220c1433c0cff2465300bc2b2dfbf4cd8eb (diff) |
Combined The file Modules and Config file existance checkers into one function
Added 'Exists' To the FileReader class of the Module API
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@192 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | include/inspircd_io.h | 3 | ||||
-rw-r--r-- | include/modules.h | 1 | ||||
-rw-r--r-- | src/inspircd.cpp | 5 | ||||
-rw-r--r-- | src/inspircd_io.cpp | 21 | ||||
-rw-r--r-- | src/modules.cpp | 13 | ||||
-rw-r--r-- | src/modules/m_randquote.cpp | 5 |
6 files changed, 26 insertions, 22 deletions
diff --git a/include/inspircd_io.h b/include/inspircd_io.h index 3460597d3..748aa53ba 100644 --- a/include/inspircd_io.h +++ b/include/inspircd_io.h @@ -17,8 +17,7 @@ void Exit (int); void Start (void); int DaemonSeed (void); -int CheckModule (char* module); -int CheckConfig (void); +int FileExists (char* file); int OpenTCPSocket (void); int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr); diff --git a/include/modules.h b/include/modules.h index a32319865..d9d04e762 100644 --- a/include/modules.h +++ b/include/modules.h @@ -354,6 +354,7 @@ class FileReader : public classbase * This method retrieves one line from the text file. If an empty non-NULL string is returned, * the index was out of bounds, or the line had no data on it. */ + bool Exists(); std::string GetLine(int x); /** Returns the size of the file in lines. * This method returns the number of lines in the read file. If it is 0, no lines have been diff --git a/src/inspircd.cpp b/src/inspircd.cpp index 6350bf659..23d32c830 100644 --- a/src/inspircd.cpp +++ b/src/inspircd.cpp @@ -2648,8 +2648,9 @@ int main (int argc, char *argv[]) { Start(); log(DEBUG,"*** InspIRCd starting up!"); - if (!CheckConfig()) + if (!FileExists(CONFIG_FILE)) { + printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE); log(DEBUG,"main: no config"); printf("ERROR: Your config file is missing, this IRCd will self destruct in 10 seconds!\n"); Exit(ERROR); @@ -4090,7 +4091,7 @@ int InspIRCd(void) /* If The File Doesnt exist, Trying to load it * Will Segfault the IRCd.. So, check to see if * it Exists, Before Proceeding. */ - if (CheckModule(modfile)) + if (FileExists(modfile)) { factory[count] = new ircd_module(modfile); if (factory[count]->LastError()) diff --git a/src/inspircd_io.cpp b/src/inspircd_io.cpp index f1fa54b69..244316c50 100644 --- a/src/inspircd_io.cpp +++ b/src/inspircd_io.cpp @@ -87,29 +87,14 @@ int DaemonSeed (void) /* Make Sure Modules Are Avaliable! * (BugFix By Craig.. See? I do work! :p) */ -int CheckModule (char* module) +int FileExists (char* file) { FILE *input; - if ((input = fopen (module, "r")) == NULL) { return(FALSE); } - else { fclose (input); return(TRUE); } + if ((input = fopen (file, "r")) == NULL) { return(false); } + else { fclose (input); return(true); } } -/* Make sure the config file is available */ -int CheckConfig (void) -{ - FILE *input; - - if ((input = fopen (CONFIG_FILE, "r")) == NULL) - { - printf("ERROR: Cannot open config file: %s\nExiting...\n",CONFIG_FILE); - return(FALSE); - } - else - fclose (input); - -return(TRUE); -} /* Counts the number of tags of a certain type within the config file, e.g. to enumerate opers */ diff --git a/src/modules.cpp b/src/modules.cpp index 75149aad0..389fb60e3 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -271,10 +271,23 @@ void FileReader::LoadFile(std::string filename) this->fc = c; } + FileReader::~FileReader() { } +bool FileReader::Exists() +{ + if (fc.size() == 0) + { + return(false); + } + else + { + return(true); + } +} + std::string FileReader::GetLine(int x) { if ((x<0) || (x>fc.size())) diff --git a/src/modules/m_randquote.cpp b/src/modules/m_randquote.cpp index 5db1c66ac..ddff1c914 100644 --- a/src/modules/m_randquote.cpp +++ b/src/modules/m_randquote.cpp @@ -39,6 +39,11 @@ class ModuleRandQuote : public Module quotes = new FileReader(q_file); + if(!quotes->Exists()) + { + printf("m_randquote: QuoteFile not Found!! Please check your config.\n\n"); + exit(0); + } } virtual ~ModuleRandQuote() |