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

* Fixed a major bug with server connections.
* cmd_dccstat is now available on leaf bots for (+a|-)
* Now calling nuke_server() directly.


svn: 763

Bryan Drewery 22 лет назад
Родитель
Сommit
754dd488dc
14 измененных файлов с 123 добавлено и 119 удалено
  1. 7 0
      doc/UPDATES
  2. 18 26
      src/cmds.c
  3. 14 10
      src/dccutil.c
  4. 5 6
      src/main.c
  5. 5 12
      src/misc.c
  6. 0 1
      src/mod/irc.mod/irc.c
  7. 1 1
      src/mod/server.mod/cmdsserv.c
  8. 7 7
      src/mod/server.mod/server.c
  9. 6 3
      src/mod/server.mod/server.h
  10. 49 33
      src/mod/server.mod/servmsg.c
  11. 3 2
      src/net.c
  12. 1 0
      src/net.h
  13. 6 17
      src/shell.c
  14. 1 1
      src/users.c

+ 7 - 0
doc/UPDATES

@@ -1,5 +1,12 @@
 This is a summary of ChangeLog basically.
 This is a summary of ChangeLog basically.
 
 
+1.1.2
+1.Fixed a major bug with server connections.
+2.Fixed a bug in share.mod where it was reconnecting if the userfile was corrupt.
+3.cmd_dccstat is now available on leaf bots for (+a|-)
+4.Remote idx's now set their socket to -1 (shouldnt cause any problems)
+5.Removed 'ppid: ' from startup.
+
 1.1.1
 1.1.1
 1.Fixed a problem with using /DCC CHAT <bot>
 1.Fixed a problem with using /DCC CHAT <bot>
 2.Fixed a bug in cmd_botcmd with picking a random leaf.
 2.Fixed a bug in cmd_botcmd with picking a random leaf.

+ 18 - 26
src/cmds.c

@@ -30,6 +30,9 @@
 #include "traffic.h" /* egg_traffic_t */
 #include "traffic.h" /* egg_traffic_t */
 #include "core_binds.h"
 #include "core_binds.h"
 #include "src/mod/console.mod/console.h"
 #include "src/mod/console.mod/console.h"
+#ifdef LEAF
+#include "src/mod/server.mod/server.h"
+#endif /* LEAF */
 
 
 #include <ctype.h>
 #include <ctype.h>
 #include <stdlib.h>
 #include <stdlib.h>
@@ -1142,13 +1145,11 @@ static void cmd_status(struct userrec *u, int idx, char *par)
   }
   }
 }
 }
 
 
-#ifdef HUB
 static void cmd_dccstat(struct userrec *u, int idx, char *par)
 static void cmd_dccstat(struct userrec *u, int idx, char *par)
 {
 {
   putlog(LOG_CMDS, "*", STR("#%s# dccstat"), dcc[idx].nick);
   putlog(LOG_CMDS, "*", STR("#%s# dccstat"), dcc[idx].nick);
   tell_dcc(idx);
   tell_dcc(idx);
 }
 }
-#endif /* HUB */
 
 
 static void cmd_boot(struct userrec *u, int idx, char *par)
 static void cmd_boot(struct userrec *u, int idx, char *par)
 {
 {
@@ -1318,7 +1319,6 @@ static void cmd_console(struct userrec *u, int idx, char *par)
   }
   }
   console_dostore(dest);
   console_dostore(dest);
 }
 }
-
 static void cmd_date(struct userrec *u, int idx, char *par)
 static void cmd_date(struct userrec *u, int idx, char *par)
 {
 {
   char date[50] = "", utctime[50] = "", ltime[50] = "";
   char date[50] = "", utctime[50] = "", ltime[50] = "";
@@ -1806,13 +1806,7 @@ static void cmd_restart(struct userrec *u, int idx, char *par)
   write_userfile(idx);
   write_userfile(idx);
 #endif /* HUB */
 #endif /* HUB */
 #ifdef LEAF
 #ifdef LEAF
-{
-  module_entry *me;
-  if ((me = module_find("server", 0, 0))) {
-    Function *func = me->funcs;
-    (func[SERVER_NUKESERVER]) ("Restarting...");
-  }
-}
+  nuke_server("Restarting...");
 #endif /* LEAF */
 #endif /* LEAF */
   botnet_send_chat(-1, conf.bot->nick, "Restarting...");
   botnet_send_chat(-1, conf.bot->nick, "Restarting...");
   botnet_send_bye();
   botnet_send_bye();
@@ -3427,17 +3421,17 @@ static void cmd_botserver(struct userrec * u, int idx, char * par) {
 
 
 void rcmd_cursrv(char * fbot, char * fhand, char * fidx) {
 void rcmd_cursrv(char * fbot, char * fhand, char * fidx) {
 #ifdef LEAF
 #ifdef LEAF
-  char tmp[2048] = "", cursrvname[500] = "";
-  int server_online = 0;
+  char tmp[2048] = "", _cursrvname[500] = "";
+  int _server_online = 0;
   module_entry *me = NULL;
   module_entry *me = NULL;
 
 
   if ((me = module_find("server", 0, 0))) {
   if ((me = module_find("server", 0, 0))) {
     Function *func = me->funcs;
     Function *func = me->funcs;
-    server_online = (*(int *)(func[25]));
-    sprintf(cursrvname, "%s", ((char *)(func[41])));
+    _server_online = (*(int *)(func[25]));
+    sprintf(_cursrvname, "%s", ((char *)(func[41])));
   }
   }
-  if (server_online)
-    sprintf(tmp, "Currently: %-40s Lag: %d", cursrvname, server_lag);
+  if (_server_online)
+    sprintf(tmp, "Currently: %-40s Lag: %d", _cursrvname, server_lag);
   else
   else
     sprintf(tmp, "Currently: none");
     sprintf(tmp, "Currently: none");
   botnet_send_cmdreply(conf.bot->nick, fbot, fhand, fidx, tmp);
   botnet_send_cmdreply(conf.bot->nick, fbot, fhand, fidx, tmp);
@@ -3499,19 +3493,19 @@ static void cmd_botnick(struct userrec * u, int idx, char * par) {
 void rcmd_curnick(char * fbot, char * fhand, char * fidx) {
 void rcmd_curnick(char * fbot, char * fhand, char * fidx) {
 #ifdef LEAF
 #ifdef LEAF
   char tmp[1024] = "";
   char tmp[1024] = "";
-  int server_online = 0;
+  int _server_online = 0;
   module_entry *me = NULL;
   module_entry *me = NULL;
 
 
   if ((me = module_find("server", 0, 0))) {
   if ((me = module_find("server", 0, 0))) {
     Function *func = me->funcs;
     Function *func = me->funcs;
-    server_online = (*(int *)(func[25]));
+    _server_online = (*(int *)(func[25]));
   }
   }
 
 
-  if (server_online)
+  if (_server_online)
     sprintf(tmp, STR("Currently: %-20s "), botname);
     sprintf(tmp, STR("Currently: %-20s "), botname);
   if (strncmp(botname, origbotname, strlen(botname)))
   if (strncmp(botname, origbotname, strlen(botname)))
     sprintf(tmp, STR("%sWant: %s"), tmp, origbotname);
     sprintf(tmp, STR("%sWant: %s"), tmp, origbotname);
-  if (!server_online)
+  if (!_server_online)
     sprintf(tmp, STR("%s(not online)"), tmp);
     sprintf(tmp, STR("%s(not online)"), tmp);
   botnet_send_cmdreply(conf.bot->nick, fbot, fhand, fidx, tmp);
   botnet_send_cmdreply(conf.bot->nick, fbot, fhand, fidx, tmp);
 #endif /* LEAF */
 #endif /* LEAF */
@@ -3816,19 +3810,19 @@ void rcmd_jump(char * frombot, char * fromhand, char * fromidx, char * par) {
   char *other = NULL;
   char *other = NULL;
   module_entry *me = NULL;
   module_entry *me = NULL;
   Function *func = NULL;
   Function *func = NULL;
-  int port, default_port = 0;
+  int port, _default_port = 0;
 
 
   if (!(me = module_find("server", 0, 0)) )
   if (!(me = module_find("server", 0, 0)) )
     return;
     return;
   func = me->funcs;
   func = me->funcs;
 
 
-  default_port = (*(int *)(func[24]));
+  _default_port = (*(int *)(func[24]));
 
 
   if (par[0]) {
   if (par[0]) {
     other = newsplit(&par);
     other = newsplit(&par);
     port = atoi(newsplit(&par));
     port = atoi(newsplit(&par));
     if (!port)
     if (!port)
-      port = default_port;
+      port = _default_port;
     strncpyz(((char *)(func[20])), other, 120); //newserver
     strncpyz(((char *)(func[20])), other, 120); //newserver
     (*(int *)(func[21])) = port; //newserverport
     (*(int *)(func[21])) = port; //newserverport
     strncpyz(((char *)(func[22])), par, 120); //newserverpass
     strncpyz(((char *)(func[22])), par, 120); //newserverpass
@@ -3836,7 +3830,7 @@ void rcmd_jump(char * frombot, char * fromhand, char * fromidx, char * par) {
   botnet_send_cmdreply(conf.bot->nick, frombot, fromhand, fromidx, STR("Jumping..."));
   botnet_send_cmdreply(conf.bot->nick, frombot, fromhand, fromidx, STR("Jumping..."));
 
 
   (*(int *)(func[23])) = 0; //cycle_time
   (*(int *)(func[23])) = 0; //cycle_time
-  (func[SERVER_NUKESERVER]) ("jumping...");
+  nuke_server("Jumping...");
 #endif /* LEAF */
 #endif /* LEAF */
 }
 }
 
 
@@ -4073,9 +4067,7 @@ cmd_t C_dcc[] =
 #endif /* HUB */
 #endif /* HUB */
   {"console",		"-|-",	(Function) cmd_console,		NULL},
   {"console",		"-|-",	(Function) cmd_console,		NULL},
   {"date",		"",	(Function) cmd_date,		NULL},
   {"date",		"",	(Function) cmd_date,		NULL},
-#ifdef HUB
   {"dccstat",		"a",	(Function) cmd_dccstat,		NULL},
   {"dccstat",		"a",	(Function) cmd_dccstat,		NULL},
-#endif /* HUB */
   {"debug",		"a",	(Function) cmd_debug,		NULL},
   {"debug",		"a",	(Function) cmd_debug,		NULL},
   {"timers",		"a",	(Function) cmd_timers,		NULL},
   {"timers",		"a",	(Function) cmd_timers,		NULL},
   {"die",		"n",	(Function) cmd_die,		NULL},
   {"die",		"n",	(Function) cmd_die,		NULL},

+ 14 - 10
src/dccutil.c

@@ -21,6 +21,7 @@
 #include "modules.h"
 #include "modules.h"
 #include "tandem.h"
 #include "tandem.h"
 #include "core_binds.h"
 #include "core_binds.h"
+#include "src/mod/server.mod/server.h"
 #include <stdarg.h>
 #include <stdarg.h>
 
 
 extern struct dcc_t	*dcc;
 extern struct dcc_t	*dcc;
@@ -348,6 +349,7 @@ void removedcc(int n)
     free(dcc[n].u.other);
     free(dcc[n].u.other);
 
 
   dcc_total--;
   dcc_total--;
+
   if (n < dcc_total)
   if (n < dcc_total)
     egg_memcpy(&dcc[n], &dcc[dcc_total], sizeof(struct dcc_t));
     egg_memcpy(&dcc[n], &dcc[dcc_total], sizeof(struct dcc_t));
   else
   else
@@ -368,12 +370,15 @@ void dcc_remove_lost(void)
       i--;
       i--;
     }
     }
   }
   }
+#ifdef LEAF
+  servidx = findanyidx(serv);		/* servidx may have moved :\ */
+#endif /* LEAF */
 }
 }
 
 
 /* Show list of current dcc's to a dcc-chatter
 /* Show list of current dcc's to a dcc-chatter
  * positive value: idx given -- negative value: sock given
  * positive value: idx given -- negative value: sock given
  */
  */
-void tell_dcc(int zidx)
+void tell_dcc(int idx)
 {
 {
   int i, j, nicklen = 0;
   int i, j, nicklen = 0;
   char other[160] = "", format[81] = "";
   char other[160] = "", format[81] = "";
@@ -385,15 +390,13 @@ void tell_dcc(int zidx)
   }
   }
   if(nicklen < 9) nicklen = 9;
   if(nicklen < 9) nicklen = 9;
   
   
-  egg_snprintf(format, sizeof format, "%%-4s %%-8s %%-5s %%-%us %%-40s %%s\n", 
-                          nicklen);
-  dprintf(zidx, format, "SOCK", "ADDR",     "PORT",  "NICK", "HOST", "TYPE");
-  dprintf(zidx, format, "----", "--------", "-----", "---------", 
+  egg_snprintf(format, sizeof format, "%%-4s %%-4s %%-8s %%-5s %%-%us %%-40s %%s\n", nicklen);
+  dprintf(idx, format, "SOCK", "IDX", "ADDR",     "PORT",  "NICK", "HOST", "TYPE");
+  dprintf(idx, format, "----", "---", "--------", "-----", "---------", 
                         "----------------------------------------", "----");
                         "----------------------------------------", "----");
 
 
-  egg_snprintf(format, sizeof format, "%%-4d %%08X %%5d %%-%us %%-40s %%s\n", 
-                          nicklen);
-  /* Show server */
+  egg_snprintf(format, sizeof format, "%%-4d %%-4d %%08X %%5d %%-%us %%-40s %%s\n", nicklen);
+
   for (i = 0; i < dcc_total; i++) {
   for (i = 0; i < dcc_total; i++) {
     j = strlen(dcc[i].host);
     j = strlen(dcc[i].host);
     if (j > 40)
     if (j > 40)
@@ -406,8 +409,9 @@ void tell_dcc(int zidx)
       sprintf(other, "?:%lX  !! ERROR !!", (long) dcc[i].type);
       sprintf(other, "?:%lX  !! ERROR !!", (long) dcc[i].type);
       break;
       break;
     }
     }
-    dprintf(zidx, format, dcc[i].sock, dcc[i].addr, dcc[i].port, dcc[i].nick, 
-			  dcc[i].host + j, other);
+    if (dcc[i].type == &DCC_LOST)
+      dprintf(idx, "LOST:\n");
+    dprintf(idx, format, dcc[i].sock, i, dcc[i].addr, dcc[i].port, dcc[i].nick, dcc[i].host + j, other);
   }
   }
 }
 }
 
 

+ 5 - 6
src/main.c

@@ -26,6 +26,9 @@
 #include "bg.h"	
 #include "bg.h"	
 #include "botnet.h"
 #include "botnet.h"
 #include "build.h"
 #include "build.h"
+#ifdef LEAF
+#include "src/mod/server.mod/server.h"
+#endif /* LEAF */
 #include <time.h>
 #include <time.h>
 #include <errno.h>
 #include <errno.h>
 #include <unistd.h>
 #include <unistd.h>
@@ -152,16 +155,12 @@ void fatal(const char *s, int recoverable)
   int i = 0;
   int i = 0;
 
 
 #ifdef LEAF
 #ifdef LEAF
-  module_entry *me = NULL;
-
-  if ((me = module_find("server", 0, 0))) {
-    Function *func = me->funcs;
-    (func[SERVER_NUKESERVER]) (s);
-  }
+  nuke_server((char *) s);
 #endif /* LEAF */
 #endif /* LEAF */
 
 
   if (s[0])
   if (s[0])
     putlog(LOG_MISC, "*", "* %s", s);
     putlog(LOG_MISC, "*", "* %s", s);
+
 /*  flushlogs(); */
 /*  flushlogs(); */
 #ifdef HAVE_SSL
 #ifdef HAVE_SSL
     ssl_cleanup();
     ssl_cleanup();

+ 5 - 12
src/misc.c

@@ -24,6 +24,9 @@
 #include "chan.h"
 #include "chan.h"
 #include "tandem.h"
 #include "tandem.h"
 #include "modules.h"
 #include "modules.h"
+#ifdef LEAF
+#include "src/mod/server.mod/server.h"
+#endif /* LEAF */
 #ifdef HUB
 #ifdef HUB
 #include "userrec.h"
 #include "userrec.h"
 #endif /* HUB */
 #endif /* HUB */
@@ -706,12 +709,7 @@ void kill_bot(char *s1, char *s2)
 static void updatelocal(void)
 static void updatelocal(void)
 {
 {
   /* let's drop the server connection ASAP */
   /* let's drop the server connection ASAP */
-  module_entry *me = NULL;
-
-  if ((me = module_find("server", 0, 0))) {
-    Function *func = me->funcs;
-    (func[SERVER_NUKESERVER]) ("Updating...");
-  }
+  nuke_server("Updating...");
 
 
   botnet_send_chat(-1, conf.bot->nick, "Updating...");
   botnet_send_chat(-1, conf.bot->nick, "Updating...");
   botnet_send_bye();
   botnet_send_bye();
@@ -800,13 +798,8 @@ int updatebin(int idx, char *par, int autoi)
   putlog(LOG_DEBUG, "*", "Running for update: %s", buf);
   putlog(LOG_DEBUG, "*", "Running for update: %s", buf);
 #ifdef LEAF
 #ifdef LEAF
   if (!autoi && localhub) {
   if (!autoi && localhub) {
-    module_entry *me = NULL;
-
     /* let's drop the server connection ASAP */
     /* let's drop the server connection ASAP */
-    if ((me = module_find("server", 0, 0))) {
-      Function *func = me->funcs;
-      (func[SERVER_NUKESERVER]) ("Updating...");
-    }
+    nuke_server("Updating...");
 #endif /* LEAF */
 #endif /* LEAF */
     logidx(idx, STR("Updating...bye"));
     logidx(idx, STR("Updating...bye"));
     putlog(LOG_MISC, "*", STR("Updating..."));
     putlog(LOG_MISC, "*", STR("Updating..."));

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

@@ -16,7 +16,6 @@
 #include "src/egg_timer.h"
 #include "src/egg_timer.h"
 #include "src/mod/share.mod/share.h"
 #include "src/mod/share.mod/share.h"
 #include "src/mod/server.mod/server.h"
 #include "src/mod/server.mod/server.h"
-#undef serv
 #include "src/mod/channels.mod/channels.h"
 #include "src/mod/channels.mod/channels.h"
 
 
 #define OP_BOTS (CFG_OPBOTS.gdata ? atoi(CFG_OPBOTS.gdata) : 1)
 #define OP_BOTS (CFG_OPBOTS.gdata ? atoi(CFG_OPBOTS.gdata) : 1)

+ 1 - 1
src/mod/server.mod/cmdsserv.c

@@ -63,8 +63,8 @@ static void cmd_jump(struct userrec *u, int idx, char *par)
   } else
   } else
     putlog(LOG_CMDS, "*", "#%s# jump", dcc[idx].nick);
     putlog(LOG_CMDS, "*", "#%s# jump", dcc[idx].nick);
   dprintf(idx, "%s...\n", IRC_JUMP);
   dprintf(idx, "%s...\n", IRC_JUMP);
-  cycle_time = 0;
   nuke_server("changing servers");
   nuke_server("changing servers");
+  cycle_time = 0;
 }
 }
 
 
 static void cmd_clearqueue(struct userrec *u, int idx, char *par)
 static void cmd_clearqueue(struct userrec *u, int idx, char *par)

+ 7 - 7
src/mod/server.mod/server.c

@@ -19,8 +19,8 @@ extern struct cfg_entry CFG_OPTIMESLACK;
 extern int		cfg_noshare;
 extern int		cfg_noshare;
 static int checked_hostmask;	/* Used in request_op()/check_hostmask() cleared on connect */
 static int checked_hostmask;	/* Used in request_op()/check_hostmask() cleared on connect */
 static int ctcp_mode;
 static int ctcp_mode;
-static int serv;		/* sock # of server currently */
-static int servidx;		/* idx of server */
+int serv;		/* sock # of server currently */
+int servidx;		/* idx of server */
 static int strict_host;		/* strict masking of hosts ? */
 static int strict_host;		/* strict masking of hosts ? */
 static char newserver[121] = "";	/* new server? */
 static char newserver[121] = "";	/* new server? */
 static int newserverport;	/* new server port? */
 static int newserverport;	/* new server port? */
@@ -1360,7 +1360,7 @@ static void server_secondly()
   if (cycle_time)
   if (cycle_time)
     cycle_time--;
     cycle_time--;
   deq_msg();
   deq_msg();
-  if (!resolvserv && serv < 0)
+  if (!resolvserv && serv < 0 && !trying_server)
     connect_server();
     connect_server();
 }
 }
 
 
@@ -1485,7 +1485,7 @@ static Function server_table[] =
   (Function) NULL,		/* char * (points to botname later on)	*/
   (Function) NULL,		/* char * (points to botname later on)	*/
   (Function) botuserhost,	/* char *				*/
   (Function) botuserhost,	/* char *				*/
   (Function) & quiet_reject,	/* int					*/
   (Function) & quiet_reject,	/* int					*/
-  (Function) & serv,		/* int					*/
+  (Function) 0,
   /* 8 - 11 */
   /* 8 - 11 */
   (Function) & flud_thr,	/* int					*/
   (Function) & flud_thr,	/* int					*/
   (Function) & flud_time,	/* int					*/
   (Function) & flud_time,	/* int					*/
@@ -1494,13 +1494,13 @@ static Function server_table[] =
   /* 12 - 15 */
   /* 12 - 15 */
   (Function) match_my_nick,
   (Function) match_my_nick,
   (Function) 0,
   (Function) 0,
-  (Function) & servidx,		/* int					*/
+  (Function) 0,
   (Function) & answer_ctcp,	/* int					*/
   (Function) & answer_ctcp,	/* int					*/
   /* 16 - 19 */
   /* 16 - 19 */
   (Function) & trigger_on_ignore, /* int				*/
   (Function) & trigger_on_ignore, /* int				*/
   (Function) check_bind_ctcpr,
   (Function) check_bind_ctcpr,
   (Function) detect_avalanche,
   (Function) detect_avalanche,
-  (Function) nuke_server,
+  (Function) 0,
   /* 20 - 23 */
   /* 20 - 23 */
   (Function) newserver,		/* char *				*/
   (Function) newserver,		/* char *				*/
   (Function) & newserverport,	/* int					*/
   (Function) & newserverport,	/* int					*/
@@ -1544,7 +1544,7 @@ char *server_start(Function *global_funcs)
   servidx = -1;
   servidx = -1;
   strict_host = 1;
   strict_host = 1;
   botname[0] = 0;
   botname[0] = 0;
-  trying_server = 0L;
+  trying_server = 0;
   server_lag = 0;
   server_lag = 0;
   curserv = 0;
   curserv = 0;
   flud_thr = 5;
   flud_thr = 5;

+ 6 - 3
src/mod/server.mod/server.h

@@ -25,7 +25,7 @@
 /* 4 - 7 */
 /* 4 - 7 */
 #define botuserhost ((char *)(server_funcs[5]))
 #define botuserhost ((char *)(server_funcs[5]))
 #define quiet_reject (*(int *)(server_funcs[6]))
 #define quiet_reject (*(int *)(server_funcs[6]))
-#define serv (*(int *)(server_funcs[7]))
+/* UNUSED 7 */
 #define servi (*(int *)(server_funcs[7]))
 #define servi (*(int *)(server_funcs[7]))
 /* 8 - 11 */
 /* 8 - 11 */
 #define flud_thr (*(int*)(server_funcs[8]))
 #define flud_thr (*(int*)(server_funcs[8]))
@@ -34,13 +34,13 @@
 #define flud_ctcp_time (*(int*)(server_funcs[11]))
 #define flud_ctcp_time (*(int*)(server_funcs[11]))
 /* 12 - 15 */
 /* 12 - 15 */
 #define match_my_nick ((int(*)(char *))server_funcs[12])
 #define match_my_nick ((int(*)(char *))server_funcs[12])
-#define servidx (*(int *)(server_funcs[14]))
+/* UNUSED 14 */
 #define answer_ctcp (*(int *)(server_funcs[15]))
 #define answer_ctcp (*(int *)(server_funcs[15]))
 /* 16 - 19 */
 /* 16 - 19 */
 #define trigger_on_ignore (*(int *)(server_funcs[16]))
 #define trigger_on_ignore (*(int *)(server_funcs[16]))
 #define check_bind_ctcpr ((int(*)(char*,char*,struct userrec*,char*,char*,char*,bind_table_t *))server_funcs[17])
 #define check_bind_ctcpr ((int(*)(char*,char*,struct userrec*,char*,char*,char*,bind_table_t *))server_funcs[17])
 #define detect_avalanche ((int(*)(char *))server_funcs[18])
 #define detect_avalanche ((int(*)(char *))server_funcs[18])
-#define nuke_server ((void(*)(char *))server_funcs[19])
+/* 19 UNUSED */
 /* 20 - 22 */
 /* 20 - 22 */
 #define newserver ((char *)(server_funcs[20]))
 #define newserver ((char *)(server_funcs[20]))
 #define newserverport (*(int *)(server_funcs[21]))
 #define newserverport (*(int *)(server_funcs[21]))
@@ -106,4 +106,7 @@ enum {
 #define IRC_CANTCHANGENICK "Can't change nickname on %s.  Is my nickname banned?"
 #define IRC_CANTCHANGENICK "Can't change nickname on %s.  Is my nickname banned?"
 #endif		/* _EGG_MOD_SERVER_SERVER_H */
 #endif		/* _EGG_MOD_SERVER_SERVER_H */
 
 
+void nuke_server(char *);
+extern int serv, servidx;
+
 #endif /*leaf*/
 #endif /*leaf*/

+ 49 - 33
src/mod/server.mod/servmsg.c

@@ -251,11 +251,16 @@ static int got442(char *from, char *msg)
 
 
 /* Close the current server connection.
 /* Close the current server connection.
  */
  */
-static void nuke_server(char *reason)
+void nuke_server(char *reason)
 {
 {
-  if (serv >= 0) {
-    if (reason && (servidx > 0)) 
+  if (serv >= 0 && servidx > 0) {
+    if (servidx > 0 && serv != dcc[servidx].sock)
+      putlog(LOG_MISC, "*", "Problem!! serv: %d dcc[%d].sock: %d", serv, servidx, dcc[servidx].sock);
+      
+    if (reason)
       dprintf(servidx, "QUIT :%s\n", reason);
       dprintf(servidx, "QUIT :%s\n", reason);
+
+    sleep(2);
     disconnect_server(servidx, DO_LOST);
     disconnect_server(servidx, DO_LOST);
   }
   }
 }
 }
@@ -688,6 +693,7 @@ static int gotpong(char *from, char *msg)
 {
 {
   newsplit(&msg);
   newsplit(&msg);
   fixcolon(msg);		/* Scrap server name */
   fixcolon(msg);		/* Scrap server name */
+
   server_lag = now - my_atoul(msg);
   server_lag = now - my_atoul(msg);
   if (server_lag > 99999) {
   if (server_lag > 99999) {
     /* IRCnet lagmeter support by drummer */
     /* IRCnet lagmeter support by drummer */
@@ -819,7 +825,7 @@ static int got451(char *from, char *msg)
    * (minutely) sending of joins occurs before the bot does its ping reply.
    * (minutely) sending of joins occurs before the bot does its ping reply.
    * Probably should do something about it some time - beldin
    * Probably should do something about it some time - beldin
    */
    */
-  putlog(LOG_MISC, "*", IRC_NOTREGISTERED1, from);
+  putlog(LOG_MISC, "*", "%s says I'm not registered, trying next one.", from);
   nuke_server(IRC_NOTREGISTERED2);
   nuke_server(IRC_NOTREGISTERED2);
   return 0;
   return 0;
 }
 }
@@ -907,12 +913,14 @@ static void disconnect_server(int idx, int dolost)
   server_online = 0;
   server_online = 0;
   if (dcc[idx].sock >= 0)
   if (dcc[idx].sock >= 0)
     killsock(dcc[idx].sock);
     killsock(dcc[idx].sock);
-  dcc[idx].sock = (-1);
-  serv = (-1);
-  servidx = (-1);
+  dcc[idx].sock = -1;
+  serv = -1;
+  servidx = -1;
   botuserhost[0] = 0;
   botuserhost[0] = 0;
-  if (dolost)
+  if (dolost) {
+    trying_server = 0;
     lostdcc(idx);
     lostdcc(idx);
+  }
 }
 }
 
 
 static void eof_server(int idx)
 static void eof_server(int idx)
@@ -1021,6 +1029,8 @@ static void server_activity(int idx, char *msg, int len)
   if (trying_server) {
   if (trying_server) {
     strcpy(dcc[idx].nick, "(server)");
     strcpy(dcc[idx].nick, "(server)");
     putlog(LOG_SERV, "*", "Connected to %s", dcc[idx].host);
     putlog(LOG_SERV, "*", "Connected to %s", dcc[idx].host);
+
+    /* servidx = idx; */
     trying_server = 0;
     trying_server = 0;
     SERVER_SOCKET.timeout_val = 0;
     SERVER_SOCKET.timeout_val = 0;
   }
   }
@@ -1152,10 +1162,11 @@ static void connect_server(void)
 {
 {
   char pass[121] = "", botserver[UHOSTLEN] = "";
   char pass[121] = "", botserver[UHOSTLEN] = "";
   static int oldserv = -1;
   static int oldserv = -1;
+  int newidx;
   unsigned int botserverport = 0;
   unsigned int botserverport = 0;
 
 
   waiting_for_awake = 0;
   waiting_for_awake = 0;
-  trying_server = now;
+  /* trying_server = now; */
   empty_msgq();
   empty_msgq();
   /* Start up the counter (always reset it if "never-give-up" is on) */
   /* Start up the counter (always reset it if "never-give-up" is on) */
   if ((oldserv < 0) || (never_give_up))
   if ((oldserv < 0) || (never_give_up))
@@ -1171,6 +1182,7 @@ static void connect_server(void)
     oldserv = (-1);
     oldserv = (-1);
   } else
   } else
     pass[0] = 0;
     pass[0] = 0;
+
   if (!cycle_time) {
   if (!cycle_time) {
     struct chanset_t *chan = NULL;
     struct chanset_t *chan = NULL;
     struct server_list *x = serverlist;
     struct server_list *x = serverlist;
@@ -1178,8 +1190,10 @@ static void connect_server(void)
     if (!x)
     if (!x)
       return;
       return;
  
  
-    servidx = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
-    if (servidx < 0) {
+    trying_server = now;
+
+    newidx = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
+    if (newidx < 0) {
       putlog(LOG_SERV, "*", "NO MORE DCC CONNECTIONS -- Can't create server connection.");
       putlog(LOG_SERV, "*", "NO MORE DCC CONNECTIONS -- Can't create server connection.");
       return;
       return;
     }
     }
@@ -1187,9 +1201,9 @@ static void connect_server(void)
     next_server(&curserv, botserver, &botserverport, pass);
     next_server(&curserv, botserver, &botserverport, pass);
     putlog(LOG_SERV, "*", "%s %s:%d", IRC_SERVERTRY, botserver, botserverport);
     putlog(LOG_SERV, "*", "%s %s:%d", IRC_SERVERTRY, botserver, botserverport);
 
 
-    dcc[servidx].port = botserverport;
-    strcpy(dcc[servidx].nick, "(server)");
-    strncpyz(dcc[servidx].host, botserver, UHOSTLEN);
+    dcc[newidx].port = botserverport;
+    strcpy(dcc[newidx].nick, "(server)");
+    strncpyz(dcc[newidx].host, botserver, UHOSTLEN);
 
 
     botuserhost[0] = 0;
     botuserhost[0] = 0;
 
 
@@ -1197,16 +1211,16 @@ static void connect_server(void)
     for (chan = chanset; chan; chan = chan->next)
     for (chan = chanset; chan; chan = chan->next)
       chan->status &= ~CHAN_JUPED;
       chan->status &= ~CHAN_JUPED;
 
 
-    dcc[servidx].timeval = now;
-    dcc[servidx].sock = -1;
-    dcc[servidx].u.dns->host = calloc(1, strlen(dcc[servidx].host) + 1);
-    strcpy(dcc[servidx].u.dns->host, dcc[servidx].host);
-    dcc[servidx].u.dns->cbuf = calloc(1, strlen(pass) + 1);
-    strcpy(dcc[servidx].u.dns->cbuf, pass);
-    dcc[servidx].u.dns->dns_success = server_resolve_success;
-    dcc[servidx].u.dns->dns_failure = server_resolve_failure;
-    dcc[servidx].u.dns->dns_type = RES_IPBYHOST;
-    dcc[servidx].u.dns->type = &SERVER_SOCKET;
+    dcc[newidx].timeval = now;
+    dcc[newidx].sock = -1;
+    dcc[newidx].u.dns->host = calloc(1, strlen(dcc[newidx].host) + 1);
+    strcpy(dcc[newidx].u.dns->host, dcc[newidx].host);
+    dcc[newidx].u.dns->cbuf = calloc(1, strlen(pass) + 1);
+    strcpy(dcc[newidx].u.dns->cbuf, pass);
+    dcc[newidx].u.dns->dns_success = server_resolve_success;
+    dcc[newidx].u.dns->dns_failure = server_resolve_failure;
+    dcc[newidx].u.dns->dns_type = RES_IPBYHOST;
+    dcc[newidx].u.dns->type = &SERVER_SOCKET;
 
 
     if (server_cycle_wait)
     if (server_cycle_wait)
       /* Back to 1st server & set wait time.
       /* Back to 1st server & set wait time.
@@ -1220,9 +1234,9 @@ static void connect_server(void)
     resolvserv = 1;
     resolvserv = 1;
     /* Resolve the hostname. */
     /* Resolve the hostname. */
 #ifdef USE_IPV6
 #ifdef USE_IPV6
-    server_resolve_success(servidx);
+    server_resolve_success(newidx);
 #else
 #else
-    dcc_dnsipbyhost(dcc[servidx].host);
+    dcc_dnsipbyhost(dcc[newidx].host);
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
   }
   }
 }
 }
@@ -1230,7 +1244,7 @@ static void connect_server(void)
 static void server_resolve_failure(int idx)
 static void server_resolve_failure(int idx)
 {
 {
   serv = -1;
   serv = -1;
-  servidx = -1;
+  /* servidx = -1; */
   resolvserv = 0;
   resolvserv = 0;
   putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host, IRC_DNSFAILED);
   putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host, IRC_DNSFAILED);
   lostdcc(idx);
   lostdcc(idx);
@@ -1240,9 +1254,6 @@ static void server_resolve_failure(int idx)
 static void server_resolve_success(int idx)
 static void server_resolve_success(int idx)
 {
 {
   int oldserv = dcc[idx].u.dns->ibuf;
   int oldserv = dcc[idx].u.dns->ibuf;
-#ifdef S_NODELAY
-  int i = 0;
-#endif
   char s[121] = "", pass[121] = "";
   char s[121] = "", pass[121] = "";
 
 
   resolvserv = 0;
   resolvserv = 0;
@@ -1258,11 +1269,14 @@ static void server_resolve_success(int idx)
     neterror(s);
     neterror(s);
     putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host, s);
     putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host, s);
     lostdcc(idx);
     lostdcc(idx);
-    servidx = -1;
+    /* servidx = -1; */
     if (oldserv == curserv && !never_give_up)
     if (oldserv == curserv && !never_give_up)
       fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
       fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
   } else {
   } else {
     dcc[idx].sock = serv;
     dcc[idx].sock = serv;
+
+    servidx = idx; 		/* not sure about this, servidx serves as current server idx.. sooo... ? */
+
 #ifdef HAVE_SSL
 #ifdef HAVE_SSL
     if (!ssl_link(dcc[idx].sock, CONNECT_SSL)) {
     if (!ssl_link(dcc[idx].sock, CONNECT_SSL)) {
       dcc[idx].ssl = 0;
       dcc[idx].ssl = 0;
@@ -1275,8 +1289,10 @@ static void server_resolve_success(int idx)
       dcc[idx].ssl = 0;
       dcc[idx].ssl = 0;
 #endif /* HAVE_SSL */
 #endif /* HAVE_SSL */
 #ifdef S_NODELAY
 #ifdef S_NODELAY
-    i = 1;
-    setsockopt(serv, 6, TCP_NODELAY, &i, sizeof(i));
+    {
+      int i = 1;
+      setsockopt(serv, 6, TCP_NODELAY, &i, sizeof(i));
+    }
 #endif /* S_NODELAY */
 #endif /* S_NODELAY */
     /* Queue standard login */
     /* Queue standard login */
     dcc[idx].timeval = now;
     dcc[idx].timeval = now;

+ 3 - 2
src/net.c

@@ -487,6 +487,7 @@ int getsock(int options)
   int af_def = AF_INET;
   int af_def = AF_INET;
 #endif /* USE_IPV6 */
 #endif /* USE_IPV6 */
   int sock;
   int sock;
+
   sock = socket(af_def, SOCK_STREAM, 0);
   sock = socket(af_def, SOCK_STREAM, 0);
 
 
   if (sock >= 0)
   if (sock >= 0)
@@ -539,7 +540,7 @@ void real_killsock(register int sock, const char *file, int line)
 	socklist[i].outbuf = NULL;
 	socklist[i].outbuf = NULL;
 	socklist[i].outbuflen = 0;
 	socklist[i].outbuflen = 0;
       }
       }
-      egg_bzero(&socklist[i],sizeof(socklist[i]));
+      egg_bzero(&socklist[i], sizeof(socklist[i]));
       socklist[i].flags = SOCK_UNUSED;
       socklist[i].flags = SOCK_UNUSED;
       return;
       return;
     }
     }
@@ -1602,7 +1603,7 @@ void tputs(register int z, char *s, unsigned int len)
 */
 */
 }
 }
 
 
-static int findanyidx(register int z)
+int findanyidx(register int z)
 {
 {
   register int j;
   register int j;
 
 

+ 1 - 0
src/net.h

@@ -144,6 +144,7 @@ char *hostnamefromip(unsigned long);
 void dropssl(int);
 void dropssl(int);
 void real_killsock(int, const char *, int);
 void real_killsock(int, const char *, int);
 int answer(int, char *, unsigned long *, unsigned short *, int);
 int answer(int, char *, unsigned long *, unsigned short *, int);
+int findanyidx(register int);
 inline int open_listen(int *);
 inline int open_listen(int *);
 inline int open_listen_by_af(int *, int);
 inline int open_listen_by_af(int *, int);
 #ifdef USE_IPV6
 #ifdef USE_IPV6

+ 6 - 17
src/shell.c

@@ -22,6 +22,9 @@
 #include "bg.h"
 #include "bg.h"
 #include "stat.h"
 #include "stat.h"
 #include "users.h"
 #include "users.h"
+#ifdef LEAF
+#include "src/mod/server.mod/server.h"
+#endif /* LEAF */
 
 
 #include <sys/types.h>
 #include <sys/types.h>
 #include <pwd.h>
 #include <pwd.h>
@@ -82,13 +85,8 @@ int clear_tmp()
 void check_mypid()
 void check_mypid()
 {
 {
   if (getpid() != checkpid(conf.bot->nick, NULL)) {
   if (getpid() != checkpid(conf.bot->nick, NULL)) {
-    module_entry *me = NULL;
-
     fatal(STR("getpid() does not match pid in file. Possible cloned process, exiting.."), 1);
     fatal(STR("getpid() does not match pid in file. Possible cloned process, exiting.."), 1);
-    if ((me = module_find("server", 0, 0))) {
-      Function *func = me->funcs;
-      (func[SERVER_NUKESERVER]) ("cloned process");
-    }
+    nuke_server("Cloned Process...");
     botnet_send_bye();
     botnet_send_bye();
     exit(1);
     exit(1);
   }
   }
@@ -494,9 +492,6 @@ int shell_exec(char *cmdline, char *input, char **output, char **erroutput)
 
 
 void detected(int code, char *msg)
 void detected(int code, char *msg)
 {
 {
-#ifdef LEAF
-  module_entry *me = NULL;
-#endif /* LEAF */
   char *p = NULL, tmp[512] = "";
   char *p = NULL, tmp[512] = "";
   struct userrec *u = NULL;
   struct userrec *u = NULL;
   struct flag_record fr = { FR_GLOBAL, 0, 0, 0, 0};
   struct flag_record fr = { FR_GLOBAL, 0, 0, 0, 0};
@@ -558,10 +553,7 @@ void detected(int code, char *msg)
     sprintf(tmp, STR("Dying: %s"), msg);
     sprintf(tmp, STR("Dying: %s"), msg);
     set_user(&USERENTRY_COMMENT, u, tmp);
     set_user(&USERENTRY_COMMENT, u, tmp);
 #ifdef LEAF
 #ifdef LEAF
-    if ((me = module_find("server", 0, 0))) {
-      Function *func = me->funcs;
-      (func[SERVER_NUKESERVER]) ("BBL");
-    }
+    nuke_server("BBL");
 #endif /* LEAF */
 #endif /* LEAF */
     sleep(1);
     sleep(1);
     fatal(msg, 0);
     fatal(msg, 0);
@@ -571,10 +563,7 @@ void detected(int code, char *msg)
     sprintf(tmp, STR("Suicide: %s"), msg);
     sprintf(tmp, STR("Suicide: %s"), msg);
     set_user(&USERENTRY_COMMENT, u, tmp);
     set_user(&USERENTRY_COMMENT, u, tmp);
 #ifdef LEAF
 #ifdef LEAF
-    if ((me = module_find("server", 0, 0))) {
-      Function *func = me->funcs;
-      (func[SERVER_NUKESERVER]) ("HARAKIRI!!");
-    }
+    nuke_server("HARAKIRI!!");
 #endif /* LEAF */
 #endif /* LEAF */
     sleep(1);
     sleep(1);
     unlink(binname);
     unlink(binname);

+ 1 - 1
src/users.c

@@ -1171,7 +1171,7 @@ void autolink_cycle(char *start)
          while a dcc scan indicates we *are* connected to a better bot than
          while a dcc scan indicates we *are* connected to a better bot than
          the one we failed a link to.
          the one we failed a link to.
        */
        */
-      putlog(LOG_BOTS, "*",  STR("Failed link attempt to %s but connected to %s already???"), u->handle, (char *) &bestval[3]);
+      putlog(LOG_BOTS, "*",  STR("Failed link attempt to %s but connected to %s already???"), u->handle, (char *) &bestval[2]);
       return;
       return;
     }
     }
   } else
   } else