ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/branches/8.2.x/modules/m_map.c
Revision: 1793
Committed: Sun Mar 31 14:06:08 2013 UTC (13 years, 3 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid/trunk/modules/m_map.c
File size: 3972 byte(s)
Log Message:
- Replaced all occurrences of ircsprintf with sprintf/snprintf
  and killed sprintf_irc.(c|h)

File Contents

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

Properties

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