ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/ircd-hybrid-newconf/modules/m_map.c
Revision: 270
Committed: Mon Nov 14 19:39:35 2005 UTC (20 years, 8 months ago) by adx
Content type: text/x-csrc
Original Path: ircd-hybrid/modules/m_map.c
File size: 4125 byte(s)
Log Message:
+ ported rate limiting fixes from 7.2

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 "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 const char *_version = "$Revision$";
55 #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 static time_t last_used = 0;
67
68 if (!ConfigServerHide.flatten_links)
69 {
70 if (!IsOper(source_p))
71 {
72 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
73 {
74 /* safe enough to give this on a local connect only */
75 sendto_one(source_p, form_str(RPL_LOAD2HI),
76 me.name, source_p->name);
77 return;
78 }
79 else
80 last_used = CurrentTime;
81 }
82
83 dump_map(client_p, &me, 0, buf);
84 sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
85 return;
86 }
87
88 m_not_oper(client_p, source_p, parc, parv);
89 }
90
91 /* mo_map()
92 * parv[0] = sender prefix
93 */
94 static void
95 mo_map(struct Client *client_p, struct Client *source_p,
96 int parc, char *parv[])
97 {
98 dump_map(client_p, &me, 0, buf);
99 sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name);
100 }
101
102 /* dump_map()
103 * dumps server map, called recursively.
104 */
105 static void
106 dump_map(struct Client *client_p, struct Client *root_p, int start_len,
107 char *pbuf)
108 {
109 int cnt = 0, i = 0, l = 0, len = start_len;
110 int users, dashes;
111 dlink_node *ptr;
112 struct Client *server_p;
113 char *pb;
114
115 *pbuf= '\0';
116 pb = pbuf;
117
118 l = ircsprintf(pb, "%s", root_p->name);
119 pb += l;
120 len += l;
121
122 /* IsOper isn't called *that* often. */
123 if (IsOper(client_p))
124 {
125 if (root_p->id[0] != '\0')
126 {
127 l = ircsprintf(pb, "[%s]", root_p->id);
128 pb += l;
129 len += l;
130 }
131 }
132
133 *pb++ = ' ';
134 len++;
135 dashes = 50 - len;
136 for(i = 0; i < dashes; i++)
137 {
138 *pb++ = '-';
139 }
140 *pb++ = ' ';
141 *pb++ = '|';
142
143 users = dlink_list_length(&root_p->serv->users);
144
145 sprintf(pb, " Users: %5d (%1.1f%%)", users,
146 100 * (float)users / (float)Count.total);
147
148 sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf);
149
150 if (root_p->serv->servers.head)
151 {
152 cnt += dlink_list_length(&root_p->serv->servers);
153
154 if (cnt)
155 {
156 if (pbuf > buf + 3)
157 {
158 pbuf[-2] = ' ';
159
160 if (pbuf[-3] == '`')
161 pbuf[-3] = ' ';
162 }
163 }
164 }
165
166 i = 1;
167
168 DLINK_FOREACH(ptr, root_p->serv->servers.head)
169 {
170 server_p = ptr->data;
171
172 *pbuf = ' ';
173 if (i < cnt)
174 *(pbuf + 1) = '|';
175 else
176 *(pbuf + 1) = '`';
177
178 *(pbuf + 2) = '-';
179 *(pbuf + 3) = ' ';
180 dump_map(client_p, server_p, start_len+4, pbuf+4);
181
182 ++i;
183 }
184 }

Properties

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