/[svn]/ircd-hybrid-7.2/modules/m_map.c
ViewVC logotype

Contents of /ircd-hybrid-7.2/modules/m_map.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 268 - (show annotations)
Mon Nov 14 11:02:39 2005 UTC (13 years, 11 months ago) by adx
File MIME type: text/x-chdr
File size: 4174 byte(s)
+ add more load2hi protection
+ style fixes

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

Properties

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

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.26