]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Combined The file Modules and Config file existance checkers into one function
authorfrostycoolslug <frostycoolslug@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 27 Sep 2003 20:33:15 +0000 (20:33 +0000)
committerfrostycoolslug <frostycoolslug@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 27 Sep 2003 20:33:15 +0000 (20:33 +0000)
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

include/inspircd_io.h
include/modules.h
src/inspircd.cpp
src/inspircd_io.cpp
src/modules.cpp
src/modules/m_randquote.cpp

index 3460597d31c928dc51b72a46fa76b1d260192a64..748aa53ba3ffdea442c4c0cb89dab93d482cfe43 100644 (file)
@@ -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);
 
index a3231986505c1aaec6e2994823c606092aa73758..d9d04e76216de1d8a43a4669a78671a9aa768516 100644 (file)
@@ -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
index 6350bf659070a60f0e3d3dc8e4c0eca983107612..23d32c830026da1d8879e8b5875df930fa5e2721 100644 (file)
@@ -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())
index f1fa54b69ebaba8fc86d40ed9de35abf2d71d99d..244316c504f1fa9bf0b9fd8ec48f68bbe21a6489 100644 (file)
@@ -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 */
 
index 75149aad09b0e9a4ef221ebca9deba5d3b8b54bb..389fb60e3afb18a575c08e63c566eb28abd8c90a 100644 (file)
@@ -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()))
index 5db1c66acd59ce7ce28050f9e34ad3ca61de410f..ddff1c91414c1928f2f846c0a60bb89ecb26e23b 100644 (file)
@@ -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()