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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1178 - (show annotations)
Mon Aug 15 08:11:31 2011 UTC (8 years, 3 months ago) by michael
File MIME type: text/x-chdr
File size: 4027 byte(s)
- Cleanup and restore older parts of the irc-command parser.
  Gives back ability to specify maximum amount of parameters
  that are processed within a command.

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 *, const struct Client *, int, char *);
41
42 struct Message map_msgtab = {
43 "MAP", 0, 0, 0, MAXPARA, MFLG_SLOW, 0,
44 { m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore }
45 };
46
47 void
48 _modinit(void)
49 {
50 mod_add_cmd(&map_msgtab);
51 }
52
53 void
54 _moddeinit(void)
55 {
56 mod_del_cmd(&map_msgtab);
57 }
58
59 const char *_version = "$Revision$";
60
61
62 /* m_map()
63 * parv[0] = sender prefix
64 */
65 static void
66 m_map(struct Client *client_p, struct Client *source_p,
67 int parc, char *parv[])
68 {
69 static time_t last_used = 0;
70
71 if (ConfigServerHide.flatten_links)
72 {
73 m_not_oper(client_p, source_p, parc, parv);
74 return;
75 }
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 dump_map(source_p, &me, 0, buf);
88 sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name);
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(source_p, &me, 0, buf);
99 sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name);
100 }
101
102 /* dump_map()
103 * dumps server map, called recursively.
104 */
105 static void
106 dump_map(struct Client *client_p, const struct Client *root_p,
107 int start_len, char *pbuf)
108 {
109 int cnt = 0, i = 0, l = 0, len = start_len;
110 int users, dashes;
111 const dlink_node *ptr = NULL;
112 char *pb;
113
114 *pbuf= '\0';
115 pb = pbuf;
116
117 l = ircsprintf(pb, "%s", root_p->name);
118 pb += l;
119 len += l;
120
121 if (root_p->id[0] != '\0')
122 {
123 l = ircsprintf(pb, "[%s]", root_p->id);
124 pb += l;
125 len += l;
126 }
127
128 *pb++ = ' ';
129 len++;
130 dashes = 50 - len;
131
132 for (i = 0; i < dashes; i++)
133 *pb++ = '-';
134
135 *pb++ = ' ';
136 *pb++ = '|';
137
138 users = dlink_list_length(&root_p->serv->client_list);
139
140 sprintf(pb, " Users: %5d (%1.1f%%)", users,
141 100 * (float)users / (float)Count.total);
142
143 sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf);
144
145 if (root_p->serv->server_list.head)
146 {
147 cnt += dlink_list_length(&root_p->serv->server_list);
148
149 if (cnt)
150 {
151 if (pbuf > buf + 3)
152 {
153 pbuf[-2] = ' ';
154
155 if (pbuf[-3] == '`')
156 pbuf[-3] = ' ';
157 }
158 }
159 }
160
161 i = 1;
162
163 DLINK_FOREACH(ptr, root_p->serv->server_list.head)
164 {
165 const struct Client *server_p = ptr->data;
166
167 *pbuf = ' ';
168
169 if (i < cnt)
170 *(pbuf + 1) = '|';
171 else
172 *(pbuf + 1) = '`';
173
174 *(pbuf + 2) = '-';
175 *(pbuf + 3) = ' ';
176 dump_map(client_p, server_p, start_len + 4, pbuf + 4);
177
178 ++i;
179 }
180 }

Properties

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

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