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

* Combined cmd_downbots/cmd_bots through tell_bots(idx, up)

svn: 1121
Bryan Drewery 22 лет назад
Родитель
Сommit
33556e2d15
3 измененных файлов с 29 добавлено и 68 удалено
  1. 26 42
      src/botnet.c
  2. 1 1
      src/botnet.h
  3. 2 25
      src/cmds.c

+ 26 - 42
src/botnet.c

@@ -535,55 +535,39 @@ void answer_local_whom(int idx, int chan)
 #ifdef HUB
 #ifdef HUB
 /* Show z a list of all bots connected
 /* Show z a list of all bots connected
  */
  */
-void tell_bots(int idx)
+void
+tell_bots(int idx, int up)
 {
 {
-  char format[81] = "";
-  int upi = 1, downi = 0;
-  size_t len;
   struct userrec *u = NULL;
   struct userrec *u = NULL;
+  int cnt = 0, tot = 0;
+  char work[128] = "";
 
 
-  len = strlen(conf.bot->nick);
-  //up = calloc(1, ulen + 1);
-  //strcpy(up, conf.bot->nick);
-  //down = calloc(1, 1);
+  if (up) {
+    strcat(work, conf.bot->nick);
+    strcat(work, " ");
+    cnt++;
+  }
 
 
-  egg_snprintf(format, sizeof format, "%%s%%-11s%%s %%-5s %%-10s %%-11s %%s\n");
-  dprintf(idx, format, "", "Bot", "", "OS", "Username", "Shell");
-  dprintf(idx, format, "", "-----------", "", "----------", "-----------", "-----------------------");
-  
-/* FIXME: NEED ME! */
   for (u = userlist; u; u = u->next) {
   for (u = userlist; u; u = u->next) {
-    if (u->bot && (egg_strcasecmp(u->handle, conf.bot->nick))) {
-      size_t hlen = strlen(u->handle);
-      int up = 0;
-
-      if (findbot(u->handle)) {
-        upi++;
-        up = 1;
-      } else
-        downi++;
-
-      dprintf(idx, format, up ? GREEN(idx) : RED(idx), u->handle, COLOR_END(idx), 
-              get_user(&USERENTRY_OS, u), get_user(&USERENTRY_USERNAME, u), 
-              get_user(&USERENTRY_NODENAME, u));
-
-//      if (up) {
+    if (u->bot) {
+      if (egg_strcasecmp(u->handle, conf.bot->nick)) {
+        if ((!up && nextbot(u->handle) == -1) || (up && nextbot(u->handle))) {
+          strcat(work, u->handle);
+          cnt++;
+          tot++;
+          if (cnt == 11) {
+            dprintf(idx, "%s bots: %s\n", up ? "Up" : "Down", work);
+            work[0] = 0;
+            cnt = 0;
+          } else
+            strcat(work, " ");
+        }
+      }
     }
     }
   }
   }
-/*
-  if (!downi)
-    dprintf(idx, "Bots up (%d) [%sall%s]: %s\n", upi, BOLD(idx), BOLD_END(idx), up);
-  else
-    dprintf(idx, "Bots up (%d): %s\n", upi, up);
-  
-  if (downi)
-    dprintf(idx, "Bots down (%d): %s\n", downi, down);
-
-  dprintf(idx, "Total: %d [%s%d%% up%s, %s%d%% down%s]\n", upi + downi, GREEN(idx), (100 * upi / (upi + downi)),
-               COLOR_END(idx), RED(idx), (100 * downi / (upi + downi)), COLOR_END(idx));
-  free(up);
-  free(down);
-*/
+  if (work[0])
+    dprintf(idx, "%s bot%s: %s\n", up ? "Up" : "Down", cnt > 1 ? "s" : "", work);
+  dprintf(idx, "(Total %s: %d)\n", up ? "up" : "down", tot);
 }
 }
 
 
 /* Show a simpleton bot tree
 /* Show a simpleton bot tree

+ 1 - 1
src/botnet.h

@@ -17,7 +17,7 @@ char *lastbot(char *);
 int nextbot(char *);
 int nextbot(char *);
 int in_chain(char *);
 int in_chain(char *);
 #ifdef HUB
 #ifdef HUB
-void tell_bots(int);
+void tell_bots(int, int);
 void tell_bottree(int);
 void tell_bottree(int);
 #endif /* HUB */
 #endif /* HUB */
 void dump_links(int);
 void dump_links(int);

+ 2 - 25
src/cmds.c

@@ -695,36 +695,13 @@ static void cmd_secpass(struct userrec *u, int idx, char *par)
 static void cmd_bots(struct userrec *u, int idx, char *par)
 static void cmd_bots(struct userrec *u, int idx, char *par)
 {
 {
   putlog(LOG_CMDS, "*", "#%s# bots", dcc[idx].nick);
   putlog(LOG_CMDS, "*", "#%s# bots", dcc[idx].nick);
-  tell_bots(idx);
+  tell_bots(idx, 1);
 }
 }
 
 
 static void cmd_downbots(struct userrec *u, int idx, char *par)
 static void cmd_downbots(struct userrec *u, int idx, char *par)
 {
 {
-  struct userrec *u2 = NULL;
-  int cnt = 0, tot = 0;
-  char work[128] = "";
-
   putlog(LOG_CMDS, "*", "#%s# downbots", dcc[idx].nick);
   putlog(LOG_CMDS, "*", "#%s# downbots", dcc[idx].nick);
-  for (u2 = userlist; u2; u2 = u2->next) {
-    if (u2->bot) {
-      if (egg_strcasecmp(u2->handle, conf.bot->nick)) {
-        if (nextbot(u2->handle) == -1) {
-          strcat(work, u2->handle);
-          cnt++;
-          tot++;
-          if (cnt == 10) {
-            dprintf(idx, "Down bots: %s\n", work);
-            work[0] = 0;
-            cnt = 0;
-          } else
-            strcat(work, " ");
-        }
-      }
-    }
-  }
-  if (work[0])
-    dprintf(idx, "Down bot%s: %s\n", cnt > 1 ? "s" : "", work);
-  dprintf(idx, "(Total down: %d)\n", tot);
+  tell_bots(idx, 0);
 }
 }