Bryan Drewery 21 лет назад
Родитель
Сommit
88377d31ae
14 измененных файлов с 67 добавлено и 121 удалено
  1. 2 1
      src/dcc.c
  2. 2 1
      src/debug.c
  3. 2 4
      src/flags.c
  4. 10 11
      src/log.c
  5. 39 59
      src/main.c
  6. 8 22
      src/misc.c
  7. 0 2
      src/mod/channels.mod/channels.h
  8. 0 2
      src/mod/channels.mod/userchan.c
  9. 2 5
      src/mod/share.mod/share.c
  10. 0 2
      src/mod/share.mod/share.h
  11. 2 4
      src/userrec.c
  12. 0 2
      src/userrec.h
  13. 0 4
      src/users.c
  14. 0 2
      src/users.h

+ 2 - 1
src/dcc.c

@@ -634,7 +634,8 @@ dcc_chat_secpass(int idx, char *buf, int atr)
       dprintf(idx, "%sWARNING: YOU DO NOT HAVE A SECPASS SET, NOW SETTING A RANDOM ONE....%s\n", FLASH(-1), FLASH_END(-1));
       make_rand_str(pass, MAXPASSLEN);
       set_user(&USERENTRY_SECPASS, dcc[idx].user, pass);
-      write_userfile(idx);
+      if (conf.bot->hub)
+        write_userfile(idx);
       dprintf(idx, "Your secpass is now: %s%s%s\n", pass, BOLD(-1), BOLD_END(-1));
       dprintf(idx, "Make sure you do not lose this, as it is needed to login for now on.\n \n");
       dprintf(idx, "********************************************************************\n");

+ 2 - 1
src/debug.c

@@ -223,7 +223,8 @@ static void got_term(int) __attribute__ ((noreturn));
 
 static void got_term(int z)
 {
-  write_userfile(-1);
+  if (conf.bot->hub)
+    write_userfile(-1);
   fatal("Received SIGTERM", 0);
   exit(1);		/* for GCC noreturn */
 }

+ 2 - 4
src/flags.c

@@ -474,18 +474,16 @@ chk_noflood(struct flag_record fr)
 int
 isupdatehub()
 {
-#ifdef HUB
-  if (conf.bot->u && (conf.bot->u->flags & USER_UPDATEHUB))
+  if (conf.bot->hub && conf.bot->u && (conf.bot->u->flags & USER_UPDATEHUB))
     return 1;
   else
-#endif /* HUB */
     return 0;
 }
 
 int
 ischanhub()
 {
-  if (conf.bot->u && (conf.bot->u->flags & USER_CHANHUB))
+  if (!conf.bot->hub && conf.bot->u && (conf.bot->u->flags & USER_CHANHUB))
     return 1;
   else
     return 0;

+ 10 - 11
src/log.c

@@ -160,17 +160,16 @@ void putlog(int type, const char *chname, const char *format, ...)
 
   int idx = 0;
   char out[LOGLINEMAX + 1] = "";
-#ifdef HUB
-  char stamp[34] = "";
-  struct tm *t = gmtime(&now);
-
-  egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
-  /* Place the timestamp in the string to be printed */
-  egg_snprintf(out, sizeof out, "%s %s", stamp, va_out);
-#endif /* HUB */
-#ifdef LEAF
-  egg_snprintf(out, sizeof out, "%s", va_out);
-#endif /* LEAF */
+
+  if (conf.bot->hub) {
+    char stamp[34] = "";
+    struct tm *t = gmtime(&now);
+
+    egg_strftime(stamp, sizeof(stamp), LOG_TS, t);
+    /* Place the timestamp in the string to be printed */
+    egg_snprintf(out, sizeof out, "%s %s", stamp, va_out);
+  } else
+    egg_snprintf(out, sizeof out, "%s", va_out);
 
   /* strcat(out, "\n"); */
 

+ 39 - 59
src/main.c

@@ -34,10 +34,8 @@
 #include "bg.h"	
 #include "botnet.h"
 #include "build.h"
-#ifdef LEAF
 #include "src/mod/irc.mod/irc.h"
 #include "src/mod/server.mod/server.h"
-#endif /* LEAF */
 #include "src/mod/channels.mod/channels.h"
 #include <time.h>
 #include <errno.h>
@@ -150,9 +148,8 @@ static char *getfullbinname(const char *argv_zero)
 
 void fatal(const char *s, int recoverable)
 {
-#ifdef LEAF
-  nuke_server((char *) s);
-#endif /* LEAF */
+  if (!conf.bot->hub)
+    nuke_server((char *) s);
 
   if (s && s[0])
     putlog(LOG_MISC, "*", "!*! %s", s);
@@ -419,9 +416,7 @@ void core_10secondly()
   if (curcheck == 1)
     check_trace(0);
 
-#ifdef LEAF
-  if (conf.bot->localhub) {
-#endif /* LEAF */
+  if (!conf.bot->hub && conf.bot->localhub) {
     check_promisc();
 
     if (curcheck == 2)
@@ -430,9 +425,7 @@ void core_10secondly()
       check_processes();
       curcheck = 0;
     }
-#ifdef LEAF
   }
-#endif /* LEAF */
 #endif /* !CYGWIN_HACKS */
 }
 
@@ -493,16 +486,14 @@ static void core_secondly()
     if (i > 1)
       putlog(LOG_MISC, "*", "(!) timer drift -- spun %lu minutes", i);
     miltime = (nowtm.tm_hour * 100) + (nowtm.tm_min);
-    if (((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) {	/* 5 min */
+    if (conf.bot->hub && ((int) (nowtm.tm_min / 5) * 5) == (nowtm.tm_min)) {	/* 5 min */
 /* 	flushlogs(); */
       if (!miltime) {	/* At midnight */
 	char s[25] = "";
 
 	strlcpy(s, ctime(&now), sizeof s);
-#ifdef HUB
 	putlog(LOG_ALL, "*", "--- %.11s%s", s, s + 20);
         backup_userfile();
-#endif /* HUB */
       }
     }
     /* These no longer need checking since they are all check vs minutely
@@ -526,10 +517,10 @@ static void core_minutely()
 {
   if (conf.bot->hub) 
     send_timesync(-1);
-#ifdef LEAF
-  check_maxfiles();
-  check_mypid();
-#endif
+  else {
+    check_maxfiles();
+    check_mypid();
+  }
   check_bind_time(&nowtm);
 //  check_autoaway();
 /*     flushlogs(); */
@@ -541,9 +532,8 @@ static void core_hourly()
 
 static void core_halfhourly()
 {
-#ifdef HUB
-  write_userfile(-1);
-#endif /* HUB */
+  if (conf.bot->hub)
+    write_userfile(-1);
 }
 
 static void check_tempdir()
@@ -619,8 +609,7 @@ static void startup_checks(int hack) {
 #endif /* !CYGWIN_HACKS */
 
   fill_conf_bot();
-#ifdef LEAF
-  if (conf.bot->localhub && !used_B) {
+  if (!conf.bot->hub && conf.bot->localhub && !used_B) {
     if (do_killbot[0]) {
       const char *what = (kill_sig == SIGKILL ? "kill" : "restart");
 
@@ -633,7 +622,6 @@ static void startup_checks(int hack) {
       }
       exit(0);
     } else {
-#endif /* LEAF */
       /* this needs to be both hub/leaf */
       if (update_bin) {					/* invokved with -u/-U */
         if (updating == UPDATE_AUTO && conf.bot->pid) {		/* invoked with -u bin, so kill  */
@@ -646,14 +634,14 @@ static void startup_checks(int hack) {
         /* never reached */
         exit(0);
       }
-#ifdef LEAF
-      spawnbots();
-      exit(0); /* our job is done! */
+      if (conf.bot->hub) {
+        spawnbots();
+        exit(0); /* our job is done! */
+      }
     }
   }
   if (!conf.bot->localhub)
     free_conf_bots();			/* not a localhub, so no need to store all bot info */
-#endif /* LEAF */
 }
 
 static char *fake_md5 = "596a96cc7bf9108cd896f33c44aedc8a";
@@ -662,10 +650,8 @@ void console_init();
 void ctcp_init();
 void update_init();
 void notes_init();
-#ifdef LEAF
 void server_init();
 void irc_init();
-#endif /* LEAF */
 void channels_init();
 void compress_init();
 void share_init();
@@ -731,12 +717,6 @@ printf("out: %s\n", out);
   egg_memcpy(&nowtm, gmtime(&now), sizeof(struct tm));
   lastmin = nowtm.tm_min;
 
-#ifdef HUB
-  egg_snprintf(tempdir, sizeof tempdir, "%s/tmp/", confdir());
-#endif /* HUB */
-#ifdef LEAF 
-  egg_snprintf(tempdir, sizeof tempdir, "%s/.../", confdir());
-#endif /* LEAF */
 #ifdef CYGWIN_HACKS
   egg_snprintf(tempdir, sizeof tempdir, "%s/tmp/", confdir());
 #endif /* CYGWIN_HACKS */
@@ -757,6 +737,11 @@ printf("out: %s\n", out);
   /* Check and load conf file */
   startup_checks(0);
 
+  if (conf.bot->hub)
+    egg_snprintf(tempdir, sizeof tempdir, "%s/tmp/", confdir());
+  else
+    egg_snprintf(tempdir, sizeof tempdir, "%s/.../", confdir());
+
   if ((conf.bot->localhub && !updating) || !conf.bot->localhub) {
     if ((conf.bot->pid > 0) && conf.bot->pid_file) {
       sdprintf("%s is already running, pid: %d", conf.bot->nick, conf.bot->pid);
@@ -778,10 +763,10 @@ printf("out: %s\n", out);
 
   egg_dns_init();
   channels_init();
-#ifdef LEAF
-  server_init();
-  irc_init();
-#endif /* LEAF */
+  if (!conf.bot->hub) {
+    server_init();
+    irc_init();
+  }
   transfer_init();
   share_init();
   update_init();
@@ -789,33 +774,29 @@ printf("out: %s\n", out);
   console_init();
   ctcp_init();
   chanprog();
-#ifdef HUB
-  cfg_noshare = 1;
-  if (!CFG_CHANSET.gdata)
-    set_cfg_str(NULL, "chanset", glob_chanset);
-  if (!CFG_SERVPORT.gdata)
-    set_cfg_str(NULL, "servport", "6667");
-  if (!CFG_REALNAME.gdata)
-    set_cfg_str(NULL, "realname", "A deranged product of evil coders.");
-  cfg_noshare = 0;
-#endif /* HUB */
+  if (conf.bot->hub) {
+    cfg_noshare = 1;
+    if (!CFG_CHANSET.gdata)
+      set_cfg_str(NULL, "chanset", glob_chanset);
+    if (!CFG_SERVPORT.gdata)
+      set_cfg_str(NULL, "servport", "6667");
+    if (!CFG_REALNAME.gdata)
+      set_cfg_str(NULL, "realname", "A deranged product of evil coders.");
+    cfg_noshare = 0;
+  }
 
   strcpy(botuser, origbotname);
   trigger_cfg_changed();
 
-#ifdef LEAF
-  if (conf.bot->localhub) {
+  if (!conf.bot->hub && conf.bot->localhub) {
     sdprintf("I am localhub (%s)", conf.bot->nick);
-#endif /* LEAF */
 #ifndef CYGWIN_HACKS
     if (conf.autocron)
       check_crontab();
 #endif /* !CYGWIN_HACKS */
-#ifdef LEAF
   }
-#endif /* LEAF */
 
-#if defined(LEAF) && defined(__linux__)
+#ifdef __linux__
   if (conf.pscloak) {
     const char *p = response(RES_PSCLOAK);
 
@@ -824,7 +805,7 @@ printf("out: %s\n", out);
 
     strcpy(argv[0], p);
   }
-#endif /* LEAF */
+#endif /* __linux_ */
 
   /* Move into background? */
   /* we don't split cygwin because to run as a service the bot shouldn't exit.
@@ -995,9 +976,8 @@ printf("out: %s\n", out);
 	}
       }
     } else if (xx == -3) {
-#ifdef LEAF
-      flush_modes();
-#endif /* LEAF */
+      if (!conf.bot->hub)
+        flush_modes();
       socket_cleanup = 0;	/* If we've been idle, cleanup & flush */
     }
   }

+ 8 - 22
src/misc.c

@@ -26,10 +26,8 @@
 #include "bg.h"	
 #include "chan.h"
 #include "tandem.h"
-#ifdef LEAF
 #include "src/mod/server.mod/server.h"
 #include "src/mod/irc.mod/irc.h"
-#endif /* LEAF */
 #include "userrec.h"
 #include "stat.h"
 
@@ -450,11 +448,6 @@ void show_channels(int idx, char *handle)
   egg_snprintf(format, sizeof format, "  %%c%%-%us %%-s%%-s%%-s%%-s%%-s\n", (l+2));
 
   for (chan = chanset;chan;chan = chan->next) {
-    int opped = 0;
-
-#ifdef LEAF
-    opped = me_op(chan);
-#endif /* LEAF */
     get_user_flagrec(u, &fr, chan->dname);
     if (chk_op(fr, chan)) {
         if (!first) { 
@@ -462,7 +455,7 @@ void show_channels(int idx, char *handle)
           
           first = 1;
         }
-        dprintf(idx, format, opped ? '@' : ' ', chan->dname, !shouldjoin(chan) ? "(inactive) " : "", 
+        dprintf(idx, format, !conf.bot->hub && me_op(chan) ? '@' : ' ', chan->dname, !shouldjoin(chan) ? "(inactive) " : "", 
            channel_privchan(chan) ? "(private)  " : "", !channel_manop(chan) ? "(no manop) " : "", 
            channel_bitch(chan) ? "(bitch)    " : "", channel_closed(chan) ?  "(closed)" : "");
     }
@@ -599,12 +592,9 @@ void str_unescape(char *str, register const char esc_char)
  */
 void kill_bot(char *s1, char *s2)
 {
-#ifdef HUB
   write_userfile(-1);
-#endif /* HUB */
-#ifdef LEAF
-  server_die();
-#endif /* LEAF */
+  if (!conf.bot->hub)
+    server_die();
   chatout("*** %s\n", s1);
   botnet_send_chat(-1, conf.bot->nick, s1);
   botnet_send_bye();
@@ -621,13 +611,11 @@ restart(int idx)
   const char *reason = updating ? "Updating..." : "Restarting...";
 
   sdprintf("restarting [%s]", reason); 
-#ifdef HUB
   write_userfile(idx);
-#endif /* HUB */
-#ifdef LEAF
-  nuke_server((char *) reason);		/* let's drop the server connection ASAP */
-  cycle_time = 0;
-#endif /* LEAF */
+  if (!conf.bot->hub) {
+    nuke_server((char *) reason);		/* let's drop the server connection ASAP */
+    cycle_time = 0;
+  }
   if (tands > 0) {
     botnet_send_chat(-1, conf.bot->nick, (char *) reason);
     botnet_send_bye();
@@ -730,8 +718,7 @@ int updatebin(int idx, char *par, int secs)
     fatal("Binary updated.", 0);
   }
 
-#ifdef LEAF
-  if (secs > 0) {
+  if (!conf.bot->hub && secs > 0) {
     char buf[DIRMAX] = "";
 
     /* this forces all running bots to be restarted (except localhub/me) */
@@ -752,7 +739,6 @@ int updatebin(int idx, char *par, int secs)
 
     return 0;
   } else
-#endif /* LEAF */
     restart(idx);	/* no timer */
 
  /* this should never be reached */

+ 0 - 2
src/mod/channels.mod/channels.h

@@ -52,9 +52,7 @@ bool u_match_mask(struct maskrec *, char *);
 bool ismasked(masklist *, const char *);
 bool ismodeline(masklist *, const char *);
 void channels_report(int, int);
-#ifdef HUB
 void channels_writeuserfile();
-#endif /* HUB */
 
 extern char		glob_chanset[], cfg_glob_chanset[];
 

+ 0 - 2
src/mod/channels.mod/userchan.c

@@ -1069,7 +1069,6 @@ exempt-time %lu invite-time %lu \
   return 1;
 }
 
-#ifdef HUB
 void channels_writeuserfile()
 {
   char s[1024] = "";
@@ -1090,7 +1089,6 @@ void channels_writeuserfile()
   if (ret < 5)
     putlog(LOG_MISC, "*", USERF_ERRWRITE);
 }
-#endif /* HUB */
 
 /* Expire mask originally set by `who' on `chan'?
  *

+ 2 - 5
src/mod/share.mod/share.c

@@ -1166,7 +1166,6 @@ share_version(int idx, char *par)
   // else higher_bot_linked(idx);
 }
 
-#ifdef HUB
 void
 hook_read_userfile()
 {
@@ -1183,16 +1182,14 @@ hook_read_userfile()
     }
   }
 }
-#endif /* HUB */
 
 static void
 share_endstartup(int idx, char *par)
 {
   dcc[idx].status &= ~STAT_GETTING;
   /* Send to any other sharebots */
-#ifdef HUB
-  hook_read_userfile();
-#endif /* HUB */
+  if (conf.bot->hub)
+    hook_read_userfile();
 }
 
 static void

+ 0 - 2
src/mod/share.mod/share.h

@@ -15,8 +15,6 @@ void shareout(const char *, ...) __attribute__((format(printf, 1, 2)));
 void finish_share(int);
 void dump_resync(int);
 void share_report(int, int);
-#ifdef HUB
 void hook_read_userfile();
-#endif /* HUB */
 
 #endif				/* _EGG_MOD_SHARE_SHARE_H */

+ 2 - 4
src/userrec.c

@@ -38,9 +38,7 @@ int		userfile_perm = 0600;	/* Userfile permissions,
 					   default rw-------		    */
 
 
-#ifdef HUB
 static bool		 sort_users = 1;	/* sort the userlist when saving    */
-#endif /* HUB */
 
 int count_users(struct userrec *bu)
 {
@@ -249,7 +247,6 @@ int u_pass_match(struct userrec *u, char *in)
   return 0;
 }
 
-#ifdef HUB
 bool write_user(struct userrec *u, FILE * f, int idx)
 {
   char s[181] = "";
@@ -283,8 +280,10 @@ bool write_user(struct userrec *u, FILE * f, int idx)
 	if (lfprintf(f, "--%s %s\n", ue->name, lt->extra) == EOF)
 	  return 0;
     } else {
+#ifdef HUB
       if (!ue->type->write_userfile(f, u, ue))
 	return 0;
+#endif /* HUB */
     }
   }
   return 1;
@@ -410,7 +409,6 @@ int write_userfile(int idx)
   free(new_userfile);
   return 0;
 }
-#endif /* HUB */
 
 int change_handle(struct userrec *u, char *newh)
 {

+ 0 - 2
src/userrec.h

@@ -12,10 +12,8 @@ int count_users(struct userrec *);
 int deluser(char *);
 int change_handle(struct userrec *, char *);
 void correct_handle(char *);
-#ifdef HUB
 bool write_user(struct userrec *u, FILE * f, int shr);
 int write_userfile(int);
-#endif /* HUB */
 void touch_laston(struct userrec *, char *, time_t);
 void user_del_chan(char *);
 

+ 0 - 4
src/users.c

@@ -33,9 +33,7 @@
 #include "src/mod/notes.mod/notes.h"
 #include <netinet/in.h>
 #include <arpa/inet.h>
-#ifdef HUB
 #include "misc_file.h"
-#endif /* HUB */
 
 char userfile[121] = "";	/* where the user records are stored */
 time_t ignore_time = 10;		/* how many minutes will ignores last? */
@@ -607,7 +605,6 @@ void tell_users_match(int idx, char *mtch, int start, int limit, char *chname, i
   dprintf(idx, MISC_FOUNDMATCH, cnt, cnt == 1 ? "" : MISC_MATCH_PLURAL);
 }
 
-#ifdef HUB
 void backup_userfile()
 {
   char s[DIRMAX] = "", s2[DIRMAX] = "";
@@ -618,7 +615,6 @@ void backup_userfile()
   movefile(s, s2);
   copyfile(userfile, s);
 }
-#endif /* HUB */
 
 /*
  * tagged lines in the user file:

+ 0 - 2
src/users.h

@@ -161,9 +161,7 @@ bool def_gotshare(struct userrec *u, struct user_entry *e, char *data, int idx);
 void def_display(int idx, struct user_entry *e, struct userrec *u);
 
 
-#ifdef HUB
 void backup_userfile();
-#endif /* HUB */
 void addignore(char *, char *, const char *, time_t);
 int delignore(char *);
 void tell_ignores(int, char *);