]> jfr.im git - irc/quakenet/newserv.git/blobdiff - trusts/trusts_commands.c
fixes for clang
[irc/quakenet/newserv.git] / trusts / trusts_commands.c
index 0a2f4e0bcbd0d417dd750a83b2b35c1fef27c278..95a986010062daaa8a1a5ab97a1a71efcbbc06b8 100644 (file)
@@ -98,25 +98,12 @@ static void outputtree(nick *np, unsigned int marker, trustgroup *originalgroup,
     outputtree(np, marker, originalgroup, th, depth + 1);
 }
 
-static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
-  nick *sender = source;
-  trustgroup *tg;
+static void displaygroup(nick *sender, trustgroup *tg) {
   trusthost *th, **p2;
-  time_t t;
   unsigned int marker;
   array parents;
   int i;
-
-  if(cargc < 1)
-    return CMD_USAGE;
-
-  tg = tg_strtotg(cargv[0]);
-  if(!tg) {
-    controlreply(sender, "Couldn't find a trustgroup with that id.");
-    return CMD_ERROR;
-  }
-
-  t = time(NULL);
+  time_t t = time(NULL);
 
   /* abusing the ternary operator a bit :( */
   controlreply(sender, "Name:            : %s", tg->name->content);
@@ -130,7 +117,7 @@ static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
   controlreply(sender, "ID:              : %u", tg->id);
   controlreply(sender, "Last used        : %s", (tg->count>0)?"(now)":((tg->lastseen>0)?trusts_timetostr(tg->lastseen):"(never)"));
   controlreply(sender, "Max usage        : %d", tg->maxusage);
-  controlreply(sender, "Last max reset   : %s", tg->lastmaxuserreset?trusts_timetostr(tg->lastmaxuserreset):"(never)");
+  controlreply(sender, "Last max reset   : %s", tg->lastmaxusereset?trusts_timetostr(tg->lastmaxusereset):"(never)");
 
   controlreply(sender, "Host                 Current    Max        Last seen            Group ID   Group name");
 
@@ -147,6 +134,40 @@ static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
   array_free(&parents);
 
   controlreply(sender, "End of list.");
+}
+
+static int trusts_cmdtrustlist(void *source, int cargc, char **cargv) {
+  nick *sender = source;
+  trustgroup *tg = NULL;
+  int found = 0, remaining = 50;
+  char *name;
+
+  if(cargc < 1)
+    return CMD_USAGE;
+
+  name = cargv[0];
+
+  tg = tg_strtotg(name);
+
+  if(tg) {
+    displaygroup(sender, tg);
+    return CMD_OK;
+  }
+
+  for(tg=tglist;tg;tg=tg->next) {
+    if(match(name, tg->name->content))
+      continue;
+
+    displaygroup(sender, tg);
+    if(--remaining == 0) {
+      controlreply(sender, "Maximum number of matches reached.");
+      return CMD_OK;
+    }
+    found = 1;
+  }
+
+  if(!found)
+    controlreply(sender, "No matches found.");
 
   return CMD_OK;
 }
@@ -192,7 +213,7 @@ static int trusts_cmdtrustdump(void *source, int argc, char **argv) {
     return CMD_ERROR;
   }
 
-  for(i=0,tg=tglist;i<totalcount&&th;tg=tg->next,i++)
+  for(i=0,tg=tglist;i<totalcount&&tg;tg=tg->next,i++)
     atg[i] = tg;
 
   qsort(atg, totalcount, sizeof(trustgroup *), comparetgs);