ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid/releases/8.2.0beta2/modules/m_map.c
Revision: 1121
Committed: Sun Jan 9 11:03:03 2011 UTC (15 years, 6 months ago) by michael
Content type: text/x-csrc
Original Path: ircd-hybrid-7.3/modules/m_map.c
File size: 4021 byte(s)
Log Message:
- removed all instances of STATIC_MODULES since we don't have
  static modules anymore
- removed m_mkpasswd module from contrib

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 "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 michael 889
37     static char buf[IRCD_BUFSIZE];
38 adx 30 static void m_map(struct Client *, struct Client *, int, char *[]);
39     static void mo_map(struct Client *, struct Client *, int, char *[]);
40 michael 979 static void dump_map(struct Client *, const struct Client *, int, char *);
41 adx 30
42     struct Message map_msgtab = {
43     "MAP", 0, 0, 0, 0, MFLG_SLOW, 0,
44 michael 889 { m_unregistered, m_map, m_ignore, m_ignore, mo_map, m_ignore }
45 adx 30 };
46    
47 michael 889 void
48     _modinit(void)
49 adx 30 {
50     mod_add_cmd(&map_msgtab);
51     }
52    
53 michael 889 void
54     _moddeinit(void)
55 adx 30 {
56     mod_del_cmd(&map_msgtab);
57     }
58    
59 knight 31 const char *_version = "$Revision$";
60 adx 30
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 adx 268 static time_t last_used = 0;
70    
71 michael 979 if (ConfigServerHide.flatten_links)
72 adx 30 {
73 michael 979 m_not_oper(client_p, source_p, parc, parv);
74     return;
75     }
76 michael 889
77 michael 979 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 adx 30 return;
83     }
84    
85 michael 979 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 adx 30 }
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 michael 979 dump_map(source_p, &me, 0, buf);
99     sendto_one(source_p, form_str(RPL_MAPEND), me.name, source_p->name);
100 adx 30 }
101    
102     /* dump_map()
103     * dumps server map, called recursively.
104     */
105     static void
106 michael 979 dump_map(struct Client *client_p, const struct Client *root_p,
107     int start_len, char *pbuf)
108 adx 30 {
109     int cnt = 0, i = 0, l = 0, len = start_len;
110     int users, dashes;
111 michael 979 const dlink_node *ptr = NULL;
112 adx 30 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 michael 889 if (root_p->id[0] != '\0')
122 adx 30 {
123 michael 889 l = ircsprintf(pb, "[%s]", root_p->id);
124     pb += l;
125     len += l;
126 adx 30 }
127    
128     *pb++ = ' ';
129     len++;
130     dashes = 50 - len;
131 michael 889
132     for (i = 0; i < dashes; i++)
133 adx 30 *pb++ = '-';
134 michael 889
135 adx 30 *pb++ = ' ';
136     *pb++ = '|';
137    
138 michael 889 users = dlink_list_length(&root_p->serv->client_list);
139 adx 30
140     sprintf(pb, " Users: %5d (%1.1f%%)", users,
141 michael 889 100 * (float)users / (float)Count.total);
142 adx 30
143     sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf);
144 michael 889
145     if (root_p->serv->server_list.head)
146 adx 30 {
147 michael 889 cnt += dlink_list_length(&root_p->serv->server_list);
148 adx 30
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 michael 889 DLINK_FOREACH(ptr, root_p->serv->server_list.head)
164 adx 30 {
165 michael 979 const struct Client *server_p = ptr->data;
166 adx 30
167     *pbuf = ' ';
168 michael 889
169 adx 30 if (i < cnt)
170     *(pbuf + 1) = '|';
171     else
172     *(pbuf + 1) = '`';
173 michael 889
174 adx 30 *(pbuf + 2) = '-';
175     *(pbuf + 3) = ' ';
176 michael 889 dump_map(client_p, server_p, start_len + 4, pbuf + 4);
177 adx 30
178     ++i;
179     }
180     }

Properties

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