Переглянути джерело

* ctcp.mod no longer is a 'module'
Several hacks were involved in making it work.. see ctcp.c
* Fixed disconnect_server()/servidx once and for all.


svn: 649

Bryan Drewery 22 роки тому
батько
коміт
f48abe350c

+ 3 - 0
src/chanprog.h

@@ -2,6 +2,9 @@
 #define _CHANPROG_H
 
 #ifndef MAKING_MODS
+extern struct chanset_t *chanset;
+extern char botname[];
+
 void do_chanset(struct chanset_t *, char *, int);
 void checkchans(int);
 void tell_verbose_uptime(int);

+ 2 - 1
src/dcc.h

@@ -24,7 +24,6 @@ struct dcc_table {
   void (*outdone) (int);
 };
 
-
 struct dcc_t {
   long sock;                    /* This should be a long to keep 64-bit
                                    machines sane                         */
@@ -208,6 +207,8 @@ struct dupwait_info {
 
 #ifndef MAKING_MODS
 
+extern struct dcc_t *dcc;
+extern int dcc_total;
 extern struct dcc_table DCC_CHAT, DCC_BOT, DCC_LOST, DCC_BOT_NEW,
  DCC_RELAY, DCC_RELAYING, DCC_FORK_RELAY, DCC_PRE_RELAY, DCC_CHAT_PASS,
  DCC_FORK_BOT, DCC_SOCKET, DCC_TELNET_ID, DCC_TELNET_NEW, DCC_TELNET_PW,

+ 1 - 1
src/main.c

@@ -1209,7 +1209,7 @@ int main(int argc, char **argv)
   module_load("update"); 
   module_load("notes");
   module_load("console");
-  module_load("ctcp");
+  ctcp_init();
   module_load("compress");
   chanprog();
   clear_tmp();

+ 3 - 1
src/main.h

@@ -1,9 +1,11 @@
 #ifndef _MAIN_H
 #define _MAIN_H
 
-extern int use_stderr;
 
 #ifndef MAKING_MODS
+extern int use_stderr;
+extern time_t now;
+
 int crontab_exists();
 void crontab_create(int);
 void fatal(const char *, int);

+ 17 - 37
src/mod/ctcp.mod/ctcp.c

@@ -6,33 +6,32 @@
 
 #define MODULE_NAME "ctcp"
 #define MAKING_CTCP
+#undef MAKING_MODS /* TEMP HACK */
 #include "ctcp.h"
-#include "src/mod/module.h"
+#include "src/common.h"
+#include "src/main.h"
+#include "src/cfg.h"
+#include "src/chanprog.h"
+#include "src/cmds.h"
+#include "src/misc.h"
 #include "src/net.h"
+#include "src/userrec.h"
+#include "src/botmsg.h"
+#include "src/tclhash.h"
+#include "src/modules.h"
 
 #ifdef LEAF
-#include "server.mod/server.h"
+//#include "server.mod/server.h"
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <sys/utsname.h>
 #include <pwd.h>
 #include <ctype.h>
-
-static Function *global = NULL, *server_funcs = NULL;
-#else /* !LEAF */
-static Function *global = NULL;
 #endif /* LEAF */
 
-#define CLOAK_COUNT             10 /* The number of scripts currently existing */
-#define CLOAK_PLAIN             1 /* This is your plain bitchx client behaviour */
-#define CLOAK_CRACKROCK         2
-#define CLOAK_NEONAPPLE         3
-#define CLOAK_TUNNELVISION      4
-#define CLOAK_ARGON             5
-#define CLOAK_EVOLVER           6
-#define CLOAK_PREVAIL           7
-#define CLOAK_CYPRESS           8 /* Now with full theme and customization support */
-#define CLOAK_MIRC              9
+extern int 		max_dcc;
+extern char 		kickprefix[], bankickprefix[], botrealname[], botuserhost[],
+			ctcp_reply[];
 
 int cloak_script = CLOAK_PLAIN;
 
@@ -726,37 +725,19 @@ struct cfg_entry CFG_CLOAK_SCRIPT = {
 };
 
 
-EXPORT_SCOPE char *ctcp_start();
-
-static Function ctcp_table[] =
-{
-  (Function) ctcp_start,
-  (Function) NULL,
-  (Function) NULL,
-  (Function) NULL,
-};
-
-char *ctcp_start(Function * global_funcs)
+void ctcp_init()
 {
 #ifdef LEAF
   char *p;
   struct utsname un;
-#endif /* LEAF */
-  global = global_funcs;
 
-  module_register(MODULE_NAME, ctcp_table, 1, 0);
-#ifdef LEAF
-  if (!(server_funcs = module_depend(MODULE_NAME, "server", 1, 0))) {
-    module_undepend(MODULE_NAME);
-    return "This module requires server module 1.0 or later.";
-  }
   egg_bzero(&un, sizeof(un));
   if (!uname(&un)) {
     strncpyz(cloak_os, un.sysname, sizeof(cloak_os));
     strncpyz(cloak_osver, un.release, sizeof(cloak_osver));
     strncpyz(cloak_host, un.nodename, sizeof(cloak_host));
   } else {
-/* shit, we have to come up with something ourselves.. */
+    /* shit, we have to come up with something ourselves.. */
     switch (random() % 2) {
     case 0:
       strcpy(cloak_os, STR("Linux"));
@@ -793,6 +774,5 @@ char *ctcp_start(Function * global_funcs)
   add_hook(HOOK_MINUTELY, (Function) ctcp_minutely);
 #endif /* LEAF */
   add_cfg(&CFG_CLOAK_SCRIPT);
-  return NULL;
 }
 

+ 13 - 0
src/mod/ctcp.mod/ctcp.h

@@ -21,4 +21,17 @@
 #define CLIENTINFO_PING "PING returns the arguments it receives"
 #define CLIENTINFO_ECHO "ECHO returns the arguments it receives"
 
+
+#define CLOAK_COUNT             10 /* The number of scripts currently existing */
+#define CLOAK_PLAIN             1 /* This is your plain bitchx client behaviour */
+#define CLOAK_CRACKROCK         2
+#define CLOAK_NEONAPPLE         3
+#define CLOAK_TUNNELVISION      4
+#define CLOAK_ARGON             5
+#define CLOAK_EVOLVER           6
+#define CLOAK_PREVAIL           7
+#define CLOAK_CYPRESS           8 /* Now with full theme and customization support */
+#define CLOAK_MIRC              9
+
+
 #endif				/* _EGG_MOD_CTCP_CTCP_H */

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

@@ -29,7 +29,7 @@ static int flud_thr;		/* msg flood threshold */
 static int flud_time;		/* msg flood time */
 static int flud_ctcp_thr;	/* ctcp flood threshold */
 static int flud_ctcp_time;	/* ctcp flood time */
-static char botuserhost[121];	/* bot's user@host (refreshed whenever the
+char botuserhost[121];	/* bot's user@host (refreshed whenever the
 				   bot joins a channel) */
 				/* may not be correct user@host BUT it's
 				   how the server sees it */
@@ -46,7 +46,7 @@ static int waiting_for_awake;	/* set when i unidle myself, cleared when
 static time_t server_online;	/* server connection time */
 static time_t server_cycle_wait;	/* seconds to wait before
 					   re-beginning the server list */
-static char botrealname[121];	/* realname of bot */
+char botrealname[121];	/* realname of bot */
 static int server_timeout;	/* server timeout for connecting */
 static int never_give_up;	/* never give up when connecting to servers? */
 static int strict_servernames;	/* don't update server list */
@@ -79,7 +79,7 @@ static int optimize_kicks;
 
 static void empty_msgq(void);
 static void next_server(int *, char *, unsigned int *, char *);
-static void disconnect_server(int);
+static void disconnect_server(int, int);
 static int calc_penalty(char *);
 static int fast_deq(int);
 static char *splitnicks(char **);
@@ -1374,7 +1374,7 @@ static void server_5minutely()
       /* Uh oh!  Never got pong from last time, five minutes ago!
        * Server is probably stoned.
        */
-      disconnect_server(1);
+      disconnect_server(servidx, DO_LOST);
       putlog(LOG_SERV, "*", IRC_SERVERSTONED);
     } else if (!trying_server) {
       /* Check for server being stoned. */

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

@@ -7,6 +7,9 @@
 #ifndef _EGG_MOD_SERVER_SERVER_H
 #define _EGG_MOD_SERVER_SERVER_H
 
+#define DO_LOST 1
+#define NO_LOST 0
+
 #define check_bind_ctcp(a,b,c,d,e,f) check_bind_ctcpr(a,b,c,d,e,f,BT_ctcp)
 #define check_bind_ctcr(a,b,c,d,e,f) check_bind_ctcpr(a,b,c,d,e,f,BT_ctcr)
 

+ 44 - 44
src/mod/server.mod/servmsg.c

@@ -246,12 +246,13 @@ static int got442(char *from, char *msg)
 static void nuke_server(char *reason)
 {
   if (serv >= 0) {
-    if (reason && (servidx > 0)) dprintf(servidx, "QUIT :%s\r\n", reason);
-    disconnect_server(1);
+    if (reason && (servidx > 0)) 
+      dprintf(servidx, "QUIT :%s\r\n", reason);
+    disconnect_server(servidx, DO_LOST);
   }
 }
 
-static char ctcp_reply[1024] = "";
+char ctcp_reply[1024] = "";
 
 static int lastmsgs[FLOOD_GLOBAL_MAX];
 static char lastmsghost[FLOOD_GLOBAL_MAX][81];
@@ -891,23 +892,22 @@ static int gotmode(char *from, char *msg)
 }
 
 
-static void disconnect_server(int dolost)
+static void disconnect_server(int idx, int dolost)
 {
-	if (server_online > 0) check_bind_event("disconnect-server");
-	server_online = 0;
-
-	if (servidx != -1 && dcc[servidx].sock >= 0 && serv == dcc[servidx].sock) {
-		killsock(dcc[servidx].sock);
-		dcc[servidx].sock = -1;
-		if (dolost) lostdcc(servidx);
-	}
-	servidx = -1;
-	serv = -1;
-	botuserhost[0] = 0;
+  server_online = 0;
+  if (dcc[idx].sock >= 0)
+    killsock(dcc[idx].sock);
+  dcc[idx].sock = (-1);
+  serv = (-1);
+  servidx = (-1);
+  botuserhost[0] = 0;
+  if (dolost)
+    lostdcc(idx);
 }
 
 static void eof_server(int idx)
 {
+
   putlog(LOG_SERV, "*", "%s %s", IRC_DISCONNECTED, dcc[idx].host);
 #ifdef S_AUTH
 {
@@ -919,13 +919,12 @@ static void eof_server(int idx)
   }
 }
 #endif /* S_AUTH */
-  disconnect_server(1);
+  disconnect_server(idx, DO_LOST);
 }
 
 static void display_server(int idx, char *buf)
 {
-  sprintf(buf, "%s  (lag: %d)", trying_server ? "conn" : "serv",
-	  server_lag);
+  sprintf(buf, "%s  (lag: %d)", trying_server ? "conn" : "serv", server_lag);
 }
 
 static void connect_server(void);
@@ -934,7 +933,7 @@ static void kill_server(int idx, void *x)
 {
   module_entry *me;
 
-  disconnect_server(0);
+  disconnect_server(idx, NO_LOST);	/* eof_server will lostdcc() it. */
   if ((me = module_find("channels", 0, 0)) && me->funcs) {
     struct chanset_t *chan;
 
@@ -947,8 +946,10 @@ static void kill_server(int idx, void *x)
 
 static void timeout_server(int idx)
 {
+
   putlog(LOG_SERV, "*", "Timeout: connect to %s", dcc[idx].host);
-  disconnect_server(1);
+
+  disconnect_server(idx, DO_LOST);
 }
 
 static void server_activity(int idx, char *msg, int len);
@@ -1170,8 +1171,7 @@ static void connect_server(void)
  
     servidx = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
     if (servidx < 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;
     }
 
@@ -1218,60 +1218,60 @@ static void connect_server(void)
   }
 }
 
-static void server_resolve_failure(int servidx)
+static void server_resolve_failure(int idx)
 {
   serv = -1;
   servidx = -1;
   resolvserv = 0;
-  putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[servidx].host,
-	 IRC_DNSFAILED);
-  lostdcc(servidx);
+  putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host, IRC_DNSFAILED);
+  lostdcc(idx);
+
 }
 
-static void server_resolve_success(int servidx)
+static void server_resolve_success(int idx)
 {
-  int oldserv = dcc[servidx].u.dns->ibuf;
+  int oldserv = dcc[idx].u.dns->ibuf;
 #ifdef S_NODELAY
   int i = 0;
 #endif
   char s[121], pass[121];
 
   resolvserv = 0;
-  dcc[servidx].addr = dcc[servidx].u.dns->ip;
-  strcpy(pass, dcc[servidx].u.dns->cbuf);
-  changeover_dcc(servidx, &SERVER_SOCKET, 0);
+  dcc[idx].addr = dcc[idx].u.dns->ip;
+  strcpy(pass, dcc[idx].u.dns->cbuf);
+  changeover_dcc(idx, &SERVER_SOCKET, 0);
 #ifdef USE_IPV6
-  serv = open_telnet(dcc[servidx].host, dcc[servidx].port);
+  serv = open_telnet(dcc[idx].host, dcc[idx].port);
 #else
-  serv = open_telnet(iptostr(htonl(dcc[servidx].addr)), dcc[servidx].port);
+  serv = open_telnet(iptostr(htonl(dcc[idx].addr)), dcc[idx].port);
 #endif /* USE_IPV6 */
   if (serv < 0) {
     neterror(s);
-    putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[servidx].host,
+    putlog(LOG_SERV, "*", "%s %s (%s)", IRC_FAILEDCONNECT, dcc[idx].host,
 	   s);
-    lostdcc(servidx);
+    lostdcc(idx);
     servidx = -1;
     if (oldserv == curserv && !never_give_up)
       fatal("NO SERVERS WILL ACCEPT MY CONNECTION.", 0);
   } else {
-    dcc[servidx].sock = serv;
+    dcc[idx].sock = serv;
 #ifdef HAVE_SSL
-    if (!ssl_link(dcc[servidx].sock, CONNECT_SSL)) {
-      dcc[servidx].ssl = 0;
-      putlog(LOG_SERV, "*", "SSL for '%s' failed", dcc[servidx].host);
+    if (!ssl_link(dcc[idx].sock, CONNECT_SSL)) {
+      dcc[idx].ssl = 0;
+      putlog(LOG_SERV, "*", "SSL for '%s' failed", dcc[idx].host);
     } else {
-      putlog(LOG_SERV, "*", "SSL for '%s' successful", dcc[servidx].host);
-      dcc[servidx].ssl = 1;
+      putlog(LOG_SERV, "*", "SSL for '%s' successful", dcc[idx].host);
+      dcc[idx].ssl = 1;
     }
 #else
-      dcc[servidx].ssl = 0;
+      dcc[idx].ssl = 0;
 #endif /* HAVE_SSL */
 #ifdef S_NODELAY
     i = 1;
     setsockopt(serv, 6, TCP_NODELAY, &i, sizeof(i));
 #endif /* S_NODELAY */
     /* Queue standard login */
-    dcc[servidx].timeval = now;
+    dcc[idx].timeval = now;
     SERVER_SOCKET.timeout_val = &server_timeout;
     /* Another server may have truncated it, so use the original */
     strcpy(botname, origbotname);
@@ -1280,7 +1280,7 @@ static void server_resolve_success(int servidx)
 
     if (pass[0]) dprintf(DP_MODE, "PASS %s\r\n", pass);
     dprintf(DP_MODE, "NICK %s\r\n", botname);
-    dprintf(DP_MODE, "USER %s localhost %s :%s\r\n", botuser, dcc[servidx].host, botrealname);
+    dprintf(DP_MODE, "USER %s localhost %s :%s\r\n", botuser, dcc[idx].host, botrealname);
     /* Wait for async result now */
   }
 }

+ 2 - 2
src/mod/static.h

@@ -8,7 +8,6 @@
 char *channels_start();
 char *compress_start();
 char *console_start();
-char *ctcp_start();
 char *dns_start();
 #ifdef LEAF
 char *irc_start();
@@ -21,12 +20,13 @@ char *share_start();
 char *transfer_start();
 char *update_start();
 
+void ctcp_init();
+
 static void link_statics()
 {
   check_static("channels", channels_start);
   check_static("compress", compress_start);
   check_static("console", console_start);
-  check_static("ctcp", ctcp_start);
   check_static("dns", dns_start);
 #ifdef LEAF
   check_static("irc", irc_start);