3be7411620bcbca61d357b6bc393fa09fcf2b013
[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
20 #include "sys.h"
21 #include "h.h"
22 #include "struct.h"
23 #include "numeric.h"
24 #include "send.h"
25 #include "match.h"
26 #include "list.h"
27 #include "s_err.h"
28 #include "ircd.h"
29 #include "s_bsd.h"
30 #include "s_misc.h"
31 #include "map.h"
32
33 RCSTAG_CC("$Id$");
34
35 static void dump_map(aClient *cptr, aClient *server, char *mask,
36     int prompt_length)
37 {
38   static char prompt[64];
39   register Dlink *lp;
40   register char *p = &prompt[prompt_length];
41   register int cnt = 0;
42
43   *p = '\0';
44   if (prompt_length > 60)
45     sendto_one(cptr, rpl_str(RPL_MAPMORE), me.name, cptr->name,
46         prompt, server->name);
47   else
48     sendto_one(cptr, rpl_str(RPL_MAP), me.name, cptr->name,
49         prompt, server->name);
50   if (prompt_length > 0)
51   {
52     p[-1] = ' ';
53     if (p[-2] == '`')
54       p[-2] = ' ';
55   }
56   if (prompt_length > 60)
57     return;
58   strcpy(p, "|-");
59   for (lp = server->serv->down; lp; lp = lp->next)
60     if (match(mask, lp->value.cptr->name))
61       lp->value.cptr->flags &= ~FLAGS_MAP;
62     else
63     {
64       lp->value.cptr->flags |= FLAGS_MAP;
65       cnt++;
66     }
67   for (lp = server->serv->down; lp; lp = lp->next)
68   {
69     if ((lp->value.cptr->flags & FLAGS_MAP) == 0)
70       continue;
71     if (--cnt == 0)
72       *p = '`';
73     dump_map(cptr, lp->value.cptr, mask, prompt_length + 2);
74   }
75   if (prompt_length > 0)
76     p[-1] = '-';
77 }
78
79 /*
80  * m_map  -- by Run
81  *
82  * parv[0] = sender prefix
83  * parv[1] = server mask
84  */
85 int m_map(aClient *UNUSED(cptr), aClient *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 }