ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/trunk/modules/m_map.c
Revision: 3117
Committed: Fri Mar 7 19:28:54 2014 UTC (11 years, 5 months ago) by michael
Content type: text/x-csrc
File size: 4582 byte(s)
Log Message:
- Removed unused header includes here and there

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced, lightweight Internet Relay Chat Daemon (ircd)
3 *
4 * Copyright (c) 2001-2014 ircd-hybrid development team
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19 * USA
20 */
21
22 /*! \file m_map.c
23 * \brief Includes required functions for processing the MAP command.
24 * \version $Id$
25 */
26
27 #include "stdinc.h"
28 #include "client.h"
29 #include "modules.h"
30 #include "numeric.h"
31 #include "send.h"
32 #include "conf.h"
33 #include "ircd.h"
34 #include "irc_string.h"
35 #include "parse.h"
36
37
38 static void dump_map(struct Client *client,
39 struct Client *server,
40 unsigned int prompt_length)
41 {
42 dlink_node *ptr = NULL;
43 struct Client *target_p = NULL;
44 static char prompt[64];
45 static char buf[IRCD_BUFSIZE];
46 char *p = prompt + prompt_length;
47 int cnt = 0;
48 int bufpos = 0;
49
50 *p = '\0';
51
52 if (prompt_length > 60)
53 sendto_one_numeric(client, &me, RPL_MAPMORE, prompt, server->name);
54 else
55 {
56 int dashes;
57
58 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "%s", server->name);
59
60 if (HasUMode(client, UMODE_OPER) && server->id[0])
61 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, "[%s]", server->id);
62
63 buf[bufpos++] = ' ';
64 dashes = 50 - bufpos - prompt_length;
65 for (; dashes > 0; --dashes)
66 buf[bufpos++] = '-';
67 buf[bufpos++] = ' ';
68 buf[bufpos++] = '|';
69
70 bufpos += snprintf(buf + bufpos, sizeof(buf) - bufpos, " Users %5d (%1.2f%%)",
71 dlink_list_length(&server->serv->client_list), 100 *
72 (float)dlink_list_length(&server->serv->client_list) /
73 (float)Count.total);
74 sendto_one_numeric(client, &me, RPL_MAP, prompt, buf);
75 }
76
77 if (prompt_length > 0)
78 {
79 *(p - 1) = ' ';
80
81 if (*(p - 2) == '`')
82 *(p - 2) = ' ';
83 }
84
85 if (prompt_length > 60)
86 return;
87 strcpy(p, "|-");
88
89 DLINK_FOREACH(ptr, server->serv->server_list.head)
90 {
91 target_p = ptr->data;
92
93 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
94 continue;
95
96 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
97 if (!HasUMode(client, UMODE_OPER))
98 continue;
99
100 ++cnt;
101 }
102
103 DLINK_FOREACH(ptr, server->serv->server_list.head)
104 {
105 target_p = ptr->data;
106
107 if (IsHidden(target_p) && !HasUMode(client, UMODE_OPER))
108 continue;
109
110 if (HasFlag(target_p, FLAGS_SERVICE) && ConfigServerHide.hide_services)
111 if (!HasUMode(client, UMODE_OPER))
112 continue;
113
114 if (--cnt == 0)
115 *p = '`';
116 dump_map(client, target_p, prompt_length + 2);
117 }
118
119 if (prompt_length > 0)
120 *(p - 1) = '-';
121 }
122
123 /* m_map()
124 * parv[0] = command
125 */
126 static int
127 m_map(struct Client *client_p, struct Client *source_p,
128 int parc, char *parv[])
129 {
130 static time_t last_used = 0;
131
132 if (ConfigServerHide.flatten_links)
133 return m_not_oper(client_p, source_p, parc, parv);
134
135 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
136 {
137 /* safe enough to give this on a local connect only */
138 sendto_one_numeric(source_p, &me, RPL_LOAD2HI);
139 return 0;
140 }
141
142 last_used = CurrentTime;
143
144 dump_map(source_p, &me, 0);
145 sendto_one_numeric(source_p, &me, RPL_MAPEND);
146 return 0;
147 }
148
149 /* mo_map()
150 * parv[0] = command
151 */
152 static int
153 mo_map(struct Client *client_p, struct Client *source_p,
154 int parc, char *parv[])
155 {
156 dump_map(source_p, &me, 0);
157 sendto_one_numeric(source_p, &me, RPL_MAPEND);
158 return 0;
159 }
160
161 static struct Message map_msgtab =
162 {
163 "MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
164 { m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore }
165 };
166
167 static void
168 module_init(void)
169 {
170 mod_add_cmd(&map_msgtab);
171 }
172
173 static void
174 module_exit(void)
175 {
176 mod_del_cmd(&map_msgtab);
177 }
178
179 struct module module_entry =
180 {
181 .node = { NULL, NULL, NULL },
182 .name = NULL,
183 .version = "$Revision$",
184 .handle = NULL,
185 .modinit = module_init,
186 .modexit = module_exit,
187 .flags = 0
188 };

Properties

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