ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/modules/m_map.c
Revision: 69
Committed: Tue Oct 4 16:09:51 2005 UTC (20 years, 10 months ago) by adx
Content type: text/x-csrc
File size: 3761 byte(s)
Log Message:
- splitted ircd/libio, all headers connected with libio sources have been
  moved for internal use only. To use libio interface, include "libio.h"
  (which is already done in "stdinc.h")


File Contents

# User Rev Content
1 adx 30 /*
2     * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3     * m_map.c: Sends an Undernet compatible map to a user.
4     *
5     * Copyright (C) 2002 by the past and present ircd coders, and others.
6     *
7     * This program is free software; you can redistribute it and/or modify
8     * it under the terms of the GNU General Public License as published by
9     * the Free Software Foundation; either version 2 of the License, or
10     * (at your option) any later version.
11     *
12     * This program is distributed in the hope that it will be useful,
13     * but WITHOUT ANY WARRANTY; without even the implied warranty of
14     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15     * GNU General Public License for more details.
16     *
17     * You should have received a copy of the GNU General Public License
18     * along with this program; if not, write to the Free Software
19     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20     * USA
21     *
22 knight 31 * $Id$
23 adx 30 */
24    
25     #include "stdinc.h"
26     #include "client.h"
27     #include "modules.h"
28     #include "handlers.h"
29     #include "numeric.h"
30     #include "send.h"
31     #include "s_conf.h"
32     #include "ircd.h"
33    
34     static void m_map(struct Client *, struct Client *, int, char *[]);
35     static void mo_map(struct Client *, struct Client *, int, char *[]);
36     static void dump_map(struct Client *, struct Client *, int, char *);
37    
38     struct Message map_msgtab = {
39     "MAP", 0, 0, 0, 0, MFLG_SLOW, 0,
40     {m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore}
41     };
42    
43     #ifndef STATIC_MODULES
44     void _modinit(void)
45     {
46     mod_add_cmd(&map_msgtab);
47     }
48    
49     void _moddeinit(void)
50     {
51     mod_del_cmd(&map_msgtab);
52     }
53    
54 knight 31 const char *_version = "$Revision$";
55 adx 30 #endif
56    
57     static char buf[IRCD_BUFSIZE];
58    
59     /* m_map()
60     * parv[0] = sender prefix
61     */
62     static void
63     m_map(struct Client *client_p, struct Client *source_p,
64     int parc, char *parv[])
65     {
66     if (!ConfigServerHide.flatten_links)
67     {
68     dump_map(client_p, &me, 0, buf);
69     sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
70     return;
71     }
72    
73     m_not_oper(client_p, source_p, parc, parv);
74     }
75    
76     /* mo_map()
77     * parv[0] = sender prefix
78     */
79     static void
80     mo_map(struct Client *client_p, struct Client *source_p,
81     int parc, char *parv[])
82     {
83     dump_map(client_p, &me, 0, buf);
84     sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
85     }
86    
87     /* dump_map()
88     * dumps server map, called recursively.
89     */
90     static void
91     dump_map(struct Client *client_p, struct Client *root_p, int start_len,
92     char *pbuf)
93     {
94     int cnt = 0, i = 0, l = 0, len = start_len;
95     int users, dashes;
96     dlink_node *ptr;
97     struct Client *server_p;
98     char *pb;
99    
100     *pbuf= '\0';
101     pb = pbuf;
102    
103     l = ircsprintf(pb, "%s", root_p->name);
104     pb += l;
105     len += l;
106    
107     /* IsOper isn't called *that* often. */
108     if (IsOper(client_p))
109     {
110     if (root_p->id[0] != '\0')
111     {
112     l = ircsprintf(pb, "[%s]", root_p->id);
113     pb += l;
114     len += l;
115     }
116     }
117    
118     *pb++ = ' ';
119     len++;
120     dashes = 50 - len;
121     for(i = 0; i < dashes; i++)
122     {
123     *pb++ = '-';
124     }
125     *pb++ = ' ';
126     *pb++ = '|';
127    
128     users = dlink_list_length(&root_p->serv->users);
129    
130     sprintf(pb, " Users: %5d (%1.1f%%)", users,
131     100 * (float)users / (float)Count.total);
132    
133     sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf);
134    
135     if (root_p->serv->servers.head)
136     {
137     cnt += dlink_list_length(&root_p->serv->servers);
138    
139     if (cnt)
140     {
141     if (pbuf > buf + 3)
142     {
143     pbuf[-2] = ' ';
144    
145     if (pbuf[-3] == '`')
146     pbuf[-3] = ' ';
147     }
148     }
149     }
150    
151     i = 1;
152    
153     DLINK_FOREACH(ptr, root_p->serv->servers.head)
154     {
155     server_p = ptr->data;
156    
157     *pbuf = ' ';
158     if (i < cnt)
159     *(pbuf + 1) = '|';
160     else
161     *(pbuf + 1) = '`';
162    
163     *(pbuf + 2) = '-';
164     *(pbuf + 3) = ' ';
165     dump_map(client_p, server_p, start_len+4, pbuf+4);
166    
167     ++i;
168     }
169     }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision