Ver código fonte

Add basic infrastructure for tracking feature flags on the botlink.

Issue #87
Bryan Drewery 10 anos atrás
pai
commit
dc837f0b75
7 arquivos alterados com 33 adições e 21 exclusões
  1. 9 5
      src/botcmd.cc
  2. 6 5
      src/botmsg.cc
  3. 7 2
      src/botnet.cc
  4. 2 2
      src/botnet.h
  5. 3 2
      src/dcc.cc
  6. 4 4
      src/mod/share.mod/share.cc
  7. 2 1
      src/tandem.h

+ 9 - 5
src/botcmd.cc

@@ -612,7 +612,7 @@ static void bot_unlink(int idx, char *par)
 static void bot_update(int idx, char *par)
 {
   char *bot = NULL, x, *vversion = NULL, *vcommit = NULL;
-  int vlocalhub = 0;
+  int vlocalhub = 0, fflags = -1;
   time_t vbuildts = 0L;
 
   bot = newsplit(&par);
@@ -630,9 +630,11 @@ static void bot_update(int idx, char *par)
     vcommit = newsplit(&par);
   if (par[0])
     vversion = newsplit(&par);
+  if (par[0])
+    fflags = atoi(newsplit(&par));
 
   if (in_chain(bot))
-    updatebot(idx, bot, x, vlocalhub, vbuildts, vcommit, vversion);
+    updatebot(idx, bot, x, vlocalhub, vbuildts, vcommit, vversion, fflags);
 }
 
 /* Newbot next share?
@@ -640,7 +642,7 @@ static void bot_update(int idx, char *par)
 static void bot_nlinked(int idx, char *par)
 {
   char *newbot = NULL, *next = NULL, *p = NULL, s[1024] = "", x = 0, *vversion = NULL, *vcommit = NULL;
-  int i, vlocalhub = 0;
+  int i, vlocalhub = 0, fflags = -1;
   time_t vbuildts = 0L;
   bool bogus = 0;
 
@@ -696,7 +698,9 @@ static void bot_nlinked(int idx, char *par)
     vcommit = newsplit(&par);
   if (par[0])
     vversion = newsplit(&par);
-  botnet_send_nlinked(idx, newbot, next, x, vlocalhub, vbuildts, vcommit, vversion);
+  if (par[0])
+    fflags = atoi(newsplit(&par));
+  botnet_send_nlinked(idx, newbot, next, x, vlocalhub, vbuildts, vcommit, vversion, fflags);
   
   if (x == '!') {
     if (conf.bot->hub)
@@ -705,7 +709,7 @@ static void bot_nlinked(int idx, char *par)
       chatout("*** %s linked to botnet.\n", newbot);
     x = '-';
   }
-  addbot(newbot, dcc[idx].nick, next, x, vlocalhub, vbuildts, vcommit, vversion ? vversion : (char *) "");
+  addbot(newbot, dcc[idx].nick, next, x, vlocalhub, vbuildts, vcommit, vversion ? vversion : (char *) "", fflags);
 }
 
 static void bot_unlinked(int idx, char *par)

+ 6 - 5
src/botmsg.cc

@@ -240,11 +240,11 @@ void botnet_send_unlinked(int idx, char *bot, char *args)
   }
 }
 
-void botnet_send_nlinked(int idx, char *bot, char *next, char flag, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion)
+void botnet_send_nlinked(int idx, char *bot, char *next, char flag, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion, int fflags)
 {
   if (tands > 0) {
-    const size_t len = simple_snprintf(OBUF, sizeof(OBUF), "n %s %s %cD0gc %d %d %s %s\n", bot, next, flag,
-                                       vlocalhub, (int) vbuildts, vcommit, vversion ? vversion : "");
+    const size_t len = simple_snprintf(OBUF, sizeof(OBUF), "n %s %s %cD0gc %d %d %s %s %d\n", bot, next, flag,
+                                       vlocalhub, (int) vbuildts, vcommit, vversion ? vversion : "", fflags);
     send_tand_but(idx, OBUF, len);
   }
 }
@@ -267,8 +267,9 @@ void botnet_send_update(int idx, tand_t * ptr)
 {
   if (tands > 0) {
     /* the D0gc is a lingering hack which probably will never be able to come out. */
-    const size_t len = simple_snprintf(OBUF, sizeof(OBUF), "u %s %cD0gc %d %d %s %s\n", ptr->bot, ptr->share, ptr->localhub,
-                                                          (int) ptr->buildts, ptr->commit, ptr->version);
+    const size_t len = simple_snprintf(OBUF, sizeof(OBUF), "u %s %cD0gc %d %d %s %s %d\n", ptr->bot, ptr->share, ptr->localhub,
+                                                          (int) ptr->buildts, ptr->commit, ptr->version,
+                                                          ptr->fflags);
     send_tand_but(idx, OBUF, len);
   }
 }

+ 7 - 2
src/botnet.cc

@@ -83,7 +83,7 @@ extern void counter_clear(const char* botnick);
 
 /* Add a tandem bot to our chain list
  */
-void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion)
+void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion, int fflags)
 {
   tand_t **ptr = &tandbot, *ptr2 = NULL;
 
@@ -98,6 +98,7 @@ void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t
   ptr2->share = flag;
   ptr2->localhub = vlocalhub;
   ptr2->buildts = vbuildts;
+  ptr2->fflags = fflags;
   strlcpy(ptr2->commit, vcommit, sizeof(ptr2->commit));
   if (vversion && vversion[0])
     strlcpy(ptr2->version, vversion, 121);
@@ -132,7 +133,7 @@ void check_should_backup()
 }
 #endif /* G_BACKUP */
 
-void updatebot(int idx, char *who, char share, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion)
+void updatebot(int idx, char *who, char share, int vlocalhub, time_t vbuildts, char *vcommit, char *vversion, int fflags)
 {
   tand_t *ptr = findbot(who);
 
@@ -147,6 +148,10 @@ void updatebot(int idx, char *who, char share, int vlocalhub, time_t vbuildts, c
       strlcpy(ptr->commit, vcommit, sizeof(ptr->commit));
     if (vversion && vversion[0])
       strlcpy(ptr->version, vversion, 121);
+    /* -1 = unknown (do not modify) */
+    if (fflags != -1)
+      ptr->fflags = fflags;
+    /* Assign flags here */
     botnet_send_update(idx, ptr);
   }
 }

+ 2 - 2
src/botnet.h

@@ -21,8 +21,8 @@ void tell_bottree(int);
 void dump_links(int);
 int botlink(char *, int, char *);
 int botunlink(int, const char *, const char *);
-void addbot(char *, char *, char *, char, int, time_t, char *, char *);
-void updatebot(int, char *, char, int, time_t, char *, char *);
+void addbot(char *, char *, char *, char, int, time_t, char *, char *, int);
+void updatebot(int, char *, char, int, time_t, char *, char *, int);
 void rembot(const char *);
 tand_t *findbot(const char *);
 void unvia(int, struct tand_t_struct *);

+ 3 - 2
src/dcc.cc

@@ -293,6 +293,7 @@ bot_version(int idx, char *par)
   char x[1024] = "", *vversion = NULL, *vcommit = NULL;
   int vlocalhub = -1;
   time_t vbuildts = 0;
+  int fflags = -1;
 
   strlcpy(dcc[idx].u.bot->version, par, 120);
   newsplit(&par);               /* 'ver' */
@@ -334,7 +335,7 @@ bot_version(int idx, char *par)
       dcc[idx].hub = 1;
     }
 
-    botnet_send_nlinked(idx, dcc[idx].nick, conf.bot->nick, '!', vlocalhub, vbuildts, vcommit, vversion);
+    botnet_send_nlinked(idx, dcc[idx].nick, conf.bot->nick, '!', vlocalhub, vbuildts, vcommit, vversion, fflags);
   } else {
         // This is now done in share_endstartup
         //have_linked_to_hub = 1;
@@ -346,7 +347,7 @@ bot_version(int idx, char *par)
 
   touch_laston(dcc[idx].user, "linked", now);
   dcc[idx].type = &DCC_BOT;
-  addbot(dcc[idx].nick, dcc[idx].nick, conf.bot->nick, '-', vlocalhub, vbuildts, vcommit, vversion);
+  addbot(dcc[idx].nick, dcc[idx].nick, conf.bot->nick, '-', vlocalhub, vbuildts, vcommit, vversion, fflags);
   simple_snprintf(x, sizeof x, "v 1001500");
   bot_share(idx, x);
   dprintf(idx, "el\n");

+ 4 - 4
src/mod/share.mod/share.cc

@@ -929,7 +929,7 @@ share_ufyes(int idx, char *par)
         dcc[idx].u.bot->uff_flags |= UFF_CHDEFAULT;
 
     if (strstr(par, "stream")) {
-      updatebot(-1, dcc[idx].nick, '+', 0, 0, 0, NULL);
+      updatebot(-1, dcc[idx].nick, '+', 0, 0, 0, NULL, -1);
       /* Start up a tbuf to queue outgoing changes for this bot until the
        * userlist is done transferring.
        */
@@ -1480,7 +1480,7 @@ static void share_read_stream(int idx, bd::Stream& stream) {
   checkchans(1);                /* remove marked channels */
   var_parse_my_botset();
   reaffirm_owners();            /* Make sure my owners are +a   */
-  updatebot(-1, dcc[idx].nick, '+', 0, 0, 0, NULL);
+  updatebot(-1, dcc[idx].nick, '+', 0, 0, 0, NULL, -1);
   send_sysinfo();
 
   if (restarting && !keepnick) {
@@ -1590,7 +1590,7 @@ start_sending_users(int idx)
            i == DCCSEND_BADFN ? "BAD FILE" : i == DCCSEND_FEMPTY ? "EMPTY FILE" : "UNKNOWN REASON!");
     dcc[idx].status &= ~(STAT_SHARE | STAT_SENDING | STAT_AGGRESSIVE);
   } else {
-    updatebot(-1, dcc[idx].nick, '+', 0, 0, 0, NULL);
+    updatebot(-1, dcc[idx].nick, '+', 0, 0, 0, NULL, -1);
     dcc[idx].status |= STAT_SENDING;
     strlcpy(dcc[j].host, dcc[idx].nick, sizeof(dcc[j].host)); /* Store bot's nick */
     dprintf(idx, "s us %lu %d %lu\n", iptolong(getmyip()), dcc[j].port, dcc[j].u.xfer->length);
@@ -1615,7 +1615,7 @@ cancel_user_xfer(int idx, void *x)
   int i, j = -1;
   if (cancel_user_xfer_staylinked) {
     /* turn off sharing flag */
-    updatebot(-1, dcc[idx].nick, '-', 0, 0, 0, NULL);
+    updatebot(-1, dcc[idx].nick, '-', 0, 0, 0, NULL, -1);
   }
   flush_tbuf(dcc[idx].nick);
 

+ 2 - 1
src/tandem.h

@@ -13,6 +13,7 @@ typedef struct tand_t_struct {
   struct tand_t_struct *next;
   time_t buildts;
   int localhub;
+  int fflags;
   struct userrec* u;
   char commit[10];
   char bot[HANDLEN + 1];
@@ -58,7 +59,7 @@ void botnet_send_trace(int, char *, char *, char *);
 void botnet_send_unlink(int, char *, char *, char *, char *);
 void botnet_send_link(int, char *, char *, char *);
 void botnet_send_update(int, tand_t *);
-void botnet_send_nlinked(int, char *, char *, char, int, time_t, char *, char *);
+void botnet_send_nlinked(int, char *, char *, char, int, time_t, char *, char *, int);
 void botnet_send_reject(int, char *, char *, char *, char *, char *);
 void botnet_send_log(int, const char *, int, const char *, bool = 0);
 void botnet_send_zapf(int, const char *, const char *, const char *);