8a607a1ca145ca061de03d5048e901dee1800bd5
[ircu2.10.12-pk.git] / ircd / map.c
1 /*
2  * IRC - Internet Relay Chat, ircd/map.c
3  * Copyright (C) 1994 Carlo Wood ( Run @ undernet.org )
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  * $Id$
20  */
21 #include "map.h"
22 #include "client.h"
23 #include "ircd.h"
24 #include "ircd_reply.h"
25 #include "list.h"
26 #include "match.h"
27 #include "numeric.h"
28 #include "numnicks.h"
29 #include "querycmds.h"
30 #include "send.h"
31 #include "struct.h"
32
33 #include <stdio.h> /* sprintf */
34
35 void dump_map(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
36 {
37   static char prompt[64];
38   struct DLink *lp;
39   char *p = &prompt[prompt_length];
40   int cnt = 0;
41
42   *p = '\0';
43   if (prompt_length > 60)
44     send_reply(cptr, RPL_MAPMORE, prompt, server->name);
45   else {
46     char lag[512];
47     if (server->serv->lag>10000)
48         strcpy(lag,"(--s)");
49     else if (server->serv->lag<0)
50         strcpy(lag,"(0s)");
51     else
52         sprintf(lag,"(%is)",server->serv->lag);
53     send_reply(cptr, RPL_MAP, prompt, ((IsBurstOrBurstAck(server)) ? "*" : ""),
54                server->name, lag, (server == &me) ? UserStats.local_clients :
55                server->serv->clients);
56   }
57   if (prompt_length > 0)
58   {
59     p[-1] = ' ';
60     if (p[-2] == '`')
61       p[-2] = ' ';
62   }
63   if (prompt_length > 60)
64     return;
65   strcpy(p, "|-");
66   for (lp = server->serv->down; lp; lp = lp->next)
67     if (match(mask, lp->value.cptr->name))
68       lp->value.cptr->flags &= ~FLAGS_MAP;
69     else
70     {
71       lp->value.cptr->flags |= FLAGS_MAP;
72       cnt++;
73     }
74   for (lp = server->serv->down; lp; lp = lp->next)
75   {
76     if ((lp->value.cptr->flags & FLAGS_MAP) == 0)
77       continue;
78     if (--cnt == 0)
79       *p = '`';
80     dump_map(cptr, lp->value.cptr, mask, prompt_length + 2);
81   }
82   if (prompt_length > 0)
83     p[-1] = '-';
84 }
85
86 #if 0
87 /*
88  * m_map  -- by Run
89  *
90  * parv[0] = sender prefix
91  * parv[1] = server mask
92  */
93 int m_map(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
94 {
95   if (parc < 2)
96     parv[1] = "*";
97
98   dump_map(sptr, &me, parv[1], 0);
99   sendto_one(sptr, rpl_str(RPL_MAPEND), me.name, parv[0]); /* XXX DEAD */
100
101   return 0;
102 }
103 #endif /* 0 */
104