Author: Kev <klmitch@mit.edu>
[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 "list.h"
25 #include "match.h"
26 #include "numeric.h"
27 #include "numnicks.h"
28 #include "querycmds.h"
29 #include "send.h"
30 #include "struct.h"
31
32 #include <stdio.h> /* sprintf */
33
34 void dump_map(struct Client *cptr, struct Client *server, char *mask, int prompt_length)
35 {
36   static char prompt[64];
37   struct DLink *lp;
38   char *p = &prompt[prompt_length];
39   int cnt = 0;
40
41   *p = '\0';
42   if (prompt_length > 60)
43     sendto_one(cptr, rpl_str(RPL_MAPMORE), me.name, cptr->name,
44         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     sendto_one(cptr, rpl_str(RPL_MAP), me.name, cptr->name,
54         prompt, 
55         ((IsBurstOrBurstAck(server)) ? "*" : ""),
56         server->name, 
57         lag,
58         (server == &me) ? UserStats.local_clients : server->serv->clients);
59   }
60   if (prompt_length > 0)
61   {
62     p[-1] = ' ';
63     if (p[-2] == '`')
64       p[-2] = ' ';
65   }
66   if (prompt_length > 60)
67     return;
68   strcpy(p, "|-");
69   for (lp = server->serv->down; lp; lp = lp->next)
70     if (match(mask, lp->value.cptr->name))
71       lp->value.cptr->flags &= ~FLAGS_MAP;
72     else
73     {
74       lp->value.cptr->flags |= FLAGS_MAP;
75       cnt++;
76     }
77   for (lp = server->serv->down; lp; lp = lp->next)
78   {
79     if ((lp->value.cptr->flags & FLAGS_MAP) == 0)
80       continue;
81     if (--cnt == 0)
82       *p = '`';
83     dump_map(cptr, lp->value.cptr, mask, prompt_length + 2);
84   }
85   if (prompt_length > 0)
86     p[-1] = '-';
87 }
88
89 #if 0
90 /*
91  * m_map  -- by Run
92  *
93  * parv[0] = sender prefix
94  * parv[1] = server mask
95  */
96 int m_map(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
97 {
98   if (parc < 2)
99     parv[1] = "*";
100
101   dump_map(sptr, &me, parv[1], 0);
102   sendto_one(sptr, rpl_str(RPL_MAPEND), me.name, parv[0]);
103
104   return 0;
105 }
106 #endif /* 0 */
107