]>
Commit | Line | Data |
---|---|---|
212380e3 AC |
1 | /* |
2 | * ircd-ratbox: A slightly useful 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: m_map.c 254 2005-09-21 23:35:12Z nenolod $ | |
23 | */ | |
24 | ||
25 | #include "stdinc.h" | |
26 | #include "client.h" | |
27 | #include "modules.h" | |
28 | #include "numeric.h" | |
29 | #include "send.h" | |
30 | #include "s_conf.h" | |
31 | #include "sprintf_irc.h" | |
32 | ||
33 | #define USER_COL 50 /* display | Users: %d at col 50 */ | |
34 | ||
35 | static int m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
36 | static int mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]); | |
37 | ||
38 | struct Message map_msgtab = { | |
39 | "MAP", 0, 0, 0, MFLG_SLOW, | |
40 | {mg_unreg, {m_map, 0}, mg_ignore, mg_ignore, mg_ignore, {mo_map, 0}} | |
41 | }; | |
42 | ||
43 | mapi_clist_av1 map_clist[] = { &map_msgtab, NULL }; | |
44 | DECLARE_MODULE_AV1(map, NULL, NULL, map_clist, NULL, NULL, "$Revision: 254 $"); | |
45 | ||
46 | static void dump_map(struct Client *client_p, struct Client *root, char *pbuf); | |
47 | ||
48 | static char buf[BUFSIZE]; | |
49 | ||
50 | /* m_map | |
51 | ** parv[0] = sender prefix | |
52 | */ | |
53 | static int | |
54 | m_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
55 | { | |
56 | if((!IsExemptShide(source_p) && ConfigServerHide.flatten_links) || | |
57 | ConfigFileEntry.map_oper_only) | |
58 | { | |
59 | m_not_oper(client_p, source_p, parc, parv); | |
60 | return 0; | |
61 | } | |
62 | ||
63 | dump_map(client_p, &me, buf); | |
64 | sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name); | |
65 | return 0; | |
66 | } | |
67 | ||
68 | /* | |
69 | ** mo_map | |
70 | ** parv[0] = sender prefix | |
71 | */ | |
72 | static int | |
73 | mo_map(struct Client *client_p, struct Client *source_p, int parc, const char *parv[]) | |
74 | { | |
75 | dump_map(client_p, &me, buf); | |
76 | sendto_one(client_p, form_str(RPL_MAPEND), me.name, client_p->name); | |
77 | ||
78 | return 0; | |
79 | } | |
80 | ||
81 | /* | |
82 | ** dump_map | |
83 | ** dumps server map, called recursively. | |
84 | */ | |
85 | static void | |
86 | dump_map(struct Client *client_p, struct Client *root_p, char *pbuf) | |
87 | { | |
88 | int cnt = 0, i = 0, len; | |
89 | struct Client *server_p; | |
90 | dlink_node *ptr; | |
91 | *pbuf = '\0'; | |
92 | ||
93 | strlcat(pbuf, root_p->name, BUFSIZE); | |
94 | if (has_id(root_p)) | |
95 | { | |
96 | strlcat(pbuf, "[", BUFSIZE); | |
97 | strlcat(pbuf, root_p->id, BUFSIZE); | |
98 | strlcat(pbuf, "]", BUFSIZE); | |
99 | } | |
100 | len = strlen(buf); | |
101 | buf[len] = ' '; | |
102 | ||
103 | if(len < USER_COL) | |
104 | { | |
105 | for (i = len + 1; i < USER_COL; i++) | |
106 | { | |
107 | buf[i] = '-'; | |
108 | } | |
109 | } | |
110 | ||
111 | ircsnprintf(buf + USER_COL, BUFSIZE - USER_COL, | |
112 | " | Users: %5lu (%4.1f%%)", dlink_list_length(&root_p->serv->users), | |
113 | 100 * (float) dlink_list_length(&root_p->serv->users) / (float) Count.total); | |
114 | ||
115 | sendto_one(client_p, form_str(RPL_MAP), me.name, client_p->name, buf); | |
116 | ||
117 | if(root_p->serv->servers.head != NULL) | |
118 | { | |
119 | cnt += dlink_list_length(&root_p->serv->servers); | |
120 | ||
121 | if(cnt) | |
122 | { | |
123 | if(pbuf > buf + 3) | |
124 | { | |
125 | pbuf[-2] = ' '; | |
126 | if(pbuf[-3] == '`') | |
127 | pbuf[-3] = ' '; | |
128 | } | |
129 | } | |
130 | } | |
131 | i = 1; | |
132 | DLINK_FOREACH(ptr, root_p->serv->servers.head) | |
133 | { | |
134 | server_p = ptr->data; | |
135 | *pbuf = ' '; | |
136 | if(i < cnt) | |
137 | *(pbuf + 1) = '|'; | |
138 | else | |
139 | *(pbuf + 1) = '`'; | |
140 | ||
141 | *(pbuf + 2) = '-'; | |
142 | *(pbuf + 3) = ' '; | |
143 | dump_map(client_p, server_p, pbuf + 4); | |
144 | ||
145 | i++; | |
146 | } | |
147 | } |