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

* irc.mod/channels.mod cfg entries moved to cfg.c
ctcp.mod is the only one left


svn: 1029

Bryan Drewery 22 лет назад
Родитель
Сommit
4f0c564e1a
6 измененных файлов с 109 добавлено и 204 удалено
  1. 37 12
      src/cfg.c
  2. 18 6
      src/cfg.h
  3. 54 0
      src/chanprog.c
  4. 0 70
      src/mod/channels.mod/channels.c
  5. 0 114
      src/mod/irc.mod/irc.c
  6. 0 2
      src/mod/server.mod/server.c

+ 37 - 12
src/cfg.c

@@ -530,7 +530,6 @@ struct cfg_entry CFG_REALNAME = {
 #ifdef HUB
 #ifdef HUB
 void getin_describe(struct cfg_entry *cfgent, int idx)
 void getin_describe(struct cfg_entry *cfgent, int idx)
 {
 {
-#ifdef HUB
   if (!strcmp(cfgent->name, "op-bots"))
   if (!strcmp(cfgent->name, "op-bots"))
     dprintf(idx, STR("op-bots is number of bots to ask every time a oprequest is to be made\n"));
     dprintf(idx, STR("op-bots is number of bots to ask every time a oprequest is to be made\n"));
   else if (!strcmp(cfgent->name, "in-bots"))
   else if (!strcmp(cfgent->name, "in-bots"))
@@ -551,8 +550,8 @@ void getin_describe(struct cfg_entry *cfgent, int idx)
     dprintf(idx, STR("No description for %s ???\n"), cfgent->name);
     dprintf(idx, STR("No description for %s ???\n"), cfgent->name);
     putlog(LOG_ERRORS, "*", STR("getin_describe() called with unknown config entry %s"), cfgent->name);
     putlog(LOG_ERRORS, "*", STR("getin_describe() called with unknown config entry %s"), cfgent->name);
   }
   }
-#endif /* HUB */
 }
 }
+#endif /* HUB */
 
 
 void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
 void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
 {
 {
@@ -629,37 +628,65 @@ void getin_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
 
 
 struct cfg_entry CFG_OPBOTS = {
 struct cfg_entry CFG_OPBOTS = {
 	"op-bots", CFGF_GLOBAL, NULL, NULL,
 	"op-bots", CFGF_GLOBAL, NULL, NULL,
-	getin_changed, NULL, getin_describe
+	getin_changed, NULL,
+#ifdef HUB
+	getin_describe
+#else
+	NULL
+#endif /* HUB */
 };
 };
 
 
 #ifdef S_AUTOLOCK
 #ifdef S_AUTOLOCK
 struct cfg_entry CFG_FIGHTTHRESHOLD = {
 struct cfg_entry CFG_FIGHTTHRESHOLD = {
 	"fight-threshold", CFGF_GLOBAL, NULL, NULL,
 	"fight-threshold", CFGF_GLOBAL, NULL, NULL,
-	getin_changed, NULL, getin_describe
+	getin_changed, NULL,
+#ifdef HUB
+	getin_describe
+#else
+	NULL
+#endif /* HUB */
 };
 };
 #endif /* S_AUTOLOCK */
 #endif /* S_AUTOLOCK */
 
 
 struct cfg_entry CFG_INBOTS = {
 struct cfg_entry CFG_INBOTS = {
 	"in-bots", CFGF_GLOBAL, NULL, NULL,
 	"in-bots", CFGF_GLOBAL, NULL, NULL,
-	getin_changed, NULL, getin_describe
+	getin_changed, NULL,
+#ifdef HUB
+	getin_describe
+#else
+	NULL
+#endif /* HUB */
 };
 };
 
 
 struct cfg_entry CFG_LAGTHRESHOLD = {
 struct cfg_entry CFG_LAGTHRESHOLD = {
 	"lag-threshold", CFGF_GLOBAL, NULL, NULL,
 	"lag-threshold", CFGF_GLOBAL, NULL, NULL,
-	getin_changed, NULL, getin_describe
+	getin_changed, NULL,
+#ifdef HUB
+	getin_describe
+#else
+	NULL
+#endif /* HUB */
 };
 };
 
 
 struct cfg_entry CFG_OPREQUESTS = {
 struct cfg_entry CFG_OPREQUESTS = {
 	"op-requests", CFGF_GLOBAL, NULL, NULL,
 	"op-requests", CFGF_GLOBAL, NULL, NULL,
-	getin_changed, NULL, getin_describe
+	getin_changed, NULL,
+#ifdef HUB
+	getin_describe
+#else
+	NULL
+#endif /* HUB */
 };
 };
 
 
 struct cfg_entry CFG_OPTIMESLACK = {
 struct cfg_entry CFG_OPTIMESLACK = {
 	"op-time-slack", CFGF_GLOBAL, NULL, NULL,
 	"op-time-slack", CFGF_GLOBAL, NULL, NULL,
-	getin_changed, NULL, getin_describe
-};
+	getin_changed, NULL,
+#ifdef HUB
+	getin_describe
+#else
+	NULL
 #endif /* HUB */
 #endif /* HUB */
-
+};
 
 
 void add_cfg(struct cfg_entry *entry)
 void add_cfg(struct cfg_entry *entry)
 {
 {
@@ -813,7 +840,6 @@ void init_config()
   add_cfg(&CFG_SERVERS);
   add_cfg(&CFG_SERVERS);
   add_cfg(&CFG_SERVERS6);
   add_cfg(&CFG_SERVERS6);
   add_cfg(&CFG_REALNAME);
   add_cfg(&CFG_REALNAME);
-#ifdef HUB
   add_cfg(&CFG_OPBOTS);
   add_cfg(&CFG_OPBOTS);
   add_cfg(&CFG_INBOTS);
   add_cfg(&CFG_INBOTS);
   add_cfg(&CFG_LAGTHRESHOLD);
   add_cfg(&CFG_LAGTHRESHOLD);
@@ -822,7 +848,6 @@ void init_config()
 #ifdef S_AUTOLOCK
 #ifdef S_AUTOLOCK
   add_cfg(&CFG_FIGHTTHRESHOLD);
   add_cfg(&CFG_FIGHTTHRESHOLD);
 #endif /* S_AUTOLOCK */
 #endif /* S_AUTOLOCK */
-#endif /* HUB */
 }
 }
 
 
 #ifdef S_DCCPASS
 #ifdef S_DCCPASS

+ 18 - 6
src/cfg.h

@@ -18,7 +18,10 @@ typedef struct cfg_entry {
   void (*describe) (struct cfg_entry *, int idx);
   void (*describe) (struct cfg_entry *, int idx);
 } cfg_entry_T;
 } cfg_entry_T;
 
 
-extern struct cfg_entry CFG_MOTD, CFG_CMDPREFIX, CFG_BADCOOKIE, CFG_MANUALOP, CFG_MDOP, CFG_MOP, CFG_FORKINTERVAL, CFG_CHANSET;
+extern struct cfg_entry CFG_MOTD, CFG_CMDPREFIX, CFG_BADCOOKIE, CFG_MANUALOP, CFG_MDOP, 
+                        CFG_MOP, CFG_FORKINTERVAL, CFG_CHANSET, CFG_SERVERS, CFG_SERVERS6, 
+                        CFG_NICK, CFG_REALNAME, CFG_INBOTS, CFG_LAGTHRESHOLD, CFG_OPREQUESTS, CFG_OPTIMESLACK,
+                        CFG_OPBOTS, CFG_INBOTS;
 #if defined(S_AUTHHASH) || defined(S_DCCAUTH)
 #if defined(S_AUTHHASH) || defined(S_DCCAUTH)
 extern struct cfg_entry CFG_AUTHKEY;
 extern struct cfg_entry CFG_AUTHKEY;
 #endif /* S_AUTHHASH || S_DCCAUTH */
 #endif /* S_AUTHHASH || S_DCCAUTH */
@@ -43,14 +46,9 @@ extern struct cfg_entry CFG_PROMISC;
 #ifdef S_PROCESSCHECK
 #ifdef S_PROCESSCHECK
 extern struct cfg_entry CFG_BADPROCESS, CFG_PROCESSLIST;
 extern struct cfg_entry CFG_BADPROCESS, CFG_PROCESSLIST;
 #endif /* S_PROCESSCHECK */
 #endif /* S_PROCESSCHECK */
-
-#ifdef HUB
-extern struct cfg_entry CFG_SERVERS, CFG_SERVERS6, CFG_NICK, CFG_REALNAME,
-	CFG_INBOTS, CFG_LAGTHRESHOLD, CFG_OPREQUESTS, CFG_OPTIMESLACK;
 #ifdef S_AUTOLOCK
 #ifdef S_AUTOLOCK
 struct cfg_entry CFG_FIGHTTHRESHOLD;
 struct cfg_entry CFG_FIGHTTHRESHOLD;
 #endif /* S_AUTOLOCK */
 #endif /* S_AUTOLOCK */
-#endif /* HUB */
 
 
 void set_cfg_str(char *, char *, char *);
 void set_cfg_str(char *, char *, char *);
 void add_cfg(struct cfg_entry *);
 void add_cfg(struct cfg_entry *);
@@ -69,4 +67,18 @@ extern char			cmdprefix;
 extern int			cfg_count, cfg_noshare;
 extern int			cfg_count, cfg_noshare;
 extern struct cfg_entry		**cfg;
 extern struct cfg_entry		**cfg;
 
 
+#define OP_BOTS (CFG_OPBOTS.gdata ? atoi(CFG_OPBOTS.gdata) : 1)
+#define IN_BOTS (CFG_INBOTS.gdata ? atoi(CFG_INBOTS.gdata) : 1)
+#define LAG_THRESHOLD (CFG_LAGTHRESHOLD.gdata ? atoi(CFG_LAGTHRESHOLD.gdata) : 15)
+#define OPREQ_COUNT (CFG_OPREQUESTS.gdata ? atoi( CFG_OPREQUESTS.gdata ) : 2)
+#define OPREQ_SECONDS (CFG_OPREQUESTS.gdata ? atoi( strchr(CFG_OPREQUESTS.gdata, ':') + 1 ) : 5)
+#define OP_TIME_SLACK (CFG_OPTIMESLACK.gdata ? atoi(CFG_OPTIMESLACK.gdata) : 60)
+#define msgop CFG_MSGOP.ldata ? CFG_MSGOP.ldata : CFG_MSGOP.gdata ? CFG_MSGOP.gdata : ""
+#define msgpass CFG_MSGPASS.ldata ? CFG_MSGPASS.ldata : CFG_MSGPASS.gdata ? CFG_MSGPASS.gdata : ""
+#define msginvite CFG_MSGINVITE.ldata ? CFG_MSGINVITE.ldata : CFG_MSGINVITE.gdata ? CFG_MSGINVITE.gdata : ""
+#define msgident CFG_MSGIDENT.ldata ? CFG_MSGIDENT.ldata : CFG_MSGIDENT.gdata ? CFG_MSGIDENT.gdata : ""
+#ifdef S_AUTOLOCK
+#define kill_threshold (CFG_KILLTHRESHOLD.gdata ? atoi(CFG_KILLTHRESHOLD.gdata) : 0)
+#endif /* S_AUTOLOCK */
+
 #endif /* !_CFG_H */
 #endif /* !_CFG_H */

+ 54 - 0
src/chanprog.c

@@ -643,13 +643,67 @@ int isowner(char *name)
   }
   }
 }
 }
 
 
+/* this method is slow, but is only called when sharing and adding/removing chans */
 
 
 int 
 int 
 botshouldjoin(struct userrec *u, struct chanset_t *chan)
 botshouldjoin(struct userrec *u, struct chanset_t *chan)
 {
 {
   /* just return 1 for now */
   /* just return 1 for now */
   return 1;
   return 1;
+/*
+  char *chans = NULL;
+  struct userrec *u = NULL;
+ 
+  u = get_user_by_handle(userlist, bot);
+  if (!u)
+    return;
+  chans = get_user(&USERENTRY_CHANS, u);
+*/
+}
+/* future use ?
+void
+chans_addbot(const char *bot, struct chanset_t *chan)
+{
+  char *chans = NULL;
+  struct userrec *u = NULL;
+ 
+  u = get_user_by_handle(userlist, bot);
+  if (!u)
+    return;
+  chans = get_user(&USERENTRY_CHANS, u);
+  if (!botshouldjoin(u, chan)) {		
+    size_t size;
+    char *buf = NULL;
+   
+    size = strlen(chans) + strlen(chan->dname) + 2;
+    buf = calloc(1, size);
+    egg_snprintf(buf, size, "%s %s", chans, chan->dname);
+    set_user(&USERENTRY_CHANS, u, buf);
+    free(buf);
+  }
+}
+
+void 
+chans_delbot(const char *bot, struct chanset_t *chan)
+{
+  char *chans = NULL;
+  struct userrec *u = NULL;
+ 
+  u = get_user_by_handle(userlist, bot);
+  if (!u)
+    return;
+ 
+  if (botshouldjoin(u, chan)) {			
+    char *chans = NULL, *buf = NULL;
+    size_t size;
+
+    chans = get_user(&USERENTRY_CHANS, u);
+    size = strlen(chans) - strlen(chan->dname) + 2;
+
+    
+  }
 }
 }
+*/
 
 
 int shouldjoin(struct chanset_t *chan)
 int shouldjoin(struct chanset_t *chan)
 {
 {

+ 0 - 70
src/mod/channels.mod/channels.c

@@ -68,13 +68,6 @@ int 				killed_bots = 0;
 #include "tclchan.c"
 #include "tclchan.c"
 #include "userchan.c"
 #include "userchan.c"
 
 
-#ifdef S_AUTOLOCK
-#define kill_threshold (CFG_KILLTHRESHOLD.gdata ? atoi(CFG_KILLTHRESHOLD.gdata) : 0)
-#endif /* S_AUTOLOCK */
-#ifdef S_AUTOLOCK
-struct cfg_entry CFG_LOCKTHRESHOLD, CFG_KILLTHRESHOLD;
-#endif /* S_AUTOLOCK */
-
 /* This will close channels if the HUB:leaf count is skewed from config setting */
 /* This will close channels if the HUB:leaf count is skewed from config setting */
 void check_should_lock()
 void check_should_lock()
 {
 {
@@ -882,64 +875,6 @@ cmd_t channels_bot[] = {
   {NULL, 	NULL, 	NULL, 			NULL}
   {NULL, 	NULL, 	NULL, 			NULL}
 };
 };
 
 
-void channels_describe(struct cfg_entry *cfgent, int idx)
-{
-#ifdef HUB
-  if (!strcmp(cfgent->name, "close-threshold")) {
-    dprintf(idx, STR("Format H:L. When at least H hubs but L or less leafs are linked, close all channels\n"));
-  } else if (!strcmp(cfgent->name, "kill-threshold")) {
-    dprintf(idx, STR("When more than kill-threshold bots have been killed/k-lined the last minute, channels are locked\n"));
-  } else {
-    dprintf(idx, "No description for %s ???\n", cfgent->name);
-    putlog(LOG_ERRORS, "*", "channels_describe() called with unknown config entry %s", cfgent->name);
-  }
-#endif /* HUB */
-}
-
-void channels_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
-{
-  int i;
-
-  if (!cfgent->gdata)
-    return;
-  *valid = 0;
-  if (!strcmp(cfgent->name, "close-threshold")) {
-    int L, R;
-    char *value = cfgent->gdata;
-
-    L = atoi(value);
-    value = strchr(value, ':');
-    if (!value)
-      return;
-    value++;
-    R = atoi(value);
-    if ((R >= 1000) || (R < 0) || (L < 0) || (L > 100))
-      return;
-    *valid = 1;
-    return;
-  }
-  i = atoi(cfgent->gdata);
-  if (!strcmp(cfgent->name, "kill-threshold")) {
-    if ((i < 0) || (i >= 200))
-      return;
-  } 
-  *valid = 1;
-  return;
-}
-
-#ifdef S_AUTOLOCK
-struct cfg_entry CFG_LOCKTHRESHOLD = {
-	"close-threshold", CFGF_GLOBAL, NULL, NULL,
-	channels_changed, NULL, channels_describe
-};
-
-struct cfg_entry CFG_KILLTHRESHOLD = {
-	"kill-threshold", CFGF_GLOBAL, NULL, NULL,
-	channels_changed, NULL, channels_describe
-};
-#endif /* S_AUTOLOCK */
-
-
 #ifdef LEAF
 #ifdef LEAF
 static void check_limitraise() {
 static void check_limitraise() {
   int i = 0;
   int i = 0;
@@ -1014,10 +949,5 @@ void channels_init()
   add_builtins("dcc", C_dcc_irc);
   add_builtins("dcc", C_dcc_irc);
   add_builtins("bot", channels_bot);
   add_builtins("bot", channels_bot);
   add_builtins("chon", my_chon);
   add_builtins("chon", my_chon);
-
-#ifdef S_AUTOLOCK
-  add_cfg(&CFG_LOCKTHRESHOLD);
-  add_cfg(&CFG_KILLTHRESHOLD);
-#endif /* S_AUTOLOCK */
 }
 }
 
 

+ 0 - 114
src/mod/irc.mod/irc.c

@@ -32,32 +32,11 @@
 
 
 #include <stdarg.h>
 #include <stdarg.h>
 
 
-#define OP_BOTS (CFG_OPBOTS.gdata ? atoi(CFG_OPBOTS.gdata) : 1)
-#define IN_BOTS (CFG_INBOTS.gdata ? atoi(CFG_INBOTS.gdata) : 1)
-#define LAG_THRESHOLD (CFG_LAGTHRESHOLD.gdata ? atoi(CFG_LAGTHRESHOLD.gdata) : 15)
-#define OPREQ_COUNT (CFG_OPREQUESTS.gdata ? atoi( CFG_OPREQUESTS.gdata ) : 2)
-#define OPREQ_SECONDS (CFG_OPREQUESTS.gdata ? atoi( strchr(CFG_OPREQUESTS.gdata, ':') + 1 ) : 5)
-#define OP_TIME_SLACK (CFG_OPTIMESLACK.gdata ? atoi(CFG_OPTIMESLACK.gdata) : 60)
-
-#define msgop CFG_MSGOP.ldata ? CFG_MSGOP.ldata : CFG_MSGOP.gdata ? CFG_MSGOP.gdata : ""
-#define msgpass CFG_MSGPASS.ldata ? CFG_MSGPASS.ldata : CFG_MSGPASS.gdata ? CFG_MSGPASS.gdata : ""
-#define msginvite CFG_MSGINVITE.ldata ? CFG_MSGINVITE.ldata : CFG_MSGINVITE.gdata ? CFG_MSGINVITE.gdata : ""
-#define msgident CFG_MSGIDENT.ldata ? CFG_MSGIDENT.ldata : CFG_MSGIDENT.gdata ? CFG_MSGIDENT.gdata : ""
-
 #define PRIO_DEOP 1
 #define PRIO_DEOP 1
 #define PRIO_KICK 2
 #define PRIO_KICK 2
 
 
 int host_synced = 0;
 int host_synced = 0;
 
 
-struct cfg_entry CFG_OPBOTS,
-  CFG_INBOTS,
-  CFG_LAGTHRESHOLD,
-  CFG_OPTIMESLACK,
-#ifdef S_AUTOLOCK
-  CFG_FIGHTTHRESHOLD,
-#endif /* S_AUTOLOCK */
-  CFG_OPREQUESTS;
-
 static int net_type = 0;
 static int net_type = 0;
 static int wait_split = 300;		/* Time to wait for user to return from
 static int wait_split = 300;		/* Time to wait for user to return from
 					   net-split. */
 					   net-split. */
@@ -1436,103 +1415,10 @@ static void getin_5secondly()
   }
   }
 }
 }
 
 
-void irc_changed(struct cfg_entry *cfgent, char *oldval, int *valid)
-{
-  int i;
-
-  if (!cfgent->gdata)
-    return;
-  *valid = 0;
-  if (!strcmp(cfgent->name, "op-requests")) {
-    int L, R;
-    char *value = cfgent->gdata;
-
-    L = atoi(value);
-    value = strchr(value, ':');
-    if (!value)
-      return;
-    value++;
-    R = atoi(value);
-    if ((R >= 60) || (R <= 3) || (L < 1) || (L > R))
-      return;
-    *valid = 1;
-    return;
-  }
-  i = atoi(cfgent->gdata);
-  if (!strcmp(cfgent->name, "op-bots")) {
-    if ((i < 1) || (i > 10))
-      return;
-  } else if (!strcmp(cfgent->name, "invite-bots")) {
-    if ((i < 1) || (i > 10))
-      return;
-  } else if (!strcmp(cfgent->name, "key-bots")) {
-    if ((i < 1) || (i > 10))
-      return;
-  } else if (!strcmp(cfgent->name, "limit-bots")) {
-    if ((i < 1) || (i > 10))
-      return;
-  } else if (!strcmp(cfgent->name, "unban-bots")) {
-    if ((i < 1) || (i > 10))
-      return;
-  } else if (!strcmp(cfgent->name, "lag-threshold")) {
-    if ((i < 3) || (i > 60))
-      return;
-  } else if (!strcmp(cfgent->name, "fight-threshold")) {
-    if (i && ((i < 50) || (i > 1000)))
-      return;
-  } else if (!strcmp(cfgent->name, "op-time-slack")) {
-    if ((i < 30) || (i > 1200))
-      return;
-  }
-  *valid = 1;
-  return;
-}
-
-
-struct cfg_entry CFG_OPBOTS = {
-	"op-bots", CFGF_GLOBAL, NULL, NULL,
-	irc_changed, NULL, NULL
-};
-
-struct cfg_entry CFG_INBOTS = {
-	"in-bots", CFGF_GLOBAL, NULL, NULL,
-	irc_changed, NULL, NULL
-};
-
-struct cfg_entry CFG_LAGTHRESHOLD = {
-	"lag-threshold", CFGF_GLOBAL, NULL, NULL,
-	irc_changed, NULL, NULL
-};
-
-struct cfg_entry CFG_OPREQUESTS = {
-	"op-requests", CFGF_GLOBAL, NULL, NULL,
-	irc_changed, NULL, NULL
-};
-
-struct cfg_entry CFG_OPTIMESLACK = {
-	"op-time-slack", CFGF_GLOBAL, NULL, NULL,
-	irc_changed, NULL, NULL
-};
-
-#ifdef S_AUTOLOCK
-struct cfg_entry CFG_FIGHTTHRESHOLD = {
-	"fight-threshold", CFGF_GLOBAL, NULL, NULL,
-	irc_changed, NULL, NULL
-};
-#endif /* S_AUTOLOCK */
-
 void irc_init()
 void irc_init()
 {
 {
   struct chanset_t *chan = NULL;
   struct chanset_t *chan = NULL;
 
 
-  add_cfg(&CFG_OPBOTS);
-  add_cfg(&CFG_INBOTS);
-  add_cfg(&CFG_LAGTHRESHOLD);
-  add_cfg(&CFG_OPREQUESTS);
-  add_cfg(&CFG_OPTIMESLACK);
-#ifdef S_AUTOLOCK
-  add_cfg(&CFG_FIGHTTHRESHOLD);
-#endif /* S_AUTOLOCK */
   for (chan = chanset; chan; chan = chan->next) {
   for (chan = chanset; chan; chan = chan->next) {
     if (shouldjoin(chan))
     if (shouldjoin(chan))
       dprintf(DP_MODE, "JOIN %s %s\n",
       dprintf(DP_MODE, "JOIN %s %s\n",

+ 0 - 2
src/mod/server.mod/server.c

@@ -23,8 +23,6 @@
 #include "src/mod/channels.mod/channels.h"
 #include "src/mod/channels.mod/channels.h"
 #include "server.h"
 #include "server.h"
 
 
-extern struct cfg_entry CFG_OPTIMESLACK;
-
 int checked_hostmask;	/* Used in request_op()/check_hostmask() cleared on connect */
 int checked_hostmask;	/* Used in request_op()/check_hostmask() cleared on connect */
 int ctcp_mode;
 int ctcp_mode;
 int serv;		/* sock # of server currently */
 int serv;		/* sock # of server currently */