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