ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/branches/ircd-hybrid-newconf/modules/m_map.c
Revision: 1027
Committed: Sun Nov 8 13:01:13 2009 UTC (16 years, 8 months ago) by michael
Content type: text/x-csrc
File size: 4086 byte(s)
Log Message:
- Move old 7.3 sources to branches/ircd-hybrid-newconf

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

Properties

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