#include "client.h"
#include "ircd.h"
#include "ircd_reply.h"
+#include "ircd_snprintf.h"
#include "ircd_string.h"
-#include "map.h"
+#include "list.h"
+#include "match.h"
#include "numeric.h"
+#include "s_user.h"
+#include "s_serv.h"
#include "send.h"
+#include "querycmds.h"
#include <assert.h>
+#include <stdio.h>
+
+static void dump_map(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
+{
+ static char prompt[64];
+ struct DLink *lp;
+ char *p = &prompt[prompt_length];
+ int cnt = 0;
+
+ *p = '\0';
+ if (prompt_length > 60)
+ send_reply(cptr, RPL_MAPMORE, prompt, server->name);
+ else {
+ char lag[512];
+ if (server->serv->lag>10000)
+ lag[0]=0;
+ else if (server->serv->lag<0)
+ strcpy(lag,"(0s)");
+ else
+ sprintf(lag,"(%is)",server->serv->lag);
+ send_reply(cptr, RPL_MAP, prompt, (
+ (IsBurst(server)) ? "*" : (IsBurstAck(server) ? "!" : "")),
+ server->name, lag, (server == &me) ? UserStats.local_clients :
+ server->serv->clients);
+ }
+ if (prompt_length > 0)
+ {
+ p[-1] = ' ';
+ if (p[-2] == '`')
+ p[-2] = ' ';
+ }
+ if (prompt_length > 60)
+ return;
+ strcpy(p, "|-");
+ for (lp = server->serv->down; lp; lp = lp->next)
+ if (match(mask, lp->value.cptr->name))
+ lp->value.cptr->flags &= ~FLAGS_MAP;
+ else
+ {
+ lp->value.cptr->flags |= FLAGS_MAP;
+ cnt++;
+ }
+ for (lp = server->serv->down; lp; lp = lp->next)
+ {
+ if ((lp->value.cptr->flags & FLAGS_MAP) == 0)
+ continue;
+ if (--cnt == 0)
+ *p = '`';
+ dump_map(cptr, lp->value.cptr, mask, prompt_length + 2);
+ }
+ if (prompt_length > 0)
+ p[-1] = '-';
+}
+
/*
* m_map - generic message handler