ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/m_map.c
Revision: 889
Committed: Thu Nov 1 12:59:05 2007 UTC (16 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 4094 byte(s)
Log Message:
- Got rid of Serv.dep_users and Serv.dep_servers

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

Properties

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