]> jfr.im git - irc/gameservirc.git/blobdiff - gameserv/config.cpp
Added a log function.
[irc/gameservirc.git] / gameserv / config.cpp
index 2d02f2385821299d81b566a98c23282c4a4be4c7..f1e29d9d732c9e3549bf9d93278223c90a8f6381 100644 (file)
@@ -1,12 +1,11 @@
 #include <fstream.h>
 #include <string.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include "extern.h"
 
 void load_config_file(char *config);
 void unload_config_file();
-int stricmp(const char *s1, const char *s2);
-int strnicmp(const char *s1, const char *s2, size_t len);
 
 /* Random Configuration Stuff Goes Here until I code it to load from a .conf file :)*/
 
@@ -16,7 +15,11 @@ char *gsident;                       // GameServ's ident/username
 char *servername;              // GameServ's Server
 char *c_Forest;                        // Forest channel
 char *c_ForestTopic;           // Forest Channel Topic
-
+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.
@@ -25,6 +28,8 @@ char *remoteport;             // Port to connect to on remoteserver
 char *remotepass;              // Password for the server link
 
 char *playerdata;              // File to store player data in
+char *monsterdata;             // File to load monster data from
+char *logfile;                 // File to log errors and info to
 
 void unload_config_file()
 {
@@ -48,7 +53,16 @@ void unload_config_file()
        delete [] remotepass;
     if (playerdata)
        delete [] playerdata;
+    if (monsterdata)
+       delete [] monsterdata;
+    if (adminpass)
+       delete [] adminpass;
+    if (welcomemsg)
+       delete [] welcomemsg;
+    if (logfile)
+       delete [] logfile;
 }
+
 void load_config_file(char *config)
 {
     char *buf, *directive, *value;
@@ -60,7 +74,7 @@ void load_config_file(char *config)
     infile.open(config);
     if (infile.fail())
     {
-       cerr << "Error opening " << config << endl;
+       cout << "Error opening " << config << endl;
        return;
     }
 
@@ -68,11 +82,17 @@ void load_config_file(char *config)
     {
        cout << "Buf: " << buf << endl;
 
-       if (buf[0] == '#' || buf[0] == ' ' || buf[0] == '\0')
+       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, "");
+           cerr << value << endl;
+           exit(0);
+       }
        if (stricmp(directive, "S_GAMESERV") == 0)
        {
            value = strtok(NULL, " ");
@@ -133,12 +153,50 @@ void load_config_file(char *config)
            playerdata = new char[strlen(value) + 1];
            strcpy(playerdata, value);
        }
+       else if (stricmp(directive, "LOGFILE") == 0)
+       {
+           value = strtok(NULL, "");
+           logfile = new char[strlen(value) + 1];
+           strcpy(logfile, value);
+       }
+       else if (stricmp(directive, "MONSTERDATA") == 0)
+       {
+           value = strtok(NULL, "");
+           monsterdata = new char[strlen(value) + 1];
+           strcpy(monsterdata, value);
+       }
+       else if (stricmp(directive, "ADMINPASS") == 0)
+       {
+           value = strtok(NULL, "");
+           adminpass = new char[strlen(value) + 1];
+           strcpy(adminpass, value);
+       }
+       else if (stricmp(directive, "WELCOMEDELAY") == 0)
+       {
+           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, " ");
+           updateperiod = stringtoint(value);
+       }
+       else if (stricmp(directive, "WELCOMEMSG") == 0)
+       {
+           value = strtok(NULL, "");
+           welcomemsg = new char[strlen(value) + 1];
+           strcpy(welcomemsg, value);
+       }
        else
        {
-           cerr << "Unknown Directive. Buffer: " << buf << endl;
+           cout << "Unknown Directive. Buffer: " << buf << endl;
            continue;
        }
-       //infile.ignore(1);
     }
 delete [] buf;
 infile.close();