Author: Isomer <isomer@coders.net>
[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 #include <string.h>
35
36 void dump_map(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
37 {
38   static char prompt[64];
39   struct DLink *lp;
40   char *p = &prompt[prompt_length];
41   int cnt = 0;
42
43   *p = '\0';
44   if (prompt_length > 60)
45     send_reply(cptr, RPL_MAPMORE, prompt, server->name);
46   else {
47     char lag[512];
48     if (server->serv->lag>10000)
49         lag[0]=0;
50     else if (server->serv->lag<0)
51         strcpy(lag,"(0s)");
52     else
53         sprintf(lag,"(%is)",server->serv->lag);
54     send_reply(cptr, RPL_MAP, prompt, ((IsBurstOrBurstAck(server)) ? "*" : ""),
55                server->name, lag, (server == &me) ? UserStats.local_clients :
56                server->serv->clients);
57   }
58   if (prompt_length > 0)
59   {
60     p[-1] = ' ';
61     if (p[-2] == '`')
62       p[-2] = ' ';
63   }
64   if (prompt_length > 60)
65     return;
66   strcpy(p, "|-");
67   for (lp = server->serv->down; lp; lp = lp->next)
68     if (match(mask, lp->value.cptr->name))
69       lp->value.cptr->flags &= ~FLAGS_MAP;
70     else
71     {
72       lp->value.cptr->flags |= FLAGS_MAP;
73       cnt++;
74     }
75   for (lp = server->serv->down; lp; lp = lp->next)
76   {
77     if ((lp->value.cptr->flags & FLAGS_MAP) == 0)
78       continue;
79     if (--cnt == 0)
80       *p = '`';
81     dump_map(cptr, lp->value.cptr, mask, prompt_length + 2);
82   }
83   if (prompt_length > 0)
84     p[-1] = '-';
85 }
86
87 #if 0
88 /*
89  * m_map  -- by Run
90  *
91  * parv[0] = sender prefix
92  * parv[1] = server mask
93  */
94 int m_map(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
95 {
96   if (parc < 2)
97     parv[1] = "*";
98
99   dump_map(sptr, &me, parv[1], 0);
100   sendto_one(sptr, rpl_str(RPL_MAPEND), me.name, parv[0]); /* XXX DEAD */
101
102   return 0;
103 }
104 #endif /* 0 */
105