09396fb315e6c91258dfd42c63dd7cb9fd8dc4fa
[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     sendto_one(cptr, rpl_str(RPL_MAP), me.name, cptr->name,
46         prompt, NumServ(server), server->name, 
47         server->serv->lag>0 ? server->serv->lag : 0,
48         (server == &me) ? UserStats.local_clients : server->serv->clients);
49   if (prompt_length > 0)
50   {
51     p[-1] = ' ';
52     if (p[-2] == '`')
53       p[-2] = ' ';
54   }
55   if (prompt_length > 60)
56     return;
57   strcpy(p, "|-");
58   for (lp = server->serv->down; lp; lp = lp->next)
59     if (match(mask, lp->value.cptr->name))
60       lp->value.cptr->flags &= ~FLAGS_MAP;
61     else
62     {
63       lp->value.cptr->flags |= FLAGS_MAP;
64       cnt++;
65     }
66   for (lp = server->serv->down; lp; lp = lp->next)
67   {
68     if ((lp->value.cptr->flags & FLAGS_MAP) == 0)
69       continue;
70     if (--cnt == 0)
71       *p = '`';
72     dump_map(cptr, lp->value.cptr, mask, prompt_length + 2);
73   }
74   if (prompt_length > 0)
75     p[-1] = '-';
76 }
77
78 #if 0
79 /*
80  * m_map  -- by Run
81  *
82  * parv[0] = sender prefix
83  * parv[1] = server mask
84  */
85 int m_map(struct Client *cptr, struct Client *sptr, int parc, char *parv[])
86 {
87   if (parc < 2)
88     parv[1] = "*";
89
90   dump_map(sptr, &me, parv[1], 0);
91   sendto_one(sptr, rpl_str(RPL_MAPEND), me.name, parv[0]);
92
93   return 0;
94 }
95 #endif /* 0 */
96