]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/config.cpp
Started to add a notice on missing directive in the config file
[irc/gameservirc.git] / gameserv / config.cpp
index 5fd1c4368a5b0c491b17e4f320c4d479db294287..4481832e3b33bd510cf7906fcd6e7d525a83813b 100644 (file)
@@ -1,9 +1,14 @@
-#include <fstream.h>
+#include <fstream>
 #include <string.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include "extern.h"
 
-void load_config_file(char *config);
+using std::ifstream;
+using std::cerr;
+using std::endl;
+
+int load_config_file(char *config);
 void unload_config_file();
 
 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
@@ -18,6 +23,7 @@ char *adminpass;              // Administrator password
 char *welcomemsg;              // Welcome Message
 int welcomedelay;              // Welcome Message Delay
 int updateperiod;              // Seconds until another player database update
+int forestfights;              // Forest fights per day
 
 // Remote server stuff. This is used for the outgoing connection gameserv needs to make
 // to a real ircd.
@@ -28,6 +34,10 @@ char *remotepass;            // Password for the server link
 char *playerdata;              // File to store player data in
 char *monsterdata;             // File to load monster data from
 
+#if defined(P10)
+       char *gsnum = "[]AAA";          // GameServ Numeric
+#endif
+
 void unload_config_file()
 {
     if (s_GameServ)
@@ -58,7 +68,7 @@ void unload_config_file()
        delete [] welcomemsg;
 }
 
-void load_config_file(char *config)
+int load_config_file(char *config)
 {
     char *buf, *directive, *value;
     buf = new char[1024];
@@ -69,19 +79,30 @@ void load_config_file(char *config)
     infile.open(config);
     if (infile.fail())
     {
-       cout << "Error opening " << config << endl;
-       return;
+       log("Error opening %s", config);
+       cerr << "Error opening " << config << endl;
+       return 0;
     }
 
     while (infile.getline(buf, 1024, '\n'))
     {
-       cout << "Buf: " << buf << endl;
+       #ifdef DEBUGMODE
+           log("Config file entry buf: %s", buf);
+       #endif
 
        if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0' || buf[0] == '\n' || buf[0] == '\r')
            continue;
        
        directive = strtok(buf, " ");
 
+        if (stricmp(directive, "DIE") == 0)
+       {
+           value = strtok(NULL, "");
+           log("You should read the entire %s file!", config);
+           cerr << "You should read the entire " << config << " file!" 
+                << endl;
+           exit(0);
+       }
        if (stricmp(directive, "S_GAMESERV") == 0)
        {
            value = strtok(NULL, " ");
@@ -159,6 +180,11 @@ void load_config_file(char *config)
            value = strtok(NULL, " ");
            welcomedelay = stringtoint(value);
        }
+       else if (stricmp(directive, "FORESTFIGHTS") == 0)
+       {
+           value = strtok(NULL, " ");
+           forestfights = stringtoint(value);
+       }
        else if (stricmp(directive, "UPDATEPERIOD") == 0)
        {
            value = strtok(NULL, " ");
@@ -172,10 +198,15 @@ void load_config_file(char *config)
        }
        else
        {
-           cout << "Unknown Directive. Buffer: " << buf << endl;
+           #ifdef DEBUGMODE
+               log("Unknown Directive. Buffer: %s", buf);
+               cerr << "Unknown " << config << " directive. Buffer: " 
+                    << buf << endl;
+           #endif
            continue;
        }
     }
 delete [] buf;
 infile.close();
+return 1;
 }