Forráskód Böngészése

Merge branch 'master' into next

* master:
  Update bdlib
  cmds_groups: Indicate down bots with '*'
  cmds_bots: Sort the bot list for shell display
  cmds_bots: Properly sort by the TLD as well
  cmd_groups: Sort the bot list as well of course
  external libs need .PHONY to handle dependencies downstream
  Sort cmd_groups
  dumplots: Let prefix be a String
  dumplots can just take a reference
Bryan Drewery 7 éve
szülő
commit
16de6799dd
9 módosított fájl, 66 hozzáadás és 27 törlés
  1. 2 0
      doc/UPDATES.md
  2. 1 0
      doc/help.txt
  3. 2 0
      lib/Makefile.in
  4. 1 1
      lib/bdlib
  5. 25 8
      src/botnet.cc
  6. 5 0
      src/botnet.h
  7. 24 12
      src/cmds.cc
  8. 5 5
      src/dccutil.cc
  9. 1 1
      src/dccutil.h

+ 2 - 0
doc/UPDATES.md

@@ -15,6 +15,8 @@
   * CPRIVMSG/CNOTICE/TIME/TOPIC/OPER should end connection bursting on ratbox.
   * Fix server connect bursting for joining channels with help from other bots.
   * Tweak server connect burst to progress quicker.
+  * Sort cmd_groups and cmd_bots better.
+  * cmd_groups: Indicate which bots are down with a _*_.
 
 # maint
   * Clear FiSH keys when a client quits.

+ 1 - 0
doc/help.txt

@@ -1098,6 +1098,7 @@ See also: console, channels%{+m}, status%{-}
    Shows the list of groups and which bots are in them.
  
    Specify a bot to only show which groups it is in.
+   Bots with a * preceding its name are down.
  
 See also: bots, downbots%{+n}, bottree%{-}
 ::handle

+ 2 - 0
lib/Makefile.in

@@ -42,11 +42,13 @@ general:
 libelf_notice:
 	@echo "[*] Building libelf"
 
+.PHONY: $(top_builddir)/lib/libelf/lib/libelf.a
 $(top_builddir)/lib/libelf/lib/libelf.a: libelf_notice
 	+@cd libelf/lib && $(MAKE) CFLAGS="-g -O2 -w" libelf.a
 
 libelf: $(LIBELF_BUNDLED)
 
+.PHONY: $(top_builddir)/lib/bdlib/libbdlib.a
 $(top_builddir)/lib/bdlib/libbdlib.a:
 	+@cd bdlib && $(MAKE)
 

+ 1 - 1
lib/bdlib

@@ -1 +1 @@
-Subproject commit 3c1dbbdb2435fbf332b35b2540d403e24ed102f5
+Subproject commit 7625ff1d29a01226f3ba6d1b1348191b401fc2e7

+ 25 - 8
src/botnet.cc

@@ -547,7 +547,17 @@ void answer_local_whom(int idx, int chan)
   dprintf(idx, "Total users: %d\n", total);
 }
 
-bool sortNodes(const bd::String nodeA, const bd::String nodeB) {
+bool
+__attribute__((pure))
+sortDownBots(bd::String botA, bd::String botB) {
+  if (botA[0] == '*') ++botA;
+  if (botB[0] == '*') ++botB;
+  return botA < botB;
+}
+
+static bool
+__attribute__((pure))
+sortNodes(const bd::String& nodeA, const bd::String& nodeB) {
   const bd::String unknown("(unknown)");
   if (nodeA == unknown) {
     return true;
@@ -561,12 +571,12 @@ bool sortNodes(const bd::String nodeA, const bd::String nodeB) {
   bd::String reversedNodeA, reversedNodeB;
 
   if (partsA.length()) {
-    for (size_t i = partsA.length() - 1; i > 0; --i) {
+    for (size_t i = partsA.length(); i > 0; --i) {
       reversedPartsA << partsA[i - 1];
     }
   }
   if (partsB.length()) {
-    for (size_t i = partsB.length() - 1; i > 0; --i) {
+    for (size_t i = partsB.length(); i > 0; --i) {
       reversedPartsB << partsB[i - 1];
     }
   }
@@ -625,14 +635,21 @@ tell_bots(int idx, int up, const char *nodename)
   }
 
   if (group.length() == 0 && !nodename) {
-    dumplots(idx, nodename ? "Matching: " : (up ? "Up: " : "Down: "), static_cast<bd::String>(bots.join(" ")).c_str());
+    dumplots(idx, nodename ? "Matching: " : (up ? "Up: " : "Down: "),
+        bots.join(" "));
   } else {
     // Sort by nodes
     std::sort(nodes.begin(), nodes.end(), sortNodes);
-    for (size_t i = 0; i < nodes.length(); ++i) {
-      const bd::String node(nodes[i]);
-      const bd::Array<bd::String> botsInNode(nodeBots[node]);
-      dumplots(idx, bd::String::printf("%*s: ", int(maxNodeNameLength), node.c_str()).c_str(), static_cast<bd::String>(botsInNode.join(" ")).c_str());
+    for (auto& kv : nodeBots) {
+      auto& botlist{kv.second};
+      std::sort(botlist.begin(), botlist.end(), sortDownBots);
+    }
+    for (const auto& node : nodes) {
+      const auto& botsInNode(nodeBots[node]);
+      dumplots(idx,
+          bd::String::printf("%*s: ",
+            int(maxNodeNameLength), node.c_str()),
+            botsInNode.join(" "));
     }
   }
 

+ 5 - 0
src/botnet.h

@@ -5,6 +5,10 @@
 #  include "config.h"
 #endif
 
+namespace bd {
+  class String;
+}
+
 #include "tandem.h"
 
 extern tand_t		*tandbot;
@@ -16,6 +20,7 @@ void answer_local_whom(int, int);
 char *lastbot(const char *) __attribute__((pure));
 int nextbot(const char *) __attribute__((pure));
 int in_chain(const char *) __attribute__((pure));
+bool sortDownBots(bd::String botA, bd::String botB) __attribute__((pure));
 void tell_bots(int, int, const char *);
 void tell_bottree(int);
 void dump_links(int);

+ 24 - 12
src/cmds.cc

@@ -911,10 +911,9 @@ static void cmd_groups(int idx, char *par)
     return;
   }
 
-  bd::Array<bd::String> globalgroups = bd::String(var_get_gdata("groups")).split(",");
-  bd::Array<bd::String> allgroups;
   bd::HashTable<bd::String, bd::Array<bd::String> > groupBots;
   bd::HashTable<bd::String, bd::Array<bd::String> > botGroups;
+  bd::String bothandle;
   size_t maxGroupLen = 0;
 
   // Need to loop over every bot and make a list of all groups and bots which are in those groups
@@ -926,27 +925,40 @@ static void cmd_groups(int idx, char *par)
         if (group.length() > maxGroupLen) {
           maxGroupLen = group.length();
         }
-        // Add their groups into the master list
-        if (allgroups.find(group) == allgroups.npos) {
-          allgroups << group;
-        }
         // Add them to the list for this group
-        groupBots[group] << u->handle;
+        if (u != conf.bot->u && !findbot(u->handle))
+          bothandle = bd::String::printf("*%s", u->handle);
+        else
+          bothandle = u->handle;
+        groupBots[group] << bothandle;
 
       }
     }
   }
 
   if (botnick.length()) {
-    dprintf(idx, "%s is in groups: %s\n", botnick.c_str(), static_cast<bd::String>(botGroups[botnick].join(" ")).c_str());
-    dprintf(idx, "Total groups: %zu/%zu\n", botGroups[botnick].length(), allgroups.length());
+    dprintf(idx, "%s is in groups: %s\n", botnick.c_str(),
+        static_cast<bd::String>(botGroups[botnick].join(" ")).c_str());
+    dprintf(idx, "Total groups: %zu/%zu\n", botGroups[botnick].length(),
+        groupBots.size());
   } else {
+    std::vector<bd::String> allgroups;
+    allgroups.reserve(groupBots.size());
+    for (auto& kv : groupBots) {
+      const auto& group{kv.first};
+      auto& botlist{kv.second};
+      allgroups.push_back(group);
+      std::sort(botlist.begin(), botlist.end(), sortDownBots);
+    }
+    std::sort(allgroups.begin(), allgroups.end());
     // Display all groups and which bots are in them
     for (const auto& group : allgroups) {
-      const bd::Array<bd::String> bots(groupBots[group]);
-      dumplots(idx, bd::String::printf("%-*s: ", int(maxGroupLen), group.c_str()).c_str(), static_cast<bd::String>(bots.join(" ")).c_str());
+      const auto& bots = groupBots[group];
+      dumplots(idx,
+          bd::String::printf("%-*s: ", int(maxGroupLen), group.c_str()),
+          bots.join(" "));
     }
-    dprintf(idx, "Total groups: %zu\n", allgroups.length());
+    dprintf(idx, "Total groups: %zu\n", groupBots.size());
   }
 
   return;

+ 5 - 5
src/dccutil.cc

@@ -217,14 +217,14 @@ colorbuf(char *buf, size_t len, int idx, size_t bufsiz)
 
 /* Dump a potentially super-long string of text.
  */
-void dumplots(int idx, const char *prefix, const bd::String data)
+void dumplots(int idx, const bd::String& prefix, const bd::String& data)
 {
   if (unlikely(!*data)) {
-    dprintf(idx, "%s\n", prefix);
+    dprintf(idx, "%s\n", prefix.c_str());
     return;
   }
 
-  const size_t max_data_len = 120 - strlen(prefix);
+  const size_t max_data_len = 120 - prefix.length();
   bd::Array<bd::String> lines = data.split('\n');
   size_t i = 0;
 
@@ -245,7 +245,7 @@ void dumplots(int idx, const char *prefix, const bd::String data)
         ++pos;
 
       if (bd::String(line(pos)).find("\n") != bd::String::npos) // Newline in remaining: dump it
-        dprintf(idx, "%s%s\n", prefix, bd::String(line(pos)).c_str());
+        dprintf(idx, "%s%s\n", prefix.c_str(), bd::String(line(pos)).c_str());
       else {
         const size_t tpos = line[pos] == ' ' ? pos + 1 : pos; // Trim out the space
         if (lines.length() - (i + 1) > 0) // Wrapped text: prepend to next line if possible
@@ -255,7 +255,7 @@ void dumplots(int idx, const char *prefix, const bd::String data)
       }
       line.resize(pos);
     }
-    dprintf(idx, "%s%s\n", prefix, line.c_str());
+    dprintf(idx, "%s%s\n", prefix.c_str(), line.c_str());
     ++i;
   }
 }

+ 1 - 1
src/dccutil.h

@@ -37,7 +37,7 @@ namespace bd {
 
 
 void init_dcc(void);
-void dumplots(int, const char *, bd::String);
+void dumplots(int, const bd::String&, const bd::String&);
 void rdprintf(const char*, int, const char *, ...) __attribute__((format(printf, 3, 4)));
 void dprintf(int, const char *, ...) __attribute__((format(printf, 2, 3)));
 void dprintf_real(int, char*, size_t, size_t, const char* = NULL);