ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-8/modules/m_map.c
Revision: 1309
Committed: Sun Mar 25 11:24:18 2012 UTC (12 years ago) by michael
Content type: text/x-csrc
File size: 4003 byte(s)
Log Message:
- renaming files:

  ircd_parser.y -> conf_parser.y
  ircd_lexer.l  -> conf_lexer.l
  s_conf.c      -> conf.c
  s_conf.h      -> conf.h
  s_log.c       -> log.c
  s_log.h       -> log.h

File Contents

# Content
1 /*
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 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "client.h"
27 #include "modules.h"
28 #include "numeric.h"
29 #include "send.h"
30 #include "conf.h"
31 #include "ircd.h"
32 #include "irc_string.h"
33 #include "sprintf_irc.h"
34 #include "parse.h"
35
36
37 static char buf[IRCD_BUFSIZE];
38
39 /* dump_map()
40 * dumps server map, called recursively.
41 */
42 static void
43 dump_map(struct Client *client_p, const struct Client *root_p,
44 int start_len, char *pbuf)
45 {
46 int cnt = 0, i = 0, l = 0, len = start_len;
47 int users, dashes;
48 const dlink_node *ptr = NULL;
49 char *pb;
50
51 *pbuf= '\0';
52 pb = pbuf;
53
54 l = ircsprintf(pb, "%s", root_p->name);
55 pb += l;
56 len += l;
57
58 if (root_p->id[0] != '\0')
59 {
60 l = ircsprintf(pb, "[%s]", root_p->id);
61 pb += l;
62 len += l;
63 }
64
65 *pb++ = ' ';
66 len++;
67 dashes = 50 - len;
68
69 for (i = 0; i < dashes; i++)
70 *pb++ = '-';
71
72 *pb++ = ' ';
73 *pb++ = '|';
74
75 users = dlink_list_length(&root_p->serv->client_list);
76
77 sprintf(pb, " Users: %5d (%1.1f%%)", users,
78 100 * (float)users / (float)Count.total);
79
80 sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf);
81
82 if (root_p->serv->server_list.head)
83 {
84 cnt += dlink_list_length(&root_p->serv->server_list);
85
86 if (cnt)
87 {
88 if (pbuf > buf + 3)
89 {
90 pbuf[-2] = ' ';
91
92 if (pbuf[-3] == '`')
93 pbuf[-3] = ' ';
94 }
95 }
96 }
97
98 i = 1;
99
100 DLINK_FOREACH(ptr, root_p->serv->server_list.head)
101 {
102 const struct Client *server_p = ptr->data;
103
104 *pbuf = ' ';
105
106 if (i < cnt)
107 *(pbuf + 1) = '|';
108 else
109 *(pbuf + 1) = '`';
110
111 *(pbuf + 2) = '-';
112 *(pbuf + 3) = ' ';
113 dump_map(client_p, server_p, start_len + 4, pbuf + 4);
114
115 ++i;
116 }
117 }
118
119 /* m_map()
120 * parv[0] = sender prefix
121 */
122 static void
123 m_map(struct Client *client_p, struct Client *source_p,
124 int parc, char *parv[])
125 {
126 static time_t last_used = 0;
127
128 if (ConfigServerHide.flatten_links)
129 {
130 m_not_oper(client_p, source_p, parc, parv);
131 return;
132 }
133
134 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
135 {
136 /* safe enough to give this on a local connect only */
137 sendto_one(source_p, form_str(RPL_LOAD2HI),
138 me.name, source_p->name);
139 return;
140 }
141
142 last_used = CurrentTime;
143
144 dump_map(source_p, &me, 0, buf);
145 sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name);
146 }
147
148 /* mo_map()
149 * parv[0] = sender prefix
150 */
151 static void
152 mo_map(struct Client *client_p, struct Client *source_p,
153 int parc, char *parv[])
154 {
155 dump_map(source_p, &me, 0, buf);
156 sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name);
157 }
158
159 static struct Message map_msgtab = {
160 "MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
161 { m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore }
162 };
163
164 static void
165 module_init(void)
166 {
167 mod_add_cmd(&map_msgtab);
168 }
169
170 static void
171 module_exit(void)
172 {
173 mod_del_cmd(&map_msgtab);
174 }
175
176 struct module module_entry = {
177 .node = { NULL, NULL, NULL },
178 .name = NULL,
179 .version = "$Revision$",
180 .handle = NULL,
181 .modinit = module_init,
182 .modexit = module_exit,
183 .flags = 0
184 };

Properties

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