ソースを参照

Add DCC_BOT_CONNWAIT

Bryan Drewery 5 ヶ月 前
コミット
adb098aba0
4 ファイル変更57 行追加8 行削除
  1. 2 1
      src/botnet.cc
  2. 46 2
      src/dcc.cc
  3. 2 1
      src/dcc.h
  4. 7 4
      src/users.cc

+ 2 - 1
src/botnet.cc

@@ -922,7 +922,7 @@ int botunlink(int idx, const char *nick, const char *reason)
     dprintf(idx, "%s\n", "Unlinking all bots...");
   for (i = 0; i < dcc_total; i++) {
     if (dcc[i].type && ((nick[0] == '*') || !strcasecmp(dcc[i].nick, nick))) {
-      if (dcc[i].type == &DCC_FORK_BOT) {
+      if (dcc[i].type == &DCC_FORK_BOT || dcc[i].type == &DCC_BOT_CONNWAIT) {
 	if (idx >= 0)
 	  dprintf(idx, "%s: %s -> %s.\n", "Killed link attempt to",
 		  dcc[i].nick, dcc[i].host);
@@ -1034,6 +1034,7 @@ int botlink(const char *linker, int idx, char *nick)
     for (i = 0; i < dcc_total; i++) {
       if (dcc[i].type && (dcc[i].user == u) &&
 	  ((dcc[i].type == &DCC_FORK_BOT) ||
+	   (dcc[i].type == &DCC_BOT_CONNWAIT) ||
 	   (dcc[i].type == &DCC_BOT_NEW))) {
 	if (idx >= 0)
 	  dprintf(idx, "Already linking to that bot\n");

+ 46 - 2
src/dcc.cc

@@ -247,7 +247,8 @@ greet_new_bot(int idx)
       egg_version);
 
   for (int i = 0; i < dcc_total; i++) {
-    if (dcc[i].type && dcc[i].type == &DCC_FORK_BOT) {
+    if (dcc[i].type &&
+        (dcc[i].type == &DCC_FORK_BOT || dcc[i].type == &DCC_BOT_CONNWAIT)) {
       killsock(dcc[i].sock);
       lostdcc(i);
     }
@@ -565,7 +566,7 @@ display_dcc_bot(int idx, char *buf, size_t bufsiz)
 static void
 display_dcc_fork_bot(int idx, char *buf, size_t bufsiz)
 {
-  simple_snprintf(buf, bufsiz, "conn  bot");
+  simple_snprintf(buf, bufsiz, "fork  bot");
 }
 
 struct dcc_table DCC_BOT = {
@@ -581,6 +582,49 @@ struct dcc_table DCC_BOT = {
   NULL
 };
 
+static void dcc_bot_connwait_eof(int idx)
+{
+	putlog(LOG_MISC, "*", "Lost connection while connecting to [%s/%d]",
+	    iptostr(htonl(dcc[idx].addr)), dcc[idx].port);
+	killsock(dcc[idx].sock);
+	lostdcc(idx);
+}
+
+static void dcc_bot_connwait(int idx, char *buf, int len)
+{
+	/* Ignore anything now. */
+}
+
+static void dcc_bot_connwait_timeout(int idx)
+{
+}
+
+static void
+dcc_bot_connwait_display(int idx, char *buf, size_t bufsiz)
+{
+  simple_snprintf(buf, bufsiz, "conn  bot");
+}
+
+static void
+dcc_bot_connwait_free(int idx, void *x)
+{
+  /* free's dcc[idx].u.other (dns_info) */
+  free(x);
+}
+
+struct dcc_table DCC_BOT_CONNWAIT = {
+  "BOT_CONNWAIT",
+  0,
+  dcc_bot_connwait_eof,
+  dcc_bot_connwait,
+  &connect_timeout,
+  dcc_bot_connwait_timeout,
+  dcc_bot_connwait_display,
+  dcc_bot_connwait_free,
+  NULL,
+  NULL
+};
+
 struct dcc_table DCC_FORK_BOT = {
   "FORK_BOT",
   0,

+ 2 - 1
src/dcc.h

@@ -233,7 +233,8 @@ extern struct cmd_pass          *cmdpass;
 extern struct dcc_table DCC_CHAT, DCC_BOT, 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,
- DCC_TELNET, DCC_IDENT, DCC_IDENTWAIT, DCC_IDENTD, DCC_IDENTD_CONNECT, DCC_DNSWAIT;
+ DCC_TELNET, DCC_IDENT, DCC_IDENTWAIT, DCC_IDENTD, DCC_IDENTD_CONNECT,
+ DCC_DNSWAIT, DCC_BOT_CONNWAIT;
 
 void send_timesync(int);
 void failed_link(int);

+ 7 - 4
src/users.cc

@@ -1011,7 +1011,7 @@ static void autolink_cycle_hub(char *start)
    if (dcc[i].type) {
     if (dcc[i].type == &DCC_BOT_NEW)
       return;
-    if (dcc[i].type == &DCC_FORK_BOT)
+    if (dcc[i].type == &DCC_FORK_BOT || dcc[i].type == &DCC_BOT_CONNWAIT)
       return;
     if (dcc[i].type == &DCC_BOT) {
       if (dcc[i].status & (STAT_OFFEREDU | STAT_GETTINGU | STAT_SENDINGU))
@@ -1137,7 +1137,8 @@ static void autolink_cycle_leaf(char *start)
 
   for (int i = 0; i < dcc_total; i++) {
    if (dcc[i].type) {
-    if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
+    if (dcc[i].type == &DCC_BOT_NEW || dcc[i].type == &DCC_FORK_BOT ||
+        dcc[i].type == &DCC_BOT_CONNWAIT)
       return;
     if (dcc[i].hub && dcc[i].type == &DCC_BOT) {
       strlcpy(curhub, dcc[i].nick, sizeof(curhub));
@@ -1210,7 +1211,8 @@ void autolink_cycle()
       // Make sure not already trying for the localhub
       for (int i = 0; i < dcc_total; i++) {
        if (dcc[i].type) {
-        if ((dcc[i].type == &DCC_BOT_NEW) || (dcc[i].type == &DCC_FORK_BOT))
+         if (dcc[i].type == &DCC_BOT_NEW || dcc[i].type == &DCC_FORK_BOT ||
+             dcc[i].type == &DCC_BOT_CONNWAIT)
           return;
        }
       }
@@ -1228,7 +1230,8 @@ void check_stale_dcc_users()
     
 
     if (dcc[i].user == NULL && !(dcc[i].user = get_user_by_handle(userlist, dcc[i].nick))) { /* Removed user */
-      if (dcc[i].type == &DCC_BOT || dcc[i].type == &DCC_FORK_BOT || dcc[i].type == &DCC_BOT_NEW)
+      if (dcc[i].type == &DCC_BOT || dcc[i].type == &DCC_FORK_BOT ||
+          dcc[i].type == &DCC_BOT_NEW || dcc[i].type == &DCC_BOT_CONNWAIT)
         botunlink(i, dcc[i].nick, "No longer a valid bot.");
       else if (dcc[i].type == &DCC_CHAT) {
         if (!backgrd && term_z && !strcmp(dcc[i].nick, "HQ"))