Просмотр исходного кода

* If we dont have a cfile, just make one
* If no bots are listed, ERROR OUT!


svn: 739

Bryan Drewery 22 лет назад
Родитель
Сommit
b8e1e3e16b
4 измененных файлов с 20 добавлено и 7 удалено
  1. 9 2
      src/conf.c
  2. 7 4
      src/main.c
  3. 2 0
      src/shell.c
  4. 2 1
      src/shell.h

+ 9 - 2
src/conf.c

@@ -354,6 +354,9 @@ void free_conf() {
 }
 }
 
 
 int parseconf() {
 int parseconf() {
+  if (!conffile.bots->nick && !conffile.bots->next) /* no bots ! */
+    werr(ERR_NOBOTS);
+
   if (conffile.uid && conffile.uid != myuid) {
   if (conffile.uid && conffile.uid != myuid) {
     sdprintf("wrong uid, conf: %d :: %d", conffile.uid, myuid);
     sdprintf("wrong uid, conf: %d :: %d", conffile.uid, myuid);
     werr(ERR_WRONGUID);
     werr(ERR_WRONGUID);
@@ -440,7 +443,11 @@ int readconf(char *cfile)
         char *option = NULL;
         char *option = NULL;
 
 
         newsplit(&line);
         newsplit(&line);
-        option = newsplit(&line);
+        if (line[0])
+          option = newsplit(&line);
+
+        if (!option)
+          continue;
 
 
         if (!strcmp(option, "autocron")) {              /* automatically check/create crontab? */
         if (!strcmp(option, "autocron")) {              /* automatically check/create crontab? */
           if (egg_isdigit(line[0]))
           if (egg_isdigit(line[0]))
@@ -641,7 +648,7 @@ void fillconf(conf_t *inconf) {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
   char *mynick = NULL;
   char *mynick = NULL;
 
 
-  if (localhub) {
+  if (localhub && conffile.bots && conffile.bots->nick) {
     mynick = strdup(conffile.bots->nick);
     mynick = strdup(conffile.bots->nick);
     strncpyz(origbotname, conffile.bots->nick, NICKLEN + 1);
     strncpyz(origbotname, conffile.bots->nick, NICKLEN + 1);
   } else
   } else

+ 7 - 4
src/main.c

@@ -552,9 +552,11 @@ static void startup_checks() {
   }
   }
   if (!fixmod(confdir()))
   if (!fixmod(confdir()))
     werr(ERR_CONFDIRMOD);
     werr(ERR_CONFDIRMOD);
-  else if (!can_stat(cfile))
-    werr(ERR_NOCONF);
-  else if (!fixmod(cfile))
+  /*technically no longer needed? 
+   else if (!can_stat(cfile))
+     werr(ERR_NOCONF);
+  */
+  else if (can_stat(cfile) && !fixmod(cfile))
     werr(ERR_CONFMOD);
     werr(ERR_CONFMOD);
 
 
   if (!can_stat(tempdir)) {
   if (!can_stat(tempdir)) {
@@ -568,7 +570,8 @@ static void startup_checks() {
   if (!fixmod(tempdir))
   if (!fixmod(tempdir))
     werr(ERR_TMPMOD);
     werr(ERR_TMPMOD);
 
 
-  readconf(cfile);
+  if (can_stat(cfile))
+    readconf(cfile);
 #ifdef LEAF
 #ifdef LEAF
   if (localhub)
   if (localhub)
 #endif /* LEAF */
 #endif /* LEAF */

+ 2 - 0
src/shell.c

@@ -650,6 +650,8 @@ char *werr_tostr(int errnum)
     return STR("No such botnick");
     return STR("No such botnick");
   case ERR_BOTDISABLED:
   case ERR_BOTDISABLED:
     return STR("Bot is disabled, remove '/' in config");
     return STR("Bot is disabled, remove '/' in config");
+  case ERR_NOBOTS:
+    return STR("There are no bots in the config! Please use ./binary -C to edit");
   default:
   default:
     return STR("Unforseen error");
     return STR("Unforseen error");
   }
   }

+ 2 - 1
src/shell.h

@@ -18,7 +18,8 @@
 #define ERR_BADBOT	15
 #define ERR_BADBOT	15
 #define ERR_BADPASS	16
 #define ERR_BADPASS	16
 #define ERR_BOTDISABLED	17
 #define ERR_BOTDISABLED	17
-#define ERR_MAX         18
+#define ERR_NOBOTS	18
+#define ERR_MAX         19
 
 
 #define EMAIL_OWNERS    0x1
 #define EMAIL_OWNERS    0x1
 #define EMAIL_TEAM      0x2
 #define EMAIL_TEAM      0x2